@onekeyfe/kaspa-core-lib 1.0.0-alpha.1
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/LICENSE +32 -0
- package/README.md +59 -0
- package/index.d.ts +410 -0
- package/index.js +93 -0
- package/lib/address.js +792 -0
- package/lib/block/block.js +281 -0
- package/lib/block/blockheader.js +296 -0
- package/lib/block/index.js +4 -0
- package/lib/block/merkleblock.js +313 -0
- package/lib/crypto/bn.js +218 -0
- package/lib/crypto/ecdsa.js +296 -0
- package/lib/crypto/hash.js +85 -0
- package/lib/crypto/point.js +166 -0
- package/lib/crypto/random.js +57 -0
- package/lib/crypto/schnorr.js +287 -0
- package/lib/crypto/signature.js +441 -0
- package/lib/encoding/base58.js +70 -0
- package/lib/encoding/base58check.js +95 -0
- package/lib/encoding/bufferreader.js +202 -0
- package/lib/encoding/bufferwriter.js +155 -0
- package/lib/encoding/varint.js +72 -0
- package/lib/errors/index.js +61 -0
- package/lib/errors/spec.js +191 -0
- package/lib/hdprivatekey.js +646 -0
- package/lib/hdpublickey.js +496 -0
- package/lib/networks.js +277 -0
- package/lib/opcode.js +261 -0
- package/lib/privatekey.js +431 -0
- package/lib/publickey.js +375 -0
- package/lib/script/index.js +3 -0
- package/lib/script/interpreter.js +2107 -0
- package/lib/script/script.js +1163 -0
- package/lib/transaction/index.js +7 -0
- package/lib/transaction/input/index.js +6 -0
- package/lib/transaction/input/input.js +375 -0
- package/lib/transaction/input/multisig.js +221 -0
- package/lib/transaction/input/multisigscripthash.js +178 -0
- package/lib/transaction/input/publickey.js +91 -0
- package/lib/transaction/input/publickeyhash.js +100 -0
- package/lib/transaction/output.js +188 -0
- package/lib/transaction/sighash.js +534 -0
- package/lib/transaction/signature.js +89 -0
- package/lib/transaction/transaction.js +1384 -0
- package/lib/transaction/unspentoutput.js +109 -0
- package/lib/unit.js +238 -0
- package/lib/uri.js +223 -0
- package/lib/util/base32.js +63 -0
- package/lib/util/buffer.js +162 -0
- package/lib/util/convertBits.js +62 -0
- package/lib/util/js.js +110 -0
- package/lib/util/log.js +10 -0
- package/lib/util/preconditions.js +34 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Copyright (c) 2013-2019 BitPay, Inc.
|
|
2
|
+
|
|
3
|
+
Parts of this software are based on Bitcoin Core
|
|
4
|
+
Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
5
|
+
|
|
6
|
+
Parts of this software are based on fullnode
|
|
7
|
+
Copyright (c) 2014 Ryan X. Charles
|
|
8
|
+
Copyright (c) 2014 reddit, Inc.
|
|
9
|
+
|
|
10
|
+
Parts of this software are based on BitcoinJS
|
|
11
|
+
Copyright (c) 2011 Stefan Thomas <justmoon@members.fsf.org>
|
|
12
|
+
|
|
13
|
+
Parts of this software are based on BitcoinJ
|
|
14
|
+
Copyright (c) 2011 Google Inc.
|
|
15
|
+
|
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
in the Software without restriction, including without limitation the rights
|
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in
|
|
24
|
+
all copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
32
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
JavaScript Data Primitives Library for Kaspa
|
|
2
|
+
=============================================
|
|
3
|
+
|
|
4
|
+
**PLEASE NOTE: This project is under heavy development and is not production ready**
|
|
5
|
+
|
|
6
|
+
Based on the popular [Bitcore library](https://github.com/bitpay/bitcore) developed by BitPay for the Bitcoin, Kaspacore library provides primitives for interfacing with the Kaspa network.
|
|
7
|
+
|
|
8
|
+
Get Started
|
|
9
|
+
-----------
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
git clone git@github.com:aspectron/kaspacore-lib
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Adding Kaspacore to your app's `package.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"aspectron/kaspacore-lib": "*"
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Kaspa adaptation
|
|
24
|
+
----------------
|
|
25
|
+
|
|
26
|
+
Kaspacore library provides primitives such as Transaction and UTXO data structures customized for use with the next-generation high-performance Kaspa network.
|
|
27
|
+
|
|
28
|
+
Documentation
|
|
29
|
+
-------------
|
|
30
|
+
|
|
31
|
+
The complete docs are hosted here: [bitcore documentation](https://github.com/bitpay/bitcore). There's also a [bitcore API reference](https://github.com/bitpay/bitcore/blob/master/packages/bitcore-node/docs/api-documentation.md) available generated from the JSDocs of the project, where you'll find low-level details on each bitcore utility.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Building the Browser Bundle
|
|
35
|
+
---------------------------
|
|
36
|
+
|
|
37
|
+
To build a kaspacore-lib full bundle for the browser:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
gulp browser
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This will generate files named `kaspacore-lib.js` and `kaspacore-lib.min.js`.
|
|
44
|
+
|
|
45
|
+
You can also use our pre-generated files, provided for each release along with a PGP signature by one of the project's maintainers. To get them, checkout the [releases](https://github.com/bitpay/bitcore/blob/master/packages/bitcore-lib/CHANGELOG.md).
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Contributing
|
|
49
|
+
------------
|
|
50
|
+
|
|
51
|
+
See [CONTRIBUTING.md](https://github.com/bitpay/bitcore/blob/master/Contributing.md) on the main bitcore repo for information about how to contribute.
|
|
52
|
+
|
|
53
|
+
License
|
|
54
|
+
-------
|
|
55
|
+
|
|
56
|
+
Code released under [the MIT license](https://github.com/bitpay/bitcore/blob/master/LICENSE).
|
|
57
|
+
|
|
58
|
+
Bitcore - Copyright 2013-2019 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.
|
|
59
|
+
Kaspacore - Copyright 2020 ASPECTRON Inc.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
declare module '@onekeyfe/kaspacore-lib' {
|
|
2
|
+
|
|
3
|
+
function initRuntime(): Promise;
|
|
4
|
+
function setDebugLevel(level:number):void;
|
|
5
|
+
|
|
6
|
+
export namespace encoding {
|
|
7
|
+
export class BufferReader {
|
|
8
|
+
constructor(buf: Buffer);
|
|
9
|
+
readReverse(): Buffer;
|
|
10
|
+
}
|
|
11
|
+
export class BufferWriter {
|
|
12
|
+
write(buf: Buffer): BufferWriter;
|
|
13
|
+
writeInt32LE(n: number): BufferWriter;
|
|
14
|
+
toBuffer(): Buffer;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export namespace util {
|
|
19
|
+
export namespace preconditions {
|
|
20
|
+
function checkArgument(condition: boolean, argumentName ? : string, message ? : string, docsPath ? : any): boolean;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export namespace crypto {
|
|
25
|
+
class BN {
|
|
26
|
+
static fromNumber(n: number): BN;
|
|
27
|
+
static fromBuffer(buf: Buffer): BN;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
namespace ECDSA {
|
|
31
|
+
function sign(message: Buffer, key: PrivateKey): Signature;
|
|
32
|
+
|
|
33
|
+
function verify(
|
|
34
|
+
hashbuf: Buffer,
|
|
35
|
+
sig: Signature,
|
|
36
|
+
pubkey: PublicKey,
|
|
37
|
+
endian ? : 'little'
|
|
38
|
+
): boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
namespace Hash {
|
|
42
|
+
function sha1(buffer: Buffer): Buffer;
|
|
43
|
+
|
|
44
|
+
function sha256(buffer: Buffer): Buffer;
|
|
45
|
+
|
|
46
|
+
function sha256sha256(buffer: Buffer): Buffer;
|
|
47
|
+
|
|
48
|
+
function sha256ripemd160(buffer: Buffer): Buffer;
|
|
49
|
+
|
|
50
|
+
function sha512(buffer: Buffer): Buffer;
|
|
51
|
+
|
|
52
|
+
function ripemd160(buffer: Buffer): Buffer;
|
|
53
|
+
|
|
54
|
+
function sha256hmac(data: Buffer, key: Buffer): Buffer;
|
|
55
|
+
|
|
56
|
+
function sha512hmac(data: Buffer, key: Buffer): Buffer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
namespace Random {
|
|
60
|
+
function getRandomBuffer(size: number): Buffer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
namespace Point {}
|
|
64
|
+
|
|
65
|
+
class Signature {
|
|
66
|
+
static fromDER(sig: Buffer): Signature;
|
|
67
|
+
static fromString(data: string): Signature;
|
|
68
|
+
SIGHASH_ALL: number;
|
|
69
|
+
static SIGHASH_ALL: number;
|
|
70
|
+
static SIGHASH_NONE: number;
|
|
71
|
+
static SIGHASH_SINGLE: number;
|
|
72
|
+
static SIGHASH_FORKID: number;
|
|
73
|
+
static SIGHASH_ANYONECANPAY: number;
|
|
74
|
+
toString(): string;
|
|
75
|
+
compressed: boolean;
|
|
76
|
+
toBuffer(): Buffer;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
namespace Schnorr {
|
|
80
|
+
function sign(hashbuf: Buffer, privateKey: PrivateKey): Signature;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class Script {
|
|
85
|
+
constructor(script ? : Script);
|
|
86
|
+
static buildPublicKeyHashIn(publicKey: PublicKey, signature: Signature, sigtype): Script;
|
|
87
|
+
static empty(): Script;
|
|
88
|
+
inspect():string;
|
|
89
|
+
toBuffer():Buffer;
|
|
90
|
+
getSignatureOperationsCount():number
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export namespace Transaction {
|
|
94
|
+
|
|
95
|
+
static class sighash {
|
|
96
|
+
// static sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod);
|
|
97
|
+
static sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, flags): Buffer;
|
|
98
|
+
}
|
|
99
|
+
class UnspentOutput {
|
|
100
|
+
static fromObject(o: object): UnspentOutput;
|
|
101
|
+
|
|
102
|
+
readonly address: Address;
|
|
103
|
+
readonly txId: string;
|
|
104
|
+
readonly outputIndex: number;
|
|
105
|
+
readonly script: Script;
|
|
106
|
+
readonly satoshis: number | string;
|
|
107
|
+
|
|
108
|
+
constructor(data: object);
|
|
109
|
+
|
|
110
|
+
inspect(): string;
|
|
111
|
+
toObject(): this;
|
|
112
|
+
toString(): string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class Output {
|
|
116
|
+
readonly script: Script;
|
|
117
|
+
readonly satoshis: number | string;
|
|
118
|
+
readonly satoshisBN: crypto.BN;
|
|
119
|
+
|
|
120
|
+
constructor(data: object);
|
|
121
|
+
|
|
122
|
+
setScript(script: Script | string | Buffer): this;
|
|
123
|
+
inspect(): string;
|
|
124
|
+
toObject(): object;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
class Input {
|
|
128
|
+
readonly prevTxId: Buffer;
|
|
129
|
+
readonly outputIndex: number;
|
|
130
|
+
sequenceNumber: number;
|
|
131
|
+
readonly script: Script;
|
|
132
|
+
readonly output ? : Output;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
class Signature {
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class Transaction {
|
|
141
|
+
static MassPerSigOp:number;
|
|
142
|
+
static EstimatedStandaloneMassWithoutInputs:number;
|
|
143
|
+
static MassPerTxByte:number;
|
|
144
|
+
inputs: Transaction.Input[];
|
|
145
|
+
outputs: Transaction.Output[];
|
|
146
|
+
readonly id: string;
|
|
147
|
+
readonly hash: string;
|
|
148
|
+
nid: string;
|
|
149
|
+
|
|
150
|
+
constructor(serialized ? : any);
|
|
151
|
+
|
|
152
|
+
from(utxos: Transaction.UnspentOutput[]): this;
|
|
153
|
+
to(address: Address[] | Address | string, amount: number | string): this;
|
|
154
|
+
change(address: Address | string): this;
|
|
155
|
+
fee(amount: number): this;
|
|
156
|
+
setVersion(version: number): this;
|
|
157
|
+
feePerKb(amount: number): this;
|
|
158
|
+
// sign(privateKey: PrivateKey|PrivateKey[] | string|string[], sigtype:number, signingMethod:string|undefined): this;
|
|
159
|
+
applySignature(sig: crypto.Signature): this;
|
|
160
|
+
addInput(input: Transaction.Input): this;
|
|
161
|
+
addOutput(output: Transaction.Output): this;
|
|
162
|
+
addData(value: Buffer): this;
|
|
163
|
+
lockUntilDate(time: Date | number): this;
|
|
164
|
+
lockUntilBlockHeight(height: number): this;
|
|
165
|
+
|
|
166
|
+
getMassAndSize():{txSize:number, mass:number};
|
|
167
|
+
|
|
168
|
+
hasWitnesses(): boolean;
|
|
169
|
+
getFee(): number;
|
|
170
|
+
getChangeOutput(): Transaction.Output | null;
|
|
171
|
+
getLockTime(): Date | number;
|
|
172
|
+
getMass(): number;
|
|
173
|
+
|
|
174
|
+
verify(): string | boolean;
|
|
175
|
+
isCoinbase(): boolean;
|
|
176
|
+
|
|
177
|
+
enableRBF(): this;
|
|
178
|
+
isRBF(): boolean;
|
|
179
|
+
|
|
180
|
+
inspect(): string;
|
|
181
|
+
serialize(): string;
|
|
182
|
+
version: number;
|
|
183
|
+
nLockTime: number;
|
|
184
|
+
fromBufferReader(reader: BufferReader): Transaction;
|
|
185
|
+
toBuffer(skipInputs?:boolean): Buffer;
|
|
186
|
+
static shallowCopy(tx: Transaction): Transaction;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class Block {
|
|
190
|
+
hash: string;
|
|
191
|
+
height: number;
|
|
192
|
+
transactions: Transaction[];
|
|
193
|
+
header: {
|
|
194
|
+
time: number;
|
|
195
|
+
prevHash: string;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
constructor(data: Buffer | object);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export class PrivateKey {
|
|
202
|
+
readonly publicKey: PublicKey;
|
|
203
|
+
readonly network: Networks.Network;
|
|
204
|
+
|
|
205
|
+
toAddress(): Address;
|
|
206
|
+
toAddress(network: string): Address;
|
|
207
|
+
toPublicKey(): PublicKey;
|
|
208
|
+
toString(): string;
|
|
209
|
+
toObject(): object;
|
|
210
|
+
toJSON(): object;
|
|
211
|
+
toWIF(): string;
|
|
212
|
+
_pubkey: PublicKey;
|
|
213
|
+
|
|
214
|
+
constructor(key ? : string, network ? : Networks.Network);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export class PublicKey {
|
|
218
|
+
constructor(source: string, extra ? : {
|
|
219
|
+
compressed ? : boolean,
|
|
220
|
+
network ? : string
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
static fromPrivateKey(privateKey: PrivateKey): PublicKey;
|
|
224
|
+
toAddress(network ? : string): Address;
|
|
225
|
+
|
|
226
|
+
toBuffer(): Buffer;
|
|
227
|
+
toDER(): Buffer;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export class HDPrivateKey {
|
|
231
|
+
readonly hdPublicKey: HDPublicKey;
|
|
232
|
+
|
|
233
|
+
constructor(data ? : string | Buffer | object);
|
|
234
|
+
|
|
235
|
+
derive(arg: string | number, hardened ? : boolean): HDPrivateKey;
|
|
236
|
+
deriveChild(arg: string | number, hardened ? : boolean): HDPrivateKey;
|
|
237
|
+
deriveNonCompliantChild(arg: string | number, hardened ? : boolean): HDPrivateKey;
|
|
238
|
+
privateKey: PrivateKey;
|
|
239
|
+
|
|
240
|
+
toString(): string;
|
|
241
|
+
toObject(): object;
|
|
242
|
+
toJSON(): object;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export class HDPublicKey {
|
|
246
|
+
readonly xpubkey: Buffer;
|
|
247
|
+
readonly network: Networks.Network;
|
|
248
|
+
readonly depth: number;
|
|
249
|
+
readonly publicKey: PublicKey;
|
|
250
|
+
readonly fingerPrint: Buffer;
|
|
251
|
+
|
|
252
|
+
constructor(arg: string | Buffer | object);
|
|
253
|
+
|
|
254
|
+
derive(arg: string | number, hardened ? : boolean): HDPublicKey;
|
|
255
|
+
deriveChild(arg: string | number, hardened ? : boolean): HDPublicKey;
|
|
256
|
+
|
|
257
|
+
toString(): string;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// export namespace Script {
|
|
261
|
+
// const types: {
|
|
262
|
+
// DATA_OUT: string;
|
|
263
|
+
// };
|
|
264
|
+
// function buildMultisigOut(publicKeys: PublicKey[], threshold: number, opts: object): Script;
|
|
265
|
+
// function buildWitnessMultisigOutFromScript(script: Script): Script;
|
|
266
|
+
// function buildMultisigIn(
|
|
267
|
+
// pubkeys: PublicKey[],
|
|
268
|
+
// threshold: number,
|
|
269
|
+
// signatures: Buffer[],
|
|
270
|
+
// opts: object
|
|
271
|
+
// ): Script;
|
|
272
|
+
// function buildP2SHMultisigIn(
|
|
273
|
+
// pubkeys: PublicKey[],
|
|
274
|
+
// threshold: number,
|
|
275
|
+
// signatures: Buffer[],
|
|
276
|
+
// opts: object
|
|
277
|
+
// ): Script;
|
|
278
|
+
// function buildPublicKeyHashOut(address: Address): Script;
|
|
279
|
+
// function buildPublicKeyOut(pubkey: PublicKey): Script;
|
|
280
|
+
// function buildDataOut(data: string | Buffer, encoding?: string): Script;
|
|
281
|
+
// function buildScriptHashOut(script: Script): Script;
|
|
282
|
+
// function buildPublicKeyIn(signature: crypto.Signature | Buffer, sigtype: number): Script;
|
|
283
|
+
// function buildPublicKeyHashIn(
|
|
284
|
+
// publicKey: PublicKey,
|
|
285
|
+
// signature: crypto.Signature | Buffer,
|
|
286
|
+
// sigtype: number
|
|
287
|
+
// ): Script;
|
|
288
|
+
|
|
289
|
+
// function fromAddress(address: string | Address): Script;
|
|
290
|
+
|
|
291
|
+
// function empty(): Script;
|
|
292
|
+
// }
|
|
293
|
+
|
|
294
|
+
// export class Script {
|
|
295
|
+
// constructor(data: string | object);
|
|
296
|
+
|
|
297
|
+
// set(obj: object): this;
|
|
298
|
+
|
|
299
|
+
// toBuffer(): Buffer;
|
|
300
|
+
// toASM(): string;
|
|
301
|
+
// toString(): string;
|
|
302
|
+
// toHex(): string;
|
|
303
|
+
|
|
304
|
+
// isPublicKeyHashOut(): boolean;
|
|
305
|
+
// isPublicKeyHashIn(): boolean;
|
|
306
|
+
|
|
307
|
+
// getPublicKey(): Buffer;
|
|
308
|
+
// getPublicKeyHash(): Buffer;
|
|
309
|
+
|
|
310
|
+
// isPublicKeyOut(): boolean;
|
|
311
|
+
// isPublicKeyIn(): boolean;
|
|
312
|
+
|
|
313
|
+
// isScriptHashOut(): boolean;
|
|
314
|
+
// isWitnessScriptHashOut(): boolean;
|
|
315
|
+
// isWitnessPublicKeyHashOut(): boolean;
|
|
316
|
+
// isWitnessProgram(): boolean;
|
|
317
|
+
// isScriptHashIn(): boolean;
|
|
318
|
+
// isMultisigOut(): boolean;
|
|
319
|
+
// isMultisigIn(): boolean;
|
|
320
|
+
// isDataOut(): boolean;
|
|
321
|
+
|
|
322
|
+
// getData(): Buffer;
|
|
323
|
+
// isPushOnly(): boolean;
|
|
324
|
+
|
|
325
|
+
// classify(): string;
|
|
326
|
+
// classifyInput(): string;
|
|
327
|
+
// classifyOutput(): string;
|
|
328
|
+
|
|
329
|
+
// isStandard(): boolean;
|
|
330
|
+
|
|
331
|
+
// prepend(obj: any): this;
|
|
332
|
+
// add(obj: any): this;
|
|
333
|
+
|
|
334
|
+
// hasCodeseparators(): boolean;
|
|
335
|
+
// removeCodeseparators(): this;
|
|
336
|
+
|
|
337
|
+
// equals(script: Script): boolean;
|
|
338
|
+
|
|
339
|
+
// getAddressInfo(): Address | boolean;
|
|
340
|
+
// findAndDelete(script: Script): this;
|
|
341
|
+
// checkMinimalPush(i: number): boolean;
|
|
342
|
+
// getSignatureOperationsCount(accurate: boolean): number;
|
|
343
|
+
|
|
344
|
+
// toAddress(): Address;
|
|
345
|
+
// }
|
|
346
|
+
|
|
347
|
+
// export class Message {
|
|
348
|
+
// constructor(message: string);
|
|
349
|
+
|
|
350
|
+
// magicHash(): Buffer;
|
|
351
|
+
// sign(privateKey: PrivateKey): string;
|
|
352
|
+
// verify(bitcoinAddress: Address | string, signatureString: string): boolean;
|
|
353
|
+
// fromString(str: string): Message;
|
|
354
|
+
// fromJSON(json: string): Message;
|
|
355
|
+
// toObject(): { message: string };
|
|
356
|
+
// toJSON(): string;
|
|
357
|
+
// toString(): string;
|
|
358
|
+
// inspect(): string;
|
|
359
|
+
// }
|
|
360
|
+
|
|
361
|
+
// export interface Util {
|
|
362
|
+
// readonly buffer: {
|
|
363
|
+
// reverse(a: any): any;
|
|
364
|
+
// };
|
|
365
|
+
// }
|
|
366
|
+
|
|
367
|
+
export namespace Networks {
|
|
368
|
+
interface Network {
|
|
369
|
+
readonly name: string;
|
|
370
|
+
readonly alias: string;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const livenet: Network;
|
|
374
|
+
const mainnet: Network;
|
|
375
|
+
const testnet: Network;
|
|
376
|
+
|
|
377
|
+
function add(data: any): Network;
|
|
378
|
+
|
|
379
|
+
function remove(network: Network): void;
|
|
380
|
+
|
|
381
|
+
function get(args: string | number | Network, keys: string | string[]): Network;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export class Address {
|
|
385
|
+
readonly hashBuffer: Buffer;
|
|
386
|
+
readonly network: Networks.Network;
|
|
387
|
+
readonly type: string;
|
|
388
|
+
|
|
389
|
+
constructor(
|
|
390
|
+
data: Buffer | Uint8Array | string | object,
|
|
391
|
+
network ? : Networks.Network,
|
|
392
|
+
type ? : string
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// export class Unit {
|
|
397
|
+
// static fromBTC(amount: number): Unit;
|
|
398
|
+
// static fromMilis(amount: number): Unit;
|
|
399
|
+
// static fromBits(amount: number): Unit;
|
|
400
|
+
// static fromSatoshis(amount: number): Unit;
|
|
401
|
+
|
|
402
|
+
// constructor(amount: number, unitPreference: string);
|
|
403
|
+
|
|
404
|
+
// toBTC(): number;
|
|
405
|
+
// toMilis(): number;
|
|
406
|
+
// toBits(): number;
|
|
407
|
+
// toSatoshis(): number;
|
|
408
|
+
// }
|
|
409
|
+
// }
|
|
410
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kaspacore = module.exports;
|
|
4
|
+
|
|
5
|
+
// module information
|
|
6
|
+
kaspacore.version = 'v' + require('./package.json').version;
|
|
7
|
+
kaspacore.versionGuard = function(version) {
|
|
8
|
+
if (version !== undefined) {
|
|
9
|
+
var message = 'More than one instance of kaspacore-lib found. ' +
|
|
10
|
+
'Please make sure to require kaspacore-lib and check that submodules do' +
|
|
11
|
+
' not also include their own kaspacore-lib dependency.';
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
kaspacore.versionGuard(global._kaspacoreLibVersion);
|
|
16
|
+
global._kaspacoreLibVersion = kaspacore.version;
|
|
17
|
+
|
|
18
|
+
const deferred = ()=>{
|
|
19
|
+
let methods = {};
|
|
20
|
+
let promise = new Promise((resolve, reject)=>{
|
|
21
|
+
methods = {resolve, reject};
|
|
22
|
+
})
|
|
23
|
+
Object.assign(promise, methods);
|
|
24
|
+
return promise;
|
|
25
|
+
}
|
|
26
|
+
const readySignal = deferred();
|
|
27
|
+
|
|
28
|
+
kaspacore.ready = ()=>{
|
|
29
|
+
readySignal.resolve(true);
|
|
30
|
+
}
|
|
31
|
+
kaspacore.initRuntime = ()=>{
|
|
32
|
+
return readySignal;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// crypto
|
|
37
|
+
kaspacore.crypto = {};
|
|
38
|
+
kaspacore.crypto.BN = require('./lib/crypto/bn');
|
|
39
|
+
kaspacore.crypto.ECDSA = require('./lib/crypto/ecdsa');
|
|
40
|
+
kaspacore.crypto.Schnorr = require('./lib/crypto/schnorr');
|
|
41
|
+
kaspacore.crypto.Hash = require('./lib/crypto/hash');
|
|
42
|
+
kaspacore.crypto.Random = require('./lib/crypto/random');
|
|
43
|
+
kaspacore.crypto.Point = require('./lib/crypto/point');
|
|
44
|
+
kaspacore.crypto.Signature = require('./lib/crypto/signature');
|
|
45
|
+
|
|
46
|
+
// encoding
|
|
47
|
+
kaspacore.encoding = {};
|
|
48
|
+
kaspacore.encoding.Base58 = require('./lib/encoding/base58');
|
|
49
|
+
kaspacore.encoding.Base58Check = require('./lib/encoding/base58check');
|
|
50
|
+
kaspacore.encoding.BufferReader = require('./lib/encoding/bufferreader');
|
|
51
|
+
kaspacore.encoding.BufferWriter = require('./lib/encoding/bufferwriter');
|
|
52
|
+
kaspacore.encoding.Varint = require('./lib/encoding/varint');
|
|
53
|
+
|
|
54
|
+
// utilities
|
|
55
|
+
kaspacore.util = {};
|
|
56
|
+
kaspacore.util.buffer = require('./lib/util/buffer');
|
|
57
|
+
kaspacore.util.js = require('./lib/util/js');
|
|
58
|
+
kaspacore.util.preconditions = require('./lib/util/preconditions');
|
|
59
|
+
kaspacore.util.base32 = require('./lib/util/base32');
|
|
60
|
+
kaspacore.util.convertBits = require('./lib/util/convertBits');
|
|
61
|
+
kaspacore.setDebugLevel = (level)=>{
|
|
62
|
+
kaspacore.util.js.debugLevel = level;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// errors thrown by the library
|
|
66
|
+
kaspacore.errors = require('./lib/errors');
|
|
67
|
+
|
|
68
|
+
// main bitcoin library
|
|
69
|
+
kaspacore.Address = require('./lib/address');
|
|
70
|
+
kaspacore.Block = require('./lib/block');
|
|
71
|
+
kaspacore.MerkleBlock = require('./lib/block/merkleblock');
|
|
72
|
+
kaspacore.BlockHeader = require('./lib/block/blockheader');
|
|
73
|
+
kaspacore.HDPrivateKey = require('./lib/hdprivatekey.js');
|
|
74
|
+
kaspacore.HDPublicKey = require('./lib/hdpublickey.js');
|
|
75
|
+
kaspacore.Networks = require('./lib/networks');
|
|
76
|
+
kaspacore.Opcode = require('./lib/opcode');
|
|
77
|
+
kaspacore.PrivateKey = require('./lib/privatekey');
|
|
78
|
+
kaspacore.PublicKey = require('./lib/publickey');
|
|
79
|
+
kaspacore.Script = require('./lib/script');
|
|
80
|
+
kaspacore.Transaction = require('./lib/transaction');
|
|
81
|
+
kaspacore.URI = require('./lib/uri');
|
|
82
|
+
kaspacore.Unit = require('./lib/unit');
|
|
83
|
+
|
|
84
|
+
// dependencies, subject to change
|
|
85
|
+
kaspacore.deps = {};
|
|
86
|
+
kaspacore.deps.bnjs = require('bn.js');
|
|
87
|
+
kaspacore.deps.bs58 = require('bs58');
|
|
88
|
+
kaspacore.deps.Buffer = Buffer;
|
|
89
|
+
kaspacore.deps.elliptic = require('elliptic');
|
|
90
|
+
kaspacore.deps._ = require('lodash');
|
|
91
|
+
|
|
92
|
+
// Internal usage, exposed for testing/advanced tweaking
|
|
93
|
+
kaspacore.Transaction.sighash = require('./lib/transaction/sighash');
|