diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..f8d4494 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,40 @@ +{ + "parser": "babel-eslint", + "plugins": [ + "eslint-plugin-flowtype" + ], + "env": { + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:flowtype/recommended" + ], + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "flowtype/space-before-type-colon": 0, + "no-undef": 0, + "no-unused-vars": 0 + }, + "settings": { + "flowtype": { + "onlyFilesWithFlowAnnotation": true + } + } +} diff --git a/.gitignore b/.gitignore index a6ec74b..b4e253f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ +lib/ *.swp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9af64ac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "7" + +install: + - npm install +script: + - npm run check diff --git a/flow-typed/npm/bcoin_vx.x.x.js b/flow-typed/npm/bcoin_vx.x.x.js index cd32081..c6663cc 100644 --- a/flow-typed/npm/bcoin_vx.x.x.js +++ b/flow-typed/npm/bcoin_vx.x.x.js @@ -1,1670 +1,103 @@ -// flow-typed signature: 52ec7d952e23091ff45f80adada48ac0 -// flow-typed version: <>/bcoin_v^1.0.0-beta.12/flow_v0.45.0 +// This is a work-in-progress attempt to type the bcoin library. -/** - * This is an autogenerated libdef stub for: - * - * 'bcoin' - * - * Fill this stub out by replacing all the `any` types. - * - * Once filled out, we encourage you to share your work with the - * community by sending a pull request to: - * https://github.com/flowtype/flow-typed - */ +type Hash = (string | Buffer); +type Network = any; -declare module 'bcoin' { - declare module.exports: any; -} - -/** - * We include stubs for each file inside this npm package in case you need to - * require those files directly. Feel free to delete any files that aren't - * needed. - */ -declare module 'bcoin/browser/empty' { - declare module.exports: any; -} - -declare module 'bcoin/browser/index' { - declare module.exports: any; -} - -declare module 'bcoin/browser/server' { - declare module.exports: any; -} - -declare module 'bcoin/browser/transform' { - declare module.exports: any; -} - -declare module 'bcoin/browser/wsproxy' { - declare module.exports: any; -} - -declare module 'bcoin/examples/chain' { - declare module.exports: any; -} - -declare module 'bcoin/examples/client' { - declare module.exports: any; -} - -declare module 'bcoin/examples/miner' { - declare module.exports: any; -} - -declare module 'bcoin/examples/node' { - declare module.exports: any; -} - -declare module 'bcoin/examples/peer' { - declare module.exports: any; -} - -declare module 'bcoin/examples/plugin' { - declare module.exports: any; -} - -declare module 'bcoin/examples/tx' { - declare module.exports: any; -} - -declare module 'bcoin/examples/wallet' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bcoin' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/certs' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/payment' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/paymentack' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/paymentdetails' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/paymentrequest' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/pk' { - declare module.exports: any; -} - -declare module 'bcoin/lib/bip70/x509' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/chain' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/chaindb' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/chainentry' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/layout-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/blockchain/layout' { - declare module.exports: any; -} - -declare module 'bcoin/lib/btc/amount' { - declare module.exports: any; -} - -declare module 'bcoin/lib/btc/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/btc/uri' { - declare module.exports: any; -} - -declare module 'bcoin/lib/coins/coins' { - declare module.exports: any; -} - -declare module 'bcoin/lib/coins/coinview' { - declare module.exports: any; -} - -declare module 'bcoin/lib/coins/compress' { - declare module.exports: any; -} - -declare module 'bcoin/lib/coins/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/coins/undocoins' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/aes' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/backend-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/backend' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/chachapoly' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/crypto' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/ec-elliptic' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/ec-secp256k1' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/ec' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/pk-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/pk' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/schnorr' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/scrypt' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/sha256' { - declare module.exports: any; -} - -declare module 'bcoin/lib/crypto/siphash' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/backends-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/backends' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/ldb' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/level' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/lowlevelup' { - declare module.exports: any; -} - -declare module 'bcoin/lib/db/memdb' { - declare module.exports: any; -} - -declare module 'bcoin/lib/env' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/hd' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/mnemonic' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/private' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/public' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/wordlist-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/wordlist' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/chinese-simplified' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/chinese-traditional' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/english' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/french' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/italian' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/japanese' { - declare module.exports: any; -} - -declare module 'bcoin/lib/hd/words/spanish' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/base' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/client' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/request' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/rpc' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/rpcbase' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/rpcclient' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/server' { - declare module.exports: any; -} - -declare module 'bcoin/lib/http/wallet' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/fees' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/layout-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/layout' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/mempool' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mempool/mempoolentry' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/cpuminer' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/mine' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/miner' { - declare module.exports: any; -} - -declare module 'bcoin/lib/mining/template' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/bip150' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/bip151' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/bip152' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/dns-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/dns' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/framer' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/hostlist' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/packets' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/parser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/peer' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/pool' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/proxysocket' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/seeds/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/seeds/main' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/seeds/testnet' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/socks' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/tcp-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/tcp' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/upnp-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/net/upnp' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/config' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/fullnode' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/logger' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/node' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/nodeclient' { - declare module.exports: any; -} - -declare module 'bcoin/lib/node/spvnode' { - declare module.exports: any; -} - -declare module 'bcoin/lib/pkg' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/abstractblock' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/address' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/block' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/coin' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/headers' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/input' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/invitem' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/keyring' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/memblock' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/merkleblock' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/mtx' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/netaddress' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/outpoint' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/output' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/tx' { - declare module.exports: any; -} - -declare module 'bcoin/lib/primitives/txmeta' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/consensus' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/errors' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/network' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/networks' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/policy' { - declare module.exports: any; -} - -declare module 'bcoin/lib/protocol/timedata' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/opcode' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/program' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/script' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/scriptnum' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/sigcache' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/stack' { - declare module.exports: any; -} - -declare module 'bcoin/lib/script/witness' { - declare module.exports: any; -} - -declare module 'bcoin/lib/types' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/asn1' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/asyncemitter' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/asyncobject' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/base32' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/base58' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/bloom' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/co' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/encoding' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/fs' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/heap' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/ip' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/lazy-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/lazy' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/list' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/lock' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/lru' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/map' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/murmur3' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/native' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/nexttick-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/nexttick' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/nfkd-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/nfkd' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/pem' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/protobuf' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/rbt' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/reader' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/staticwriter' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/util' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/validator' { - declare module.exports: any; -} - -declare module 'bcoin/lib/utils/writer' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/account' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/client' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/common' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/http' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/layout-browser' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/layout' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/masterkey' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/path' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/plugin' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/records' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/rpc' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/server' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/txdb' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/wallet' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/walletdb' { - declare module.exports: any; -} - -declare module 'bcoin/lib/wallet/walletkey' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/framer' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/index' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/jobs' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/master' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/packets' { - declare module.exports: any; -} - -declare module 'bcoin/lib/workers/parser-client' { - declare module.exports: any; +declare class bcoin$FullNode { + on(eventName : string, eventHandler : Function) : void; + getTX(hash : Hash) : Promise; + getCoin(hash : Hash, index : number) : bcoin$Coin; } -declare module 'bcoin/lib/workers/parser' { - declare module.exports: any; +declare class bcoin$Address { + toBase58() : string; + hash : Buffer; + static fromHash(Hash) : bcoin$Address; + static fromBase58(string) : bcoin$Address; } -declare module 'bcoin/lib/workers/worker-browser' { - declare module.exports: any; -} +declare class bcoin$TX { + inputs : bcoin$Input[]; + outputs : bcoin$Output[]; -declare module 'bcoin/lib/workers/worker' { - declare module.exports: any; + hash(enc : ?'hex') : Buffer; } -declare module 'bcoin/lib/workers/workerpool' { - declare module.exports: any; -} -declare module 'bcoin/migrate/chaindb0to1' { - declare module.exports: any; -} +declare class bcoin$MTX { + inputs : bcoin$Input[]; + outputs : bcoin$Output[]; -declare module 'bcoin/migrate/chaindb1to2' { - declare module.exports: any; + toTX : bcoin$TX; + template(ring : bcoin$KeyRing) : number; + scriptVector(outputScript : bcoin$Script, inputScript : bcoin$Script, ring : bcoin$KeyRing) : boolean; + addOutput(output : bcoin$Output) : void; + addCoin(coin : bcoin$Coin) : void; + sign(ring : bcoin$KeyRing) : number; + signInput(index : number, coin : bcoin$Coin, keyRing : bcoin$KeyRing) : boolean; } -declare module 'bcoin/migrate/coins-old' { - declare module.exports: any; -} +declare class bcoin$Output { + script : bcoin$Script; + value : number; -declare module 'bcoin/migrate/coinview-old' { - declare module.exports: any; + getType() : ('pubkeyhash' | 'multisig'); + getAddress() : bcoin$Address; } -declare module 'bcoin/migrate/compress-old' { - declare module.exports: any; -} +declare class bcoin$Input { + static fromOutpoint(outpoint : bcoin$Outpoint) : bcoin$Input; -declare module 'bcoin/migrate/ensure-tip-index' { - declare module.exports: any; -} + script : bcoin$Script; + prevout : bcoin$Outpoint; -declare module 'bcoin/migrate/walletdb2to3' { - declare module.exports: any; + getType() : ('pubkeyhash' | 'multisig'); + getAddress() : bcoin$Address; } -declare module 'bcoin/migrate/walletdb3to4' { - declare module.exports: any; -} +declare class bcoin$Script { + static fromMultisig(m : number, n : number, keys : Buffer[]) : bcoin$Script; + static fromPubkeyhash(hash : Hash) : bcoin$Script; -declare module 'bcoin/migrate/walletdb4to5' { - declare module.exports: any; + get(n : number) : (Buffer); } -declare module 'bcoin/migrate/walletdb5to6' { - declare module.exports: any; +declare class bcoin$Outpoint { + hash : Buffer; + index : number; } -declare module 'bcoin/scripts/dump' { - declare module.exports: any; -} +declare class bcoin$KeyRing { + static fromPrivate(key : Buffer, compressed : ?boolean, network : ?Network) : bcoin$KeyRing; + static fromPublic(key : Buffer, network : ?Network) : bcoin$KeyRing; -declare module 'bcoin/scripts/fuzz' { - declare module.exports: any; + getPublicKey() : Buffer; + getPrivateKey() : Buffer; } -declare module 'bcoin/scripts/gen' { - declare module.exports: any; +declare class bcoin$Coin extends bcoin$Output { + script : bcoin$Script; + value : number; } -declare module 'bcoin/vendor/setimmediate' { - declare module.exports: any; +declare module 'bcoin' { + declare module.exports: { + fullnode : Class, + script : Class, + primitives : { + Address : Class, + TX : Class, + MTX : Class, + Output : Class, + Input : Class, + Outpoint : Class, + KeyRing : Class, + Coin : Class + }, + crypto : { + hash160(str : (string | Buffer)) : Hash + } + } } -declare module 'bcoin/vendor/unorm' { - declare module.exports: any; -} -// Filename aliases -declare module 'bcoin/browser/empty.js' { - declare module.exports: $Exports<'bcoin/browser/empty'>; -} -declare module 'bcoin/browser/index.js' { - declare module.exports: $Exports<'bcoin/browser/index'>; -} -declare module 'bcoin/browser/server.js' { - declare module.exports: $Exports<'bcoin/browser/server'>; -} -declare module 'bcoin/browser/transform.js' { - declare module.exports: $Exports<'bcoin/browser/transform'>; -} -declare module 'bcoin/browser/wsproxy.js' { - declare module.exports: $Exports<'bcoin/browser/wsproxy'>; -} -declare module 'bcoin/examples/chain.js' { - declare module.exports: $Exports<'bcoin/examples/chain'>; -} -declare module 'bcoin/examples/client.js' { - declare module.exports: $Exports<'bcoin/examples/client'>; -} -declare module 'bcoin/examples/miner.js' { - declare module.exports: $Exports<'bcoin/examples/miner'>; -} -declare module 'bcoin/examples/node.js' { - declare module.exports: $Exports<'bcoin/examples/node'>; -} -declare module 'bcoin/examples/peer.js' { - declare module.exports: $Exports<'bcoin/examples/peer'>; -} -declare module 'bcoin/examples/plugin.js' { - declare module.exports: $Exports<'bcoin/examples/plugin'>; -} -declare module 'bcoin/examples/tx.js' { - declare module.exports: $Exports<'bcoin/examples/tx'>; -} -declare module 'bcoin/examples/wallet.js' { - declare module.exports: $Exports<'bcoin/examples/wallet'>; -} -declare module 'bcoin/lib/bcoin.js' { - declare module.exports: $Exports<'bcoin/lib/bcoin'>; -} -declare module 'bcoin/lib/bip70/certs.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/certs'>; -} -declare module 'bcoin/lib/bip70/index.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/index'>; -} -declare module 'bcoin/lib/bip70/payment.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/payment'>; -} -declare module 'bcoin/lib/bip70/paymentack.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/paymentack'>; -} -declare module 'bcoin/lib/bip70/paymentdetails.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/paymentdetails'>; -} -declare module 'bcoin/lib/bip70/paymentrequest.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/paymentrequest'>; -} -declare module 'bcoin/lib/bip70/pk.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/pk'>; -} -declare module 'bcoin/lib/bip70/x509.js' { - declare module.exports: $Exports<'bcoin/lib/bip70/x509'>; -} -declare module 'bcoin/lib/blockchain/chain.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/chain'>; -} -declare module 'bcoin/lib/blockchain/chaindb.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/chaindb'>; -} -declare module 'bcoin/lib/blockchain/chainentry.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/chainentry'>; -} -declare module 'bcoin/lib/blockchain/common.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/common'>; -} -declare module 'bcoin/lib/blockchain/index.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/index'>; -} -declare module 'bcoin/lib/blockchain/layout-browser.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/layout-browser'>; -} -declare module 'bcoin/lib/blockchain/layout.js' { - declare module.exports: $Exports<'bcoin/lib/blockchain/layout'>; -} -declare module 'bcoin/lib/btc/amount.js' { - declare module.exports: $Exports<'bcoin/lib/btc/amount'>; -} -declare module 'bcoin/lib/btc/index.js' { - declare module.exports: $Exports<'bcoin/lib/btc/index'>; -} -declare module 'bcoin/lib/btc/uri.js' { - declare module.exports: $Exports<'bcoin/lib/btc/uri'>; -} -declare module 'bcoin/lib/coins/coins.js' { - declare module.exports: $Exports<'bcoin/lib/coins/coins'>; -} -declare module 'bcoin/lib/coins/coinview.js' { - declare module.exports: $Exports<'bcoin/lib/coins/coinview'>; -} -declare module 'bcoin/lib/coins/compress.js' { - declare module.exports: $Exports<'bcoin/lib/coins/compress'>; -} -declare module 'bcoin/lib/coins/index.js' { - declare module.exports: $Exports<'bcoin/lib/coins/index'>; -} -declare module 'bcoin/lib/coins/undocoins.js' { - declare module.exports: $Exports<'bcoin/lib/coins/undocoins'>; -} -declare module 'bcoin/lib/crypto/aes.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/aes'>; -} -declare module 'bcoin/lib/crypto/backend-browser.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/backend-browser'>; -} -declare module 'bcoin/lib/crypto/backend.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/backend'>; -} -declare module 'bcoin/lib/crypto/chachapoly.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/chachapoly'>; -} -declare module 'bcoin/lib/crypto/crypto.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/crypto'>; -} -declare module 'bcoin/lib/crypto/ec-elliptic.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/ec-elliptic'>; -} -declare module 'bcoin/lib/crypto/ec-secp256k1.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/ec-secp256k1'>; -} -declare module 'bcoin/lib/crypto/ec.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/ec'>; -} -declare module 'bcoin/lib/crypto/index.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/index'>; -} -declare module 'bcoin/lib/crypto/pk-browser.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/pk-browser'>; -} -declare module 'bcoin/lib/crypto/pk.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/pk'>; -} -declare module 'bcoin/lib/crypto/schnorr.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/schnorr'>; -} -declare module 'bcoin/lib/crypto/scrypt.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/scrypt'>; -} -declare module 'bcoin/lib/crypto/sha256.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/sha256'>; -} -declare module 'bcoin/lib/crypto/siphash.js' { - declare module.exports: $Exports<'bcoin/lib/crypto/siphash'>; -} -declare module 'bcoin/lib/db/backends-browser.js' { - declare module.exports: $Exports<'bcoin/lib/db/backends-browser'>; -} -declare module 'bcoin/lib/db/backends.js' { - declare module.exports: $Exports<'bcoin/lib/db/backends'>; -} -declare module 'bcoin/lib/db/index.js' { - declare module.exports: $Exports<'bcoin/lib/db/index'>; -} -declare module 'bcoin/lib/db/ldb.js' { - declare module.exports: $Exports<'bcoin/lib/db/ldb'>; -} -declare module 'bcoin/lib/db/level.js' { - declare module.exports: $Exports<'bcoin/lib/db/level'>; -} -declare module 'bcoin/lib/db/lowlevelup.js' { - declare module.exports: $Exports<'bcoin/lib/db/lowlevelup'>; -} -declare module 'bcoin/lib/db/memdb.js' { - declare module.exports: $Exports<'bcoin/lib/db/memdb'>; -} -declare module 'bcoin/lib/env.js' { - declare module.exports: $Exports<'bcoin/lib/env'>; -} -declare module 'bcoin/lib/hd/common.js' { - declare module.exports: $Exports<'bcoin/lib/hd/common'>; -} -declare module 'bcoin/lib/hd/hd.js' { - declare module.exports: $Exports<'bcoin/lib/hd/hd'>; -} -declare module 'bcoin/lib/hd/index.js' { - declare module.exports: $Exports<'bcoin/lib/hd/index'>; -} -declare module 'bcoin/lib/hd/mnemonic.js' { - declare module.exports: $Exports<'bcoin/lib/hd/mnemonic'>; -} -declare module 'bcoin/lib/hd/private.js' { - declare module.exports: $Exports<'bcoin/lib/hd/private'>; -} -declare module 'bcoin/lib/hd/public.js' { - declare module.exports: $Exports<'bcoin/lib/hd/public'>; -} -declare module 'bcoin/lib/hd/wordlist-browser.js' { - declare module.exports: $Exports<'bcoin/lib/hd/wordlist-browser'>; -} -declare module 'bcoin/lib/hd/wordlist.js' { - declare module.exports: $Exports<'bcoin/lib/hd/wordlist'>; -} -declare module 'bcoin/lib/hd/words/chinese-simplified.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/chinese-simplified'>; -} -declare module 'bcoin/lib/hd/words/chinese-traditional.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/chinese-traditional'>; -} -declare module 'bcoin/lib/hd/words/english.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/english'>; -} -declare module 'bcoin/lib/hd/words/french.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/french'>; -} -declare module 'bcoin/lib/hd/words/index.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/index'>; -} -declare module 'bcoin/lib/hd/words/italian.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/italian'>; -} -declare module 'bcoin/lib/hd/words/japanese.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/japanese'>; -} -declare module 'bcoin/lib/hd/words/spanish.js' { - declare module.exports: $Exports<'bcoin/lib/hd/words/spanish'>; -} -declare module 'bcoin/lib/http/base.js' { - declare module.exports: $Exports<'bcoin/lib/http/base'>; -} -declare module 'bcoin/lib/http/client.js' { - declare module.exports: $Exports<'bcoin/lib/http/client'>; -} -declare module 'bcoin/lib/http/index.js' { - declare module.exports: $Exports<'bcoin/lib/http/index'>; -} -declare module 'bcoin/lib/http/request.js' { - declare module.exports: $Exports<'bcoin/lib/http/request'>; -} -declare module 'bcoin/lib/http/rpc.js' { - declare module.exports: $Exports<'bcoin/lib/http/rpc'>; -} -declare module 'bcoin/lib/http/rpcbase.js' { - declare module.exports: $Exports<'bcoin/lib/http/rpcbase'>; -} -declare module 'bcoin/lib/http/rpcclient.js' { - declare module.exports: $Exports<'bcoin/lib/http/rpcclient'>; -} -declare module 'bcoin/lib/http/server.js' { - declare module.exports: $Exports<'bcoin/lib/http/server'>; -} -declare module 'bcoin/lib/http/wallet.js' { - declare module.exports: $Exports<'bcoin/lib/http/wallet'>; -} -declare module 'bcoin/lib/mempool/fees.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/fees'>; -} -declare module 'bcoin/lib/mempool/index.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/index'>; -} -declare module 'bcoin/lib/mempool/layout-browser.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/layout-browser'>; -} -declare module 'bcoin/lib/mempool/layout.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/layout'>; -} -declare module 'bcoin/lib/mempool/mempool.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/mempool'>; -} -declare module 'bcoin/lib/mempool/mempoolentry.js' { - declare module.exports: $Exports<'bcoin/lib/mempool/mempoolentry'>; -} -declare module 'bcoin/lib/mining/common.js' { - declare module.exports: $Exports<'bcoin/lib/mining/common'>; -} -declare module 'bcoin/lib/mining/cpuminer.js' { - declare module.exports: $Exports<'bcoin/lib/mining/cpuminer'>; -} -declare module 'bcoin/lib/mining/index.js' { - declare module.exports: $Exports<'bcoin/lib/mining/index'>; -} -declare module 'bcoin/lib/mining/mine.js' { - declare module.exports: $Exports<'bcoin/lib/mining/mine'>; -} -declare module 'bcoin/lib/mining/miner.js' { - declare module.exports: $Exports<'bcoin/lib/mining/miner'>; -} -declare module 'bcoin/lib/mining/template.js' { - declare module.exports: $Exports<'bcoin/lib/mining/template'>; -} -declare module 'bcoin/lib/net/bip150.js' { - declare module.exports: $Exports<'bcoin/lib/net/bip150'>; -} -declare module 'bcoin/lib/net/bip151.js' { - declare module.exports: $Exports<'bcoin/lib/net/bip151'>; -} -declare module 'bcoin/lib/net/bip152.js' { - declare module.exports: $Exports<'bcoin/lib/net/bip152'>; -} -declare module 'bcoin/lib/net/common.js' { - declare module.exports: $Exports<'bcoin/lib/net/common'>; -} -declare module 'bcoin/lib/net/dns-browser.js' { - declare module.exports: $Exports<'bcoin/lib/net/dns-browser'>; -} -declare module 'bcoin/lib/net/dns.js' { - declare module.exports: $Exports<'bcoin/lib/net/dns'>; -} -declare module 'bcoin/lib/net/framer.js' { - declare module.exports: $Exports<'bcoin/lib/net/framer'>; -} -declare module 'bcoin/lib/net/hostlist.js' { - declare module.exports: $Exports<'bcoin/lib/net/hostlist'>; -} -declare module 'bcoin/lib/net/index.js' { - declare module.exports: $Exports<'bcoin/lib/net/index'>; -} -declare module 'bcoin/lib/net/packets.js' { - declare module.exports: $Exports<'bcoin/lib/net/packets'>; -} -declare module 'bcoin/lib/net/parser.js' { - declare module.exports: $Exports<'bcoin/lib/net/parser'>; -} -declare module 'bcoin/lib/net/peer.js' { - declare module.exports: $Exports<'bcoin/lib/net/peer'>; -} -declare module 'bcoin/lib/net/pool.js' { - declare module.exports: $Exports<'bcoin/lib/net/pool'>; -} -declare module 'bcoin/lib/net/proxysocket.js' { - declare module.exports: $Exports<'bcoin/lib/net/proxysocket'>; -} -declare module 'bcoin/lib/net/seeds/index.js' { - declare module.exports: $Exports<'bcoin/lib/net/seeds/index'>; -} -declare module 'bcoin/lib/net/seeds/main.js' { - declare module.exports: $Exports<'bcoin/lib/net/seeds/main'>; -} -declare module 'bcoin/lib/net/seeds/testnet.js' { - declare module.exports: $Exports<'bcoin/lib/net/seeds/testnet'>; -} -declare module 'bcoin/lib/net/socks.js' { - declare module.exports: $Exports<'bcoin/lib/net/socks'>; -} -declare module 'bcoin/lib/net/tcp-browser.js' { - declare module.exports: $Exports<'bcoin/lib/net/tcp-browser'>; -} -declare module 'bcoin/lib/net/tcp.js' { - declare module.exports: $Exports<'bcoin/lib/net/tcp'>; -} -declare module 'bcoin/lib/net/upnp-browser.js' { - declare module.exports: $Exports<'bcoin/lib/net/upnp-browser'>; -} -declare module 'bcoin/lib/net/upnp.js' { - declare module.exports: $Exports<'bcoin/lib/net/upnp'>; -} -declare module 'bcoin/lib/node/config.js' { - declare module.exports: $Exports<'bcoin/lib/node/config'>; -} -declare module 'bcoin/lib/node/fullnode.js' { - declare module.exports: $Exports<'bcoin/lib/node/fullnode'>; -} -declare module 'bcoin/lib/node/index.js' { - declare module.exports: $Exports<'bcoin/lib/node/index'>; -} -declare module 'bcoin/lib/node/logger.js' { - declare module.exports: $Exports<'bcoin/lib/node/logger'>; -} -declare module 'bcoin/lib/node/node.js' { - declare module.exports: $Exports<'bcoin/lib/node/node'>; -} -declare module 'bcoin/lib/node/nodeclient.js' { - declare module.exports: $Exports<'bcoin/lib/node/nodeclient'>; -} -declare module 'bcoin/lib/node/spvnode.js' { - declare module.exports: $Exports<'bcoin/lib/node/spvnode'>; -} -declare module 'bcoin/lib/pkg.js' { - declare module.exports: $Exports<'bcoin/lib/pkg'>; -} -declare module 'bcoin/lib/primitives/abstractblock.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/abstractblock'>; -} -declare module 'bcoin/lib/primitives/address.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/address'>; -} -declare module 'bcoin/lib/primitives/block.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/block'>; -} -declare module 'bcoin/lib/primitives/coin.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/coin'>; -} -declare module 'bcoin/lib/primitives/headers.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/headers'>; -} -declare module 'bcoin/lib/primitives/index.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/index'>; -} -declare module 'bcoin/lib/primitives/input.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/input'>; -} -declare module 'bcoin/lib/primitives/invitem.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/invitem'>; -} -declare module 'bcoin/lib/primitives/keyring.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/keyring'>; -} -declare module 'bcoin/lib/primitives/memblock.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/memblock'>; -} -declare module 'bcoin/lib/primitives/merkleblock.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/merkleblock'>; -} -declare module 'bcoin/lib/primitives/mtx.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/mtx'>; -} -declare module 'bcoin/lib/primitives/netaddress.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/netaddress'>; -} -declare module 'bcoin/lib/primitives/outpoint.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/outpoint'>; -} -declare module 'bcoin/lib/primitives/output.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/output'>; -} -declare module 'bcoin/lib/primitives/tx.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/tx'>; -} -declare module 'bcoin/lib/primitives/txmeta.js' { - declare module.exports: $Exports<'bcoin/lib/primitives/txmeta'>; -} -declare module 'bcoin/lib/protocol/consensus.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/consensus'>; -} -declare module 'bcoin/lib/protocol/errors.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/errors'>; -} -declare module 'bcoin/lib/protocol/index.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/index'>; -} -declare module 'bcoin/lib/protocol/network.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/network'>; -} -declare module 'bcoin/lib/protocol/networks.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/networks'>; -} -declare module 'bcoin/lib/protocol/policy.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/policy'>; -} -declare module 'bcoin/lib/protocol/timedata.js' { - declare module.exports: $Exports<'bcoin/lib/protocol/timedata'>; -} -declare module 'bcoin/lib/script/common.js' { - declare module.exports: $Exports<'bcoin/lib/script/common'>; -} -declare module 'bcoin/lib/script/index.js' { - declare module.exports: $Exports<'bcoin/lib/script/index'>; -} -declare module 'bcoin/lib/script/opcode.js' { - declare module.exports: $Exports<'bcoin/lib/script/opcode'>; -} -declare module 'bcoin/lib/script/program.js' { - declare module.exports: $Exports<'bcoin/lib/script/program'>; -} -declare module 'bcoin/lib/script/script.js' { - declare module.exports: $Exports<'bcoin/lib/script/script'>; -} -declare module 'bcoin/lib/script/scriptnum.js' { - declare module.exports: $Exports<'bcoin/lib/script/scriptnum'>; -} -declare module 'bcoin/lib/script/sigcache.js' { - declare module.exports: $Exports<'bcoin/lib/script/sigcache'>; -} -declare module 'bcoin/lib/script/stack.js' { - declare module.exports: $Exports<'bcoin/lib/script/stack'>; -} -declare module 'bcoin/lib/script/witness.js' { - declare module.exports: $Exports<'bcoin/lib/script/witness'>; -} -declare module 'bcoin/lib/types.js' { - declare module.exports: $Exports<'bcoin/lib/types'>; -} -declare module 'bcoin/lib/utils/asn1.js' { - declare module.exports: $Exports<'bcoin/lib/utils/asn1'>; -} -declare module 'bcoin/lib/utils/asyncemitter.js' { - declare module.exports: $Exports<'bcoin/lib/utils/asyncemitter'>; -} -declare module 'bcoin/lib/utils/asyncobject.js' { - declare module.exports: $Exports<'bcoin/lib/utils/asyncobject'>; -} -declare module 'bcoin/lib/utils/base32.js' { - declare module.exports: $Exports<'bcoin/lib/utils/base32'>; -} -declare module 'bcoin/lib/utils/base58.js' { - declare module.exports: $Exports<'bcoin/lib/utils/base58'>; -} -declare module 'bcoin/lib/utils/bloom.js' { - declare module.exports: $Exports<'bcoin/lib/utils/bloom'>; -} -declare module 'bcoin/lib/utils/co.js' { - declare module.exports: $Exports<'bcoin/lib/utils/co'>; -} -declare module 'bcoin/lib/utils/encoding.js' { - declare module.exports: $Exports<'bcoin/lib/utils/encoding'>; -} -declare module 'bcoin/lib/utils/fs.js' { - declare module.exports: $Exports<'bcoin/lib/utils/fs'>; -} -declare module 'bcoin/lib/utils/heap.js' { - declare module.exports: $Exports<'bcoin/lib/utils/heap'>; -} -declare module 'bcoin/lib/utils/index.js' { - declare module.exports: $Exports<'bcoin/lib/utils/index'>; -} -declare module 'bcoin/lib/utils/ip.js' { - declare module.exports: $Exports<'bcoin/lib/utils/ip'>; -} -declare module 'bcoin/lib/utils/lazy-browser.js' { - declare module.exports: $Exports<'bcoin/lib/utils/lazy-browser'>; -} -declare module 'bcoin/lib/utils/lazy.js' { - declare module.exports: $Exports<'bcoin/lib/utils/lazy'>; -} -declare module 'bcoin/lib/utils/list.js' { - declare module.exports: $Exports<'bcoin/lib/utils/list'>; -} -declare module 'bcoin/lib/utils/lock.js' { - declare module.exports: $Exports<'bcoin/lib/utils/lock'>; -} -declare module 'bcoin/lib/utils/lru.js' { - declare module.exports: $Exports<'bcoin/lib/utils/lru'>; -} -declare module 'bcoin/lib/utils/map.js' { - declare module.exports: $Exports<'bcoin/lib/utils/map'>; -} -declare module 'bcoin/lib/utils/murmur3.js' { - declare module.exports: $Exports<'bcoin/lib/utils/murmur3'>; -} -declare module 'bcoin/lib/utils/native.js' { - declare module.exports: $Exports<'bcoin/lib/utils/native'>; -} -declare module 'bcoin/lib/utils/nexttick-browser.js' { - declare module.exports: $Exports<'bcoin/lib/utils/nexttick-browser'>; -} -declare module 'bcoin/lib/utils/nexttick.js' { - declare module.exports: $Exports<'bcoin/lib/utils/nexttick'>; -} -declare module 'bcoin/lib/utils/nfkd-browser.js' { - declare module.exports: $Exports<'bcoin/lib/utils/nfkd-browser'>; -} -declare module 'bcoin/lib/utils/nfkd.js' { - declare module.exports: $Exports<'bcoin/lib/utils/nfkd'>; -} -declare module 'bcoin/lib/utils/pem.js' { - declare module.exports: $Exports<'bcoin/lib/utils/pem'>; -} -declare module 'bcoin/lib/utils/protobuf.js' { - declare module.exports: $Exports<'bcoin/lib/utils/protobuf'>; -} -declare module 'bcoin/lib/utils/rbt.js' { - declare module.exports: $Exports<'bcoin/lib/utils/rbt'>; -} -declare module 'bcoin/lib/utils/reader.js' { - declare module.exports: $Exports<'bcoin/lib/utils/reader'>; -} -declare module 'bcoin/lib/utils/staticwriter.js' { - declare module.exports: $Exports<'bcoin/lib/utils/staticwriter'>; -} -declare module 'bcoin/lib/utils/util.js' { - declare module.exports: $Exports<'bcoin/lib/utils/util'>; -} -declare module 'bcoin/lib/utils/validator.js' { - declare module.exports: $Exports<'bcoin/lib/utils/validator'>; -} -declare module 'bcoin/lib/utils/writer.js' { - declare module.exports: $Exports<'bcoin/lib/utils/writer'>; -} -declare module 'bcoin/lib/wallet/account.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/account'>; -} -declare module 'bcoin/lib/wallet/client.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/client'>; -} -declare module 'bcoin/lib/wallet/common.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/common'>; -} -declare module 'bcoin/lib/wallet/http.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/http'>; -} -declare module 'bcoin/lib/wallet/index.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/index'>; -} -declare module 'bcoin/lib/wallet/layout-browser.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/layout-browser'>; -} -declare module 'bcoin/lib/wallet/layout.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/layout'>; -} -declare module 'bcoin/lib/wallet/masterkey.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/masterkey'>; -} -declare module 'bcoin/lib/wallet/path.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/path'>; -} -declare module 'bcoin/lib/wallet/plugin.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/plugin'>; -} -declare module 'bcoin/lib/wallet/records.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/records'>; -} -declare module 'bcoin/lib/wallet/rpc.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/rpc'>; -} -declare module 'bcoin/lib/wallet/server.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/server'>; -} -declare module 'bcoin/lib/wallet/txdb.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/txdb'>; -} -declare module 'bcoin/lib/wallet/wallet.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/wallet'>; -} -declare module 'bcoin/lib/wallet/walletdb.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/walletdb'>; -} -declare module 'bcoin/lib/wallet/walletkey.js' { - declare module.exports: $Exports<'bcoin/lib/wallet/walletkey'>; -} -declare module 'bcoin/lib/workers/framer.js' { - declare module.exports: $Exports<'bcoin/lib/workers/framer'>; -} -declare module 'bcoin/lib/workers/index.js' { - declare module.exports: $Exports<'bcoin/lib/workers/index'>; -} -declare module 'bcoin/lib/workers/jobs.js' { - declare module.exports: $Exports<'bcoin/lib/workers/jobs'>; -} -declare module 'bcoin/lib/workers/master.js' { - declare module.exports: $Exports<'bcoin/lib/workers/master'>; -} -declare module 'bcoin/lib/workers/packets.js' { - declare module.exports: $Exports<'bcoin/lib/workers/packets'>; -} -declare module 'bcoin/lib/workers/parser-client.js' { - declare module.exports: $Exports<'bcoin/lib/workers/parser-client'>; -} -declare module 'bcoin/lib/workers/parser.js' { - declare module.exports: $Exports<'bcoin/lib/workers/parser'>; -} -declare module 'bcoin/lib/workers/worker-browser.js' { - declare module.exports: $Exports<'bcoin/lib/workers/worker-browser'>; -} -declare module 'bcoin/lib/workers/worker.js' { - declare module.exports: $Exports<'bcoin/lib/workers/worker'>; -} -declare module 'bcoin/lib/workers/workerpool.js' { - declare module.exports: $Exports<'bcoin/lib/workers/workerpool'>; -} -declare module 'bcoin/migrate/chaindb0to1.js' { - declare module.exports: $Exports<'bcoin/migrate/chaindb0to1'>; -} -declare module 'bcoin/migrate/chaindb1to2.js' { - declare module.exports: $Exports<'bcoin/migrate/chaindb1to2'>; -} -declare module 'bcoin/migrate/coins-old.js' { - declare module.exports: $Exports<'bcoin/migrate/coins-old'>; -} -declare module 'bcoin/migrate/coinview-old.js' { - declare module.exports: $Exports<'bcoin/migrate/coinview-old'>; -} -declare module 'bcoin/migrate/compress-old.js' { - declare module.exports: $Exports<'bcoin/migrate/compress-old'>; -} -declare module 'bcoin/migrate/ensure-tip-index.js' { - declare module.exports: $Exports<'bcoin/migrate/ensure-tip-index'>; -} -declare module 'bcoin/migrate/walletdb2to3.js' { - declare module.exports: $Exports<'bcoin/migrate/walletdb2to3'>; -} -declare module 'bcoin/migrate/walletdb3to4.js' { - declare module.exports: $Exports<'bcoin/migrate/walletdb3to4'>; -} -declare module 'bcoin/migrate/walletdb4to5.js' { - declare module.exports: $Exports<'bcoin/migrate/walletdb4to5'>; -} -declare module 'bcoin/migrate/walletdb5to6.js' { - declare module.exports: $Exports<'bcoin/migrate/walletdb5to6'>; -} -declare module 'bcoin/scripts/dump.js' { - declare module.exports: $Exports<'bcoin/scripts/dump'>; -} -declare module 'bcoin/scripts/fuzz.js' { - declare module.exports: $Exports<'bcoin/scripts/fuzz'>; -} -declare module 'bcoin/scripts/gen.js' { - declare module.exports: $Exports<'bcoin/scripts/gen'>; -} -declare module 'bcoin/vendor/setimmediate.js' { - declare module.exports: $Exports<'bcoin/vendor/setimmediate'>; -} -declare module 'bcoin/vendor/unorm.js' { - declare module.exports: $Exports<'bcoin/vendor/unorm'>; -} diff --git a/flow-typed/npm/graph-theory-ford-fulkerson_vx.x.x.js b/flow-typed/npm/graph-theory-ford-fulkerson_vx.x.x.js new file mode 100644 index 0000000..983c36c --- /dev/null +++ b/flow-typed/npm/graph-theory-ford-fulkerson_vx.x.x.js @@ -0,0 +1,45 @@ +// flow-typed signature: 2849579ad8dda7785593fce35e7021fd +// flow-typed version: <>/graph-theory-ford-fulkerson_v^1.0.0/flow_v0.45.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'graph-theory-ford-fulkerson' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'graph-theory-ford-fulkerson' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'graph-theory-ford-fulkerson/example/example' { + declare module.exports: any; +} + +declare module 'graph-theory-ford-fulkerson/test/index' { + declare module.exports: any; +} + +// Filename aliases +declare module 'graph-theory-ford-fulkerson/example/example.js' { + declare module.exports: $Exports<'graph-theory-ford-fulkerson/example/example'>; +} +declare module 'graph-theory-ford-fulkerson/index' { + declare module.exports: $Exports<'graph-theory-ford-fulkerson'>; +} +declare module 'graph-theory-ford-fulkerson/index.js' { + declare module.exports: $Exports<'graph-theory-ford-fulkerson'>; +} +declare module 'graph-theory-ford-fulkerson/test/index.js' { + declare module.exports: $Exports<'graph-theory-ford-fulkerson/test/index'>; +} diff --git a/flow-typed/npm/should-sinon_vx.x.x.js b/flow-typed/npm/should-sinon_vx.x.x.js new file mode 100644 index 0000000..6de6924 --- /dev/null +++ b/flow-typed/npm/should-sinon_vx.x.x.js @@ -0,0 +1,39 @@ +// flow-typed signature: 45843e3ce6bf3afc28721ddbe8e0ce2f +// flow-typed version: <>/should-sinon_v0.0.5/flow_v0.45.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'should-sinon' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'should-sinon' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'should-sinon/should-sinon' { + declare module.exports: any; +} + +declare module 'should-sinon/test' { + declare module.exports: any; +} + +// Filename aliases +declare module 'should-sinon/should-sinon.js' { + declare module.exports: $Exports<'should-sinon/should-sinon'>; +} +declare module 'should-sinon/test.js' { + declare module.exports: $Exports<'should-sinon/test'>; +} diff --git a/flow-typed/npm/sinon_vx.x.x.js b/flow-typed/npm/sinon_vx.x.x.js new file mode 100644 index 0000000..c75f639 --- /dev/null +++ b/flow-typed/npm/sinon_vx.x.x.js @@ -0,0 +1,375 @@ +// flow-typed signature: 49be0b929be2f6361f541fdb8e279527 +// flow-typed version: <>/sinon_v^2.2.0/flow_v0.45.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'sinon' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'sinon' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'sinon/lib/sinon' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/assert' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/behavior' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/blob' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/call' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/collect-own-methods' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/collection' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/color' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/default-behaviors' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/match' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/mock-expectation' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/mock' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/sandbox' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/spy-formatters' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/spy' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/stub-descriptor' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/stub-entire-object' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/stub-non-function-property' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/stub' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/throw-on-falsy-object' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/called-in-order' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/deep-equal' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/default-config' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/deprecated' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/every' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/extend' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/format' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/function-name' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/function-to-string' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/get-config' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/get-property-descriptor' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/index' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/iterable-to-string' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/log_error' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/order-by-first-call' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/restore' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/times-in-words' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/typeOf' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/value-to-string' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/walk' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/core/wrap-method' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/event' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/fake_server_with_clock' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/fake_server' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/fake_timers' { + declare module.exports: any; +} + +declare module 'sinon/lib/sinon/util/fake_xml_http_request' { + declare module.exports: any; +} + +declare module 'sinon/pkg/sinon-2.2.0' { + declare module.exports: any; +} + +declare module 'sinon/pkg/sinon-no-sourcemaps-2.2.0' { + declare module.exports: any; +} + +declare module 'sinon/pkg/sinon-no-sourcemaps' { + declare module.exports: any; +} + +declare module 'sinon/pkg/sinon' { + declare module.exports: any; +} + +// Filename aliases +declare module 'sinon/lib/sinon.js' { + declare module.exports: $Exports<'sinon/lib/sinon'>; +} +declare module 'sinon/lib/sinon/assert.js' { + declare module.exports: $Exports<'sinon/lib/sinon/assert'>; +} +declare module 'sinon/lib/sinon/behavior.js' { + declare module.exports: $Exports<'sinon/lib/sinon/behavior'>; +} +declare module 'sinon/lib/sinon/blob.js' { + declare module.exports: $Exports<'sinon/lib/sinon/blob'>; +} +declare module 'sinon/lib/sinon/call.js' { + declare module.exports: $Exports<'sinon/lib/sinon/call'>; +} +declare module 'sinon/lib/sinon/collect-own-methods.js' { + declare module.exports: $Exports<'sinon/lib/sinon/collect-own-methods'>; +} +declare module 'sinon/lib/sinon/collection.js' { + declare module.exports: $Exports<'sinon/lib/sinon/collection'>; +} +declare module 'sinon/lib/sinon/color.js' { + declare module.exports: $Exports<'sinon/lib/sinon/color'>; +} +declare module 'sinon/lib/sinon/default-behaviors.js' { + declare module.exports: $Exports<'sinon/lib/sinon/default-behaviors'>; +} +declare module 'sinon/lib/sinon/match.js' { + declare module.exports: $Exports<'sinon/lib/sinon/match'>; +} +declare module 'sinon/lib/sinon/mock-expectation.js' { + declare module.exports: $Exports<'sinon/lib/sinon/mock-expectation'>; +} +declare module 'sinon/lib/sinon/mock.js' { + declare module.exports: $Exports<'sinon/lib/sinon/mock'>; +} +declare module 'sinon/lib/sinon/sandbox.js' { + declare module.exports: $Exports<'sinon/lib/sinon/sandbox'>; +} +declare module 'sinon/lib/sinon/spy-formatters.js' { + declare module.exports: $Exports<'sinon/lib/sinon/spy-formatters'>; +} +declare module 'sinon/lib/sinon/spy.js' { + declare module.exports: $Exports<'sinon/lib/sinon/spy'>; +} +declare module 'sinon/lib/sinon/stub-descriptor.js' { + declare module.exports: $Exports<'sinon/lib/sinon/stub-descriptor'>; +} +declare module 'sinon/lib/sinon/stub-entire-object.js' { + declare module.exports: $Exports<'sinon/lib/sinon/stub-entire-object'>; +} +declare module 'sinon/lib/sinon/stub-non-function-property.js' { + declare module.exports: $Exports<'sinon/lib/sinon/stub-non-function-property'>; +} +declare module 'sinon/lib/sinon/stub.js' { + declare module.exports: $Exports<'sinon/lib/sinon/stub'>; +} +declare module 'sinon/lib/sinon/throw-on-falsy-object.js' { + declare module.exports: $Exports<'sinon/lib/sinon/throw-on-falsy-object'>; +} +declare module 'sinon/lib/sinon/util/core/called-in-order.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/called-in-order'>; +} +declare module 'sinon/lib/sinon/util/core/deep-equal.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/deep-equal'>; +} +declare module 'sinon/lib/sinon/util/core/default-config.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/default-config'>; +} +declare module 'sinon/lib/sinon/util/core/deprecated.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/deprecated'>; +} +declare module 'sinon/lib/sinon/util/core/every.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/every'>; +} +declare module 'sinon/lib/sinon/util/core/extend.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/extend'>; +} +declare module 'sinon/lib/sinon/util/core/format.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/format'>; +} +declare module 'sinon/lib/sinon/util/core/function-name.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/function-name'>; +} +declare module 'sinon/lib/sinon/util/core/function-to-string.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/function-to-string'>; +} +declare module 'sinon/lib/sinon/util/core/get-config.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/get-config'>; +} +declare module 'sinon/lib/sinon/util/core/get-property-descriptor.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/get-property-descriptor'>; +} +declare module 'sinon/lib/sinon/util/core/index.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/index'>; +} +declare module 'sinon/lib/sinon/util/core/iterable-to-string.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/iterable-to-string'>; +} +declare module 'sinon/lib/sinon/util/core/log_error.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/log_error'>; +} +declare module 'sinon/lib/sinon/util/core/order-by-first-call.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/order-by-first-call'>; +} +declare module 'sinon/lib/sinon/util/core/restore.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/restore'>; +} +declare module 'sinon/lib/sinon/util/core/times-in-words.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/times-in-words'>; +} +declare module 'sinon/lib/sinon/util/core/typeOf.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/typeOf'>; +} +declare module 'sinon/lib/sinon/util/core/value-to-string.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/value-to-string'>; +} +declare module 'sinon/lib/sinon/util/core/walk.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/walk'>; +} +declare module 'sinon/lib/sinon/util/core/wrap-method.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/core/wrap-method'>; +} +declare module 'sinon/lib/sinon/util/event.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/event'>; +} +declare module 'sinon/lib/sinon/util/fake_server_with_clock.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/fake_server_with_clock'>; +} +declare module 'sinon/lib/sinon/util/fake_server.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/fake_server'>; +} +declare module 'sinon/lib/sinon/util/fake_timers.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/fake_timers'>; +} +declare module 'sinon/lib/sinon/util/fake_xml_http_request.js' { + declare module.exports: $Exports<'sinon/lib/sinon/util/fake_xml_http_request'>; +} +declare module 'sinon/pkg/sinon-2.2.0.js' { + declare module.exports: $Exports<'sinon/pkg/sinon-2.2.0'>; +} +declare module 'sinon/pkg/sinon-no-sourcemaps-2.2.0.js' { + declare module.exports: $Exports<'sinon/pkg/sinon-no-sourcemaps-2.2.0'>; +} +declare module 'sinon/pkg/sinon-no-sourcemaps.js' { + declare module.exports: $Exports<'sinon/pkg/sinon-no-sourcemaps'>; +} +declare module 'sinon/pkg/sinon.js' { + declare module.exports: $Exports<'sinon/pkg/sinon'>; +} diff --git a/flow-typed/npm/sorted-set_vx.x.x.js b/flow-typed/npm/sorted-set_vx.x.x.js new file mode 100644 index 0000000..be9ce1e --- /dev/null +++ b/flow-typed/npm/sorted-set_vx.x.x.js @@ -0,0 +1,87 @@ +// flow-typed signature: 49b561be32534814522dc2da04fa8dea +// flow-typed version: <>/sorted-set_v1.x.x/flow_v0.45.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'sorted-set' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'sorted-set' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'sorted-set/examples/distance' { + declare module.exports: any; +} + +declare module 'sorted-set/examples/kademlia' { + declare module.exports: any; +} + +declare module 'sorted-set/examples/ttl' { + declare module.exports: any; +} + +declare module 'sorted-set/lib/intersect-sorted' { + declare module.exports: any; +} + +declare module 'sorted-set/lib/intersect-unique' { + declare module.exports: any; +} + +declare module 'sorted-set/lib/set' { + declare module.exports: any; +} + +declare module 'sorted-set/test/index' { + declare module.exports: any; +} + +declare module 'sorted-set/test/set' { + declare module.exports: any; +} + +// Filename aliases +declare module 'sorted-set/examples/distance.js' { + declare module.exports: $Exports<'sorted-set/examples/distance'>; +} +declare module 'sorted-set/examples/kademlia.js' { + declare module.exports: $Exports<'sorted-set/examples/kademlia'>; +} +declare module 'sorted-set/examples/ttl.js' { + declare module.exports: $Exports<'sorted-set/examples/ttl'>; +} +declare module 'sorted-set/index' { + declare module.exports: $Exports<'sorted-set'>; +} +declare module 'sorted-set/index.js' { + declare module.exports: $Exports<'sorted-set'>; +} +declare module 'sorted-set/lib/intersect-sorted.js' { + declare module.exports: $Exports<'sorted-set/lib/intersect-sorted'>; +} +declare module 'sorted-set/lib/intersect-unique.js' { + declare module.exports: $Exports<'sorted-set/lib/intersect-unique'>; +} +declare module 'sorted-set/lib/set.js' { + declare module.exports: $Exports<'sorted-set/lib/set'>; +} +declare module 'sorted-set/test/index.js' { + declare module.exports: $Exports<'sorted-set/test/index'>; +} +declare module 'sorted-set/test/set.js' { + declare module.exports: $Exports<'sorted-set/test/set'>; +} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 2b229a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,12 +0,0 @@ -// -var bcoin = require('bcoin'); - -class fullnode extends bcoin.fullnode { - constructor(options ) { - super(options); - } -} - -module.exports = { - fullnode -} diff --git a/package.json b/package.json index 681643a..116b868 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "main": "lib/index.js", "scripts": { "build": "flow-remove-types -d lib/ src/", - "test": "npm run build && mocha", + "test": "npm run build && mocha -t 10000", "prepublish": "npm run build", - "typecheck": "flow check" + "typecheck": "flow check", + "lint": "./node_modules/.bin/eslint --fix src/ test/", + "check": "npm run lint && npm run typecheck && npm run test" }, "repository": { "type": "git", @@ -19,17 +21,25 @@ "blockchain" ], "author": "Decrypto-org", - "license": "ISC", + "license": "MIT", "bugs": { "url": "https://github.com/decrypto-org/TrustIsRisk.js/issues" }, "homepage": "https://github.com/decrypto-org/TrustIsRisk.js#readme", "devDependencies": { + "babel-eslint": "^7.2.3", + "eslint": "^3.19.0", + "eslint-plugin-flowtype": "^2.33.0", "flow-bin": "^0.45.0", "flow-remove-types": "^1.2.0", - "should": "^11.2.1" + "mocha": "^3.4.2", + "should": "^11.2.1", + "should-sinon": "0.0.5", + "sinon": "^2.2.0" }, "dependencies": { - "bcoin": "^1.0.0-beta.12" + "bcoin": "1.0.0-beta.12", + "graph-theory-ford-fulkerson": "^1.0.0", + "sorted-set": "^0.3.0" } } diff --git a/src/direct_trust.js b/src/direct_trust.js new file mode 100644 index 0000000..3ed4fcf --- /dev/null +++ b/src/direct_trust.js @@ -0,0 +1,103 @@ +// @flow +import type {Entity, Key} from "./types"; +import type {script} from "bcoin"; +var assert = require("assert"); +var helpers = require("./helpers"); + +type DirectTrustOptions = { + origin : Key, + dest : Key, + amount : number, + + txHash : string, + outputIndex? : number, + script? : bcoin$Script, + + prev? : DirectTrust, + next? : DirectTrust +} + +class DirectTrust { + origin : Key + dest : Key + amount : number + + // Every DT is associated with a transaction output, except for non-standard trust decreasing + // transactions, which reduce trust to zero and are related to a whole transaction and not + // a specific output. + txHash : string + outputIndex : (number | null) + script : (bcoin$Script | null) + + prev : (DirectTrust | null) + next : (DirectTrust | null) + + constructor(options : DirectTrustOptions) { + this.outputIndex = null; + this.script = null; + this.prev = null; + this.next = null; + Object.assign(this, options); + } + + isNull() { + return this.amount === 0; + } + + isIncrease() : boolean { + return this.prev === null; + } + + isDecrease() : boolean { + return !this.isIncrease(); + } + + isSpent() : boolean { + return this.next !== null; + } + + isSpendable() : boolean { + return !this.isSpent() && !this.isNull(); + } + + isValid() : boolean { + // TODO: Consider removing this function and ensure validity at build time by using the flow + // type system, possibly by creating sub-types like "IncreasingDirectTrust" etc. + if ((this.outputIndex === null) !== (this.script === null)) return false; + if (this.outputIndex === null && this.isIncrease()) return false; + if (this.outputIndex === null && this.amount > 0) return false; + if (this.isIncrease() && this.isNull()) return false; + if (this.isSpent() && this.isNull()) return false; + return true; + } + + getOriginEntity() : Entity { + return helpers.pubKeyToEntity(this.origin); + } + + getDestEntity() : Entity { + return helpers.pubKeyToEntity(this.dest); + } + + spend(next : DirectTrust) : void { + assert(!this.isSpent()); + assert(this.origin.equals(next.origin) && this.dest.equals(next.dest)); + assert(next.amount <= this.amount); + + this.next = next; + next.prev = this; + } + + getNullifying(txHash : string) : DirectTrust { + return new DirectTrust({ + origin: this.origin, + dest: this.dest, + amount: 0, + + prev: this, + txHash, + }); + } +} + +module.exports = DirectTrust; diff --git a/src/full_node.js b/src/full_node.js new file mode 100644 index 0000000..93e664d --- /dev/null +++ b/src/full_node.js @@ -0,0 +1,14 @@ +// @flow +var bcoin = require("bcoin"); +var TrustIsRisk = require("./trust_is_risk"); + +class FullNode extends bcoin.fullnode { + trust : TrustIsRisk + + constructor(options : Object) { + super(options); + this.trust = new TrustIsRisk(this); + } +} + +module.exports = FullNode; diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000..6416a31 --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,12 @@ +// @flow +import type {Entity, TXHash, Key} from "./types"; +var bcoin = require("bcoin"); +var Address = bcoin.primitives.Address; + +var helpers = { + pubKeyToEntity: (key : Key) : Entity => { + return Address.fromHash(bcoin.crypto.hash160(key)).toBase58(); + } +}; + +module.exports = helpers; diff --git a/src/index.js b/src/index.js index 2db0e64..66a1290 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,5 @@ // @flow -var bcoin = require('bcoin'); - -class fullnode extends bcoin.fullnode { - constructor(options : Object) { - super(options); - } -} - module.exports = { - fullnode -} + FullNode: require("./full_node"), + TrustIsRisk: require("./trust_is_risk") +}; diff --git a/src/trust_db.js b/src/trust_db.js new file mode 100644 index 0000000..d41e680 --- /dev/null +++ b/src/trust_db.js @@ -0,0 +1,115 @@ +// @flow +import type {Entity, TXHash, Key} from "./types"; +var assert = require("assert"); +var SortedSet = require("sorted-set"); +var maxFlow = require("graph-theory-ford-fulkerson"); +var bcoin = require("bcoin"); +var Address = bcoin.primitives.Address; +var KeyRing = bcoin.primitives.KeyRing; +var MTX = bcoin.primitives.MTX; +var Input = bcoin.primitives.Input; +var Output = bcoin.primitives.Output; +var Outpoint = bcoin.primitives.Outpoint; +var DirectTrust = require("./direct_trust"); + +class TrustDB { + directTrusts : Map>> + txToDirectTrust : Map + entities : SortedSet; + + constructor() { + this.directTrusts = new Map(); + this.txToDirectTrust = new Map(); + this.entities = new SortedSet(); + } + + getDirectTrustByOutpoint(outpoint : bcoin$Outpoint) : (DirectTrust | null) { + var trust = this.txToDirectTrust.get(outpoint.hash.toString("hex")); + if (!trust) return null; + if (trust.outputIndex !== outpoint.index) return null; + return trust; + } + + getDirectTrustAmount(origin : Entity, dest : Entity) : number { + if (origin === dest) return Infinity; + + var trusts = this.getSpendableDirectTrusts(origin, dest); + return trusts.reduce((sum, t) => sum + t.amount, 0); + } + + getSpendableDirectTrusts(origin : Entity, dest : Entity) : DirectTrust[] { + return this.getDirectTrusts(origin, dest).filter((t) => t.isSpendable()); + } + + getDirectTrusts(origin : Entity, dest : Entity) : DirectTrust[] { + var originMap = this.directTrusts.get(origin); + if (!originMap) return []; + + var trusts = originMap.get(dest); + if (!trusts) return []; + + return trusts; + } + + getGraphWeightMatrix() : number[][] { + var entitiesArr = this.getEntities(); + return entitiesArr.map((origin) => { + return entitiesArr.map((dest) => this.getDirectTrustAmount(origin, dest)); + }); + } + + getTrustAmount(origin : Entity, dest : Entity) : number { + // TODO: Optimize + if (origin === dest) return Infinity; + + var graph = this.getGraphWeightMatrix(); + var originIndex = this.getEntityIndex(origin); + var destIndex = this.getEntityIndex(dest); + + if (originIndex === -1 || destIndex === -1) return 0; + else return maxFlow(graph, originIndex, destIndex); + } + + getEntities() : Entity[] { + return this.entities.slice(); + } + + getEntityIndex(entity : Entity) : number { + return this.entities.rank(entity); + } + + isTrustTX(txHash : string) : boolean { + return this.txToDirectTrust.has(txHash); + } + + isTrustOutput(txHash : string, outputIndex : number) : boolean { + var trust = this.txToDirectTrust.get(txHash); + return trust !== undefined && trust.outputIndex === outputIndex; + } + + add(trust : DirectTrust) { + var origin = trust.getOriginEntity(); + var dest = trust.getDestEntity(); + assert(origin !== dest); + + if (!this.directTrusts.has(origin)) this.directTrusts.set(origin, new Map()); + var originMap = ((this.directTrusts.get(origin) : any) : Map>); + + if (!originMap.has(dest)) originMap.set(dest, []); + var trusts = ((originMap.get(dest) : any) : Array); + + if (trust.prev !== null) { + trust.prev.spend(trust); + assert(trust.prev && trust.prev.isValid() && !trust.prev.isSpendable()); + } + + assert(trust.isValid()); + trusts.push(trust); + this.txToDirectTrust.set(trust.txHash, trust); + + this.entities.add(origin); + this.entities.add(dest); + } +} + +module.exports = TrustDB; diff --git a/src/trust_is_risk.js b/src/trust_is_risk.js new file mode 100644 index 0000000..d92a947 --- /dev/null +++ b/src/trust_is_risk.js @@ -0,0 +1,283 @@ +// @flow +import type {Entity, TXHash, Key} from "./types"; +var bcoin = require("bcoin"); +var Address = bcoin.primitives.Address; +var KeyRing = bcoin.primitives.KeyRing; +var MTX = bcoin.primitives.MTX; +var Input = bcoin.primitives.Input; +var Output = bcoin.primitives.Output; +var Outpoint = bcoin.primitives.Outpoint; +var Coin = bcoin.primitives.Coin; +var assert = require("assert"); +var helpers = require("./helpers"); +var TrustDB = require("./trust_db"); +var DirectTrust = require("./direct_trust"); + +class TrustIsRisk { + node : bcoin$FullNode + db : TrustDB + + constructor(node : bcoin$FullNode) { + this.node = node; + this.db = new TrustDB(); + + this.node.on("tx", this.addTX.bind(this)); + } + + getIndirectTrust(origin : Entity, dest : Entity) { + return this.db.getTrustAmount(origin, dest); + } + + getDirectTrust(origin : Entity, dest : Entity) { + return this.db.getDirectTrustAmount(origin, dest); + } + + // Attempts to parse a bitcoin transaction as a trust change and adds it to the trust network + // if successful. + // Returns true if the transaction is a TIR transaction and was successfully added to the + // network, false otherwise. + // Throws an error if the transaction was processed earlier. + addTX(tx : bcoin$TX) : boolean { + var txHash = tx.hash().toString("hex"); + if (this.db.isTrustTX(txHash)) { + throw new Error(`Transaction already processed: Transaction ${txHash} already carries trust`); + } + + var directTrusts = this.getDirectTrusts(tx); + if (directTrusts.length === 0) return false; + else { + directTrusts.forEach(this.db.add.bind(this.db)); + return true; + } + } + + // Returns a list of trusts that a transaction contains, which will be one of the following: + // * An empty list (for non-TIR transactions). + // * A list containing a single trust increase (for trust-increasing transactions). + // * A list containing one or more trust decreases (for trust-decreasing transactions). + getDirectTrusts(tx : bcoin$TX) : DirectTrust[] { + var trustIncrease = this.parseTXAsTrustIncrease(tx); + if (trustIncrease !== null) { + return [trustIncrease]; + } else { + return this.getTrustDecreases(tx); + } + } + + // Returns a promise resolving to a mutable transaction object, which increases a trust + // relationship by some amount. It will spend the outpoint, which must reference a P2PKH output + // payable to the sender. The origin key must be a private key. Any satoshis not spent will be + // returned to the sender, minus the fees, via P2PKH. + async createTrustIncreasingMTX(origin : Key, dest : Key, outpoint : bcoin$Outpoint, + trustAmount : number, fee : ?number) + : Promise { + if (!fee) fee = 1000; // TODO: estimate this + var coin = await this.node.getCoin(outpoint.hash, outpoint.index); + if (!coin) throw new Error("Could not find coin"); + if (origin === dest) throw new Error("Can not increase self-trust."); + + var originKeyRing = KeyRing.fromPrivate(origin); + var originPubKey = originKeyRing.getPublicKey(); + + var mtx = new MTX({ + outputs: [ + new Output({ + script: bcoin.script.fromMultisig(1, 2, [originPubKey, dest]), + value: trustAmount + }) + ] + }); + + var changeAmount = coin.value - trustAmount - fee; + assert(changeAmount >= 0); + if (changeAmount) { + mtx.addOutput(new Output({ + script: bcoin.script.fromPubkeyhash(bcoin.crypto.hash160(originPubKey)), + value: changeAmount + })); + } + + mtx.addCoin(coin); + var success = mtx.scriptVector(coin.script, mtx.inputs[0].script, originKeyRing); + assert(success); + + var signedCount = mtx.sign(originKeyRing); + assert(signedCount === 1); + + return mtx; + } + + // Returns an array of trust-decreasing mutable transaction objects, which reduce a trust + // relationship by the amount specified. The payee will receive the amount deducted minus the + // transaction fees via P2PKH. + // If steal is undefined or set to false, then the `origin` key is expected to be a private key + // and the `dest` key is expected to be a public key. If steal is set to true, then `origin` is + // expected to be a public key and `dest` is expected to be a private key. The private key will be + // used to sign the transaction. + createTrustDecreasingMTXs(origin : Key, dest : Key, trustDecreaseAmount : number, payee : ?Entity, + steal : ?boolean, fee : ?number) : bcoin$MTX[] { + if (steal === undefined) steal = false; + + var signingKeyRing, originKeyRing, destKeyRing; + if (!steal) { + signingKeyRing = KeyRing.fromPrivate(origin); + originKeyRing = KeyRing.fromPrivate(origin); + destKeyRing = KeyRing.fromPublic(dest); + } else { + signingKeyRing = KeyRing.fromPrivate(dest); + originKeyRing = KeyRing.fromPublic(origin); + destKeyRing = KeyRing.fromPrivate(dest); + } + + var originAddress = helpers.pubKeyToEntity(originKeyRing.getPublicKey()); + var destAddress = helpers.pubKeyToEntity(destKeyRing.getPublicKey()); + + if (originAddress === destAddress) throw new Error("Can't decrease self-trust"); + + var existingTrustAmount = this.db.getDirectTrustAmount(originAddress, destAddress); + if (existingTrustAmount < trustDecreaseAmount) throw new Error("Insufficient trust"); + + var directTrusts = this.db.getSpendableDirectTrusts(originAddress, destAddress); + return directTrusts.map((directTrust) => { + var decrease = Math.min(trustDecreaseAmount, directTrust.amount); + if (decrease === 0) return null; + trustDecreaseAmount -= decrease; + return this.getTrustDecreasingMTX(directTrust, decrease, payee, signingKeyRing, fee); + }).filter(Boolean); + } + + getTrustDecreasingMTX(directTrust : DirectTrust, decreaseAmount : number, payee : ?Entity, + signingKeyRing : bcoin$KeyRing, fee : ?number) { + if (!payee) payee = directTrust.getOriginEntity(); + if (!fee) fee = 1000; // TODO: estimate this + + var mtx = new MTX({ + inputs: [ + Input.fromOutpoint(new Outpoint(directTrust.txHash, directTrust.outputIndex)) + ], + outputs: [new Output({ + script: bcoin.script.fromPubkeyhash(Address.fromBase58(payee).hash), + value: ((decreaseAmount - fee) < 0) ? 0 : (decreaseAmount - fee) + })] + }); + + var remainingTrustAmount = directTrust.amount - decreaseAmount; + if (remainingTrustAmount > 0) { + mtx.addOutput(new Output({ + script: bcoin.script.fromMultisig(1, 2, [directTrust.origin, directTrust.dest]), + value: remainingTrustAmount + })); + } + + var success = mtx.scriptVector(((directTrust.script : any) : bcoin$Script), + mtx.inputs[0].script, KeyRing.fromPublic(directTrust.origin)); + assert(success); + + success = mtx.signInput(0, new Coin({script: directTrust.script, value: directTrust.amount}), + signingKeyRing); + assert(success); + + return mtx; + } + + parseTXAsTrustIncrease(tx : bcoin$TX) : (DirectTrust | null) { + if (tx.inputs.length !== 1) return null; + var input = tx.inputs[0]; + if (input.getType() !== "pubkeyhash") return null; // TODO: This is unreliable + if (this.db.isTrustOutput(input.prevout.hash.toString("hex"), input.prevout.index)) return null; + var origin = tx.inputs[0].getAddress().toBase58(); + + if (tx.outputs.length === 0 || tx.outputs.length > 2) return null; + + var trustOutputs = this.searchForDirectTrustOutputs(tx, origin); + if (trustOutputs.length !== 1) return null; + + var changeOutputCount = tx.outputs.filter((o) => this.isChangeOutput(o, origin)).length; + if (changeOutputCount + 1 !== tx.outputs.length) return null; + + return trustOutputs[0]; + } + + getTrustDecreases(tx : bcoin$TX) : DirectTrust[] { + var inputTrusts = this.getInputTrusts(tx.inputs); + return inputTrusts.map(this.getTrustDecrease.bind(this, tx)); + } + + getInputTrusts(inputs : bcoin$Input[]) : DirectTrust[] { + return inputs.map((input) => { + return this.db.getDirectTrustByOutpoint(input.prevout); + }).filter(Boolean); + } + + getTrustDecrease(tx : bcoin$TX, prevTrust : DirectTrust) : DirectTrust { + var txHash = tx.hash().toString("hex"); + var nullTrust = prevTrust.getNullifying(txHash); + + if (tx.inputs.length !== 1) return nullTrust; + + var trustOutputs = this.searchForDirectTrustOutputs(tx, prevTrust.getOriginEntity(), + prevTrust.getDestEntity()); + if (trustOutputs.length != 1) return nullTrust; + var nextTrust = trustOutputs[0]; + + nextTrust.prev = prevTrust; + + assert(nextTrust.amount <= prevTrust.amount); + return nextTrust; + } + + // Looks for direct trust outputs that originate from a sender in a transaction. + // Returns an array of the corresponding DirectTrust objects. + // If the recipient parameter is set, it will limit the results only to the outputs being sent to + // the recipient. + searchForDirectTrustOutputs(tx : bcoin$TX, origin : Entity, recipient : ?Entity) : DirectTrust[] { + var directTrusts = tx.outputs.map((output, outputIndex) => + this.parseOutputAsDirectTrust(tx, outputIndex, origin) + ).filter(Boolean); // filter out nulls + + if (recipient) { + directTrusts = directTrusts.filter((trust) => + helpers.pubKeyToEntity(trust.dest) === recipient); + } + + return directTrusts; + } + + isChangeOutput(output : bcoin$Output, origin : Entity) : boolean { + return (output.getType() === "pubkeyhash") + && (output.getAddress().toBase58() === origin); + } + + parseOutputAsDirectTrust(tx : bcoin$TX, outputIndex : number, origin : Entity) + : (DirectTrust | null) { + var txHash = tx.hash().toString("hex"); + var output = tx.outputs[outputIndex]; + if (output.getType() !== "multisig") return null; + + var entities = [1, 2].map((i) => helpers.pubKeyToEntity(output.script.get(i))); + if (entities[0] === entities[1]) return null; + + var originPubKey, destPubKey; + if (entities[0] === origin) { + originPubKey = output.script.get(1); + destPubKey = output.script.get(2); + } + else if (entities[1] === origin) { + originPubKey = output.script.get(2); + destPubKey = output.script.get(1); + } + else return null; + + return new DirectTrust({ + origin: originPubKey, + dest: destPubKey, + amount: Number(output.value), + + txHash, + outputIndex, + script: output.script + }); + } +} + +module.exports = TrustIsRisk; diff --git a/src/types.js b/src/types.js new file mode 100644 index 0000000..1bb788b --- /dev/null +++ b/src/types.js @@ -0,0 +1,8 @@ +//@flow + +// base58 bitcoin address: +export type Entity = string; + +export type TXHash = string; + +export type Key = Buffer; diff --git a/test/fixtures.js b/test/fixtures.js new file mode 100644 index 0000000..a11f021 --- /dev/null +++ b/test/fixtures.js @@ -0,0 +1,23 @@ +var bcoin = require("bcoin"); +var KeyRing = bcoin.primitives.KeyRing; + +var privateKeys = { + "alice": "02B8F07A401ECA4888039B1898F94DB44C43CCC6D3AA8B27E9B6ED7B377B24C0", + "bob": "2437025954568A8273968AA7535DBFC444FD8F8D0F5237CD96AC7234C77810AD", + "charlie": "3BBA2AF9539D09B4FD2BDEA1D3A2CE4BF5D779831B8781EE2ACF9C03378B2AD7", + "dave": "19BD8D853FAEFDB9B01E4DE7F6096FF8F5F96D43E6564A5258307334A4AA59F3", + "eve": "0503054CF7EBB4E62191AF1D8DE97945178D3F465EE88EF1FB4E80A70CB4A49A", + "frank": "878DFE5B43AC858EA37B3A9EEBA9E244F1848A30F78B2E5AC5B3EBDE81AC7D45", + "george": "1349A1318B1426E6F724CBFE7ECD2C46008A364A96C4BD20C83FC1C4EBB2EB4A" +}; + +var keyRings = {}; +for (let name in privateKeys) { + let key = privateKeys[name]; + keyRings[name] = KeyRing.fromPrivate(new Buffer(key, "hex")); +} + +module.exports = { + keyRings, + names: Object.keys(keyRings) +}; diff --git a/test/full_node.js b/test/full_node.js new file mode 100644 index 0000000..a3260ba --- /dev/null +++ b/test/full_node.js @@ -0,0 +1,197 @@ +var Trust = require("../"); +var helpers = require("../lib/helpers.js"); +var bcoin = require("bcoin"); +var Script = bcoin.script; +var Address = bcoin.primitives.Address; +var KeyRing = bcoin.primitives.KeyRing; +var MTX = bcoin.primitives.MTX; +var Input = bcoin.primitives.Input; +var Output = bcoin.primitives.Output; +var Outpoint = bcoin.primitives.Outpoint; +var testHelpers = require("./helpers"); +var consensus = require("bcoin/lib/protocol/consensus"); +var sinon = require("sinon"); +var should = require("should"); +var assert = require("assert"); +var fixtures = require("./fixtures"); +require("should-sinon"); + +const COIN = consensus.COIN; + +describe("FullNode", () => { + var node = null; + var walletDB = null; + var NodeWatcher = null; + var watcher = null; + sinon.spy(Trust.TrustIsRisk.prototype, "addTX"); + + beforeEach("get node", async () => { + node = await testHelpers.getNode(); + watcher = new testHelpers.NodeWatcher(node); + }); + + beforeEach("get walletDB", async () => { + walletDB = await testHelpers.getWalletDB(node); + }); + + afterEach("close walletDB", async () => walletDB.close()); + afterEach("close node", async () => node.close()); + + it("should call trust.addTX() on every transaction", async function() { + var sender = await testHelpers.createWallet(walletDB, "sender"); + var receiver = await testHelpers.createWallet(walletDB, "receiver"); + + await testHelpers.delay(1000); + // Produce a block and reward the sender, so that we have a coin to spend. + await testHelpers.mineBlock(node, sender.getAddress("base58")); + + // Make the coin spendable. + consensus.COINBASE_MATURITY = 0; + await testHelpers.delay(100); + + await sender.send({ + outputs: [{ + value: 10 * COIN, + address: receiver.getAddress("base58") + }] + }); + await watcher.waitForTX(); + + node.trust.addTX.should.be.calledOnce(); + }); + + describe("with the nobodyLikesFrank.json example", () => { + var addresses, rings = {}; + + beforeEach("apply graph transactions", async () => { + addresses = {}; + + for (var [name, keyRing] of Object.entries(fixtures.keyRings)) { + addresses[name] = helpers.pubKeyToEntity(keyRing.getPublicKey()); + } + + // Alice mines three blocks, each rewards her with 50 spendable BTC + consensus.COINBASE_MATURITY = 0; + var blockCount = 3; + var coinbaseHashes = []; + for(let i = 0; i < blockCount; i++) { + var block = await testHelpers.mineBlock(node, addresses.alice); + coinbaseHashes.push(block.txs[0].hash()); + await testHelpers.delay(500); + } + + // Alice sends 20 BTC to everyone (including herself) via P2PKH + var sendAmount = 20; + var outputs = fixtures.names.map((name) => { + return testHelpers.getP2PKHOutput( + Address.fromHash(bcoin.crypto.hash160(fixtures.keyRings[name].getPublicKey())) + .toBase58(), + sendAmount * consensus.COIN); + }); + + // We have to use a change output, because transaction with too large a fee are considered + // invalid. + var fee = 0.01; + var changeAmount = 50 * blockCount - sendAmount * fixtures.names.length - fee; + if (changeAmount >= 0.01) { + outputs.push(new Output({ + script: Script.fromPubkeyhash(bcoin.crypto.hash160( + fixtures.keyRings.alice.getPublicKey())), + value: changeAmount * consensus.COIN + })); + } + + // Use the coinbase coins as inputs + var coinbaseCoins = await Promise.all(coinbaseHashes.map((hash) => { + return node.getCoin(hash.toString("hex"), 0); + })); + var mtx = new MTX({outputs}); + coinbaseCoins.forEach((coin) => mtx.addCoin(coin)); + + var signedCount = mtx.sign(fixtures.keyRings.alice); + assert(signedCount === blockCount); + assert(await mtx.verify()); + + var tx = mtx.toTX(); + node.sendTX(tx); + await watcher.waitForTX(); + + prevout = {}; + fixtures.names.forEach((name) => { + prevout[name] = { + hash: tx.hash().toString("hex"), + index: fixtures.names.indexOf(name) + }; + }); + + // Alice mines another block + await testHelpers.mineBlock(node, helpers.pubKeyToEntity( + fixtures.keyRings.alice.getPublicKey())); + await testHelpers.delay(500); + + var graph = require("./graphs/nobodyLikesFrank.json"); + for (var origin in graph) { + var neighbours = graph[origin]; + for (var dest in neighbours) { + var value = neighbours[dest]; + if (!value || value < 1) continue; + + let outpoint = new Outpoint(prevout[origin].hash, prevout[origin].index); + + let mtx = await node.trust.createTrustIncreasingMTX( + fixtures.keyRings[origin].getPrivateKey(), + fixtures.keyRings[dest].getPublicKey(), + outpoint, + value * consensus.COIN); + + assert(await mtx.verify()); + + let tx = mtx.toTX(); + node.sendTX(tx); + await watcher.waitForTX(); + + prevout[origin] = {hash: tx.hash().toString("hex"), index: 1}; + } + } + + // Alice mines yet another block + await testHelpers.mineBlock(node, helpers.pubKeyToEntity( + fixtures.keyRings.alice.getPublicKey())); + await testHelpers.delay(500); + }); + + it("computes trusts correctly", () => { + for (name in addresses) { // Add addresses to scope + eval(`var ${name} = "${addresses[name]}";`); + } + + should(node.trust.getIndirectTrust(alice, alice)).equal(Infinity); + should(node.trust.getIndirectTrust(alice, bob)).equal(10 * COIN); + should(node.trust.getIndirectTrust(alice, charlie)).equal(1 * COIN); + should(node.trust.getIndirectTrust(alice, frank)).equal(0); + should(node.trust.getIndirectTrust(alice, eve)).equal(6 * COIN); + + should(node.trust.getIndirectTrust(bob, alice)).equal(1 * COIN); + should(node.trust.getIndirectTrust(bob, eve)).equal(3 * COIN); + should(node.trust.getIndirectTrust(dave, eve)).equal(12 * COIN); + should(node.trust.getIndirectTrust(george, eve)).equal(0); + }); + + it("after decreasing some trusts computes trusts correctly", async () => { + var mtxs = node.trust.createTrustDecreasingMTXs(fixtures.keyRings.alice.getPrivateKey(), + fixtures.keyRings.bob.getPublicKey(), 3 * COIN); + mtxs.length.should.equal(1); + var mtx = mtxs[0]; + + should(await mtx.verify()); + node.sendTX(mtx.toTX()); + + await testHelpers.delay(750); + should(node.trust.getIndirectTrust(addresses.alice, addresses.bob)).equal(7 * COIN); + }); + }); + + describe("with the topcoder.json example", () => { + //TODO: Write tests here. + }); +}); diff --git a/test/graphs/nobodyLikesFrank.json b/test/graphs/nobodyLikesFrank.json new file mode 100644 index 0000000..9c246bc --- /dev/null +++ b/test/graphs/nobodyLikesFrank.json @@ -0,0 +1,24 @@ +{ + "alice": { + "bob": 10, + "dave": 3 + }, + "bob": { + "charlie": 1, + "eve": 2, + "dave": 1, + "george": 1 + }, + "charlie": { + "george": 3 + }, + "dave": { + "eve": 10, + "alice": 2 + }, + "eve": {}, + "frank": { + "charlie": 10 + }, + "george": {} +} diff --git a/test/graphs/topcoder.json b/test/graphs/topcoder.json new file mode 100644 index 0000000..f051965 --- /dev/null +++ b/test/graphs/topcoder.json @@ -0,0 +1,19 @@ +{ + "alice": { + "bob": 3, + "dave": 1 + }, + "bob": { + "charlie": 3 + }, + "charlie": { + "frank": 2 + }, + "dave": { + "charlie": 5, + "eve": 4 + }, + "eve": { + "frank": 2 + } +} diff --git a/test/helpers.js b/test/helpers.js new file mode 100644 index 0000000..855c1de --- /dev/null +++ b/test/helpers.js @@ -0,0 +1,160 @@ +var TrustIsRisk = require("../"); +var WalletDB = require("bcoin/lib/wallet/walletdb"); +var bcoin = require("bcoin"); +var fixtures = require("./fixtures"); +var KeyRing = bcoin.primitives.KeyRing; +var assert = require("assert"); + +var testHelpers = { + getNode: async () => { + var node = new TrustIsRisk.FullNode({network: "regtest", passphrase: "secret"}); + + await node.open(); + await node.connect(); + node.startSync(); + + return node; + }, + + getWalletDB: async (node) => { + var walletDB = new WalletDB({ + network: "regtest", + db: "memory", + client: new bcoin.node.NodeClient(node) + }); + + await walletDB.open(); + await walletDB.connect(); + + return walletDB; + }, + + createWallet: async (walletDB, id) => { + var options = { + id, + passphrase: "secret", + witness: false, + type: "pubkeyhash" + }; + + return walletDB.create(options); + }, + + mineBlock: async (node, rewardAddress) => { + var block = await node.miner.mineBlock(node.chain.tip, rewardAddress); + await node.chain.add(block); + // node.chain.tip does not contain all the properties we want, + // so we need to fetch it: + return node.getBlock(node.chain.tip.hash); + }, + + delay: async (milliseconds) => { + return new Promise((resolve, reject) => { + setTimeout(resolve, milliseconds); + }); + }, + + bufferToScript: (data) => { + return `0x${Number(data.length).toString(16)} 0x${data.toString("hex")}`; + }, + + getP2PKHOutput: (dest, value) => { + var address = bcoin.primitives.Address.fromBase58(dest); + var script = bcoin.script.fromPubkeyhash(address.hash); + + return new bcoin.primitives.Output({script, value}); + }, + + getP2PKHInput: (pubKey, prevout) => { + if (!prevout) { + prevout = { // Don't care + hash: "v0pnhphaf4r5wz63j60vnh27s1bftl260qq621y458tn0g4x64u64yqz6d7qi6i8", + index: 2 + }; + } + + return new bcoin.primitives.Input({ + prevout, + script: bcoin.script.fromString( + // Don't care about the signature + "0x47 0x3044022035e32834c6ee4db1696cc06762feca2809d865ca12a3b98c801f3f451341a2570220573bf3ffef55f2651e1563acc0a22f8056222f277f5ddf17dd583d4edd40fa6001 " + + testHelpers.bufferToScript(pubKey)) + }); + }, + + getOneOfTwoMultisigOutput: (originPubKey, destPubKey, value) => { + return new bcoin.primitives.Output({ + script: bcoin.script.fromMultisig(1, 2, [originPubKey, destPubKey]), + value + }); + }, + + getTrustIncreasingMTX: (originPubKey, destPubKey, value) => { + return new bcoin.primitives.MTX({ + inputs: [ + testHelpers.getP2PKHInput(originPubKey) + ], + outputs: [ + testHelpers.getOneOfTwoMultisigOutput(originPubKey, destPubKey, value) + ] + }); + }, + + applyGraph: (trust, fileName, addressBook) => { + var graph = require(fileName); + + for (var origin in graph) { + var neighbours = graph[origin]; + for (var dest in neighbours) { + var value = neighbours[dest]; + trust.addTX(testHelpers.getTrustIncreasingMTX(addressBook[origin].pubKey, addressBook[dest].pubKey, value).toTX()); + } + } + } +}; + +class NodeWatcher { + constructor(node) { + this.txCount = 0; + this.blockCount = 0; + this.node = node; + this.node.on("tx", this.onTX.bind(this)); + this.node.on("block", this.onBlock.bind(this)); + } + + onTX() { + this.txCount++; + } + + onBlock() { + this.blockCount++; + } + + async waitForBlock(initialCount) { + if (initialCount === undefined) initialCount = this.blockCount; + await new Promise((resolve, reject) => { + var check = (() => { + if (this.blockCount > initialCount) resolve(); + else setTimeout(check, 100); + }).bind(this); + + check(); + }); + } + + async waitForTX(initialCount) { + if (initialCount === undefined) initialCount = this.txCount; + await new Promise((resolve, reject) => { + var check = (() => { + if (this.txCount > initialCount) resolve(); + else setTimeout(check, 100); + }).bind(this); + + check(); + }); + } +} + +testHelpers.NodeWatcher = NodeWatcher; + +module.exports = testHelpers; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index cd34a7d..0000000 --- a/test/test.js +++ /dev/null @@ -1,10 +0,0 @@ -var TrustIsRisk = require('../'); -var bcoin = require('bcoin'); -var should = require('should'); - -describe('new TrustIsRisk.fullnode', () => { - it('should be a bcoin instance', () => { - var node = new TrustIsRisk.fullnode({}); - should(node).be.an.instanceof(bcoin.fullnode); - }); -}); diff --git a/test/trust_is_risk.js b/test/trust_is_risk.js new file mode 100644 index 0000000..2040784 --- /dev/null +++ b/test/trust_is_risk.js @@ -0,0 +1,383 @@ +var Trust = require("../"); +var helpers = require("../lib/helpers.js"); +var bcoin = require("bcoin"); +var Coin = bcoin.primitives.Coin; +var Address = bcoin.primitives.Address; +var Input = bcoin.primitives.Input; +var MTX = bcoin.primitives.MTX; +var testHelpers = require("./helpers"); +var consensus = require("bcoin/lib/protocol/consensus"); +var sinon = require("sinon"); +var should = require("should"); +var fixtures = require("./fixtures"); +require("should-sinon"); + +const COIN = bcoin.consensus.COIN; + +describe("TrustIsRisk", () => { + var addr = {}; + for (let [name, keyRing] of Object.entries(fixtures.keyRings)) { + var pubKey = keyRing.getPublicKey(); + var privKey = keyRing.getPrivateKey(); + + addr[name] = {}; + addr[name].pubKey = pubKey; + addr[name].privKey = privKey; + addr[name].base58 = bcoin.primitives.Address.fromHash(bcoin.crypto.hash160(pubKey)).toString(); + } + + // Add base58 address variables to scope. + for (name in fixtures.keyRings) { + var keyRing = fixtures.keyRings[name]; + eval(`var ${name} = "${bcoin.primitives.Address.fromHash(bcoin.crypto.hash160(keyRing.getPublicKey())).toString()}";`); + } + + var node, tir, trustIncreasingMTX, trustDecreasingMTX, trustIncreasingTX; + beforeEach(() => { + node = new bcoin.fullnode({}); + tir = new Trust.TrustIsRisk(node); + + trustIncreasingMTX = testHelpers.getTrustIncreasingMTX(addr.alice.pubKey, addr.bob.pubKey, 42 * COIN); + trustIncreasingTX = trustIncreasingMTX.toTX(); + + var inputOneOfTwoMultisig = new Input({ + prevout: { + hash: trustIncreasingTX.hash().toString("hex"), + index: 0 + }, + script: bcoin.script.fromString( + // 17P8kCbDBPmqLDCCe9dYwbfiEDaRb5xDYE + "0x47 0x3044022035e32834c6ee4db1696cc06762feca2809d865ca12a3b98c801f3f451341a2570220573bf3ffef55f2651e1563acc0a22f8056222f277f5ddf17dd583d4edd40fa6001 0x21 0x02b8f07a401eca4888039b1898f94db44c43ccc6d3aa8b27e9b6ed7b377b24c083") + }); + + trustDecreasingMTX = new MTX({ + inputs: [ + inputOneOfTwoMultisig + ], + outputs: [ + testHelpers.getOneOfTwoMultisigOutput(addr.alice.pubKey, addr.bob.pubKey, 20 * COIN), + testHelpers.getP2PKHOutput(addr.alice.base58, 22 * COIN) + ] + }); + }); + + describe(".getDirectTrust()", () => { + it("returns zero for two arbitary parties that do not trust each other", () => { + tir.getDirectTrust(alice, bob).should.equal(0); + tir.getDirectTrust(bob, alice).should.equal(0); + tir.getDirectTrust(charlie, alice).should.equal(0); + tir.getDirectTrust(alice, charlie).should.equal(0); + tir.getDirectTrust(charlie, frank).should.equal(0); + }); + + it("returns Infinity for one's direct trust to themselves", () => { + tir.getDirectTrust(alice, alice).should.equal(Infinity); + tir.getDirectTrust(bob, bob).should.equal(Infinity); + }); + }); + + describe(".addTX()", () => { + describe("with a non-TIR transaction", () => { + it("does not change trust", () => { + trustIncreasingMTX.outputs[0] = testHelpers.getP2PKHOutput(charlie, 50 * COIN); + tir.addTX(trustIncreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + tir.getDirectTrust(bob, alice).should.equal(0); + tir.getDirectTrust(alice, charlie).should.equal(0); + tir.getDirectTrust(charlie, alice).should.equal(0); + tir.getDirectTrust(charlie, dave).should.equal(0); + }); + }); + + describe("with a trust increasing transaction", () => { + it("correctly increases trust", () => { + tir.addTX(trustIncreasingTX); + + tir.getDirectTrust(alice, bob).should.equal(42 * COIN); + tir.getDirectTrust(bob, alice).should.equal(0); + tir.getDirectTrust(charlie, dave).should.equal(0); + }); + + it("which has more than one input does not change trust", () => { + trustIncreasingMTX.inputs.push(trustIncreasingMTX.inputs[0].clone()); + tir.addTX(trustIncreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + }); + + it("which has a change output correctly increases trust", () => { + trustIncreasingMTX.outputs[0].value -= 10 * COIN; + trustIncreasingMTX.outputs.push(testHelpers.getP2PKHOutput(alice, 10 * COIN)); + tir.addTX(trustIncreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(32 * COIN); + }); + + it("which has two change outputs does not change trust", () => { + trustIncreasingMTX.outputs[0].value -= 10; + for (var i = 0; i < 2; i++) { + trustIncreasingMTX.outputs.push(testHelpers.getP2PKHOutput(alice, 5 * COIN)); + } + tir.addTX(trustIncreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + }); + + it("which has a second output that is not a change output does not change trust", () => { + trustIncreasingMTX.outputs[0].value -= 10 * COIN; + trustIncreasingMTX.outputs.push(testHelpers.getP2PKHOutput(charlie, 5 * COIN)); + tir.addTX(trustIncreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + }); + + it("which has been processed before throws", () => { + var tx = trustIncreasingMTX.toTX(); + should(tir.addTX(tx)); + should.throws(() => tir.addTX(tx), /already processed/i); + tir.getDirectTrust(alice, bob).should.equal(42 * COIN); + }); + }); + + describe("with a trust decreasing transaction", () => { + beforeEach(() => { + tir.addTX(trustIncreasingTX); + }); + + it("correctly decreases trust", () => { + tir.addTX(trustDecreasingMTX.toTX()); + tir.getDirectTrust(alice, bob).should.equal(20 * COIN); + }); + + it("decreases trust to zero for trust decreasing transactions with a wrong recipient", () => { + // By changing the trust recipient from bob to charlie, we make the transaction a + // nullifying trust transaction. + trustDecreasingMTX.outputs[0] = + testHelpers.getOneOfTwoMultisigOutput(addr.alice.pubKey, addr.charlie.pubKey, 20 * COIN); + + tir.addTX(trustDecreasingMTX.toTX()); + tir.getDirectTrust(alice, bob).should.equal(0); + }); + + it("which has a second input decreases trust to zero", () => { + trustDecreasingMTX.inputs.push(testHelpers.getP2PKHInput(addr.alice.pubKey)); + tir.addTX(trustDecreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + }); + + it("which has more than one trust outputs decreases trust to zero", () => { + trustDecreasingMTX.outputs[0].value -= 15 * COIN; + trustDecreasingMTX.outputs.push( + testHelpers.getOneOfTwoMultisigOutput(addr.alice.pubKey, addr.bob.pubKey, 5 * COIN)); + tir.addTX(trustDecreasingMTX.toTX()); + + tir.getDirectTrust(alice, bob).should.equal(0); + }); + }); + }); + + describe(".createTrustIncreasingMTX()", () => { + it("creates valid trust-increasing transactions", async () => { + var getTXStub = sinon.stub(node, "getCoin"); + + var prevOutput = { + hash: "v1pnhp2af4r5wz63j60vnh27s1bftl260qq621y458tn0g4x64u64yqz6d7qi6i8", + index: 1 + }; + + getTXStub.withArgs(prevOutput.hash).returns(new Coin({ + script: testHelpers.getP2PKHOutput(alice, 1).script, + value: 1000 * COIN + })); + + var mtx = await tir.createTrustIncreasingMTX(addr.alice.privKey, addr.bob.pubKey, prevOutput, + 100 * COIN); + + mtx.inputs.length.should.equal(1); + + mtx.outputs.length.should.equal(2); + + var trustOutput = mtx.outputs[0]; + trustOutput.getType().should.equal("multisig"); + [1, 2].map((i) => helpers.pubKeyToEntity(trustOutput.script.get(i))).sort() + .should.deepEqual([alice, bob].sort()); + trustOutput.value.should.equal(100 * COIN); + + var changeOutput = mtx.outputs[1]; + changeOutput.getType().should.equal("pubkeyhash"); + changeOutput.getAddress().toBase58().should.equal(alice); + changeOutput.value.should.equal(900 * COIN - 1000); + }); + }); + + describe(".getTrustDecreasingMTX()", () => { + var trustTXs; + beforeEach(() => { + var tx; + trustTXs = []; + + tx = trustIncreasingTX; + trustTXs.push(tx); + tir.addTX(tx); + + trustIncreasingMTX.outputs[0].value = 100 * COIN; + tx = trustIncreasingMTX.toTX(); + trustTXs.push(tx); + tir.addTX(tx); + + trustIncreasingMTX.outputs[0].value = 500 * COIN; + tx = trustIncreasingMTX.toTX(); + trustTXs.push(tx); + tir.addTX(tx); + + // Total trust 642 BTC + }); + + // Helper specific to the next couple of tests: + // Checks that mtxs is a list of two trust decreasing transactions. The first one spends the + // entire first trust increasing transaction, and the second spends part of the second. + // Also checks that the reduced trust is sent via P2PKH outputs to the correct recipient. + var checkMTXs = (mtxs, recipient) => { + mtxs.length.should.equal(2); + + var mtx = mtxs[0]; + + mtx.inputs.length.should.equal(1); + mtx.inputs[0].prevout.should.have.properties({ + hash: trustTXs[0].hash().toString("hex"), + index: 0 + }); + + mtx.outputs.length.should.equal(1); // Single P2PKH output + mtx.outputs[0].getType().should.equal("pubkeyhash"); + mtx.outputs[0].getAddress().toBase58().should.equal(recipient); + mtx.outputs[0].value.should.equal(42 * COIN - 1000); + + mtx = mtxs[1]; + + mtx.inputs.length.should.equal(1); + mtx.inputs[0].prevout.should.have.properties({ + hash: trustTXs[1].hash().toString("hex"), + index: 0 + }); + + mtx.outputs.length.should.equal(2); // One P2PKH output and one multisig trust output + mtx.outputs[1].script.toString().should.equal(trustTXs[1].outputs[0].script.toString()); + mtx.outputs[1].value.should.equal(60 * COIN); + mtx.outputs[0].getType().should.equal("pubkeyhash"); + mtx.outputs[0].getAddress().toBase58().should.equal(recipient); + mtx.outputs[0].value.should.equal(40 * COIN - 1000); + }; + + it("creates correct trust decreasing transactions", () => { + var mtxs = tir.createTrustDecreasingMTXs(addr.alice.privKey, addr.bob.pubKey, 82 * COIN); + checkMTXs(mtxs, alice); + }); + + it("creates correct trust stealing transactions", () => { + var mtxs = tir.createTrustDecreasingMTXs(addr.alice.privKey, addr.bob.pubKey, 82 * COIN, charlie); + checkMTXs(mtxs, charlie); + }); + + it("throws when trying to decrease self-trust", () => { + should.throws(() => tir.createTrustDecreasingMTXs(addr.alice.privKey, addr.alice.pubKey, 10 * COIN) + , /self-trust/i); + }); + + it("throws when there is not enough trust", () => { + should.throws(() => tir.createTrustDecreasingMTXs(addr.alice.privKey, addr.bob.pubKey, 700 * COIN) + , /insufficient trust/i); + + }); + }); + + describe(".getIndirectTrust()", () => { + it("returns zero for two arbitary parties that do not trust each other", () => { + should(tir.getIndirectTrust(alice, bob)).equal(0); + should(tir.getIndirectTrust(bob, alice)).equal(0); + should(tir.getIndirectTrust(charlie, alice)).equal(0); + should(tir.getIndirectTrust(alice, charlie)).equal(0); + }); + + it("returns Infinity for one's trust to themselves", () => { + should(tir.getIndirectTrust(alice, alice)).equal(Infinity); + should(tir.getIndirectTrust(bob, bob)).equal(Infinity); + }); + + describe("after applying the Nobody Likes Frank graph example", () => { + beforeEach(() => { + testHelpers.applyGraph(tir, "./graphs/nobodyLikesFrank.json", addr); + }); + + it("correctly computes trusts", () => { + should(tir.getIndirectTrust(alice, alice)).equal(Infinity); + should(tir.getIndirectTrust(alice, bob)).equal(10); + should(tir.getIndirectTrust(alice, charlie)).equal(1); + should(tir.getIndirectTrust(alice, dave)).equal(4); + should(tir.getIndirectTrust(alice, eve)).equal(6); + should(tir.getIndirectTrust(alice, frank)).equal(0); + should(tir.getIndirectTrust(alice, george)).equal(2); + + should(tir.getIndirectTrust(bob, alice)).equal(1); + should(tir.getIndirectTrust(bob, bob)).equal(Infinity); + should(tir.getIndirectTrust(bob, charlie)).equal(1); + should(tir.getIndirectTrust(bob, dave)).equal(1); + should(tir.getIndirectTrust(bob, eve)).equal(3); + should(tir.getIndirectTrust(bob, frank)).equal(0); + should(tir.getIndirectTrust(bob, george)).equal(2); + + should(tir.getIndirectTrust(charlie, alice)).equal(0); + should(tir.getIndirectTrust(charlie, bob)).equal(0); + should(tir.getIndirectTrust(charlie, charlie)).equal(Infinity); + should(tir.getIndirectTrust(charlie, dave)).equal(0); + should(tir.getIndirectTrust(charlie, eve)).equal(0); + should(tir.getIndirectTrust(charlie, frank)).equal(0); + should(tir.getIndirectTrust(charlie, george)).equal(3); + + should(tir.getIndirectTrust(dave, alice)).equal(2); + should(tir.getIndirectTrust(dave, bob)).equal(2); + should(tir.getIndirectTrust(dave, charlie)).equal(1); + should(tir.getIndirectTrust(dave, dave)).equal(Infinity); + should(tir.getIndirectTrust(dave, eve)).equal(12); + should(tir.getIndirectTrust(dave, frank)).equal(0); + should(tir.getIndirectTrust(dave, george)).equal(2); + + should(tir.getIndirectTrust(eve, alice)).equal(0); + should(tir.getIndirectTrust(eve, bob)).equal(0); + should(tir.getIndirectTrust(eve, charlie)).equal(0); + should(tir.getIndirectTrust(eve, dave)).equal(0); + should(tir.getIndirectTrust(eve, eve)).equal(Infinity); + should(tir.getIndirectTrust(eve, frank)).equal(0); + should(tir.getIndirectTrust(eve, george)).equal(0); + + should(tir.getIndirectTrust(frank, alice)).equal(0); + should(tir.getIndirectTrust(frank, bob)).equal(0); + should(tir.getIndirectTrust(frank, charlie)).equal(10); + should(tir.getIndirectTrust(frank, dave)).equal(0); + should(tir.getIndirectTrust(frank, eve)).equal(0); + should(tir.getIndirectTrust(frank, frank)).equal(Infinity); + should(tir.getIndirectTrust(frank, george)).equal(3); + + should(tir.getIndirectTrust(george, alice)).equal(0); + should(tir.getIndirectTrust(george, bob)).equal(0); + should(tir.getIndirectTrust(george, charlie)).equal(0); + should(tir.getIndirectTrust(george, dave)).equal(0); + should(tir.getIndirectTrust(george, eve)).equal(0); + should(tir.getIndirectTrust(george, frank)).equal(0); + should(tir.getIndirectTrust(george, george)).equal(Infinity); + }); + + it("correctly computes trusts when bob trusts frank", () => { + tir.addTX(testHelpers.getTrustIncreasingMTX(addr.bob.pubKey, addr.frank.pubKey, 8).toTX()); + should(tir.getIndirectTrust(george, frank)).equal(0); + should(tir.getIndirectTrust(alice, frank)).equal(8); + should(tir.getIndirectTrust(dave, frank)).equal(2); + should(tir.getIndirectTrust(bob, frank)).equal(8); + }); + + // TODO: Decrement direct trusts and test that indirect trusts update correctly + }); + }); +});