@opcat-labs/opcat 1.0.0 → 1.0.2
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/.cjs2esm.json +18 -0
- package/.mocharc.yaml +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +6 -0
- package/{lib/address.js → cjs/address.cjs} +77 -72
- package/cjs/block/block.cjs +332 -0
- package/{lib/block/blockheader.js → cjs/block/blockheader.cjs} +8 -7
- package/cjs/block/index.cjs +2 -0
- package/{lib/block/merkleblock.js → cjs/block/merkleblock.cjs} +23 -15
- package/cjs/bn.cjs +3411 -0
- package/{lib/crypto/bn.js → cjs/crypto/bn.cjs} +3 -3
- package/{lib/crypto/ecdsa.js → cjs/crypto/ecdsa.cjs} +150 -14
- package/{lib/crypto/hash.node.js → cjs/crypto/hash.cjs} +13 -2
- package/cjs/crypto/index.cjs +16 -0
- package/{lib/crypto/point.js → cjs/crypto/point.cjs} +11 -4
- package/cjs/crypto/random.cjs +18 -0
- package/{lib/crypto/signature.js → cjs/crypto/signature.cjs} +158 -8
- package/{lib/encoding/base58.js → cjs/encoding/base58.cjs} +58 -2
- package/cjs/encoding/base58check.cjs +192 -0
- package/cjs/encoding/bufferreader.cjs +333 -0
- package/cjs/encoding/bufferwriter.cjs +244 -0
- package/{lib/encoding/decode-asm.js → cjs/encoding/decode-asm.cjs} +4 -4
- package/{lib/encoding/decode-hex.js → cjs/encoding/decode-hex.cjs} +1 -1
- package/cjs/encoding/index.cjs +14 -0
- package/cjs/encoding/varint.cjs +116 -0
- package/{lib/errors/index.js → cjs/errors/index.cjs} +9 -9
- package/{lib/errors/spec.js → cjs/errors/spec.cjs} +2 -2
- package/cjs/hash-cache.cjs +98 -0
- package/{lib/hdprivatekey.js → cjs/hdprivatekey.cjs} +232 -140
- package/{lib/hdpublickey.js → cjs/hdpublickey.cjs} +120 -93
- package/cjs/index.cjs +94 -0
- package/cjs/interpreter/index.cjs +2 -0
- package/cjs/interpreter/interpreter.cjs +1988 -0
- package/{lib/script/stack.js → cjs/interpreter/stack.cjs} +9 -2
- package/{lib/message/message.js → cjs/message/message.cjs} +62 -25
- package/cjs/mnemonic/index.cjs +3 -0
- package/{lib/mnemonic/mnemonic.js → cjs/mnemonic/mnemonic.cjs} +44 -13
- package/{lib/mnemonic/pbkdf2.node.js → cjs/mnemonic/pbkdf2.cjs} +9 -2
- package/cjs/mnemonic/words/index.cjs +66 -0
- package/cjs/network.cjs +13 -0
- package/cjs/networks.cjs +321 -0
- package/{lib/opcode.js → cjs/opcode.cjs} +69 -5
- package/cjs/privatekey.cjs +422 -0
- package/{lib/publickey.js → cjs/publickey.cjs} +14 -16
- package/cjs/script/index.cjs +2 -0
- package/{lib/script/script.js → cjs/script/script.cjs} +322 -67
- package/cjs/transaction/index.cjs +5 -0
- package/cjs/transaction/input/index.cjs +34 -0
- package/cjs/transaction/input/input.cjs +396 -0
- package/{lib/transaction/input/multisig.js → cjs/transaction/input/multisig.cjs} +112 -18
- package/{lib/transaction/input/publickey.js → cjs/transaction/input/publickey.cjs} +29 -19
- package/{lib/transaction/input/publickeyhash.js → cjs/transaction/input/publickeyhash.cjs} +25 -17
- package/{lib/transaction/output.js → cjs/transaction/output.cjs} +100 -15
- package/cjs/transaction/sighash.cjs +187 -0
- package/{lib/transaction/signature.js → cjs/transaction/signature.cjs} +30 -6
- package/cjs/transaction/transaction.cjs +2000 -0
- package/{lib/transaction/unspentoutput.js → cjs/transaction/unspentoutput.cjs} +5 -5
- package/cjs/util/derivation.cjs +53 -0
- package/cjs/util/index.cjs +11 -0
- package/cjs/util/js.cjs +95 -0
- package/{lib/util/preconditions.js → cjs/util/preconditions.cjs} +2 -2
- package/esm/address.js +483 -0
- package/{lib → esm}/block/block.js +82 -27
- package/esm/block/blockheader.js +296 -0
- package/esm/block/index.js +2 -0
- package/esm/block/merkleblock.js +331 -0
- package/esm/bn.js +3411 -0
- package/esm/crypto/bn.js +278 -0
- package/esm/crypto/ecdsa.js +475 -0
- package/{lib/crypto/hash.browser.js → esm/crypto/hash.js} +18 -7
- package/esm/crypto/index.js +16 -0
- package/esm/crypto/point.js +228 -0
- package/esm/crypto/random.js +18 -0
- package/esm/crypto/signature.js +475 -0
- package/esm/encoding/base58.js +167 -0
- package/esm/encoding/base58check.js +192 -0
- package/esm/encoding/bufferreader.js +333 -0
- package/esm/encoding/bufferwriter.js +243 -0
- package/esm/encoding/decode-asm.js +24 -0
- package/esm/encoding/decode-hex.js +32 -0
- package/esm/encoding/decode-script-chunks.js +43 -0
- package/esm/encoding/encode-hex.js +284 -0
- package/esm/encoding/index.js +14 -0
- package/esm/encoding/is-hex.js +7 -0
- package/esm/encoding/varint.js +116 -0
- package/esm/errors/index.js +54 -0
- package/esm/errors/spec.js +314 -0
- package/esm/hash-cache.js +98 -0
- package/esm/hdprivatekey.js +768 -0
- package/esm/hdpublickey.js +549 -0
- package/esm/index.js +66 -0
- package/esm/interpreter/index.js +2 -0
- package/{lib/script → esm/interpreter}/interpreter.js +219 -66
- package/esm/interpreter/stack.js +116 -0
- package/esm/message/message.js +228 -0
- package/esm/mnemonic/index.js +3 -0
- package/esm/mnemonic/mnemonic.js +332 -0
- package/{lib/mnemonic/pbkdf2.browser.js → esm/mnemonic/pbkdf2.js} +13 -6
- package/esm/mnemonic/words/chinese.js +2054 -0
- package/esm/mnemonic/words/english.js +2054 -0
- package/esm/mnemonic/words/french.js +2054 -0
- package/esm/mnemonic/words/index.js +66 -0
- package/esm/mnemonic/words/italian.js +2054 -0
- package/esm/mnemonic/words/japanese.js +2054 -0
- package/esm/mnemonic/words/spanish.js +2054 -0
- package/esm/network.js +13 -0
- package/{lib → esm}/networks.js +61 -120
- package/esm/opcode.js +319 -0
- package/{lib → esm}/privatekey.js +76 -28
- package/esm/publickey.js +384 -0
- package/esm/script/index.js +2 -0
- package/esm/script/script.js +1329 -0
- package/esm/script/write-i32-le.js +17 -0
- package/esm/script/write-push-data.js +35 -0
- package/esm/script/write-u16-le.js +12 -0
- package/esm/script/write-u32-le.js +16 -0
- package/esm/script/write-u64-le.js +24 -0
- package/esm/script/write-u8-le.js +8 -0
- package/esm/script/write-varint.js +46 -0
- package/esm/transaction/index.js +5 -0
- package/esm/transaction/input/index.js +33 -0
- package/{lib → esm}/transaction/input/input.js +132 -90
- package/esm/transaction/input/multisig.js +335 -0
- package/esm/transaction/input/publickey.js +108 -0
- package/esm/transaction/input/publickeyhash.js +124 -0
- package/esm/transaction/output.js +316 -0
- package/{lib → esm}/transaction/sighash.js +42 -22
- package/esm/transaction/signature.js +120 -0
- package/{lib → esm}/transaction/transaction.js +522 -163
- package/esm/transaction/unspentoutput.js +112 -0
- package/esm/util/_.js +47 -0
- package/esm/util/derivation.js +53 -0
- package/esm/util/index.js +12 -0
- package/esm/util/js.js +95 -0
- package/esm/util/preconditions.js +33 -0
- package/fixup.cjs +17 -0
- package/package.json +40 -26
- package/test/{address.js → address.cjs} +14 -43
- package/test/block/{block.js → block.cjs} +3 -5
- package/test/block/{blockheader.js → blockheader.cjs} +2 -2
- package/test/block/{merklebloack.js → merklebloack.cjs} +2 -2
- package/test/crypto/{ecdsa.js → ecdsa.cjs} +9 -9
- package/test/crypto/{hash.browser.js → hash.browser.cjs} +2 -1
- package/test/crypto/{signature.js → signature.cjs} +2 -2
- package/test/data/bitcoind/script_tests.json +5 -5
- package/test/{hashCache.js → hashCache.cjs} +2 -1
- package/test/{hdkeys.js → hdkeys.cjs} +4 -2
- package/test/{hdprivatekey.js → hdprivatekey.cjs} +7 -6
- package/test/{hdpublickey.js → hdpublickey.cjs} +2 -7
- package/test/mnemonic/{pbkdf2.test.js → pbkdf2.test.cjs} +2 -2
- package/test/{networks.js → networks.cjs} +12 -31
- package/test/{publickey.js → publickey.cjs} +2 -2
- package/test/script/{interpreter.js → interpreter.cjs} +5 -5
- package/test/script/{script.js → script.cjs} +8 -2
- package/test/transaction/{deserialize.js → deserialize.cjs} +2 -2
- package/test/transaction/input/{input.js → input.cjs} +1 -1
- package/test/transaction/input/{multisig.js → multisig.cjs} +2 -1
- package/test/transaction/input/{publickeyhash.js → publickeyhash.cjs} +1 -1
- package/test/transaction/{sighash.js → sighash.cjs} +1 -1
- package/test/transaction/{transaction.js → transaction.cjs} +2 -2
- package/tsconfig.json +13 -0
- package/types/address.d.cts +252 -0
- package/types/block/block.d.cts +139 -0
- package/types/block/blockheader.d.cts +125 -0
- package/types/block/index.d.cts +2 -0
- package/types/block/merkleblock.d.cts +95 -0
- package/types/bn.d.cts +202 -0
- package/types/crypto/bn.d.cts +2 -0
- package/types/crypto/ecdsa.d.cts +187 -0
- package/types/crypto/hash.d.cts +118 -0
- package/types/crypto/index.d.cts +7 -0
- package/types/crypto/point.d.cts +134 -0
- package/types/crypto/random.d.cts +13 -0
- package/types/crypto/signature.d.cts +160 -0
- package/types/encoding/base58.d.cts +106 -0
- package/types/encoding/base58check.d.cts +107 -0
- package/types/encoding/bufferreader.d.cts +164 -0
- package/types/encoding/bufferwriter.d.cts +126 -0
- package/types/encoding/decode-asm.d.cts +2 -0
- package/types/encoding/decode-hex.d.cts +2 -0
- package/types/encoding/decode-script-chunks.d.cts +14 -0
- package/types/encoding/encode-hex.d.cts +2 -0
- package/types/encoding/index.d.cts +6 -0
- package/types/encoding/is-hex.d.cts +2 -0
- package/types/encoding/varint.d.cts +66 -0
- package/types/errors/index.d.cts +4 -0
- package/types/errors/spec.d.cts +22 -0
- package/types/hash-cache.d.cts +65 -0
- package/types/hdprivatekey.d.cts +281 -0
- package/types/hdpublickey.d.cts +240 -0
- package/types/index.d.cts +26 -0
- package/types/interpreter/index.d.cts +2 -0
- package/types/interpreter/interpreter.d.cts +228 -0
- package/types/interpreter/stack.d.cts +35 -0
- package/types/message/message.d.cts +110 -0
- package/types/mnemonic/index.d.cts +2 -0
- package/types/mnemonic/mnemonic.d.cts +171 -0
- package/types/mnemonic/pbkdf2.d.cts +14 -0
- package/types/mnemonic/words/chinese.d.cts +2 -0
- package/types/mnemonic/words/english.d.cts +2 -0
- package/types/mnemonic/words/french.d.cts +2 -0
- package/types/mnemonic/words/index.d.cts +22 -0
- package/types/mnemonic/words/italian.d.cts +2 -0
- package/types/mnemonic/words/japanese.d.cts +2 -0
- package/types/mnemonic/words/spanish.d.cts +2 -0
- package/types/network.d.cts +11 -0
- package/types/networks.d.cts +76 -0
- package/types/opcode.d.cts +93 -0
- package/types/privatekey.d.cts +169 -0
- package/types/publickey.d.cts +202 -0
- package/types/script/index.d.cts +2 -0
- package/types/script/script.d.cts +449 -0
- package/types/script/write-i32-le.d.cts +2 -0
- package/types/script/write-push-data.d.cts +2 -0
- package/types/script/write-u16-le.d.cts +2 -0
- package/types/script/write-u32-le.d.cts +2 -0
- package/types/script/write-u64-le.d.cts +2 -0
- package/types/script/write-u8-le.d.cts +2 -0
- package/types/script/write-varint.d.cts +2 -0
- package/types/transaction/index.d.cts +2 -0
- package/types/transaction/input/index.d.cts +2 -0
- package/types/transaction/input/input.d.cts +178 -0
- package/types/transaction/input/multisig.d.cts +127 -0
- package/types/transaction/input/publickey.d.cts +44 -0
- package/types/transaction/input/publickeyhash.d.cts +45 -0
- package/types/transaction/output.d.cts +118 -0
- package/types/transaction/sighash.d.cts +61 -0
- package/types/transaction/signature.d.cts +43 -0
- package/types/transaction/transaction.d.cts +716 -0
- package/types/transaction/unspentoutput.d.cts +83 -0
- package/types/util/_.d.cts +26 -0
- package/types/util/derivation.d.cts +21 -0
- package/types/util/index.d.cts +5 -0
- package/types/util/js.d.cts +50 -0
- package/types/util/preconditions.d.cts +3 -0
- package/index.d.ts +0 -1541
- package/index.js +0 -74
- package/lib/block/index.js +0 -4
- package/lib/bn.js +0 -3423
- package/lib/crypto/hash.js +0 -2
- package/lib/crypto/random.browser.js +0 -28
- package/lib/crypto/random.js +0 -2
- package/lib/crypto/random.node.js +0 -11
- package/lib/encoding/base58check.js +0 -121
- package/lib/encoding/bufferreader.js +0 -212
- package/lib/encoding/bufferwriter.js +0 -140
- package/lib/encoding/varint.js +0 -75
- package/lib/hash-cache.js +0 -50
- package/lib/mnemonic/pbkdf2.js +0 -2
- package/lib/mnemonic/words/index.js +0 -8
- package/lib/script/index.js +0 -5
- package/lib/transaction/index.js +0 -7
- package/lib/transaction/input/index.js +0 -5
- package/lib/util/js.js +0 -90
- /package/{lib/encoding/decode-script-chunks.js → cjs/encoding/decode-script-chunks.cjs} +0 -0
- /package/{lib/encoding/encode-hex.js → cjs/encoding/encode-hex.cjs} +0 -0
- /package/{lib/encoding/is-hex.js → cjs/encoding/is-hex.cjs} +0 -0
- /package/{lib/mnemonic/words/chinese.js → cjs/mnemonic/words/chinese.cjs} +0 -0
- /package/{lib/mnemonic/words/english.js → cjs/mnemonic/words/english.cjs} +0 -0
- /package/{lib/mnemonic/words/french.js → cjs/mnemonic/words/french.cjs} +0 -0
- /package/{lib/mnemonic/words/italian.js → cjs/mnemonic/words/italian.cjs} +0 -0
- /package/{lib/mnemonic/words/japanese.js → cjs/mnemonic/words/japanese.cjs} +0 -0
- /package/{lib/mnemonic/words/spanish.js → cjs/mnemonic/words/spanish.cjs} +0 -0
- /package/{lib/script/write-i32-le.js → cjs/script/write-i32-le.cjs} +0 -0
- /package/{lib/script/write-push-data.js → cjs/script/write-push-data.cjs} +0 -0
- /package/{lib/script/write-u16-le.js → cjs/script/write-u16-le.cjs} +0 -0
- /package/{lib/script/write-u32-le.js → cjs/script/write-u32-le.cjs} +0 -0
- /package/{lib/script/write-u64-le.js → cjs/script/write-u64-le.cjs} +0 -0
- /package/{lib/script/write-u8-le.js → cjs/script/write-u8-le.cjs} +0 -0
- /package/{lib/script/write-varint.js → cjs/script/write-varint.cjs} +0 -0
- /package/{lib/util/_.js → cjs/util/_.cjs} +0 -0
- /package/test/crypto/{bn.js → bn.cjs} +0 -0
- /package/test/crypto/{hash.js → hash.cjs} +0 -0
- /package/test/crypto/{point.js → point.cjs} +0 -0
- /package/test/crypto/{random.js → random.cjs} +0 -0
- /package/test/data/{blk86756-testnet.js → blk86756-testnet.cjs} +0 -0
- /package/test/data/{merkleblocks.js → merkleblocks.cjs} +0 -0
- /package/test/encoding/{base58.js → base58.cjs} +0 -0
- /package/test/encoding/{base58check.js → base58check.cjs} +0 -0
- /package/test/encoding/{bufferreader.js → bufferreader.cjs} +0 -0
- /package/test/encoding/{bufferwriter.js → bufferwriter.cjs} +0 -0
- /package/test/encoding/{varint.js → varint.cjs} +0 -0
- /package/test/{index.js → index.cjs} +0 -0
- /package/test/message/{message.js → message.cjs} +0 -0
- /package/test/mnemonic/{mnemonic.js → mnemonic.cjs} +0 -0
- /package/test/{opcode.js → opcode.cjs} +0 -0
- /package/test/{privatekey.js → privatekey.cjs} +0 -0
- /package/test/transaction/input/{publickey.js → publickey.cjs} +0 -0
- /package/test/transaction/{output.js → output.cjs} +0 -0
- /package/test/transaction/{signature.js → signature.cjs} +0 -0
- /package/test/transaction/{unspentoutput.js → unspentoutput.cjs} +0 -0
- /package/test/util/{js.js → js.cjs} +0 -0
- /package/test/util/{preconditions.js → preconditions.cjs} +0 -0
|
@@ -1435,7 +1435,7 @@
|
|
|
1435
1435
|
"'a' 'zngyivniryrgefgnvqwfwqplmramujzilzyrsdvinxfkfmuowdpuzycnzbupwwpzrfxsbyrhdlsyixyzysodseayvvrtbsfxtikrjwkbduulrjyjlwlaigomhyohsukawdwbrpuacdijzzgxhataguajvuopuktvtklwhsxqvzzfttpdgnxtnbpsiqecxurlczqmoxznlsuejvneiyejetcxlblzrydscnrbydnqytorstjtuzlbbtbyzfiniuehbisqnqhvexylhohjiyiknzgjowvobsrwcxyfowqcvakgdolwpltfcxtrhuysrrvtprzpsucgogsjapdkrbobpxccqgkdumskaleycwsbkabdkuukqiyizceduplmauszwjdzptvmthxocwrignxjogxsvrsjrrlecvdmazlpfkgmskiqqitrevuwiisvpxvkeypzaqjwwiozvmahmtvtjpbolwrymvzfstopzcexalirwbbcqgjvfjfuirrcnlgcfyqnafhh'",
|
|
1436
1436
|
"CAT",
|
|
1437
1437
|
"P2SH,STRICTENC,MONOLITH_OPCODES",
|
|
1438
|
-
"
|
|
1438
|
+
"OK",
|
|
1439
1439
|
"CAT oversized result"
|
|
1440
1440
|
],
|
|
1441
1441
|
|
|
@@ -1563,8 +1563,8 @@
|
|
|
1563
1563
|
"-42 521",
|
|
1564
1564
|
"NUM2BIN",
|
|
1565
1565
|
"P2SH,STRICTENC,MONOLITH_OPCODES",
|
|
1566
|
-
"
|
|
1567
|
-
"Pushing 521 bytes is
|
|
1566
|
+
"OK",
|
|
1567
|
+
"Pushing 521 bytes is OK"
|
|
1568
1568
|
],
|
|
1569
1569
|
["-42 -3", "NUM2BIN", "P2SH,STRICTENC,MONOLITH_OPCODES", "PUSH_SIZE", "Negative size"],
|
|
1570
1570
|
[
|
|
@@ -2670,14 +2670,14 @@
|
|
|
2670
2670
|
"NOP",
|
|
2671
2671
|
"'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'",
|
|
2672
2672
|
"P2SH,STRICTENC",
|
|
2673
|
-
"
|
|
2673
|
+
"OK",
|
|
2674
2674
|
">520 byte push"
|
|
2675
2675
|
],
|
|
2676
2676
|
[
|
|
2677
2677
|
"0",
|
|
2678
2678
|
"IF 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' ENDIF 1",
|
|
2679
2679
|
"P2SH,STRICTENC",
|
|
2680
|
-
"
|
|
2680
|
+
"OK",
|
|
2681
2681
|
">520 byte push in non-executed IF branch"
|
|
2682
2682
|
],
|
|
2683
2683
|
[
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
// * store test vectors at the end, latedef: false
|
|
7
7
|
// * should call is never defined
|
|
8
8
|
|
|
9
|
-
var _ = require('../lib/util/_');
|
|
10
9
|
require('chai').should();
|
|
11
10
|
var expect = require('chai').expect;
|
|
12
11
|
var sinon = require('sinon');
|
|
13
12
|
var opcat = require('..');
|
|
13
|
+
var _ = opcat.util._;
|
|
14
14
|
var Networks = opcat.Networks;
|
|
15
15
|
var HDPrivateKey = opcat.HDPrivateKey;
|
|
16
16
|
var HDPublicKey = opcat.HDPublicKey;
|
|
@@ -57,7 +57,9 @@ describe('BIP32 compliance', function () {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('can initialize a public key from an extended private key', function () {
|
|
60
|
-
|
|
60
|
+
expect(()=> {
|
|
61
|
+
new HDPublicKey(vector1MPrivate)
|
|
62
|
+
}).to.throw(/Argument is an extended private key/)
|
|
61
63
|
});
|
|
62
64
|
|
|
63
65
|
it('toString should be equal to the `xpubkey` member', function () {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _ = require('../lib/util/_');
|
|
4
3
|
var assert = require('assert');
|
|
5
4
|
var should = require('chai').should();
|
|
6
5
|
var expect = require('chai').expect;
|
|
7
6
|
var opcat = require('..');
|
|
7
|
+
var _ = opcat.util._;
|
|
8
8
|
var errors = opcat.errors;
|
|
9
9
|
var hdErrors = errors.HDPrivateKey;
|
|
10
10
|
var buffer = require('buffer');
|
|
11
11
|
var Networks = opcat.Networks;
|
|
12
|
-
var JSUtil =
|
|
12
|
+
var JSUtil = opcat.util.js;
|
|
13
|
+
var Derivation = opcat.util.derivation;
|
|
13
14
|
var HDPrivateKey = opcat.HDPrivateKey;
|
|
14
15
|
var Base58Check = opcat.encoding.Base58Check;
|
|
15
16
|
|
|
@@ -237,20 +238,20 @@ describe('HDPrivate key interface', function () {
|
|
|
237
238
|
invalid.forEach(function (datum) {
|
|
238
239
|
it('rejects illegal path ' + datum, function () {
|
|
239
240
|
HDPrivateKey.isValidPath(datum).should.equal(false);
|
|
240
|
-
expect(
|
|
241
|
+
expect(Derivation.getDerivationIndexes(datum)).to.equal(null);
|
|
241
242
|
});
|
|
242
243
|
});
|
|
243
244
|
|
|
244
245
|
it('generates deriving indexes correctly', function () {
|
|
245
246
|
var indexes;
|
|
246
247
|
|
|
247
|
-
indexes =
|
|
248
|
+
indexes = Derivation.getDerivationIndexes('m/-1/12');
|
|
248
249
|
expect(indexes).to.equal(null);
|
|
249
250
|
|
|
250
|
-
indexes =
|
|
251
|
+
indexes = Derivation.getDerivationIndexes("m/0/12/12'");
|
|
251
252
|
indexes.should.eql([0, 12, HDPrivateKey.Hardened + 12]);
|
|
252
253
|
|
|
253
|
-
indexes =
|
|
254
|
+
indexes = Derivation.getDerivationIndexes("m/0/12/12'");
|
|
254
255
|
indexes.should.eql([0, 12, HDPrivateKey.Hardened + 12]);
|
|
255
256
|
});
|
|
256
257
|
});
|
|
@@ -7,7 +7,7 @@ var opcat = require('..');
|
|
|
7
7
|
var buffer = require('buffer');
|
|
8
8
|
var errors = opcat.errors;
|
|
9
9
|
var hdErrors = opcat.errors.HDPublicKey;
|
|
10
|
-
var JSUtil =
|
|
10
|
+
var JSUtil = opcat.util.js;
|
|
11
11
|
var HDPrivateKey = opcat.HDPrivateKey;
|
|
12
12
|
var HDPublicKey = opcat.HDPublicKey;
|
|
13
13
|
var Base58Check = opcat.encoding.Base58Check;
|
|
@@ -50,11 +50,6 @@ describe('HDPublicKey interface', function () {
|
|
|
50
50
|
publicKey.should.equal(new HDPublicKey(publicKey));
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
it('returns the correct xpubkey for a xprivkey', function () {
|
|
54
|
-
var publicKey = new HDPublicKey(xprivkey);
|
|
55
|
-
publicKey.xpubkey.should.equal(xpubkey);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
53
|
it('allows to call the argument with no "new" keyword', function () {
|
|
59
54
|
HDPublicKey(xpubkey).xpubkey.should.equal(new HDPublicKey(xpubkey).xpubkey);
|
|
60
55
|
});
|
|
@@ -64,7 +59,7 @@ describe('HDPublicKey interface', function () {
|
|
|
64
59
|
});
|
|
65
60
|
|
|
66
61
|
it('should not be able to change read-only properties', function () {
|
|
67
|
-
var publicKey =
|
|
62
|
+
var publicKey = HDPublicKey(xpubkey);
|
|
68
63
|
expect(function () {
|
|
69
64
|
publicKey.fingerPrint = 'notafingerprint';
|
|
70
65
|
}).to.throw(TypeError);
|
|
@@ -11,7 +11,7 @@ describe('Networks', function () {
|
|
|
11
11
|
it('should contain all Networks', function () {
|
|
12
12
|
should.exist(networks.livenet);
|
|
13
13
|
should.exist(networks.testnet);
|
|
14
|
-
should.exist(networks.
|
|
14
|
+
should.exist(networks.regtest);
|
|
15
15
|
should.exist(networks.defaultNetwork);
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -45,11 +45,6 @@ describe('Networks', function () {
|
|
|
45
45
|
Buffer.isBuffer(testnet.networkMagic).should.equal(true);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('should have network magic for stn', function () {
|
|
49
|
-
var stn = networks.get('stn');
|
|
50
|
-
Buffer.isBuffer(stn.networkMagic).should.equal(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
48
|
it('can remove a custom network', function () {
|
|
54
49
|
networks.remove(customnet);
|
|
55
50
|
var net = networks.get('customnet');
|
|
@@ -80,10 +75,10 @@ describe('Networks', function () {
|
|
|
80
75
|
var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey'];
|
|
81
76
|
|
|
82
77
|
constants.forEach(function (key) {
|
|
83
|
-
it('should have constant ' + key + ' for livenet, testnet and
|
|
78
|
+
it('should have constant ' + key + ' for livenet, testnet and regtest', function () {
|
|
84
79
|
networks.testnet.hasOwnProperty(key).should.equal(true);
|
|
85
80
|
networks.livenet.hasOwnProperty(key).should.equal(true);
|
|
86
|
-
networks.
|
|
81
|
+
networks.regtest.hasOwnProperty(key).should.equal(true);
|
|
87
82
|
});
|
|
88
83
|
});
|
|
89
84
|
|
|
@@ -106,44 +101,30 @@ describe('Networks', function () {
|
|
|
106
101
|
expect(networks.get('testnet').name).to.equal('testnet');
|
|
107
102
|
});
|
|
108
103
|
|
|
109
|
-
it('should have stn network', function () {
|
|
110
|
-
expect(networks.get('stn').name).to.equal('stn');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
104
|
it('should have livenet network', function () {
|
|
114
105
|
expect(networks.get('livenet').name).to.equal('livenet');
|
|
115
106
|
});
|
|
116
107
|
|
|
117
|
-
it('should have
|
|
118
|
-
expect(networks.get('testnet').cashAddrPrefix).to.equal('
|
|
108
|
+
it('should have opcattest cashAddrPrefix', function () {
|
|
109
|
+
expect(networks.get('testnet').cashAddrPrefix).to.equal('opcattest');
|
|
119
110
|
});
|
|
120
111
|
|
|
121
|
-
it('should have
|
|
122
|
-
expect(networks.get('regtest').cashAddrPrefix).to.equal('
|
|
112
|
+
it('should have opcatreg cashAddrPrefix', function () {
|
|
113
|
+
expect(networks.get('regtest').cashAddrPrefix).to.equal('opcatreg');
|
|
123
114
|
});
|
|
124
115
|
|
|
125
|
-
it('should have
|
|
116
|
+
it('should have opcatreg cashAddrPrefix after enableRegtest is called', function () {
|
|
126
117
|
var network = networks.get('testnet');
|
|
127
118
|
networks.enableRegtest();
|
|
128
|
-
expect(network.cashAddrPrefix).to.equal('
|
|
119
|
+
expect(network.cashAddrPrefix).to.equal('opcatreg');
|
|
129
120
|
});
|
|
130
121
|
|
|
131
|
-
it('should have
|
|
122
|
+
it('should have opcattest cashAddrPrefix after disableRegtest is called', function () {
|
|
132
123
|
var network = networks.get('testnet');
|
|
133
124
|
networks.disableRegtest();
|
|
134
|
-
expect(network.cashAddrPrefix).to.equal('
|
|
135
|
-
});
|
|
136
|
-
it('should have opcatstn cashAddrPrefix after enableStn is called', function () {
|
|
137
|
-
var network = networks.get('testnet');
|
|
138
|
-
networks.enableStn();
|
|
139
|
-
expect(network.cashAddrPrefix).to.equal('opcatstn');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should have bchtest cashAddrPrefix after disableStn is called', function () {
|
|
143
|
-
var network = networks.get('testnet');
|
|
144
|
-
networks.disableStn();
|
|
145
|
-
expect(network.cashAddrPrefix).to.equal('bchtest');
|
|
125
|
+
expect(network.cashAddrPrefix).to.equal('opcattest');
|
|
146
126
|
});
|
|
127
|
+
|
|
147
128
|
|
|
148
129
|
it('converts to string using the "name" property', function () {
|
|
149
130
|
networks.livenet.toString().should.equal('livenet');
|
|
@@ -46,7 +46,7 @@ describe('PublicKey', function () {
|
|
|
46
46
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
|
|
47
47
|
var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
|
|
48
48
|
var privkey = new PrivateKey(new BN(Buffer.from(privhex, 'hex')));
|
|
49
|
-
var pk =
|
|
49
|
+
var pk = privkey.toPublicKey();
|
|
50
50
|
pk.toString().should.equal(pubhex);
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -512,7 +512,7 @@ describe('PublicKey', function () {
|
|
|
512
512
|
|
|
513
513
|
it('should output known compressed pubkey with network for console', function () {
|
|
514
514
|
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
|
|
515
|
-
var pubkey =
|
|
515
|
+
var pubkey = privkey.toPublicKey();
|
|
516
516
|
pubkey
|
|
517
517
|
.inspect()
|
|
518
518
|
.should.equal(
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var should = require('chai').should();
|
|
4
4
|
var opcat = require('../../');
|
|
5
|
-
var Interpreter = opcat.
|
|
5
|
+
var Interpreter = opcat.Interpreter;
|
|
6
6
|
var Transaction = opcat.Transaction;
|
|
7
7
|
var PrivateKey = opcat.PrivateKey;
|
|
8
8
|
var Script = opcat.Script;
|
|
9
9
|
var BN = opcat.crypto.BN;
|
|
10
10
|
var BufferWriter = opcat.encoding.BufferWriter;
|
|
11
11
|
var Opcode = opcat.Opcode;
|
|
12
|
-
var _ =
|
|
12
|
+
var _ = opcat.util._;
|
|
13
13
|
|
|
14
|
-
var scriptTests = require('../data/bitcoind/script_tests');
|
|
15
|
-
var txValid = require('../data/bitcoind/tx_valid');
|
|
16
|
-
var txInvalid = require('../data/bitcoind/tx_invalid');
|
|
14
|
+
var scriptTests = require('../data/bitcoind/script_tests.json');
|
|
15
|
+
var txValid = require('../data/bitcoind/tx_valid.json');
|
|
16
|
+
var txInvalid = require('../data/bitcoind/tx_invalid.json');
|
|
17
17
|
|
|
18
18
|
// the script string format used in bitcoind data tests
|
|
19
19
|
Script.fromBitcoindString = function (str) {
|
|
@@ -1349,7 +1349,10 @@ describe('Script', function () {
|
|
|
1349
1349
|
});
|
|
1350
1350
|
|
|
1351
1351
|
it('fails if content is not recognized', function () {
|
|
1352
|
-
|
|
1352
|
+
expect(function () {
|
|
1353
|
+
Script().toAddress(Networks.livenet)
|
|
1354
|
+
}).to.throw(/Can't derive address associated with script:/);
|
|
1355
|
+
|
|
1353
1356
|
});
|
|
1354
1357
|
|
|
1355
1358
|
it('works for p2pkh output', function () {
|
|
@@ -1376,7 +1379,10 @@ describe('Script', function () {
|
|
|
1376
1379
|
// no address scripts
|
|
1377
1380
|
it('works for OP_RETURN script', function () {
|
|
1378
1381
|
var script = new Script('OP_RETURN 20 0x99d29051af0c29adcb9040034752bba7dde33e35');
|
|
1379
|
-
|
|
1382
|
+
expect(function () {
|
|
1383
|
+
script.toAddress()
|
|
1384
|
+
}).to.throw(/Can't derive address associated with script: OP_RETURN 20 0x99d29051af0c29adcb9040034752bba7dde33e35, needs to be p2pkh in, p2pkh out/);
|
|
1385
|
+
|
|
1380
1386
|
});
|
|
1381
1387
|
});
|
|
1382
1388
|
describe('equals', function () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
var Transaction =
|
|
2
|
+
var opcat = require('../../')
|
|
3
|
+
var Transaction = opcat.Transaction;
|
|
4
4
|
|
|
5
5
|
var vectorsValid = require('../data/bitcoind/tx_valid.json');
|
|
6
6
|
var vectorsInvalid = require('../data/bitcoind/tx_invalid.json');
|
|
@@ -13,7 +13,7 @@ var Input = opcat.Transaction.Input;
|
|
|
13
13
|
describe('Transaction.Input', function () {
|
|
14
14
|
var privateKey = new PrivateKey('KwF9LjRraetZuEjR8VqEq539z137LW5anYDUnVK11vM3mNMHTWb4');
|
|
15
15
|
var publicKey = privateKey.publicKey;
|
|
16
|
-
var address = new Address(publicKey, Networks.livenet);
|
|
16
|
+
var address = new Address(publicKey.toBuffer(), Networks.livenet);
|
|
17
17
|
var output = {
|
|
18
18
|
address: '33zbk2aSZYdNbRsMPPt6jgy6Kq1kQreqeb',
|
|
19
19
|
prevTxId: '66e64ef8a3b384164b78453fa8c8194de9a473ba14f89485a0e433699daec140',
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var should = require('chai').should();
|
|
4
|
-
var _ = require('../../../lib/util/_');
|
|
5
4
|
|
|
6
5
|
var opcat = require('../../..');
|
|
7
6
|
var Transaction = opcat.Transaction;
|
|
8
7
|
var PrivateKey = opcat.PrivateKey;
|
|
9
8
|
var Script = opcat.Script;
|
|
10
9
|
var MultiSigInput = opcat.Transaction.Input.MultiSig;
|
|
10
|
+
var _ = opcat.util._;
|
|
11
|
+
|
|
11
12
|
|
|
12
13
|
describe('MultiSigInput', function () {
|
|
13
14
|
var privateKey1 = new PrivateKey('KwF9LjRraetZuEjR8VqEq539z137LW5anYDUnVK11vM3mNMHTWb4');
|
|
@@ -12,7 +12,7 @@ var Networks = opcat.Networks;
|
|
|
12
12
|
describe('PublicKeyHashInput', function () {
|
|
13
13
|
var privateKey = new PrivateKey('KwF9LjRraetZuEjR8VqEq539z137LW5anYDUnVK11vM3mNMHTWb4');
|
|
14
14
|
var publicKey = privateKey.publicKey;
|
|
15
|
-
var address = new Address(publicKey, Networks.livenet);
|
|
15
|
+
var address = new Address(publicKey.toBuffer(), Networks.livenet);
|
|
16
16
|
|
|
17
17
|
var output = {
|
|
18
18
|
address: address.toString(),
|
|
@@ -9,7 +9,7 @@ var Script = opcat.Script;
|
|
|
9
9
|
var BN = opcat.crypto.BN;
|
|
10
10
|
var Transaction = opcat.Transaction;
|
|
11
11
|
var Signature = opcat.crypto.Signature;
|
|
12
|
-
var sighash = Transaction.
|
|
12
|
+
var sighash = Transaction.Sighash;
|
|
13
13
|
|
|
14
14
|
var vectorsSighash = require('../data/sighash.json');
|
|
15
15
|
|
|
@@ -5,7 +5,7 @@ var expect = require('chai').expect;
|
|
|
5
5
|
var sinon = require('sinon');
|
|
6
6
|
|
|
7
7
|
var opcat = require('../..');
|
|
8
|
-
var _ = opcat.
|
|
8
|
+
var _ = opcat.util._
|
|
9
9
|
var BN = opcat.crypto.BN;
|
|
10
10
|
var Transaction = opcat.Transaction;
|
|
11
11
|
var Input = opcat.Transaction.Input;
|
|
@@ -258,8 +258,8 @@ describe('Transaction', function () {
|
|
|
258
258
|
.from(simpleUtxoWith100000Satoshis)
|
|
259
259
|
.addSafeData('genesis is coming')
|
|
260
260
|
.change(changeAddress)
|
|
261
|
+
.feePerKb(50)
|
|
261
262
|
.sign(privateKey);
|
|
262
|
-
// update if change default FEE_PER_KB
|
|
263
263
|
transaction
|
|
264
264
|
.serialize()
|
|
265
265
|
.should.equal(
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"emitDeclarationOnly": true,
|
|
8
|
+
"outDir": "types",
|
|
9
|
+
"strict": false
|
|
10
|
+
},
|
|
11
|
+
"include": ["cjs/**/*.cjs"],
|
|
12
|
+
"exclude": ["node_modules/**/*"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
export = Address;
|
|
2
|
+
/**
|
|
3
|
+
* Instantiate an address from an address String or Buffer, a public key hash Buffer,
|
|
4
|
+
* or a {@link PublicKey} Buffer.
|
|
5
|
+
*
|
|
6
|
+
* This is an immutable class, and if the first parameter provided to this constructor is an
|
|
7
|
+
* `Address` instance, the same argument will be returned.
|
|
8
|
+
*
|
|
9
|
+
* An address has two key properties: `network` and `type`. The type is either
|
|
10
|
+
* `Address.PayToPublicKeyHash` (value is the `'pubkeyhash'` string).
|
|
11
|
+
* The network is an instance of {@link Network}.
|
|
12
|
+
* You can quickly check whether an address is of a given kind by using the methods
|
|
13
|
+
* `isPayToPublicKeyHash`
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```javascript
|
|
17
|
+
* // validate that an input field is valid
|
|
18
|
+
* var error = Address.getValidationError(input, 'testnet');
|
|
19
|
+
* if (!error) {
|
|
20
|
+
* var address = Address(input, 'testnet');
|
|
21
|
+
* } else {
|
|
22
|
+
* // invalid network or checksum (typo?)
|
|
23
|
+
* var message = error.messsage;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // get an address from a public key
|
|
27
|
+
* var address = Address(publicKey, 'testnet').toString();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param {*} data - The encoded data in various formats
|
|
31
|
+
* @param {Network|String|number} [network] - The network: 'livenet' or 'testnet'
|
|
32
|
+
* @param {string} [type] - The type of address: 'pubkey'
|
|
33
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
34
|
+
* @constructor
|
|
35
|
+
*/
|
|
36
|
+
declare function Address(data: any, network?: Network | string | number, type?: string): Address;
|
|
37
|
+
declare class Address {
|
|
38
|
+
/**
|
|
39
|
+
* Instantiate an address from an address String or Buffer, a public key hash Buffer,
|
|
40
|
+
* or a {@link PublicKey} Buffer.
|
|
41
|
+
*
|
|
42
|
+
* This is an immutable class, and if the first parameter provided to this constructor is an
|
|
43
|
+
* `Address` instance, the same argument will be returned.
|
|
44
|
+
*
|
|
45
|
+
* An address has two key properties: `network` and `type`. The type is either
|
|
46
|
+
* `Address.PayToPublicKeyHash` (value is the `'pubkeyhash'` string).
|
|
47
|
+
* The network is an instance of {@link Network}.
|
|
48
|
+
* You can quickly check whether an address is of a given kind by using the methods
|
|
49
|
+
* `isPayToPublicKeyHash`
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```javascript
|
|
53
|
+
* // validate that an input field is valid
|
|
54
|
+
* var error = Address.getValidationError(input, 'testnet');
|
|
55
|
+
* if (!error) {
|
|
56
|
+
* var address = Address(input, 'testnet');
|
|
57
|
+
* } else {
|
|
58
|
+
* // invalid network or checksum (typo?)
|
|
59
|
+
* var message = error.messsage;
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* // get an address from a public key
|
|
63
|
+
* var address = Address(publicKey, 'testnet').toString();
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param {*} data - The encoded data in various formats
|
|
67
|
+
* @param {Network|String|number} [network] - The network: 'livenet' or 'testnet'
|
|
68
|
+
* @param {string} [type] - The type of address: 'pubkey'
|
|
69
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
70
|
+
* @constructor
|
|
71
|
+
*/
|
|
72
|
+
constructor(data: any, network?: Network | string | number, type?: string);
|
|
73
|
+
get hashBuffer(): any;
|
|
74
|
+
get network(): any;
|
|
75
|
+
get type(): any;
|
|
76
|
+
private _classifyArguments;
|
|
77
|
+
/**
|
|
78
|
+
* Returns true if an address is of pay to public key hash type
|
|
79
|
+
* @return boolean
|
|
80
|
+
*/
|
|
81
|
+
isPayToPublicKeyHash(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Will return a buffer representation of the address
|
|
84
|
+
*
|
|
85
|
+
* @returns {Buffer} Bitcoin address buffer
|
|
86
|
+
*/
|
|
87
|
+
toBuffer(): Buffer;
|
|
88
|
+
/**
|
|
89
|
+
* Converts the address to a hexadecimal string representation.
|
|
90
|
+
* @returns {string} The hexadecimal string representation of the address.
|
|
91
|
+
*/
|
|
92
|
+
toHex(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Converts the address to a publickey hash string representation.
|
|
95
|
+
* @returns {string} The hexadecimal string of the publickey hash buffer.
|
|
96
|
+
*/
|
|
97
|
+
toPublickeyHash(): string;
|
|
98
|
+
/**
|
|
99
|
+
* @returns {Object} A plain object with the address information
|
|
100
|
+
*/
|
|
101
|
+
toObject: () => any;
|
|
102
|
+
toJSON(): any;
|
|
103
|
+
/**
|
|
104
|
+
* Will return a string formatted for the console
|
|
105
|
+
*
|
|
106
|
+
* @returns {string} Bitcoin address
|
|
107
|
+
*/
|
|
108
|
+
inspect(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Will return a the base58 string representation of the address
|
|
111
|
+
*
|
|
112
|
+
* @returns {string} Bitcoin address
|
|
113
|
+
*/
|
|
114
|
+
toString(): string;
|
|
115
|
+
}
|
|
116
|
+
declare namespace Address {
|
|
117
|
+
let PayToPublicKeyHash: string;
|
|
118
|
+
/**
|
|
119
|
+
* @param {Buffer} hash - An instance of a hash Buffer
|
|
120
|
+
* @returns {Object} An object with keys: hashBuffer
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
function _transformHash(hash: Buffer): any;
|
|
124
|
+
/**
|
|
125
|
+
* Deserializes an address serialized through `Address#toObject()`
|
|
126
|
+
* @param {Object} data
|
|
127
|
+
* @param {string} data.hash - the hash that this address encodes
|
|
128
|
+
* @param {string} data.type - either 'pubkeyhash' or 'scripthash'
|
|
129
|
+
* @param {Network=} data.network - the name of the network associated
|
|
130
|
+
* @return {Address}
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
function _transformObject(data: {
|
|
134
|
+
hash: string;
|
|
135
|
+
type: string;
|
|
136
|
+
network?: Network;
|
|
137
|
+
}): Address;
|
|
138
|
+
/**
|
|
139
|
+
* Internal function to discover the network and type based on the first data byte
|
|
140
|
+
*
|
|
141
|
+
* @param {Buffer} buffer - An instance of a hex encoded address Buffer
|
|
142
|
+
* @returns {Object} An object with keys: network and type
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
function _classifyFromVersion(buffer: Buffer): any;
|
|
146
|
+
/**
|
|
147
|
+
* Internal function to transform a bitcoin address buffer
|
|
148
|
+
*
|
|
149
|
+
* @param {Buffer} buffer - An instance of a hex encoded address Buffer
|
|
150
|
+
* @param {string=} network - The network: 'livenet' or 'testnet'
|
|
151
|
+
* @param {string=} type - The type: 'pubkeyhash' or 'scripthash'
|
|
152
|
+
* @returns {Object} An object with keys: hashBuffer, network and type
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
function _transformBuffer(buffer: Buffer, network?: string, type?: string): any;
|
|
156
|
+
/**
|
|
157
|
+
* Internal function to transform a {@link PublicKey}
|
|
158
|
+
*
|
|
159
|
+
* @param {PublicKey} pubkey - An instance of PublicKey
|
|
160
|
+
* @returns {Object} An object with keys: hashBuffer, type
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
function _transformPublicKey(pubkey: PublicKey): any;
|
|
164
|
+
/**
|
|
165
|
+
* Internal function to transform a bitcoin cash address string
|
|
166
|
+
*
|
|
167
|
+
* @param {string} data
|
|
168
|
+
* @param {String|Network=} network - either a Network instance, 'livenet', or 'testnet'
|
|
169
|
+
* @param {string=} type - The type: 'pubkeyhash'
|
|
170
|
+
* @returns {Object} An object with keys: hashBuffer, network and type
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
function _transformString(data: string, network?: any, type?: string): any;
|
|
174
|
+
/**
|
|
175
|
+
* Instantiate an address from a PublicKey buffer
|
|
176
|
+
*
|
|
177
|
+
* @param {Buffer} data - A buffer of the public key
|
|
178
|
+
* @param {String|Network} network - either a Network instance, 'livenet', or 'testnet'
|
|
179
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
180
|
+
*/
|
|
181
|
+
function fromPublicKey(data: Buffer, network: any): Address;
|
|
182
|
+
/**
|
|
183
|
+
* Instantiate an address from a ripemd160 public key hash
|
|
184
|
+
*
|
|
185
|
+
* @param {Buffer} hash - An instance of buffer of the hash
|
|
186
|
+
* @param {String|Network} network - either a Network instance, 'livenet', or 'testnet'
|
|
187
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
188
|
+
*/
|
|
189
|
+
function fromPublicKeyHash(hash: Buffer, network: any): Address;
|
|
190
|
+
/**
|
|
191
|
+
* Instantiate an address from a bitcoin address buffer
|
|
192
|
+
*
|
|
193
|
+
* @param {Buffer} buffer - An instance of buffer of the address
|
|
194
|
+
* @param {String|Network=} network - either a Network instance, 'livenet', or 'testnet'
|
|
195
|
+
* @param {string=} type - The type of address: 'pubkey'
|
|
196
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
197
|
+
*/
|
|
198
|
+
function fromBuffer(buffer: Buffer, network?: any, type?: string): Address;
|
|
199
|
+
/**
|
|
200
|
+
* Creates an Address instance from a hex string.
|
|
201
|
+
* @param {string} hex - The hex string representation of the address.
|
|
202
|
+
* @param {Network} network - The network type (e.g., 'mainnet', 'testnet').
|
|
203
|
+
* @param {AddressType} [type] - Optional address type.
|
|
204
|
+
* @returns {Address} The Address instance created from the hex string.
|
|
205
|
+
*/
|
|
206
|
+
function fromHex(hex: string, network: Network, type?: AddressType): Address;
|
|
207
|
+
/**
|
|
208
|
+
* Instantiate an address from an address string
|
|
209
|
+
*
|
|
210
|
+
* @param {string} str - An string of the bitcoin address
|
|
211
|
+
* @param {String|Network=} network - either a Network instance, 'livenet', or 'testnet'
|
|
212
|
+
* @param {string=} type - The type of address: 'pubkey'
|
|
213
|
+
* @returns {Address} A new valid and frozen instance of an Address
|
|
214
|
+
*/
|
|
215
|
+
function fromString(str: string, network?: any, type?: string): Address;
|
|
216
|
+
/**
|
|
217
|
+
* Instantiate an address from an Object
|
|
218
|
+
*
|
|
219
|
+
* @param {string} json - An JSON string or Object with keys: hash, network and type
|
|
220
|
+
* @returns {Address} A new valid instance of an Address
|
|
221
|
+
*/
|
|
222
|
+
function fromObject(obj: any): Address;
|
|
223
|
+
/**
|
|
224
|
+
* Will return a validation error if exists
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```javascript
|
|
228
|
+
* // a network mismatch error
|
|
229
|
+
* var error = Address.getValidationError('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'testnet');
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @param {string} data - The encoded data
|
|
233
|
+
* @param {String|Network} network - either a Network instance, 'livenet', or 'testnet'
|
|
234
|
+
* @param {string} type - The type of address: 'pubkey'
|
|
235
|
+
* @returns {null|Error} The corresponding error message
|
|
236
|
+
*/
|
|
237
|
+
function getValidationError(data: string, network: any, type: string): Error;
|
|
238
|
+
/**
|
|
239
|
+
* Will return a boolean if an address is valid
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```javascript
|
|
243
|
+
* assert(Address.isValid('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'livenet'));
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* @param {string} data - The encoded data
|
|
247
|
+
* @param {String|Network} network - either a Network instance, 'livenet', or 'testnet'
|
|
248
|
+
* @param {string} type - The type of address: 'pubkey'
|
|
249
|
+
* @returns {boolean} The corresponding error message
|
|
250
|
+
*/
|
|
251
|
+
function isValid(data: string, network: any, type: string): boolean;
|
|
252
|
+
}
|