xpi-ts 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +516 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/lib/bitcore/address.d.ts +66 -0
- package/dist/lib/bitcore/address.d.ts.map +1 -0
- package/dist/lib/bitcore/address.js +407 -0
- package/dist/lib/bitcore/block/block.d.ts +57 -0
- package/dist/lib/bitcore/block/block.d.ts.map +1 -0
- package/dist/lib/bitcore/block/block.js +233 -0
- package/dist/lib/bitcore/block/blockheader.d.ts +82 -0
- package/dist/lib/bitcore/block/blockheader.d.ts.map +1 -0
- package/dist/lib/bitcore/block/blockheader.js +323 -0
- package/dist/lib/bitcore/block/index.d.ts +5 -0
- package/dist/lib/bitcore/block/index.d.ts.map +1 -0
- package/dist/lib/bitcore/block/index.js +2 -0
- package/dist/lib/bitcore/chunk.d.ts +22 -0
- package/dist/lib/bitcore/chunk.d.ts.map +1 -0
- package/dist/lib/bitcore/chunk.js +46 -0
- package/dist/lib/bitcore/crypto/bn.d.ts +53 -0
- package/dist/lib/bitcore/crypto/bn.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/bn.js +238 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts +46 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/ecdsa.js +247 -0
- package/dist/lib/bitcore/crypto/hash.d.ts +16 -0
- package/dist/lib/bitcore/crypto/hash.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/hash.js +87 -0
- package/dist/lib/bitcore/crypto/index.d.ts +9 -0
- package/dist/lib/bitcore/crypto/index.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/index.js +8 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts +40 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/musig2.js +236 -0
- package/dist/lib/bitcore/crypto/point.d.ts +20 -0
- package/dist/lib/bitcore/crypto/point.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/point.js +133 -0
- package/dist/lib/bitcore/crypto/random.d.ts +7 -0
- package/dist/lib/bitcore/crypto/random.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/random.js +30 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts +40 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/schnorr.js +185 -0
- package/dist/lib/bitcore/crypto/signature.d.ts +53 -0
- package/dist/lib/bitcore/crypto/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/signature.js +300 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts +5 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/sigtype.js +18 -0
- package/dist/lib/bitcore/encoding/base58.d.ts +16 -0
- package/dist/lib/bitcore/encoding/base58.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58.js +55 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts +9 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58check.js +82 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts +34 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferreader.js +198 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts +36 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferwriter.js +189 -0
- package/dist/lib/bitcore/encoding/varint.d.ts +20 -0
- package/dist/lib/bitcore/encoding/varint.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/varint.js +61 -0
- package/dist/lib/bitcore/errors.d.ts +28 -0
- package/dist/lib/bitcore/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/errors.js +325 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts +78 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdprivatekey.js +381 -0
- package/dist/lib/bitcore/hdpublickey.d.ts +98 -0
- package/dist/lib/bitcore/hdpublickey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdpublickey.js +416 -0
- package/dist/lib/bitcore/index.d.ts +60 -0
- package/dist/lib/bitcore/index.d.ts.map +1 -0
- package/dist/lib/bitcore/index.js +44 -0
- package/dist/lib/bitcore/message.d.ts +23 -0
- package/dist/lib/bitcore/message.d.ts.map +1 -0
- package/dist/lib/bitcore/message.js +112 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts +7 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/errors.js +20 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts +5 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/index.js +4 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts +23 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.js +164 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.js +25 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/english.js +2050 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts +4 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/index.js +4 -0
- package/dist/lib/bitcore/musig2/index.d.ts +3 -0
- package/dist/lib/bitcore/musig2/index.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/index.js +2 -0
- package/dist/lib/bitcore/musig2/session.d.ts +79 -0
- package/dist/lib/bitcore/musig2/session.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/session.js +346 -0
- package/dist/lib/bitcore/musig2/signer.d.ts +61 -0
- package/dist/lib/bitcore/musig2/signer.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/signer.js +146 -0
- package/dist/lib/bitcore/networks.d.ts +53 -0
- package/dist/lib/bitcore/networks.d.ts.map +1 -0
- package/dist/lib/bitcore/networks.js +150 -0
- package/dist/lib/bitcore/opcode.d.ts +250 -0
- package/dist/lib/bitcore/opcode.d.ts.map +1 -0
- package/dist/lib/bitcore/opcode.js +270 -0
- package/dist/lib/bitcore/privatekey.d.ts +56 -0
- package/dist/lib/bitcore/privatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/privatekey.js +237 -0
- package/dist/lib/bitcore/publickey.d.ts +59 -0
- package/dist/lib/bitcore/publickey.d.ts.map +1 -0
- package/dist/lib/bitcore/publickey.js +263 -0
- package/dist/lib/bitcore/script/interpreter.d.ts +98 -0
- package/dist/lib/bitcore/script/interpreter.d.ts.map +1 -0
- package/dist/lib/bitcore/script/interpreter.js +1704 -0
- package/dist/lib/bitcore/script.d.ts +111 -0
- package/dist/lib/bitcore/script.d.ts.map +1 -0
- package/dist/lib/bitcore/script.js +1112 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts +29 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/musig2.js +104 -0
- package/dist/lib/bitcore/taproot/nft.d.ts +164 -0
- package/dist/lib/bitcore/taproot/nft.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/nft.js +407 -0
- package/dist/lib/bitcore/taproot.d.ts +65 -0
- package/dist/lib/bitcore/taproot.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot.js +288 -0
- package/dist/lib/bitcore/transaction/index.d.ts +12 -0
- package/dist/lib/bitcore/transaction/index.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/index.js +6 -0
- package/dist/lib/bitcore/transaction/input.d.ts +202 -0
- package/dist/lib/bitcore/transaction/input.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/input.js +911 -0
- package/dist/lib/bitcore/transaction/output.d.ts +48 -0
- package/dist/lib/bitcore/transaction/output.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/output.js +231 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts +32 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/sighash.js +335 -0
- package/dist/lib/bitcore/transaction/signature.d.ts +36 -0
- package/dist/lib/bitcore/transaction/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/signature.js +130 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts +164 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/transaction.js +1016 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts +58 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/unspentoutput.js +167 -0
- package/dist/lib/bitcore/unit.d.ts +44 -0
- package/dist/lib/bitcore/unit.d.ts.map +1 -0
- package/dist/lib/bitcore/unit.js +106 -0
- package/dist/lib/bitcore/uri.d.ts +29 -0
- package/dist/lib/bitcore/uri.d.ts.map +1 -0
- package/dist/lib/bitcore/uri.js +163 -0
- package/dist/lib/bitcore/util/base32.d.ts +5 -0
- package/dist/lib/bitcore/util/base32.d.ts.map +1 -0
- package/dist/lib/bitcore/util/base32.js +58 -0
- package/dist/lib/bitcore/util/buffer.d.ts +18 -0
- package/dist/lib/bitcore/util/buffer.d.ts.map +1 -0
- package/dist/lib/bitcore/util/buffer.js +76 -0
- package/dist/lib/bitcore/util/convertBits.d.ts +2 -0
- package/dist/lib/bitcore/util/convertBits.d.ts.map +1 -0
- package/dist/lib/bitcore/util/convertBits.js +26 -0
- package/dist/lib/bitcore/util/js.d.ts +9 -0
- package/dist/lib/bitcore/util/js.d.ts.map +1 -0
- package/dist/lib/bitcore/util/js.js +45 -0
- package/dist/lib/bitcore/util/preconditions.d.ts +6 -0
- package/dist/lib/bitcore/util/preconditions.d.ts.map +1 -0
- package/dist/lib/bitcore/util/preconditions.js +31 -0
- package/dist/lib/bitcore/util.d.ts +14 -0
- package/dist/lib/bitcore/util.d.ts.map +1 -0
- package/dist/lib/bitcore/util.js +13 -0
- package/dist/lib/bitcore/xaddress.d.ts +45 -0
- package/dist/lib/bitcore/xaddress.d.ts.map +1 -0
- package/dist/lib/bitcore/xaddress.js +279 -0
- package/dist/lib/rank/api.d.ts +75 -0
- package/dist/lib/rank/api.d.ts.map +1 -0
- package/dist/lib/rank/api.js +4 -0
- package/dist/lib/rank/index.d.ts +127 -0
- package/dist/lib/rank/index.d.ts.map +1 -0
- package/dist/lib/rank/index.js +421 -0
- package/dist/lib/rank/opcode.d.ts +23 -0
- package/dist/lib/rank/opcode.d.ts.map +1 -0
- package/dist/lib/rank/opcode.js +23 -0
- package/dist/lib/rank/script.d.ts +2 -0
- package/dist/lib/rank/script.d.ts.map +1 -0
- package/dist/lib/rank/script.js +7 -0
- package/dist/lib/rank/transaction.d.ts +3 -0
- package/dist/lib/rank/transaction.d.ts.map +1 -0
- package/dist/lib/rank/transaction.js +12 -0
- package/dist/lib/rpc.d.ts +136 -0
- package/dist/lib/rpc.d.ts.map +1 -0
- package/dist/lib/rpc.js +62 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +20 -0
- package/dist/utils/env.d.ts +3 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +8 -0
- package/dist/utils/string.d.ts +11 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +47 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/wallet.d.ts +12 -0
- package/dist/utils/wallet.d.ts.map +1 -0
- package/dist/utils/wallet.js +28 -0
- package/package.json +91 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
2
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
3
|
+
const ALPHABET_MAP = {};
|
|
4
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
5
|
+
ALPHABET_MAP[ALPHABET[i]] = i;
|
|
6
|
+
}
|
|
7
|
+
export class Base58Check {
|
|
8
|
+
static encode(buf) {
|
|
9
|
+
if (!Buffer.isBuffer(buf)) {
|
|
10
|
+
throw new Error('Input must be a Buffer');
|
|
11
|
+
}
|
|
12
|
+
const checksum = this.checksum(buf);
|
|
13
|
+
const payload = Buffer.concat([buf, checksum]);
|
|
14
|
+
return this.base58Encode(payload);
|
|
15
|
+
}
|
|
16
|
+
static decode(str) {
|
|
17
|
+
if (typeof str !== 'string') {
|
|
18
|
+
throw new Error('Input must be a string');
|
|
19
|
+
}
|
|
20
|
+
const buf = this.base58Decode(str);
|
|
21
|
+
if (buf.length < 4) {
|
|
22
|
+
throw new Error('Input string too short');
|
|
23
|
+
}
|
|
24
|
+
const data = buf.subarray(0, -4);
|
|
25
|
+
const checksum = buf.subarray(-4);
|
|
26
|
+
if (!this.validChecksum(data, checksum)) {
|
|
27
|
+
throw new Error('Invalid checksum');
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
static checksum(data) {
|
|
32
|
+
const hash1 = sha256(data);
|
|
33
|
+
const hash2 = sha256(hash1);
|
|
34
|
+
return Buffer.from(hash2).subarray(0, 4);
|
|
35
|
+
}
|
|
36
|
+
static validChecksum(data, checksum) {
|
|
37
|
+
const calculatedChecksum = this.checksum(data);
|
|
38
|
+
return calculatedChecksum.equals(checksum);
|
|
39
|
+
}
|
|
40
|
+
static base58Encode(buf) {
|
|
41
|
+
if (buf.length === 0)
|
|
42
|
+
return '';
|
|
43
|
+
let num = 0n;
|
|
44
|
+
for (let i = 0; i < buf.length; i++) {
|
|
45
|
+
num = num * 256n + BigInt(buf[i]);
|
|
46
|
+
}
|
|
47
|
+
let result = '';
|
|
48
|
+
while (num > 0n) {
|
|
49
|
+
result = ALPHABET[Number(num % 58n)] + result;
|
|
50
|
+
num = num / 58n;
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < buf.length && buf[i] === 0; i++) {
|
|
53
|
+
result = '1' + result;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
static base58Decode(str) {
|
|
58
|
+
if (str.length === 0)
|
|
59
|
+
return Buffer.alloc(0);
|
|
60
|
+
let num = 0n;
|
|
61
|
+
let leadingZeros = 0;
|
|
62
|
+
for (let i = 0; i < str.length; i++) {
|
|
63
|
+
const char = str[i];
|
|
64
|
+
if (ALPHABET_MAP[char] === undefined) {
|
|
65
|
+
throw new Error(`Invalid character: ${char}`);
|
|
66
|
+
}
|
|
67
|
+
num = num * 58n + BigInt(ALPHABET_MAP[char]);
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < str.length && str[i] === '1'; i++) {
|
|
70
|
+
leadingZeros++;
|
|
71
|
+
}
|
|
72
|
+
const bytes = [];
|
|
73
|
+
while (num > 0n) {
|
|
74
|
+
bytes.unshift(Number(num % 256n));
|
|
75
|
+
num = num / 256n;
|
|
76
|
+
}
|
|
77
|
+
for (let i = 0; i < leadingZeros; i++) {
|
|
78
|
+
bytes.unshift(0);
|
|
79
|
+
}
|
|
80
|
+
return Buffer.from(bytes);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BN } from '../crypto/bn.js';
|
|
2
|
+
export interface BufferReaderData {
|
|
3
|
+
buf?: Buffer;
|
|
4
|
+
pos?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class BufferReader {
|
|
7
|
+
buf: Buffer;
|
|
8
|
+
pos: number;
|
|
9
|
+
constructor(buf?: Buffer | string | BufferReaderData);
|
|
10
|
+
static create(buf?: Buffer | string | BufferReaderData): BufferReader;
|
|
11
|
+
set(obj: BufferReaderData): BufferReader;
|
|
12
|
+
eof(): boolean;
|
|
13
|
+
finished(): boolean;
|
|
14
|
+
read(len: number): Buffer;
|
|
15
|
+
readAll(): Buffer;
|
|
16
|
+
readUInt8(): number;
|
|
17
|
+
readUInt16BE(): number;
|
|
18
|
+
readUInt16LE(): number;
|
|
19
|
+
readUInt32BE(): number;
|
|
20
|
+
readUInt32LE(): number;
|
|
21
|
+
readUInt48LE(): number;
|
|
22
|
+
readUInt56LEBN(): BN;
|
|
23
|
+
readInt32LE(): number;
|
|
24
|
+
readUInt64BEBN(): BN;
|
|
25
|
+
readUInt64LEBN(): BN;
|
|
26
|
+
readUInt32LEBN(): BN;
|
|
27
|
+
readVarintNum(): number;
|
|
28
|
+
readVarLengthBuffer(): Buffer;
|
|
29
|
+
readVarintBuf(): Buffer;
|
|
30
|
+
readVarintBN(): BN;
|
|
31
|
+
reverse(): BufferReader;
|
|
32
|
+
readReverse(len?: number): Buffer;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=bufferreader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferreader.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/encoding/bufferreader.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAGpC,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,qBAAa,YAAY;IACvB,GAAG,EAAG,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAI;gBAEH,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB;IA0BpD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,GAAG,YAAY;IAIrE,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY;IAMxC,GAAG,IAAI,OAAO;IAId,QAAQ,IAAI,OAAO;IAInB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAWzB,OAAO,IAAI,MAAM;IAMjB,SAAS,IAAI,MAAM;IAMnB,YAAY,IAAI,MAAM;IAMtB,YAAY,IAAI,MAAM;IAMtB,YAAY,IAAI,MAAM;IAMtB,YAAY,IAAI,MAAM;IAMtB,YAAY,IAAI,MAAM;IAMtB,cAAc,IAAI,EAAE;IAOpB,WAAW,IAAI,MAAM;IAMrB,cAAc,IAAI,EAAE;IAOpB,cAAc,IAAI,EAAE;IAqBpB,cAAc,IAAI,EAAE;IAMpB,aAAa,IAAI,MAAM;IA0BvB,mBAAmB,IAAI,MAAM;IAc7B,aAAa,IAAI,MAAM;IAcvB,YAAY,IAAI,EAAE;IAclB,OAAO,IAAI,YAAY;IASvB,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM;CAQlC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Preconditions } from '../util/preconditions.js';
|
|
2
|
+
import { BN } from '../crypto/bn.js';
|
|
3
|
+
import { BufferUtil } from '../util/buffer.js';
|
|
4
|
+
export class BufferReader {
|
|
5
|
+
buf;
|
|
6
|
+
pos = 0;
|
|
7
|
+
constructor(buf) {
|
|
8
|
+
if (buf === undefined) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (Buffer.isBuffer(buf)) {
|
|
12
|
+
this.set({
|
|
13
|
+
buf: buf,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else if (typeof buf === 'string') {
|
|
17
|
+
const b = Buffer.from(buf, 'hex');
|
|
18
|
+
if (b.length * 2 !== buf.length) {
|
|
19
|
+
throw new TypeError('Invalid hex string');
|
|
20
|
+
}
|
|
21
|
+
this.set({
|
|
22
|
+
buf: b,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else if (typeof buf === 'object' && buf !== null) {
|
|
26
|
+
const obj = buf;
|
|
27
|
+
this.set(obj);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new TypeError('Unrecognized argument for BufferReader');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
static create(buf) {
|
|
34
|
+
return new BufferReader(buf);
|
|
35
|
+
}
|
|
36
|
+
set(obj) {
|
|
37
|
+
this.buf = obj.buf || this.buf || undefined;
|
|
38
|
+
this.pos = obj.pos || this.pos || 0;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
eof() {
|
|
42
|
+
return this.pos >= this.buf.length;
|
|
43
|
+
}
|
|
44
|
+
finished() {
|
|
45
|
+
return this.eof();
|
|
46
|
+
}
|
|
47
|
+
read(len) {
|
|
48
|
+
Preconditions.checkArgument(len !== undefined, 'len', 'Must specify a length');
|
|
49
|
+
const buf = this.buf.slice(this.pos, this.pos + len);
|
|
50
|
+
this.pos = this.pos + len;
|
|
51
|
+
return buf;
|
|
52
|
+
}
|
|
53
|
+
readAll() {
|
|
54
|
+
const buf = this.buf.slice(this.pos, this.buf.length);
|
|
55
|
+
this.pos = this.buf.length;
|
|
56
|
+
return buf;
|
|
57
|
+
}
|
|
58
|
+
readUInt8() {
|
|
59
|
+
const val = this.buf.readUInt8(this.pos);
|
|
60
|
+
this.pos = this.pos + 1;
|
|
61
|
+
return val;
|
|
62
|
+
}
|
|
63
|
+
readUInt16BE() {
|
|
64
|
+
const val = this.buf.readUInt16BE(this.pos);
|
|
65
|
+
this.pos = this.pos + 2;
|
|
66
|
+
return val;
|
|
67
|
+
}
|
|
68
|
+
readUInt16LE() {
|
|
69
|
+
const val = this.buf.readUInt16LE(this.pos);
|
|
70
|
+
this.pos = this.pos + 2;
|
|
71
|
+
return val;
|
|
72
|
+
}
|
|
73
|
+
readUInt32BE() {
|
|
74
|
+
const val = this.buf.readUInt32BE(this.pos);
|
|
75
|
+
this.pos = this.pos + 4;
|
|
76
|
+
return val;
|
|
77
|
+
}
|
|
78
|
+
readUInt32LE() {
|
|
79
|
+
const val = this.buf.readUInt32LE(this.pos);
|
|
80
|
+
this.pos = this.pos + 4;
|
|
81
|
+
return val;
|
|
82
|
+
}
|
|
83
|
+
readUInt48LE() {
|
|
84
|
+
const val = this.buf.readUIntLE(this.pos, 6);
|
|
85
|
+
this.pos = this.pos + 6;
|
|
86
|
+
return val;
|
|
87
|
+
}
|
|
88
|
+
readUInt56LEBN() {
|
|
89
|
+
const buf = this.buf.slice(this.pos, this.pos + 7);
|
|
90
|
+
const bn = BN.fromBuffer(buf, { endian: 'little' });
|
|
91
|
+
this.pos = this.pos + 7;
|
|
92
|
+
return bn;
|
|
93
|
+
}
|
|
94
|
+
readInt32LE() {
|
|
95
|
+
const val = this.buf.readInt32LE(this.pos);
|
|
96
|
+
this.pos = this.pos + 4;
|
|
97
|
+
return val;
|
|
98
|
+
}
|
|
99
|
+
readUInt64BEBN() {
|
|
100
|
+
const buf = this.buf.slice(this.pos, this.pos + 8);
|
|
101
|
+
const bn = BN.fromBuffer(buf);
|
|
102
|
+
this.pos = this.pos + 8;
|
|
103
|
+
return bn;
|
|
104
|
+
}
|
|
105
|
+
readUInt64LEBN() {
|
|
106
|
+
const second = this.buf.readUInt32LE(this.pos);
|
|
107
|
+
const first = this.buf.readUInt32LE(this.pos + 4);
|
|
108
|
+
const combined = first * 0x100000000 + second;
|
|
109
|
+
let bn;
|
|
110
|
+
if (combined <= 0x1fffffffffffff) {
|
|
111
|
+
bn = new BN(combined);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
|
|
115
|
+
bn = new BN(Buffer.from(data), 'le');
|
|
116
|
+
}
|
|
117
|
+
this.pos = this.pos + 8;
|
|
118
|
+
return bn;
|
|
119
|
+
}
|
|
120
|
+
readUInt32LEBN() {
|
|
121
|
+
const value = this.buf.readUInt32LE(this.pos);
|
|
122
|
+
this.pos = this.pos + 4;
|
|
123
|
+
return new BN(value);
|
|
124
|
+
}
|
|
125
|
+
readVarintNum() {
|
|
126
|
+
const first = this.readUInt8();
|
|
127
|
+
switch (first) {
|
|
128
|
+
case 0xfd:
|
|
129
|
+
return this.readUInt16LE();
|
|
130
|
+
case 0xfe:
|
|
131
|
+
return this.readUInt32LE();
|
|
132
|
+
case 0xff: {
|
|
133
|
+
const bn = this.readUInt64LEBN();
|
|
134
|
+
const n = Number(bn);
|
|
135
|
+
if (n <= Math.pow(2, 53)) {
|
|
136
|
+
return n;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error('number too large to retain precision - use readVarintBN');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
default:
|
|
143
|
+
return first;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
readVarLengthBuffer() {
|
|
147
|
+
const len = this.readVarintNum();
|
|
148
|
+
const buf = this.read(len);
|
|
149
|
+
Preconditions.checkState(buf.length === len, 'Invalid length while reading varlength buffer. ' +
|
|
150
|
+
'Expected to read: ' +
|
|
151
|
+
len +
|
|
152
|
+
' and read ' +
|
|
153
|
+
buf.length);
|
|
154
|
+
return buf;
|
|
155
|
+
}
|
|
156
|
+
readVarintBuf() {
|
|
157
|
+
const first = this.buf.readUInt8(this.pos);
|
|
158
|
+
switch (first) {
|
|
159
|
+
case 0xfd:
|
|
160
|
+
return this.read(1 + 2);
|
|
161
|
+
case 0xfe:
|
|
162
|
+
return this.read(1 + 4);
|
|
163
|
+
case 0xff:
|
|
164
|
+
return this.read(1 + 8);
|
|
165
|
+
default:
|
|
166
|
+
return this.read(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
readVarintBN() {
|
|
170
|
+
const first = this.readUInt8();
|
|
171
|
+
switch (first) {
|
|
172
|
+
case 0xfd:
|
|
173
|
+
return new BN(this.readUInt16LE());
|
|
174
|
+
case 0xfe:
|
|
175
|
+
return new BN(this.readUInt32LE());
|
|
176
|
+
case 0xff:
|
|
177
|
+
return this.readUInt64LEBN();
|
|
178
|
+
default:
|
|
179
|
+
return new BN(first);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
reverse() {
|
|
183
|
+
const buf = Buffer.alloc(this.buf.length);
|
|
184
|
+
for (let i = 0; i < buf.length; i++) {
|
|
185
|
+
buf[i] = this.buf[this.buf.length - 1 - i];
|
|
186
|
+
}
|
|
187
|
+
this.buf = buf;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
readReverse(len) {
|
|
191
|
+
if (len === undefined) {
|
|
192
|
+
len = this.buf.length;
|
|
193
|
+
}
|
|
194
|
+
const buf = this.buf.slice(this.pos, this.pos + len);
|
|
195
|
+
this.pos = this.pos + len;
|
|
196
|
+
return BufferUtil.reverse(buf);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BN } from '../crypto/bn.js';
|
|
2
|
+
export interface BufferWriterData {
|
|
3
|
+
bufs?: Buffer[];
|
|
4
|
+
}
|
|
5
|
+
export declare class BufferWriter {
|
|
6
|
+
bufs: Buffer[];
|
|
7
|
+
bufLen: number;
|
|
8
|
+
constructor(obj?: BufferWriterData);
|
|
9
|
+
static create(obj?: BufferWriterData): BufferWriter;
|
|
10
|
+
set(obj: BufferWriterData): BufferWriter;
|
|
11
|
+
toBuffer(): Buffer;
|
|
12
|
+
concat(): Buffer;
|
|
13
|
+
write(buf: Buffer): BufferWriter;
|
|
14
|
+
writeReverse(buf: Buffer): BufferWriter;
|
|
15
|
+
writeUInt8(n: number): BufferWriter;
|
|
16
|
+
writeUInt16BE(n: number): BufferWriter;
|
|
17
|
+
writeUInt16LE(n: number): BufferWriter;
|
|
18
|
+
writeUInt32BE(n: number): BufferWriter;
|
|
19
|
+
writeInt32LE(n: number): BufferWriter;
|
|
20
|
+
writeUInt32LE(n: number): BufferWriter;
|
|
21
|
+
writeUInt48LE(n: number): BufferWriter;
|
|
22
|
+
writeUInt56LE(n: number): BufferWriter;
|
|
23
|
+
writeUInt64BEBN(bn: BN): BufferWriter;
|
|
24
|
+
writeUInt56LEBN(bn: BN): BufferWriter;
|
|
25
|
+
writeUInt64LEBN(bn: BN): BufferWriter;
|
|
26
|
+
writeUInt64LEBigInt(value: bigint): BufferWriter;
|
|
27
|
+
writeUInt32LEBN(bn: BN): BufferWriter;
|
|
28
|
+
writeUInt32LENumber(value: number): BufferWriter;
|
|
29
|
+
writeVarintNum(n: number): BufferWriter;
|
|
30
|
+
writeVarintBN(bn: BN): BufferWriter;
|
|
31
|
+
writeVarLengthBuffer(buf: Buffer): BufferWriter;
|
|
32
|
+
static varintBufNum(n: number): Buffer;
|
|
33
|
+
static varintBufBN(bn: BN): Buffer;
|
|
34
|
+
}
|
|
35
|
+
export declare function BufferWriterFactory(obj?: BufferWriterData): BufferWriter;
|
|
36
|
+
//# sourceMappingURL=bufferwriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferwriter.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/encoding/bufferwriter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,qBAAa,YAAY;IACvB,IAAI,EAAE,MAAM,EAAE,CAAK;IACnB,MAAM,EAAE,MAAM,CAAI;gBAEN,GAAG,CAAC,EAAE,gBAAgB;IAUlC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,gBAAgB,GAAG,YAAY;IAInD,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,YAAY;IAMxC,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,MAAM;IAIhB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAShC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IASvC,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOnC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOrC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAOtC,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY;IAMrC,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY;IAMrC,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY;IAMrC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAKhD,eAAe,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY;IAMrC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAKhD,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY;IAMvC,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY;IAMnC,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAM/C,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAsBtC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM;CAuBnC;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,gBAAgB,GAAG,YAAY,CAExE"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { BufferUtil } from '../util/buffer.js';
|
|
2
|
+
import { BN } from '../crypto/bn.js';
|
|
3
|
+
export class BufferWriter {
|
|
4
|
+
bufs = [];
|
|
5
|
+
bufLen = 0;
|
|
6
|
+
constructor(obj) {
|
|
7
|
+
this.bufLen = 0;
|
|
8
|
+
if (obj) {
|
|
9
|
+
this.set(obj);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.bufs = [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static create(obj) {
|
|
16
|
+
return new BufferWriter(obj);
|
|
17
|
+
}
|
|
18
|
+
set(obj) {
|
|
19
|
+
this.bufs = obj.bufs || this.bufs || [];
|
|
20
|
+
this.bufLen = this.bufs.reduce((prev, buf) => prev + buf.length, 0);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
toBuffer() {
|
|
24
|
+
return this.concat();
|
|
25
|
+
}
|
|
26
|
+
concat() {
|
|
27
|
+
return Buffer.concat(this.bufs, this.bufLen);
|
|
28
|
+
}
|
|
29
|
+
write(buf) {
|
|
30
|
+
if (!BufferUtil.isBuffer(buf)) {
|
|
31
|
+
throw new Error('Expected Buffer');
|
|
32
|
+
}
|
|
33
|
+
this.bufs.push(buf);
|
|
34
|
+
this.bufLen += buf.length;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
writeReverse(buf) {
|
|
38
|
+
if (!BufferUtil.isBuffer(buf)) {
|
|
39
|
+
throw new Error('Expected Buffer');
|
|
40
|
+
}
|
|
41
|
+
this.bufs.push(BufferUtil.reverse(buf));
|
|
42
|
+
this.bufLen += buf.length;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
writeUInt8(n) {
|
|
46
|
+
const buf = Buffer.alloc(1);
|
|
47
|
+
buf.writeUInt8(n, 0);
|
|
48
|
+
this.write(buf);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
writeUInt16BE(n) {
|
|
52
|
+
const buf = Buffer.alloc(2);
|
|
53
|
+
buf.writeUInt16BE(n, 0);
|
|
54
|
+
this.write(buf);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
writeUInt16LE(n) {
|
|
58
|
+
const buf = Buffer.alloc(2);
|
|
59
|
+
buf.writeUInt16LE(n, 0);
|
|
60
|
+
this.write(buf);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
writeUInt32BE(n) {
|
|
64
|
+
const buf = Buffer.alloc(4);
|
|
65
|
+
buf.writeUInt32BE(n, 0);
|
|
66
|
+
this.write(buf);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
writeInt32LE(n) {
|
|
70
|
+
const buf = Buffer.alloc(4);
|
|
71
|
+
buf.writeInt32LE(n, 0);
|
|
72
|
+
this.write(buf);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
writeUInt32LE(n) {
|
|
76
|
+
const buf = Buffer.alloc(4);
|
|
77
|
+
buf.writeUInt32LE(n, 0);
|
|
78
|
+
this.write(buf);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
writeUInt48LE(n) {
|
|
82
|
+
const buf = Buffer.alloc(6);
|
|
83
|
+
buf.writeUIntLE(n, 0, 6);
|
|
84
|
+
this.write(buf);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
writeUInt56LE(n) {
|
|
88
|
+
const buf = Buffer.alloc(7);
|
|
89
|
+
buf.writeUIntLE(n, 0, 7);
|
|
90
|
+
this.write(buf);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
writeUInt64BEBN(bn) {
|
|
94
|
+
const buf = bn.toBuffer({ size: 8 });
|
|
95
|
+
this.write(buf);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
writeUInt56LEBN(bn) {
|
|
99
|
+
const buf = bn.toBuffer({ size: 7 });
|
|
100
|
+
this.writeReverse(buf);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
writeUInt64LEBN(bn) {
|
|
104
|
+
const buf = bn.toBuffer({ size: 8 });
|
|
105
|
+
this.writeReverse(buf);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
writeUInt64LEBigInt(value) {
|
|
109
|
+
const bn = new BN(value.toString());
|
|
110
|
+
return this.writeUInt64LEBN(bn);
|
|
111
|
+
}
|
|
112
|
+
writeUInt32LEBN(bn) {
|
|
113
|
+
const value = bn.toNumber();
|
|
114
|
+
this.writeUInt32LE(value);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
writeUInt32LENumber(value) {
|
|
118
|
+
this.writeUInt32LE(value);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
writeVarintNum(n) {
|
|
122
|
+
const buf = BufferWriter.varintBufNum(n);
|
|
123
|
+
this.write(buf);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
writeVarintBN(bn) {
|
|
127
|
+
const buf = BufferWriter.varintBufBN(bn);
|
|
128
|
+
this.write(buf);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
writeVarLengthBuffer(buf) {
|
|
132
|
+
this.writeVarintNum(buf.length);
|
|
133
|
+
this.write(buf);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
static varintBufNum(n) {
|
|
137
|
+
let buf;
|
|
138
|
+
if (n < 253) {
|
|
139
|
+
buf = Buffer.alloc(1);
|
|
140
|
+
buf.writeUInt8(n, 0);
|
|
141
|
+
}
|
|
142
|
+
else if (n < 0x10000) {
|
|
143
|
+
buf = Buffer.alloc(1 + 2);
|
|
144
|
+
buf.writeUInt8(253, 0);
|
|
145
|
+
buf.writeUInt16LE(n, 1);
|
|
146
|
+
}
|
|
147
|
+
else if (n < 0x100000000) {
|
|
148
|
+
buf = Buffer.alloc(1 + 4);
|
|
149
|
+
buf.writeUInt8(254, 0);
|
|
150
|
+
buf.writeUInt32LE(n, 1);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
buf = Buffer.alloc(1 + 8);
|
|
154
|
+
buf.writeUInt8(255, 0);
|
|
155
|
+
buf.writeInt32LE(n & -1, 1);
|
|
156
|
+
buf.writeUInt32LE(Math.floor(n / 0x100000000), 5);
|
|
157
|
+
}
|
|
158
|
+
return buf;
|
|
159
|
+
}
|
|
160
|
+
static varintBufBN(bn) {
|
|
161
|
+
const n = bn.toNumber();
|
|
162
|
+
if (n < 253) {
|
|
163
|
+
const buf = Buffer.alloc(1);
|
|
164
|
+
buf.writeUInt8(n, 0);
|
|
165
|
+
return buf;
|
|
166
|
+
}
|
|
167
|
+
else if (n < 0x10000) {
|
|
168
|
+
const buf = Buffer.alloc(1 + 2);
|
|
169
|
+
buf.writeUInt8(253, 0);
|
|
170
|
+
buf.writeUInt16LE(n, 1);
|
|
171
|
+
return buf;
|
|
172
|
+
}
|
|
173
|
+
else if (n < 0x100000000) {
|
|
174
|
+
const buf = Buffer.alloc(1 + 4);
|
|
175
|
+
buf.writeUInt8(254, 0);
|
|
176
|
+
buf.writeUInt32LE(n, 1);
|
|
177
|
+
return buf;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const bw = new BufferWriter();
|
|
181
|
+
bw.writeUInt8(255);
|
|
182
|
+
bw.writeUInt64LEBN(bn);
|
|
183
|
+
return bw.concat();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export function BufferWriterFactory(obj) {
|
|
188
|
+
return new BufferWriter(obj);
|
|
189
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BufferReader } from './bufferreader.js';
|
|
2
|
+
import { BN } from '../crypto/bn.js';
|
|
3
|
+
export interface VarintData {
|
|
4
|
+
buf?: Buffer;
|
|
5
|
+
}
|
|
6
|
+
export declare class Varint {
|
|
7
|
+
buf: Buffer;
|
|
8
|
+
constructor(buf?: Buffer | number | BN | VarintData);
|
|
9
|
+
set(obj: VarintData): Varint;
|
|
10
|
+
fromString(str: string): Varint;
|
|
11
|
+
toString(): string;
|
|
12
|
+
fromBuffer(buf: Buffer): Varint;
|
|
13
|
+
fromBufferReader(br: BufferReader): Varint;
|
|
14
|
+
fromBN(bn: BN): Varint;
|
|
15
|
+
fromNumber(num: number): Varint;
|
|
16
|
+
toBuffer(): Buffer;
|
|
17
|
+
toBN(): BN;
|
|
18
|
+
toNumber(): number;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=varint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/encoding/varint.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAEpC,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,qBAAa,MAAM;IACjB,GAAG,EAAE,MAAM,CAAkB;gBAEjB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,EAAE,GAAG,UAAU;IAenD,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM;IAK5B,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAO/B,QAAQ,IAAI,MAAM;IAIlB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK/B,gBAAgB,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM;IAK1C,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM;IAKtB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK/B,QAAQ,IAAI,MAAM;IAIlB,IAAI,IAAI,EAAE;IAIV,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BufferWriter } from './bufferwriter.js';
|
|
2
|
+
import { BufferReader } from './bufferreader.js';
|
|
3
|
+
import { BN } from '../crypto/bn.js';
|
|
4
|
+
export class Varint {
|
|
5
|
+
buf = Buffer.alloc(0);
|
|
6
|
+
constructor(buf) {
|
|
7
|
+
if (Buffer.isBuffer(buf)) {
|
|
8
|
+
this.buf = buf;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof buf === 'number') {
|
|
11
|
+
const num = buf;
|
|
12
|
+
this.fromNumber(num);
|
|
13
|
+
}
|
|
14
|
+
else if (buf instanceof BN) {
|
|
15
|
+
const bn = buf;
|
|
16
|
+
this.fromBN(bn);
|
|
17
|
+
}
|
|
18
|
+
else if (buf) {
|
|
19
|
+
const obj = buf;
|
|
20
|
+
this.set(obj);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
set(obj) {
|
|
24
|
+
this.buf = obj.buf || this.buf;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
fromString(str) {
|
|
28
|
+
this.set({
|
|
29
|
+
buf: Buffer.from(str, 'hex'),
|
|
30
|
+
});
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
toString() {
|
|
34
|
+
return this.buf.toString('hex');
|
|
35
|
+
}
|
|
36
|
+
fromBuffer(buf) {
|
|
37
|
+
this.buf = buf;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
fromBufferReader(br) {
|
|
41
|
+
this.buf = br.readVarintBuf();
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
fromBN(bn) {
|
|
45
|
+
this.buf = BufferWriter.varintBufBN(bn);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
fromNumber(num) {
|
|
49
|
+
this.buf = new BufferWriter().writeVarintNum(num).concat();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
toBuffer() {
|
|
53
|
+
return this.buf;
|
|
54
|
+
}
|
|
55
|
+
toBN() {
|
|
56
|
+
return new BufferReader(this.buf).readVarintBN();
|
|
57
|
+
}
|
|
58
|
+
toNumber() {
|
|
59
|
+
return new BufferReader(this.buf).readVarintNum();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface ErrorDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string | ((...args: unknown[]) => string);
|
|
4
|
+
errors?: ErrorDefinition[];
|
|
5
|
+
}
|
|
6
|
+
export declare class BitcoreError extends Error {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
static extend(spec: ErrorDefinition): Function;
|
|
9
|
+
static NotImplemented: new (message?: string) => BitcoreError;
|
|
10
|
+
static Script: {
|
|
11
|
+
InvalidBuffer: new (buffer: string) => BitcoreError;
|
|
12
|
+
UnrecognizedAddress: new (address: unknown) => BitcoreError;
|
|
13
|
+
CantDeriveAddress: new (script: string) => BitcoreError;
|
|
14
|
+
InvalidScriptString: new (script: string) => BitcoreError;
|
|
15
|
+
};
|
|
16
|
+
static Precondition: {
|
|
17
|
+
InvalidState: new (message: string) => BitcoreError;
|
|
18
|
+
InvalidArgument: new (argumentName: string, message?: string, docsPath?: string) => BitcoreError;
|
|
19
|
+
InvalidArgumentType: new (argument: unknown, type: string | Function, argumentName?: string) => BitcoreError;
|
|
20
|
+
};
|
|
21
|
+
static Transaction: {
|
|
22
|
+
Input: {
|
|
23
|
+
MissingScript: new () => BitcoreError;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../lib/bitcore/errors.ts"],"names":[],"mappings":"AAoDA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC,CAAA;IAClD,MAAM,CAAC,EAAE,eAAe,EAAE,CAAA;CAC3B;AAoSD,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,CAAC,EAAE,MAAM;IAM5B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,QAAQ;IAK9C,MAAM,CAAC,cAAc,EAAE,KAAK,OAAO,CAAC,EAAE,MAAM,KAAK,YAAY,CAAA;IAC7D,MAAM,CAAC,MAAM,EAAE;QACb,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,YAAY,CAAA;QACnD,mBAAmB,EAAE,KAAK,OAAO,EAAE,OAAO,KAAK,YAAY,CAAA;QAC3D,iBAAiB,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,YAAY,CAAA;QACvD,mBAAmB,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,YAAY,CAAA;KAC1D,CAAA;IACD,MAAM,CAAC,YAAY,EAAE;QACnB,YAAY,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,YAAY,CAAA;QACnD,eAAe,EAAE,KACf,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,KACd,YAAY,CAAA;QACjB,mBAAmB,EAAE,KACnB,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,YAAY,CAAC,EAAE,MAAM,KAClB,YAAY,CAAA;KAClB,CAAA;IACD,MAAM,CAAC,WAAW,EAAE;QAClB,KAAK,EAAE;YACL,aAAa,EAAE,UAAU,YAAY,CAAA;SACtC,CAAA;KACF,CAAA;CACF"}
|