@smartledger/bsv 9.0.0 → 9.1.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/CHANGELOG.md +137 -0
- package/README.md +152 -1041
- package/STABILITY.md +134 -0
- package/bsv-gdaf.min.js +53 -48
- package/bsv-ltp.min.js +23 -18
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +53 -48
- package/bsv.min.js +53 -48
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/docs/proposals/10.0.0-package-split.md +131 -0
- package/index.js +5 -0
- package/lib/block/merkleblock.js +19 -5
- package/lib/hdprivatekey.js +15 -0
- package/lib/script/interpreter.js +109 -1
- package/lib/smart_contract/builder.js +14 -0
- package/lib/util/deprecate.js +159 -0
- package/package.json +19 -82
- package/version.js +1 -1
- package/.mocharc.json +0 -5
- package/test/address.js +0 -629
- package/test/block/block.js +0 -239
- package/test/block/blockheader.js +0 -270
- package/test/block/merkleblock.js +0 -207
- package/test/build/bundle_crypto_shim.js +0 -104
- package/test/build/bundle_externals.js +0 -125
- package/test/build/bundle_smoke.js +0 -55
- package/test/build/esbuild_main.js +0 -65
- package/test/build/esm_wrapper.js +0 -97
- package/test/build/exports_resolution.js +0 -84
- package/test/build/version_sync.js +0 -14
- package/test/cli/smoke.js +0 -261
- package/test/consensus/base58-vectors.js +0 -120
- package/test/consensus/sv-script-vectors.js +0 -81
- package/test/consensus/sv-sighash-vectors.js +0 -51
- package/test/consensus/sv-tx-vectors.js +0 -48
- package/test/credentials-test.js +0 -332
- package/test/crypto/backend_selection.js +0 -126
- package/test/crypto/bn.js +0 -168
- package/test/crypto/ecdsa.js +0 -426
- package/test/crypto/elliptic-fixed.js +0 -61
- package/test/crypto/hash.browser.js +0 -121
- package/test/crypto/hash.js +0 -122
- package/test/crypto/point.js +0 -193
- package/test/crypto/random.js +0 -105
- package/test/crypto/security.js +0 -176
- package/test/crypto/shamir.js +0 -177
- package/test/crypto/shamir_rngcap.js +0 -29
- package/test/crypto/signature.js +0 -399
- package/test/data/bip69.json +0 -215
- package/test/data/bitcoin-sv/README.md +0 -170
- package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
- package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
- package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
- package/test/data/bitcoin-sv/script_tests.json +0 -2591
- package/test/data/bitcoin-sv/sighash.json +0 -1003
- package/test/data/bitcoin-sv/tx_invalid.json +0 -285
- package/test/data/bitcoin-sv/tx_valid.json +0 -367
- package/test/data/bitcoind/base58_keys_invalid.json +0 -152
- package/test/data/bitcoind/base58_keys_valid.json +0 -452
- package/test/data/bitcoind/blocks.json +0 -27
- package/test/data/bitcoind/script_tests.json +0 -2244
- package/test/data/bitcoind/sig_canonical.json +0 -7
- package/test/data/bitcoind/sig_noncanonical.json +0 -22
- package/test/data/bitcoind/tx_invalid.json +0 -177
- package/test/data/bitcoind/tx_valid.json +0 -224
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +0 -12
- package/test/data/blk86756-testnet.json +0 -684
- package/test/data/brc220-batch-vector.json +0 -129
- package/test/data/ecdsa.json +0 -230
- package/test/data/merkleblocks.js +0 -486
- package/test/data/messages.json +0 -22
- package/test/data/sighash.json +0 -1004
- package/test/data/tx_creation.json +0 -85
- package/test/didweb/relationships.js +0 -144
- package/test/ecies/bitcore-ecies.js +0 -178
- package/test/ecies/electrum-ecies.js +0 -206
- package/test/encoding/base58.js +0 -131
- package/test/encoding/base58check.js +0 -145
- package/test/encoding/bufferreader.js +0 -328
- package/test/encoding/bufferwriter.js +0 -160
- package/test/encoding/varint.js +0 -104
- package/test/gdaf/anchor_no_key_leak.js +0 -146
- package/test/gdaf/anchor_spv.js +0 -163
- package/test/gdaf/canonicalization.js +0 -106
- package/test/gdaf/canonicalize.js +0 -140
- package/test/gdaf/zk_prover.js +0 -204
- package/test/hdkeys.js +0 -365
- package/test/hdprivatekey.js +0 -339
- package/test/hdpublickey.js +0 -293
- package/test/index.js +0 -16
- package/test/ltp/ids.js +0 -74
- package/test/ltp/right.js +0 -198
- package/test/ltp/verify_failclosed.js +0 -134
- package/test/message/message.js +0 -190
- package/test/mnemonic/data/fixtures.json +0 -300
- package/test/mnemonic/mnemonic.js +0 -277
- package/test/mnemonic/mocha.opts +0 -1
- package/test/mnemonic/pbkdf2.test.js +0 -43
- package/test/networks.js +0 -207
- package/test/notaryhash/batch_leaf.js +0 -140
- package/test/notaryhash/batch_vector.js +0 -282
- package/test/notaryhash/certificate.js +0 -249
- package/test/notaryhash/encoding.js +0 -186
- package/test/notaryhash/interop.js +0 -112
- package/test/notaryhash/merkle.js +0 -181
- package/test/notaryhash/script.js +0 -270
- package/test/notaryhash/verify.js +0 -342
- package/test/opcode.js +0 -186
- package/test/ordinals/bsv20.js +0 -337
- package/test/ordinals/inscription.js +0 -329
- package/test/ordinals/ordlock.js +0 -567
- package/test/privatekey.js +0 -540
- package/test/publickey.js +0 -411
- package/test/regressions.js +0 -215
- package/test/script/chronicle.js +0 -543
- package/test/script/defaults.js +0 -160
- package/test/script/genesis_limits.js +0 -203
- package/test/script/interpreter.js +0 -776
- package/test/script/script.js +0 -1259
- package/test/script/string_ops.js +0 -88
- package/test/security/fail_closed_contracts.js +0 -104
- package/test/security/threat_model_coverage.js +0 -31
- package/test/smart_contract/covenants.js +0 -207
- package/test/smart_contract/dsl_debugger.js +0 -92
- package/test/smart_contract/extract_field.js +0 -61
- package/test/smart_contract/nonenforcing_guard.js +0 -44
- package/test/smart_contract/ordinal_transfer.js +0 -71
- package/test/smart_contract/preimage.js +0 -98
- package/test/smart_contract/sighash_marketplace.js +0 -98
- package/test/smart_contract/token_generalized.js +0 -175
- package/test/spv/headerchain.js +0 -86
- package/test/spv/merkleproof.js +0 -133
- package/test/statuslist/failclosed.js +0 -78
- package/test/transaction/deserialize.js +0 -33
- package/test/transaction/input/input.js +0 -92
- package/test/transaction/input/multisig.js +0 -174
- package/test/transaction/input/multisigscripthash.js +0 -111
- package/test/transaction/input/publickey.js +0 -68
- package/test/transaction/input/publickeyhash.js +0 -59
- package/test/transaction/output.js +0 -185
- package/test/transaction/sighash.js +0 -91
- package/test/transaction/signature.js +0 -127
- package/test/transaction/transaction.js +0 -1299
- package/test/transaction/unspentoutput.js +0 -97
- package/test/types/dts_drift.js +0 -124
- package/test/types/surface_honesty.js +0 -102
- package/test/util/id.js +0 -72
- package/test/util/js.js +0 -76
- package/test/util/preconditions.js +0 -79
- package/test/vcjwt/interop.js +0 -126
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
"from", [{
|
|
4
|
-
"address": "mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1",
|
|
5
|
-
"txId": "a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458",
|
|
6
|
-
"outputIndex": 0,
|
|
7
|
-
"script": "OP_DUP OP_HASH160 20 0x88d9931ea73d60eaf7e5671efc0552b912911f2a OP_EQUALVERIFY OP_CHECKSIG",
|
|
8
|
-
"satoshis": 1020000
|
|
9
|
-
}],
|
|
10
|
-
"to", ["mrU9pEmAx26HcbKVrABvgL7AwA5fjNFoDc", 1010000],
|
|
11
|
-
"sign", ["cSBnVM4xvxarwGQuAfQFwqDg9k5tErHUHzgWsEfD4zdwUasvqRVY", 1],
|
|
12
|
-
"serialize", "01000000015884e5db9de218238671572340b207ee85b628074e7e467096c267266baf77a4000000006b4830450221009972100061da4a17a471ac1906c18bb5445c03da2a0be52c59aca6c58f1e342302202b7a19a22572cabb6e55c368ebdb5921541358fa969d5c76b5e0d6ad3f26a7d701210223078d2942df62c45621d209fab84ea9a7a23346201b7727b9b45a29c4e76f5effffffff0150690f00000000001976a9147821c0a3768aa9d1a37e16cf76002aef5373f1a888ac00000000"
|
|
13
|
-
],
|
|
14
|
-
[
|
|
15
|
-
"from", [{
|
|
16
|
-
"txid": "e42447187db5a29d6db161661e4bc66d61c3e499690fe5ea47f87b79ca573986",
|
|
17
|
-
"vout": 1,
|
|
18
|
-
"address": "mgBCJAsvzgT2qNNeXsoECg2uPKrUsZ76up",
|
|
19
|
-
"scriptPubKey": "76a914073b7eae2823efa349e3b9155b8a735526463a0f88ac",
|
|
20
|
-
"amount": 0.01080000
|
|
21
|
-
}],
|
|
22
|
-
"to", ["mn9new5vPYWuVN5m3gUBujfKh1uPQvR9mf", 500000],
|
|
23
|
-
"to", ["mw5ctwgEaNRbxkM4JhXH3rp5AyGvTWDZCD", 570000],
|
|
24
|
-
"sign", ["cSQUuwwJBAg6tYQhzqqLWW115D1s5KFZDyhCF2ffrnukZxMK6rNZ", 1],
|
|
25
|
-
"serialize", "0100000001863957ca797bf847eae50f6999e4c3616dc64b1e6661b16d9da2b57d184724e4010000006b483045022100855691c90510edf83ab632f0a0b17f5202d2cf7071050dcf0c2778325ed403cd022014ee7a4e787da8bc088d2ece43108a7b8d7112eba89876a27bb44195a0715a910121039dd446bbc85db6917f39c0b4c295b0f8cce76d1926fa76d7b84e3f7ff1c5eec5ffffffff0220a10700000000001976a91448c819246ae5645ceecd41fbe1aa6202a0a9b5ca88ac90b20800000000001976a914aab76ba4877d696590d94ea3e02948b55294815188ac00000000"
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
"from", [
|
|
29
|
-
[{
|
|
30
|
-
"txid": "a9db84566e0fc9351e86337d2828ab281b25ddc06fab798f6d4b5baef48c02b3",
|
|
31
|
-
"vout": 0,
|
|
32
|
-
"address": "mn9new5vPYWuVN5m3gUBujfKh1uPQvR9mf",
|
|
33
|
-
"account": "",
|
|
34
|
-
"scriptPubKey": "76a91448c819246ae5645ceecd41fbe1aa6202a0a9b5ca88ac",
|
|
35
|
-
"amount": 0.00500000,
|
|
36
|
-
"confirmations": 0
|
|
37
|
-
}, {
|
|
38
|
-
"txid": "a9db84566e0fc9351e86337d2828ab281b25ddc06fab798f6d4b5baef48c02b3",
|
|
39
|
-
"vout": 1,
|
|
40
|
-
"address": "mw5ctwgEaNRbxkM4JhXH3rp5AyGvTWDZCD",
|
|
41
|
-
"account": "",
|
|
42
|
-
"scriptPubKey": "76a914aab76ba4877d696590d94ea3e02948b55294815188ac",
|
|
43
|
-
"amount": 0.00570000,
|
|
44
|
-
"confirmations": 0
|
|
45
|
-
}]
|
|
46
|
-
],
|
|
47
|
-
"to", ["mtymcCX5KixPjT1zxtg59qewBGWptj9etH", 1060000],
|
|
48
|
-
"sign", [
|
|
49
|
-
["cPGbA2C54ZZ1sw4dc2ckBE1WqkdrNSbEV8Tkjhi2p1J15oErdgP2", "cSpyve5bXAuyHrNeV9MjTdFz3HLw739yUjjUAUSMe3ppf2qzj2hw"], 1
|
|
50
|
-
],
|
|
51
|
-
"serialize", "0100000002b3028cf4ae5b4b6d8f79ab6fc0dd251b28ab28287d33861e35c90f6e5684dba9000000006a4730440220635e95e1981bbb360feaf4c232f626a0af8eb5c043a99749a21b0e37fd0048fd02201c5db8a93f1f5c268be6167da7c92f5030481acf65bef750c81ec9907aba3b170121030253c73236acf5ea9085d408220141197f6094de07426bd0d32c7a543614fdd7ffffffffb3028cf4ae5b4b6d8f79ab6fc0dd251b28ab28287d33861e35c90f6e5684dba9010000006a4730440220319a0b5ee9c67ccb7de4222234f31059354be4f239c99ca24bff30adfec8e8ec02204ad4c6dedebb20d100f9484b9ea6c5ba36712e9da155c24509e793c02e4805fd012102977a001a0a7bbfd1f8a647c7d46e13e8f6920635b328390b43b3303977101149ffffffff01a02c1000000000001976a91493abf1e9e4a20c125b93f93ee39efc16b6e4bc4688ac00000000"
|
|
52
|
-
],
|
|
53
|
-
[
|
|
54
|
-
"from", [{
|
|
55
|
-
"address": "mgJT8iegL4f9NCgQFeFyfvnSw1Yj4M5Woi",
|
|
56
|
-
"txid": "f50e13cecda9a438ebd7df213a2899e42b2461a18d4630ee773d26b4f2688bdc",
|
|
57
|
-
"vout": 1,
|
|
58
|
-
"scriptPubKey": "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
|
|
59
|
-
"amount": 0.01
|
|
60
|
-
}],
|
|
61
|
-
"to", ["n3riXZowrjGnY74rx7Hdi9wCyvgyJC28zZ", 990000],
|
|
62
|
-
"sign", ["cPwWtDztEgRCMCU8pMQp4HgphvyadrAsYBrCjXUZuDSmnZkyoyNF", 1],
|
|
63
|
-
"serialize", "0100000001dc8b68f2b4263d77ee30468da161242be499283a21dfd7eb38a4a9cdce130ef5010000006a473044022012610834051e6af8594dd5d9c47123d6ce03537d321f9fe3f6ff244b23f47dd5022034901bb0d83688758a9248fdef48bd2000b55cf70111cbef8f206e72a31aaf61012103e26b47e7c0d8946954bf9dd4bc7f9e415437eb98271d05f69e78cef8fc6c9a54ffffffff01301b0f00000000001976a914f50f9826ef186074c6fe206cca6b71472ff07ba888ac00000000"
|
|
64
|
-
],
|
|
65
|
-
[
|
|
66
|
-
"from", [{
|
|
67
|
-
"address":"38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z","txid":"073281b2cc94e879aaf30ea2e92947d9827b270015849d3a5b96a89ee15bfa66","vout":0,"ts":1418877950,"scriptPubKey":"a9144de752833233fe69a20064f29b2ca0f6399c8af387","amount":0.00318512,"confirmationsFromCache":false
|
|
68
|
-
}, ["03411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba", "03bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab", "03c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea7330"], 2],
|
|
69
|
-
"to", ["3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9", 300299],
|
|
70
|
-
"sign", [["L3y1PAXfjayeB3w6NP7qfNxPbuPpQFA6hd6gj4BUKa2xSdLwoVSZ", "L3a57fiNjqfbXBdYvvGYPQ1HiDX463mwA2xFGTYVkXYdooaz9Z2u"], 1],
|
|
71
|
-
"serialize", "010000000166fa5be19ea8965b3a9d841500277b82d94729e9a20ef3aa79e894ccb281320700000000fc0047304402202f66fcfc0d5bff109ec12327ca37e0bc7722d08da9538f12468994799534bed602203a0b374f3a6810b0ee26028c390e14f5b6bada8fa390f4364d70d04aee240d350147304402206757f710f25937cd846fd8c56687c463a4561e9e0421fc173c78eaf2de9b9a7d02204995db6b81513b67a42b09dabab6ed4cb90901c52f6f945b768827a9390bda60014c69522103411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba2103bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab2103c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea733053aeffffffff010b9504000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
|
|
72
|
-
],
|
|
73
|
-
[
|
|
74
|
-
"from", [{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"afbf98ca4a43db8915d75184b5204fbe71d916482adfe85cb0ed3635764fc220","vout":0,"ts":1418878108,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00318512,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2
|
|
75
|
-
],
|
|
76
|
-
"from", [
|
|
77
|
-
{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"dc2e197ab72f71912c39bc23a42d823a3aa8d469fe65eb591c086e60d14c64a0","vout":0,"ts":1418878014,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00300299,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2],
|
|
78
|
-
"to", ["38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z", 150000],
|
|
79
|
-
"to", ["38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z", 160000],
|
|
80
|
-
"change", ["3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9"],
|
|
81
|
-
"sign", ["L2U9m5My3cdyN5qX1PH4B7XstGDZFWwyukdX8gj8vsJ3fkrqArQo", 1],
|
|
82
|
-
"sign", ["L4jFVcDaqZCkknP5KQWjCBgiLFxKxRxywNGTucm3jC3ozByZcbZv", 1],
|
|
83
|
-
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fdfd0000473044022049971af56696e7468c82fde7502487c5a71c207029e18b8525e7947ed33c8b7e022008faed03c20cfd593d3e57ee938781dd1419c2b9b9caca98d0e2928cb05484fb01483045022100d6d3cc551fbd0d97117c60f4abe1471fcf57bb2f02a41a9102ed64b45df30428022078186f084e1c05f2656f9a407d8ca2b4965270cdf3aeba6dc5d4afda51be6983014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fdfe0000483045022100ccadfd2f98a3a8eea787c19d7d3119d0504b051293c0e1eb420c26dc535a74b702207d5b38040994e86204604222d87278456ee4a376c340d1376d1cf86c88d0f8c801483045022100cadab93035584dc94f498898a2df329dd83e2a86e94bb96b54a629386095f59e022043a1dc8d8160495b63180163278513d9d8dfbf8faa580e58fa3ee3169a5adee5014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387dba403000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
|
|
84
|
-
]
|
|
85
|
-
]
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* global describe, it */
|
|
4
|
-
|
|
5
|
-
// DID Core defines the verification relationships to be DISTINCT. `authentication`
|
|
6
|
-
// proves who you are right now; `assertionMethod` makes a claim that outlives the
|
|
7
|
-
// session. Keeping them apart is what stops a low-friction login signature from being
|
|
8
|
-
// redeemed as a signed statement.
|
|
9
|
-
//
|
|
10
|
-
// This module used to cross-list every key into both, and `rotateIssuerKey` rewrote both
|
|
11
|
-
// regardless of which one was being rotated — so replacing a compromised authentication
|
|
12
|
-
// key invalidated every statement the issuer had ever signed.
|
|
13
|
-
|
|
14
|
-
require('chai').should()
|
|
15
|
-
var didweb = require('../../lib/didweb')
|
|
16
|
-
|
|
17
|
-
var DOMAIN = 'example.com'
|
|
18
|
-
var DID = 'did:web:example.com'
|
|
19
|
-
var P256 = { kid: 'auth-1', jwk: { kty: 'EC', crv: 'P-256', x: 'a', y: 'b' } }
|
|
20
|
-
var K1 = { kid: 'sign-1', jwk: { kty: 'EC', crv: 'secp256k1', x: 'c', y: 'd' } }
|
|
21
|
-
|
|
22
|
-
function scoped (key, rels) {
|
|
23
|
-
return { kid: key.kid, jwk: key.jwk, relationships: rels }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('did:web verification relationships', function () {
|
|
27
|
-
describe('buildDidWebDocuments', function () {
|
|
28
|
-
// The compatibility guarantee: callers that never heard of `relationships` must get
|
|
29
|
-
// byte-identical documents, including key order.
|
|
30
|
-
it('keeps the previous output when no relationships are given', function () {
|
|
31
|
-
var doc = didweb.buildDidWebDocuments({ domain: DOMAIN, p256: P256, k1: K1 }).didDocument
|
|
32
|
-
doc.authentication.should.deep.equal([DID + '#auth-1', DID + '#sign-1'])
|
|
33
|
-
doc.assertionMethod.should.deep.equal([DID + '#auth-1', DID + '#sign-1'])
|
|
34
|
-
Object.keys(doc).should.deep.equal([
|
|
35
|
-
'@context', 'id', 'verificationMethod', 'authentication', 'assertionMethod'
|
|
36
|
-
])
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('scopes each key to the relationships it was given', function () {
|
|
40
|
-
var doc = didweb.buildDidWebDocuments({
|
|
41
|
-
domain: DOMAIN,
|
|
42
|
-
p256: scoped(P256, ['authentication']),
|
|
43
|
-
k1: scoped(K1, ['assertionMethod'])
|
|
44
|
-
}).didDocument
|
|
45
|
-
doc.authentication.should.deep.equal([DID + '#auth-1'])
|
|
46
|
-
doc.assertionMethod.should.deep.equal([DID + '#sign-1'])
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('supports the other three relationships and omits empty ones', function () {
|
|
50
|
-
var doc = didweb.buildDidWebDocuments({
|
|
51
|
-
domain: DOMAIN,
|
|
52
|
-
p256: scoped(P256, ['keyAgreement', 'capabilityInvocation', 'capabilityDelegation'])
|
|
53
|
-
}).didDocument
|
|
54
|
-
doc.keyAgreement.should.deep.equal([DID + '#auth-1'])
|
|
55
|
-
doc.capabilityInvocation.should.deep.equal([DID + '#auth-1'])
|
|
56
|
-
doc.capabilityDelegation.should.deep.equal([DID + '#auth-1'])
|
|
57
|
-
;(doc.authentication === undefined).should.equal(true)
|
|
58
|
-
;(doc.assertionMethod === undefined).should.equal(true)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('rejects an unknown relationship rather than silently dropping it', function () {
|
|
62
|
-
;(function () {
|
|
63
|
-
didweb.buildDidWebDocuments({ domain: DOMAIN, p256: scoped(P256, ['notARelationship']) })
|
|
64
|
-
}).should.throw(/unknown verification relationship/)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('rejects an empty relationship list', function () {
|
|
68
|
-
;(function () {
|
|
69
|
-
didweb.buildDidWebDocuments({ domain: DOMAIN, p256: scoped(P256, []) })
|
|
70
|
-
}).should.throw(/non-empty array/)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('rotateIssuerKey', function () {
|
|
75
|
-
function currentDoc () {
|
|
76
|
-
return didweb.buildDidWebDocuments({
|
|
77
|
-
domain: DOMAIN,
|
|
78
|
-
p256: scoped(P256, ['authentication']),
|
|
79
|
-
k1: scoped(K1, ['assertionMethod'])
|
|
80
|
-
}).didDocument
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// The reported failure. Rotating a compromised auth key must not touch
|
|
84
|
-
// assertionMethod, or every seal the issuer ever made stops verifying.
|
|
85
|
-
it('leaves assertionMethod intact when only authentication is rotated', function () {
|
|
86
|
-
var before = currentDoc()
|
|
87
|
-
var after = didweb.rotateIssuerKey({
|
|
88
|
-
domain: DOMAIN,
|
|
89
|
-
newKey: { kid: 'auth-2', jwk: { kty: 'EC', crv: 'P-256', x: 'e', y: 'f' }, relationships: ['authentication'] },
|
|
90
|
-
currentDocument: before
|
|
91
|
-
}).didDocument
|
|
92
|
-
|
|
93
|
-
after.authentication.should.deep.equal([DID + '#auth-2'])
|
|
94
|
-
after.assertionMethod.should.deep.equal(before.assertionMethod)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('still defines the key that the carried-over relationship points at', function () {
|
|
98
|
-
var after = didweb.rotateIssuerKey({
|
|
99
|
-
domain: DOMAIN,
|
|
100
|
-
newKey: { kid: 'auth-2', jwk: { kty: 'EC' }, relationships: ['authentication'] },
|
|
101
|
-
currentDocument: currentDoc()
|
|
102
|
-
}).didDocument
|
|
103
|
-
|
|
104
|
-
var defined = after.verificationMethod.map(function (vm) { return vm.id })
|
|
105
|
-
// Every referenced id resolves — no dangling references.
|
|
106
|
-
Object.keys(after).forEach(function (k) {
|
|
107
|
-
if (Array.isArray(after[k]) && k !== 'verificationMethod' && k !== '@context') {
|
|
108
|
-
after[k].forEach(function (id) { defined.indexOf(id).should.be.above(-1, k + ' references undefined ' + id) })
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('drops the rotated-out key, which nothing references any more', function () {
|
|
114
|
-
var after = didweb.rotateIssuerKey({
|
|
115
|
-
domain: DOMAIN,
|
|
116
|
-
newKey: { kid: 'auth-2', jwk: { kty: 'EC' }, relationships: ['authentication'] },
|
|
117
|
-
currentDocument: currentDoc()
|
|
118
|
-
}).didDocument
|
|
119
|
-
after.verificationMethod.some(function (vm) {
|
|
120
|
-
return vm.id === DID + '#auth-1'
|
|
121
|
-
}).should.equal(false)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('keeps the previous behaviour with no currentDocument', function () {
|
|
125
|
-
var doc = didweb.rotateIssuerKey({
|
|
126
|
-
domain: DOMAIN, newKey: { kid: 'k9', jwk: { kty: 'EC' } }
|
|
127
|
-
}).didDocument
|
|
128
|
-
doc.authentication.should.deep.equal([DID + '#k9'])
|
|
129
|
-
doc.assertionMethod.should.deep.equal([DID + '#k9'])
|
|
130
|
-
doc.verificationMethod.length.should.equal(1)
|
|
131
|
-
Object.keys(doc).should.deep.equal([
|
|
132
|
-
'@context', 'id', 'verificationMethod', 'authentication', 'assertionMethod', 'rotationInfo'
|
|
133
|
-
])
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('still reports rotationInfo', function () {
|
|
137
|
-
var doc = didweb.rotateIssuerKey({
|
|
138
|
-
domain: DOMAIN, newKey: { kid: 'k9', jwk: { kty: 'EC' } }, keepOldForDays: 7
|
|
139
|
-
}).didDocument
|
|
140
|
-
doc.rotationInfo.gracePeriodDays.should.equal(7)
|
|
141
|
-
doc.rotationInfo.rotatedAt.should.be.a('string')
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
})
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var ECIES = require('../../lib/ecies/bitcore-ecies')
|
|
4
|
-
|
|
5
|
-
var should = require('chai').should()
|
|
6
|
-
var bsv = require('../../')
|
|
7
|
-
var PrivateKey = bsv.PrivateKey
|
|
8
|
-
|
|
9
|
-
var aliceKey = new PrivateKey('L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ')
|
|
10
|
-
var bobKey = new PrivateKey('KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG')
|
|
11
|
-
|
|
12
|
-
describe('Bitcore ECIES', function () {
|
|
13
|
-
it('should exist', function () {
|
|
14
|
-
should.exist(ECIES)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('constructor', function () {
|
|
18
|
-
(typeof ECIES).should.equal('function')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('constructs an instance', function () {
|
|
22
|
-
var ecies = new ECIES();
|
|
23
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('doesnt require the "new" keyword', function () {
|
|
27
|
-
var ecies = ECIES();
|
|
28
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Regression: the no-`new` factory path used to drop opts (return new ECIES()),
|
|
32
|
-
// silently ignoring { noKey, shortTag } and changing the wire format.
|
|
33
|
-
it('forwards opts through the no-"new" factory path', function () {
|
|
34
|
-
var ecies = ECIES({ noKey: true, shortTag: true })
|
|
35
|
-
ecies.opts.noKey.should.equal(true)
|
|
36
|
-
ecies.opts.shortTag.should.equal(true)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('privateKey fails with no argument', function () {
|
|
40
|
-
var ecies = ECIES()
|
|
41
|
-
var fail = function () {
|
|
42
|
-
ecies.privateKey()
|
|
43
|
-
}
|
|
44
|
-
fail.should.throw('no private key provided')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('chainable function', function () {
|
|
48
|
-
var ecies = ECIES()
|
|
49
|
-
.privateKey(aliceKey)
|
|
50
|
-
.publicKey(bobKey.publicKey);
|
|
51
|
-
|
|
52
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
var alice = ECIES()
|
|
56
|
-
.privateKey(aliceKey)
|
|
57
|
-
.publicKey(bobKey.publicKey)
|
|
58
|
-
|
|
59
|
-
var bob = ECIES()
|
|
60
|
-
.privateKey(bobKey)
|
|
61
|
-
.publicKey(aliceKey.publicKey)
|
|
62
|
-
|
|
63
|
-
var message = 'attack at dawn'
|
|
64
|
-
var encrypted = '0339e504d6492b082da96e11e8f039796b06cd4855c101e2492a6f10f3e056a9e712c732611c6917ab5c57a1926973bc44a1586e94a783f81d05ce72518d9b0a80e2e13c7ff7d1306583f9cc7a48def5b37fbf2d5f294f128472a6e9c78dede5f5'
|
|
65
|
-
var encBuf = Buffer.from(encrypted, 'hex')
|
|
66
|
-
|
|
67
|
-
it('correctly encrypts a message', function () {
|
|
68
|
-
var ciphertext = alice.encrypt(message)
|
|
69
|
-
Buffer.isBuffer(ciphertext).should.equal(true)
|
|
70
|
-
ciphertext.toString('hex').should.equal(encrypted)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('correctly decrypts a message', function () {
|
|
74
|
-
var decrypted = bob
|
|
75
|
-
.decrypt(encBuf)
|
|
76
|
-
.toString()
|
|
77
|
-
decrypted.should.equal(message)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('retrieves senders publickey from the encypted buffer', function () {
|
|
81
|
-
var bob2 = ECIES().privateKey(bobKey)
|
|
82
|
-
var decrypted = bob2.decrypt(encBuf).toString()
|
|
83
|
-
bob2._publicKey.toDER().should.deep.equal(aliceKey.publicKey.toDER())
|
|
84
|
-
decrypted.should.equal(message)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('roundtrips', function () {
|
|
88
|
-
var secret = 'some secret message!!!'
|
|
89
|
-
var encrypted = alice.encrypt(secret)
|
|
90
|
-
var decrypted = bob
|
|
91
|
-
.decrypt(encrypted)
|
|
92
|
-
.toString()
|
|
93
|
-
decrypted.should.equal(secret)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('roundtrips (no public key)', function () {
|
|
97
|
-
alice.opts.noKey = true
|
|
98
|
-
bob.opts.noKey = true
|
|
99
|
-
var secret = 'some secret message!!!'
|
|
100
|
-
var encrypted = alice.encrypt(secret)
|
|
101
|
-
var decrypted = bob
|
|
102
|
-
.decrypt(encrypted)
|
|
103
|
-
.toString()
|
|
104
|
-
decrypted.should.equal(secret)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('roundtrips (short tag)', function () {
|
|
108
|
-
alice.opts.shortTag = true
|
|
109
|
-
bob.opts.shortTag = true
|
|
110
|
-
var secret = 'some secret message!!!'
|
|
111
|
-
var encrypted = alice.encrypt(secret)
|
|
112
|
-
var decrypted = bob
|
|
113
|
-
.decrypt(encrypted)
|
|
114
|
-
.toString()
|
|
115
|
-
decrypted.should.equal(secret)
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('roundtrips (no public key & short tag)', function () {
|
|
119
|
-
alice.opts.noKey = true
|
|
120
|
-
alice.opts.shortTag = true
|
|
121
|
-
bob.opts.noKey = true
|
|
122
|
-
bob.opts.shortTag = true
|
|
123
|
-
var secret = 'some secret message!!!'
|
|
124
|
-
var encrypted = alice.encrypt(secret)
|
|
125
|
-
var decrypted = bob
|
|
126
|
-
.decrypt(encrypted)
|
|
127
|
-
.toString()
|
|
128
|
-
decrypted.should.equal(secret)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('correctly fails if trying to decrypt a bad message', function () {
|
|
132
|
-
var encrypted = Buffer.from(encBuf)
|
|
133
|
-
encrypted[encrypted.length - 1] = 2;
|
|
134
|
-
(function () {
|
|
135
|
-
return bob.decrypt(encrypted)
|
|
136
|
-
}).should.throw('Invalid checksum')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
it('decrypting uncompressed keys', function () {
|
|
140
|
-
var secret = 'test'
|
|
141
|
-
|
|
142
|
-
// test uncompressed
|
|
143
|
-
var alicePrivateKey = bsv.PrivateKey.fromObject({
|
|
144
|
-
bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
|
|
145
|
-
compressed: false,
|
|
146
|
-
network: 'livenet'
|
|
147
|
-
})
|
|
148
|
-
var alicePublicKey = bsv.PublicKey.fromPrivateKey(alicePrivateKey) // alicePrivateKey.publicKey
|
|
149
|
-
alicePrivateKey.compressed.should.equal(false)
|
|
150
|
-
|
|
151
|
-
var cypher1 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
152
|
-
var encrypted = cypher1.encrypt(secret)
|
|
153
|
-
|
|
154
|
-
var cypher2 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
155
|
-
var decrypted = cypher2.decrypt(encrypted)
|
|
156
|
-
secret.should.equal(decrypted.toString())
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
it('decrypting compressed keys', function () {
|
|
160
|
-
var secret = 'test'
|
|
161
|
-
|
|
162
|
-
// test compressed
|
|
163
|
-
var alicePrivateKey = bsv.PrivateKey.fromObject({
|
|
164
|
-
bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
|
|
165
|
-
compressed: true,
|
|
166
|
-
network: 'livenet'
|
|
167
|
-
})
|
|
168
|
-
var alicePublicKey = bsv.PublicKey.fromPrivateKey(alicePrivateKey) // alicePrivateKey.publicKey
|
|
169
|
-
alicePrivateKey.compressed.should.equal(true)
|
|
170
|
-
|
|
171
|
-
var cypher1 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
172
|
-
var encrypted = cypher1.encrypt(secret)
|
|
173
|
-
|
|
174
|
-
var cypher2 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
175
|
-
var decrypted = cypher2.decrypt(encrypted)
|
|
176
|
-
secret.should.equal(decrypted.toString())
|
|
177
|
-
})
|
|
178
|
-
})
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var ECIES = require('../../lib/ecies/electrum-ecies')
|
|
4
|
-
|
|
5
|
-
var should = require('chai').should()
|
|
6
|
-
var bsv = require('../../')
|
|
7
|
-
var PrivateKey = bsv.PrivateKey
|
|
8
|
-
|
|
9
|
-
var aliceKey = new PrivateKey('L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ')
|
|
10
|
-
var bobKey = new PrivateKey('KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG')
|
|
11
|
-
|
|
12
|
-
describe('ECIES', function () {
|
|
13
|
-
it('constructor', function () {
|
|
14
|
-
(typeof ECIES).should.equal('function')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('constructs an instance', function () {
|
|
18
|
-
var ecies = new ECIES();
|
|
19
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('doesnt require the "new" keyword', function () {
|
|
23
|
-
var ecies = ECIES();
|
|
24
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('use ephemeral privateKey if privateKey is not set', function () {
|
|
28
|
-
var ecies = ECIES()
|
|
29
|
-
var ephemeralKey = ecies._privateKey;
|
|
30
|
-
(ephemeralKey instanceof bsv.PrivateKey).should.equal(true)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('chainable function', function () {
|
|
34
|
-
var ecies = ECIES()
|
|
35
|
-
.privateKey(aliceKey)
|
|
36
|
-
.publicKey(bobKey.publicKey);
|
|
37
|
-
|
|
38
|
-
(ecies instanceof ECIES).should.equal(true)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should do these test vectors correctly', function () {
|
|
42
|
-
let message = Buffer.from('this is my test message')
|
|
43
|
-
|
|
44
|
-
let alice = ECIES()
|
|
45
|
-
.privateKey(aliceKey)
|
|
46
|
-
.publicKey(bobKey.publicKey)
|
|
47
|
-
alice.decrypt(Buffer.from('QklFMQOGFyMXLo9Qv047K3BYJhmnJgt58EC8skYP/R2QU/U0yXXHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbiaH4FsxKIOOvzolIFVAS0FplUmib2HnlAM1yP/iiPsU=', 'base64')).toString().should.equal(message.toString())
|
|
48
|
-
|
|
49
|
-
let bob = ECIES()
|
|
50
|
-
.privateKey(bobKey)
|
|
51
|
-
.publicKey(aliceKey.publicKey)
|
|
52
|
-
bob.decrypt(Buffer.from('QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap53XHOt6L3tKmrXho6yj6phfoiMkBOhUldRPnEI4fSZXbvZJHgyAzxA6SoujduvJXv+A9ri3po9veilrmc8p6dwo=', 'base64')).toString().should.equal(message.toString())
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
var alice = ECIES()
|
|
56
|
-
.privateKey(aliceKey)
|
|
57
|
-
.publicKey(bobKey.publicKey)
|
|
58
|
-
|
|
59
|
-
var bob = ECIES()
|
|
60
|
-
.privateKey(bobKey)
|
|
61
|
-
.publicKey(aliceKey.publicKey)
|
|
62
|
-
|
|
63
|
-
var aliceReloaded = ECIES()
|
|
64
|
-
.privateKey(aliceKey)
|
|
65
|
-
.publicKey(bobKey.publicKey)
|
|
66
|
-
|
|
67
|
-
var message = 'attack at dawn'
|
|
68
|
-
var encrypted = 'QklFMQM55QTWSSsILaluEejwOXlrBs1IVcEB4kkqbxDz4Fap56+ajq0hzmnaQJXwUMZ/DUNgEx9i2TIhCA1mpBFIfxWZy+sH6H+sqqfX3sPHsGu0ug=='
|
|
69
|
-
var encBuf = Buffer.from(encrypted, 'base64')
|
|
70
|
-
|
|
71
|
-
it('correctly encrypts a message', function () {
|
|
72
|
-
var ciphertext = alice.encrypt(message)
|
|
73
|
-
Buffer.isBuffer(ciphertext).should.equal(true)
|
|
74
|
-
ciphertext.toString('base64').should.equal(encrypted)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('correctly decrypts a message', function () {
|
|
78
|
-
var decrypted = bob
|
|
79
|
-
.decrypt(encBuf)
|
|
80
|
-
.toString()
|
|
81
|
-
decrypted.should.equal(message)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('correctly recovers a message', function () {
|
|
85
|
-
var decrypted = aliceReloaded
|
|
86
|
-
.decrypt(encBuf)
|
|
87
|
-
.toString()
|
|
88
|
-
decrypted.should.equal(message)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('retrieves senders publickey from the encypted buffer', function () {
|
|
92
|
-
var bob2 = ECIES().privateKey(bobKey)
|
|
93
|
-
var decrypted = bob2.decrypt(encBuf).toString()
|
|
94
|
-
bob2._publicKey.toDER().should.deep.equal(aliceKey.publicKey.toDER())
|
|
95
|
-
decrypted.should.equal(message)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
var message1 = 'This is message from first sender'
|
|
99
|
-
var message2 = 'This is message from second sender'
|
|
100
|
-
|
|
101
|
-
it('decrypt messages from different senders', function () {
|
|
102
|
-
var sender1 = ECIES().publicKey(bobKey.publicKey)
|
|
103
|
-
var sender2 = ECIES().publicKey(bobKey.publicKey)
|
|
104
|
-
var bob2 = ECIES().privateKey(bobKey)
|
|
105
|
-
var decrypted1 = bob2.decrypt(sender1.encrypt(message1)).toString()
|
|
106
|
-
var decrypted2 = bob2.decrypt(sender2.encrypt(message2)).toString()
|
|
107
|
-
decrypted1.should.equal(message1)
|
|
108
|
-
decrypted2.should.equal(message2)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('roundtrips', function () {
|
|
112
|
-
var secret = 'some secret message!!!'
|
|
113
|
-
var encrypted = alice.encrypt(secret)
|
|
114
|
-
var decrypted = bob
|
|
115
|
-
.decrypt(encrypted)
|
|
116
|
-
.toString()
|
|
117
|
-
decrypted.should.equal(secret)
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('roundtrips (no public key)', function () {
|
|
121
|
-
alice.opts.noKey = true
|
|
122
|
-
bob.opts.noKey = true
|
|
123
|
-
var secret = 'some secret message!!!'
|
|
124
|
-
var encrypted = alice.encrypt(secret)
|
|
125
|
-
var decrypted = bob
|
|
126
|
-
.decrypt(encrypted)
|
|
127
|
-
.toString()
|
|
128
|
-
decrypted.should.equal(secret)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('roundtrips (short tag)', function () {
|
|
132
|
-
alice.opts.shortTag = true
|
|
133
|
-
bob.opts.shortTag = true
|
|
134
|
-
var secret = 'some secret message!!!'
|
|
135
|
-
var encrypted = alice.encrypt(secret)
|
|
136
|
-
var decrypted = bob
|
|
137
|
-
.decrypt(encrypted)
|
|
138
|
-
.toString()
|
|
139
|
-
decrypted.should.equal(secret)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('roundtrips (no public key & short tag)', function () {
|
|
143
|
-
alice.opts.noKey = true
|
|
144
|
-
alice.opts.shortTag = true
|
|
145
|
-
bob.opts.noKey = true
|
|
146
|
-
bob.opts.shortTag = true
|
|
147
|
-
var secret = 'some secret message!!!'
|
|
148
|
-
var encrypted = alice.encrypt(secret)
|
|
149
|
-
var decrypted = bob
|
|
150
|
-
.decrypt(encrypted)
|
|
151
|
-
.toString()
|
|
152
|
-
decrypted.should.equal(secret)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('errors', function () {
|
|
156
|
-
should.exist(bsv.errors.ECIES)
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
it('correctly fails if trying to decrypt a bad message', function () {
|
|
160
|
-
var encrypted = Buffer.from(encBuf)
|
|
161
|
-
encrypted[encrypted.length - 1] = 2;
|
|
162
|
-
(function () {
|
|
163
|
-
return bob.decrypt(encrypted)
|
|
164
|
-
}).should.throw('Invalid checksum')
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('decrypting uncompressed keys', function () {
|
|
168
|
-
var secret = 'test'
|
|
169
|
-
|
|
170
|
-
// test uncompressed
|
|
171
|
-
var alicePrivateKey = bsv.PrivateKey.fromObject({
|
|
172
|
-
bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
|
|
173
|
-
compressed: false,
|
|
174
|
-
network: 'livenet'
|
|
175
|
-
})
|
|
176
|
-
var alicePublicKey = bsv.PublicKey.fromPrivateKey(alicePrivateKey) // alicePrivateKey.publicKey
|
|
177
|
-
alicePrivateKey.compressed.should.equal(false)
|
|
178
|
-
|
|
179
|
-
var cypher1 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
180
|
-
var encrypted = cypher1.encrypt(secret)
|
|
181
|
-
|
|
182
|
-
var cypher2 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
183
|
-
var decrypted = cypher2.decrypt(encrypted)
|
|
184
|
-
secret.should.equal(decrypted.toString())
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('decrypting compressed keys', function () {
|
|
188
|
-
var secret = 'test'
|
|
189
|
-
|
|
190
|
-
// test compressed
|
|
191
|
-
var alicePrivateKey = bsv.PrivateKey.fromObject({
|
|
192
|
-
bn: '1fa76f9c799ca3a51e2c7c901d3ba8e24f6d870beccf8df56faf30120b38f360',
|
|
193
|
-
compressed: true,
|
|
194
|
-
network: 'livenet'
|
|
195
|
-
})
|
|
196
|
-
var alicePublicKey = bsv.PublicKey.fromPrivateKey(alicePrivateKey) // alicePrivateKey.publicKey
|
|
197
|
-
alicePrivateKey.compressed.should.equal(true)
|
|
198
|
-
|
|
199
|
-
var cypher1 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
200
|
-
var encrypted = cypher1.encrypt(secret)
|
|
201
|
-
|
|
202
|
-
var cypher2 = ECIES().privateKey(alicePrivateKey).publicKey(alicePublicKey)
|
|
203
|
-
var decrypted = cypher2.decrypt(encrypted)
|
|
204
|
-
secret.should.equal(decrypted.toString())
|
|
205
|
-
})
|
|
206
|
-
})
|