diff --git a/browserify.js b/browserify.js index b70f27b..36f0b06 100644 --- a/browserify.js +++ b/browserify.js @@ -15,6 +15,8 @@ module.exports = { opcodes: require('bitcoin-ops'), script: require('bitcoinjs-lib/src/script'), payments: require('bitcoinjs-lib/src/payments'), + descriptors: require('@bitcoinerlab/descriptors'), + descriptorsSecp: require('@bitcoinerlab/secp256k1'), ecurve: ecurve, secp256k1: secp256k1, tinySecp256k1: require('tiny-secp256k1'), diff --git a/libs/js/bitcoin.js b/libs/js/bitcoin.js index e8ea099..ad6e741 100644 --- a/libs/js/bitcoin.js +++ b/libs/js/bitcoin.js @@ -16,6 +16,8 @@ module.exports = { opcodes: require('bitcoin-ops'), script: require('bitcoinjs-lib/src/script'), payments: require('bitcoinjs-lib/src/payments'), + descriptors: require('@bitcoinerlab/descriptors'), + descriptorsSecp: require('@bitcoinerlab/secp256k1'), ecurve: ecurve, secp256k1: secp256k1, tinySecp256k1: require('tiny-secp256k1'), @@ -47,7277 +49,23533 @@ module.exports = { macaroonIdProtobuf: require('./pages/macaroon/id-protobuf'), }; -},{"./pages/macaroon/id-protobuf":333,"aez":6,"bech32":27,"bigi":30,"bip-schnorr":34,"bip32":41,"bip38":42,"bip39":43,"bip39/wordlists/english.json":46,"bip66":52,"bitcoin-ops":53,"bitcoinjs-lib/src/address":56,"bitcoinjs-lib/src/block":57,"bitcoinjs-lib/src/crypto":60,"bitcoinjs-lib/src/ecpair":61,"bitcoinjs-lib/src/networks":62,"bitcoinjs-lib/src/payments":64,"bitcoinjs-lib/src/script":72,"bitcoinjs-lib/src/transaction":96,"bitcoinjs-lib/src/transaction_builder":97,"bs58check":152,"create-hmac":161,"ecurve":176,"fast-crc32c/impls/js_crc32c":197,"google-protobuf":198,"macaroon":234,"merkle-lib/fastRoot":236,"pbkdf2":246,"random-bytes":261,"safe-buffer":280,"scrypt-js":282,"secrets.js-grempe":287,"tiny-secp256k1":301,"unorm":326,"varuint-bitcoin":331,"wif":332}],2:[function(require,module,exports){ -const { xorBytes1x16, xorBytes4x16, uint8, uint32 } = require('./functions'); - -const TE0 = [ - 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, - 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, - 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, - 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, - 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, - 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, - 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, - 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, - 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, - 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, - 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, - 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, - 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, - 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, - 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, - 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, - 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, - 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, - 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, - 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, - 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, - 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, - 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, - 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, - 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, - 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, - 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, - 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, - 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, - 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, - 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, - 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, - 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, - 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, - 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, - 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, - 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, - 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, - 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, - 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, - 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, - 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, - 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, - 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, - 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, - 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, - 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, - 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, - 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, - 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, - 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, - 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, - 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, - 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, - 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, - 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, - 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, - 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, - 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, - 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, - 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, - 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, - 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, - 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a, -]; - -const TE1 = [ - 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, - 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, - 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, - 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, - 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, - 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, - 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, - 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, - 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, - 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, - 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, - 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, - 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, - 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, - 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, - 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, - 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, - 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, - 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, - 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, - 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, - 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, - 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, - 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, - 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, - 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, - 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, - 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, - 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, - 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, - 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, - 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, - 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, - 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, - 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, - 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, - 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, - 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, - 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, - 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, - 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, - 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, - 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, - 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, - 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, - 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, - 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, - 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, - 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, - 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, - 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, - 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, - 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, - 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, - 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, - 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, - 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, - 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, - 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, - 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, - 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, - 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, - 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, - 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616, -]; - -const TE2 = [ - 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, - 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, - 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, - 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, - 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, - 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, - 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, - 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, - 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, - 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, - 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, - 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, - 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, - 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, - 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, - 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, - 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, - 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, - 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, - 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, - 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, - 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, - 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, - 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, - 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, - 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, - 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, - 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, - 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, - 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, - 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, - 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, - 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, - 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, - 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, - 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, - 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, - 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, - 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, - 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, - 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, - 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, - 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, - 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, - 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, - 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, - 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, - 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, - 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, - 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, - 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, - 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, - 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, - 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, - 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, - 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, - 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, - 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, - 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, - 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, - 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, - 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, - 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, - 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16, -]; - -const TE3 = [ - 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, - 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, - 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, - 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, - 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, - 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, - 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, - 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, - 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, - 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, - 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, - 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, - 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, - 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, - 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, - 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, - 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, - 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, - 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, - 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, - 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, - 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, - 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, - 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, - 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, - 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, - 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, - 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, - 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, - 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, - 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, - 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, - 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, - 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, - 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, - 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, - 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, - 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, - 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, - 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, - 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, - 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, - 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, - 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, - 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, - 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, - 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, - 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, - 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, - 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, - 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, - 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, - 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, - 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, - 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, - 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, - 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, - 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, - 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, - 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, - 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, - 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, - 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, - 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c, -]; - -const AESRound = function(key) { - - this.aes10Key = new Uint32Array(4 * 10); - this.aes4Key = new Uint32Array(4 * 4); - - const keys = new Uint32Array(12); - for (let i = 0; i < 12; i++) { - keys[i] = key.readUInt32BE(4 * i); - } - - this.aes10Key.set(keys, 0); - this.aes10Key.set(keys, 12); - this.aes10Key.set(keys, 24); - this.aes10Key.set(keys.subarray(0, 4), 36); - - this.aes4Key.set(keys.subarray(4, 8), 0); - this.aes4Key.set(keys.subarray(0, 4), 4); - this.aes4Key.set(keys.subarray(8, 12), 8); - - this.reset = function () { - this.aes10Key.fill(0); - this.aes4Key.fill(0); - }; - - this.AES4 = function(j, i, l, src, dst) { - xorBytes4x16(j, i, l, src, dst); - this.rounds(dst, 4); - }; - - this.AES10 = function (l, src, dst) { - xorBytes1x16(src, l, dst); - this.rounds(dst, 10); - }; - - this.rounds = function (block, rounds) { - const keys = rounds === 4 ? this.aes4Key : this.aes10Key; - - let s0 = block.readUInt32BE(0); - let s1 = block.readUInt32BE(4); - let s2 = block.readUInt32BE(8); - let s3 = block.readUInt32BE(12); - - // Always do MixColumns. - for (let r = 0; r < rounds; r++) { - let rkOff = r * 4; - const t0 = TE0[uint8(s0>>>24)] ^ - TE1[uint8(s1>>>16)] ^ - TE2[uint8(s2>>>8)] ^ - TE3[uint8(s3)] ^ - keys[rkOff+0]; - - const t1 = TE0[uint8(s1>>>24)] ^ - TE1[uint8(s2>>>16)] ^ - TE2[uint8(s3>>>8)] ^ - TE3[uint8(s0)] ^ - keys[rkOff+1]; - - const t2 = TE0[uint8(s2>>>24)] ^ - TE1[uint8(s3>>>16)] ^ - TE2[uint8(s0>>>8)] ^ - TE3[uint8(s1)] ^ - keys[rkOff+2]; - - const t3 = TE0[uint8(s3>>>24)] ^ - TE1[uint8(s0>>>16)] ^ - TE2[uint8(s1>>>8)] ^ - TE3[uint8(s2)] ^ - keys[rkOff+3]; - - s0 = uint32(t0); - s1 = uint32(t1); - s2 = uint32(t2); - s3 = uint32(t3); +},{"./pages/macaroon/id-protobuf":531,"@bitcoinerlab/descriptors":4,"@bitcoinerlab/secp256k1":81,"aez":98,"bech32":120,"bigi":123,"bip-schnorr":127,"bip32":135,"bip38":136,"bip39":137,"bip39/wordlists/english.json":140,"bip66":146,"bitcoin-ops":148,"bitcoinjs-lib/src/address":151,"bitcoinjs-lib/src/block":152,"bitcoinjs-lib/src/crypto":155,"bitcoinjs-lib/src/ecpair":156,"bitcoinjs-lib/src/networks":157,"bitcoinjs-lib/src/payments":159,"bitcoinjs-lib/src/script":167,"bitcoinjs-lib/src/transaction":191,"bitcoinjs-lib/src/transaction_builder":192,"bs58check":246,"create-hmac":256,"ecurve":277,"fast-crc32c/impls/js_crc32c":306,"google-protobuf":311,"macaroon":432,"merkle-lib/fastRoot":434,"pbkdf2":444,"random-bytes":459,"safe-buffer":463,"scrypt-js":465,"secrets.js-grempe":470,"tiny-secp256k1":498,"unorm":523,"varuint-bitcoin":528,"wif":530}],2:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DescriptorChecksum = exports.CHECKSUM_CHARSET = void 0; +// Converted to Javascript by Jose-Luis Landabaso, 2023 - https://bitcoinerlab.com +// Source: https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp +// Distributed under the MIT software license +const PolyMod = (c, val) => { + const c0 = c >> 35n; + c = ((c & 0x7ffffffffn) << 5n) ^ val; + if (c0 & 1n) + c ^= 0xf5dee51989n; + if (c0 & 2n) + c ^= 0xa9fdca3312n; + if (c0 & 4n) + c ^= 0x1bab10e32dn; + if (c0 & 8n) + c ^= 0x3706b1677an; + if (c0 & 16n) + c ^= 0x644d626ffdn; + return c; +}; +exports.CHECKSUM_CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'; +/** + * Implements the Bitcoin descriptor's checksum algorithm described in + * {@link https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp} + */ +const DescriptorChecksum = (span) => { + const INPUT_CHARSET = '0123456789()[],\'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#"\\ '; + let c = 1n; + let cls = 0n; + let clscount = 0n; + for (const ch of span) { + const pos = BigInt(INPUT_CHARSET.indexOf(ch)); + if (pos === -1n) + return ''; + c = PolyMod(c, pos & 31n); + cls = cls * 3n + (pos >> 5n); + if (++clscount === 3n) { + c = PolyMod(c, cls); + cls = 0n; + clscount = 0n; + } } - - block.writeUInt32BE(s0, 0); - block.writeUInt32BE(s1, 4); - block.writeUInt32BE(s2, 8); - block.writeUInt32BE(s3, 12); - }; + if (clscount > 0n) + c = PolyMod(c, cls); + for (let j = 0; j < 8; ++j) + c = PolyMod(c, 0n); + c ^= 1n; + let ret = ''; + for (let j = 0; j < 8; ++j) { + const index = (c >> (5n * (7n - BigInt(j)))) & 31n; + if (index < 0 || index > Number.MAX_SAFE_INTEGER) + throw new Error(`Error: could not compute checksum, invalid index ${index}`); + ret += exports.CHECKSUM_CHARSET[Number(index)]; + } + return ret; }; +exports.DescriptorChecksum = DescriptorChecksum; -module.exports = AESRound; - -},{"./functions":5}],3:[function(require,module,exports){ -const AEZState = require('./aez_state'); -const { mkBlock } = require('./functions'); - -const VERSION = 'v5'; - -function encrypt(key, nonce, additionalData, tau, plaintext) { - let state = new AEZState(); - state.reset(); - state.init(key); - let delta = state.aezHash(nonce, additionalData, tau * 8); - let x = mkBlock(plaintext.length + tau); - - if (!plaintext || plaintext.length === 0) { - state.aezPRF(delta, tau, x); - } else { - plaintext.copy(x); - state.encipher(delta, x, x); - } - - return x; +},{}],3:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DescriptorsFactory = void 0; +const lodash_memoize_1 = __importDefault(require("lodash.memoize")); +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const varuint_bitcoin_1 = require("varuint-bitcoin"); +const { p2sh, p2wpkh, p2pkh, p2pk, p2wsh, p2tr } = bitcoinjs_lib_1.payments; +const bip32_1 = require("bip32"); +const ecpair_1 = require("ecpair"); +const psbt_1 = require("./psbt"); +const checksum_1 = require("./checksum"); +const keyExpressions_1 = require("./keyExpressions"); +const RE = __importStar(require("./re")); +const miniscript_1 = require("./miniscript"); +//See "Resource limitations" https://bitcoin.sipa.be/miniscript/ +//https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-September/017306.html +const MAX_SCRIPT_ELEMENT_SIZE = 520; +const MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600; +const MAX_OPS_PER_SCRIPT = 201; +function countNonPushOnlyOPs(script) { + const decompile = bitcoinjs_lib_1.script.decompile(script); + if (!decompile) + throw new Error(`Error: cound not decompile ${script}`); + return decompile.filter(op => typeof op === 'number' && op > bitcoinjs_lib_1.script.OPS['OP_16']).length; } - -function decrypt(key, nonce, additionalData, tau, ciphertext) { - let state = new AEZState(); - state.reset(); - state.init(key); - let delta = state.aezHash(nonce, additionalData, tau * 8); - let sum = 0; - let x = mkBlock(ciphertext.length); - - if (ciphertext && ciphertext.length === tau) { - state.aezPRF(delta, tau, x); - for (let i = 0; i < tau; i++) { - sum |= x[i] ^ ciphertext[i]; - } - x = x.slice(0, ciphertext.length - tau); - } else { - state.decipher(delta, ciphertext, x); - for (let i = 0; i < tau; i++) { - sum |= x[ciphertext.length - tau + i]; +function vectorSize(someVector) { + const length = someVector.length; + return ((0, varuint_bitcoin_1.encodingLength)(length) + + someVector.reduce((sum, witness) => { + return sum + varSliceSize(witness); + }, 0)); +} +function varSliceSize(someScript) { + const length = someScript.length; + return (0, varuint_bitcoin_1.encodingLength)(length) + length; +} +/** + * This function will typically return 73; since it assumes a signature size of + * 72 bytes (this is the max size of a DER encoded signature) and it adds 1 + * extra byte for encoding its length + */ +function signatureSize(signature) { + const length = signature === 'DANGEROUSLY_USE_FAKE_SIGNATURES' + ? 72 + : signature.signature.length; + return (0, varuint_bitcoin_1.encodingLength)(length) + length; +} +/* + * Returns a bare descriptor without checksum and particularized for a certain + * index (if desc was a range descriptor) + * @hidden + */ +function evaluate({ descriptor, checksumRequired, index }) { + if (!descriptor) + throw new Error('You must provide a descriptor.'); + const mChecksum = descriptor.match(String.raw `(${RE.reChecksum})$`); + if (mChecksum === null && checksumRequired === true) + throw new Error(`Error: descriptor ${descriptor} has not checksum`); + //evaluatedDescriptor: a bare desc without checksum and particularized for a certain + //index (if desc was a range descriptor) + let evaluatedDescriptor = descriptor; + if (mChecksum !== null) { + const checksum = mChecksum[0].substring(1); //remove the leading # + evaluatedDescriptor = descriptor.substring(0, descriptor.length - mChecksum[0].length); + if (checksum !== (0, checksum_1.DescriptorChecksum)(evaluatedDescriptor)) { + throw new Error(`Error: invalid descriptor checksum for ${descriptor}`); + } } - if (sum === 0) { - x = x.slice(0, ciphertext.length - tau); + if (index !== undefined) { + const mWildcard = evaluatedDescriptor.match(/\*/g); + if (mWildcard && mWildcard.length > 0) { + //From https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md + //To prevent a combinatorial explosion of the search space, if more than + //one of the multi() key arguments is a BIP32 wildcard path ending in /* or + //*', the multi() descriptor only matches multisig scripts with the ith + //child key from each wildcard path in lockstep, rather than scripts with + //any combination of child keys from each wildcard path. + //We extend this reasoning for musig for all cases + evaluatedDescriptor = evaluatedDescriptor.replaceAll('*', index.toString()); + } + else + throw new Error(`Error: index passed for non-ranged descriptor: ${descriptor}`); } - } - - if (sum !== 0) { - return null; - } - - return x; + return evaluatedDescriptor; } - -module.exports = { - VERSION, - encrypt, - decrypt, -}; - -},{"./aez_state":4,"./functions":5}],4:[function(require,module,exports){ -const { - BLOCK_SIZE, uint32, mkBlock, xorBytes1x16, xorBytes4x16, - extractKey, multBlock, doubleBlock, oneZeroPad, xorBytes -} = require('./functions'); -const AESRound = require('./aes_round'); -const Buffer = require('safe-buffer').Buffer; -const floor = Math.floor; - -const ZERO = mkBlock(); - -const AEZState = function () { - - this.I = [mkBlock(), mkBlock()]; - this.J = [mkBlock(), mkBlock(), mkBlock()]; - this.L = [ - mkBlock(), mkBlock(), mkBlock(), mkBlock(), - mkBlock(), mkBlock(), mkBlock(), mkBlock(), - ]; - - this.reset = function () { - this.I.forEach(buf => buf.fill(0)); - this.J.forEach(buf => buf.fill(0)); - this.L.forEach(buf => buf.fill(0)); - - if (this.aes) { - this.aes.reset(); +/** + * Constructs the necessary functions and classes for working with descriptors + * using an external elliptic curve (ecc) library. + * + * Notably, it returns the {@link _Internal_.Output | `Output`} class, which + * provides methods to create, sign, and finalize PSBTs based on descriptor + * expressions. + * + * While this Factory function includes the `Descriptor` class, note that + * this class was deprecated in v2.0 in favor of `Output`. For backward + * compatibility, the `Descriptor` class remains, but using `Output` is advised. + * + * The Factory also returns utility methods like `expand` (detailed below) + * and `parseKeyExpression` (see {@link ParseKeyExpression}). + * + * Additionally, for convenience, the function returns `BIP32` and `ECPair`. + * These are {@link https://github.com/bitcoinjs bitcoinjs-lib} classes designed + * for managing {@link https://github.com/bitcoinjs/bip32 | `BIP32`} keys and + * public/private key pairs: + * {@link https://github.com/bitcoinjs/ecpair | `ECPair`}, respectively. + * + * @param {Object} ecc - An object with elliptic curve operations, such as + * [tiny-secp256k1](https://github.com/bitcoinjs/tiny-secp256k1) or + * [@bitcoinerlab/secp256k1](https://github.com/bitcoinerlab/secp256k1). + */ +function DescriptorsFactory(ecc) { + var _Output_instances, _Output_payment, _Output_preimages, _Output_signersPubKeys, _Output_miniscript, _Output_witnessScript, _Output_redeemScript, _Output_isSegwit, _Output_expandedExpression, _Output_expandedMiniscript, _Output_expansionMap, _Output_network, _Output_getTimeConstraints, _Output_assertPsbtInput; + const BIP32 = (0, bip32_1.BIP32Factory)(ecc); + const ECPair = (0, ecpair_1.ECPairFactory)(ecc); + const signatureValidator = (pubkey, msghash, signature) => ECPair.fromPublicKey(pubkey).verify(msghash, signature); + /** + * Takes a string key expression (xpub, xprv, pubkey or wif) and parses it + */ + const parseKeyExpression = ({ keyExpression, isSegwit, network = bitcoinjs_lib_1.networks.bitcoin }) => { + return (0, keyExpressions_1.parseKeyExpression)({ + keyExpression, + network, + ...(typeof isSegwit === 'boolean' ? { isSegwit } : {}), + ECPair, + BIP32 + }); + }; + /** + * @hidden + * To be removed in v3.0 and replaced by the version with the signature that + * does not accept descriptors + */ + function expand({ descriptor, expression, index, checksumRequired = false, network = bitcoinjs_lib_1.networks.bitcoin, allowMiniscriptInP2SH = false }) { + if (descriptor && expression) + throw new Error(`expression param has been deprecated`); + descriptor = descriptor || expression; + if (!descriptor) + throw new Error(`descriptor not provided`); + let expandedExpression; + let miniscript; + let expansionMap; + let isSegwit; + let expandedMiniscript; + let payment; + let witnessScript; + let redeemScript; + const isRanged = descriptor.indexOf('*') !== -1; + if (index !== undefined) + if (!Number.isInteger(index) || index < 0) + throw new Error(`Error: invalid index ${index}`); + //Verify and remove checksum (if exists) and + //particularize range descriptor for index (if desc is range descriptor) + const canonicalExpression = evaluate({ + descriptor, + ...(index !== undefined ? { index } : {}), + checksumRequired + }); + const isCanonicalRanged = canonicalExpression.indexOf('*') !== -1; + //addr(ADDR) + if (canonicalExpression.match(RE.reAddrAnchored)) { + if (isRanged) + throw new Error(`Error: addr() cannot be ranged`); + const matchedAddress = canonicalExpression.match(RE.reAddrAnchored)?.[1]; //[1]-> whatever is found addr(->HERE<-) + if (!matchedAddress) + throw new Error(`Error: could not get an address in ${descriptor}`); + let output; + try { + output = bitcoinjs_lib_1.address.toOutputScript(matchedAddress, network); + } + catch (e) { + throw new Error(`Error: invalid address ${matchedAddress}`); + } + try { + payment = p2pkh({ output, network }); + isSegwit = false; + } + catch (e) { } + try { + payment = p2sh({ output, network }); + // It assumes that an addr(SH_ADDRESS) is always a add(SH_WPKH) address + isSegwit = true; + } + catch (e) { } + try { + payment = p2wpkh({ output, network }); + isSegwit = true; + } + catch (e) { } + try { + payment = p2wsh({ output, network }); + isSegwit = true; + } + catch (e) { } + try { + payment = p2tr({ output, network }); + isSegwit = true; + } + catch (e) { } + if (!payment) { + throw new Error(`Error: invalid address ${matchedAddress}`); + } + } + //pk(KEY) + else if (canonicalExpression.match(RE.rePkAnchored)) { + isSegwit = false; + const keyExpression = canonicalExpression.match(RE.reKeyExp)?.[0]; + if (!keyExpression) + throw new Error(`Error: keyExpression could not me extracted`); + if (canonicalExpression !== `pk(${keyExpression})`) + throw new Error(`Error: invalid expression ${descriptor}`); + expandedExpression = 'pk(@0)'; + const pKE = parseKeyExpression({ keyExpression, network, isSegwit }); + expansionMap = { '@0': pKE }; + if (!isCanonicalRanged) { + const pubkey = pKE.pubkey; + //Note there exists no address for p2pk, but we can still use the script + if (!pubkey) + throw new Error(`Error: could not extract a pubkey from ${descriptor}`); + payment = p2pk({ pubkey, network }); + } + } + //pkh(KEY) - legacy + else if (canonicalExpression.match(RE.rePkhAnchored)) { + isSegwit = false; + const keyExpression = canonicalExpression.match(RE.reKeyExp)?.[0]; + if (!keyExpression) + throw new Error(`Error: keyExpression could not me extracted`); + if (canonicalExpression !== `pkh(${keyExpression})`) + throw new Error(`Error: invalid expression ${descriptor}`); + expandedExpression = 'pkh(@0)'; + const pKE = parseKeyExpression({ keyExpression, network, isSegwit }); + expansionMap = { '@0': pKE }; + if (!isCanonicalRanged) { + const pubkey = pKE.pubkey; + if (!pubkey) + throw new Error(`Error: could not extract a pubkey from ${descriptor}`); + payment = p2pkh({ pubkey, network }); + } + } + //sh(wpkh(KEY)) - nested segwit + else if (canonicalExpression.match(RE.reShWpkhAnchored)) { + isSegwit = true; + const keyExpression = canonicalExpression.match(RE.reKeyExp)?.[0]; + if (!keyExpression) + throw new Error(`Error: keyExpression could not me extracted`); + if (canonicalExpression !== `sh(wpkh(${keyExpression}))`) + throw new Error(`Error: invalid expression ${descriptor}`); + expandedExpression = 'sh(wpkh(@0))'; + const pKE = parseKeyExpression({ keyExpression, network, isSegwit }); + expansionMap = { '@0': pKE }; + if (!isCanonicalRanged) { + const pubkey = pKE.pubkey; + if (!pubkey) + throw new Error(`Error: could not extract a pubkey from ${descriptor}`); + payment = p2sh({ redeem: p2wpkh({ pubkey, network }), network }); + redeemScript = payment.redeem?.output; + if (!redeemScript) + throw new Error(`Error: could not calculate redeemScript for ${descriptor}`); + } + } + //wpkh(KEY) - native segwit + else if (canonicalExpression.match(RE.reWpkhAnchored)) { + isSegwit = true; + const keyExpression = canonicalExpression.match(RE.reKeyExp)?.[0]; + if (!keyExpression) + throw new Error(`Error: keyExpression could not me extracted`); + if (canonicalExpression !== `wpkh(${keyExpression})`) + throw new Error(`Error: invalid expression ${descriptor}`); + expandedExpression = 'wpkh(@0)'; + const pKE = parseKeyExpression({ keyExpression, network, isSegwit }); + expansionMap = { '@0': pKE }; + if (!isCanonicalRanged) { + const pubkey = pKE.pubkey; + if (!pubkey) + throw new Error(`Error: could not extract a pubkey from ${descriptor}`); + payment = p2wpkh({ pubkey, network }); + } + } + //sh(wsh(miniscript)) + else if (canonicalExpression.match(RE.reShWshMiniscriptAnchored)) { + isSegwit = true; + miniscript = canonicalExpression.match(RE.reShWshMiniscriptAnchored)?.[1]; //[1]-> whatever is found sh(wsh(->HERE<-)) + if (!miniscript) + throw new Error(`Error: could not get miniscript in ${descriptor}`); + ({ expandedMiniscript, expansionMap } = expandMiniscript({ + miniscript, + isSegwit, + network + })); + expandedExpression = `sh(wsh(${expandedMiniscript}))`; + if (!isCanonicalRanged) { + const script = (0, miniscript_1.miniscript2Script)({ expandedMiniscript, expansionMap }); + witnessScript = script; + if (script.byteLength > MAX_STANDARD_P2WSH_SCRIPT_SIZE) { + throw new Error(`Error: script is too large, ${script.byteLength} bytes is larger than ${MAX_STANDARD_P2WSH_SCRIPT_SIZE} bytes`); + } + const nonPushOnlyOps = countNonPushOnlyOPs(script); + if (nonPushOnlyOps > MAX_OPS_PER_SCRIPT) { + throw new Error(`Error: too many non-push ops, ${nonPushOnlyOps} non-push ops is larger than ${MAX_OPS_PER_SCRIPT}`); + } + payment = p2sh({ + redeem: p2wsh({ redeem: { output: script, network }, network }), + network + }); + redeemScript = payment.redeem?.output; + if (!redeemScript) + throw new Error(`Error: could not calculate redeemScript for ${descriptor}`); + } + } + //sh(miniscript) + else if (canonicalExpression.match(RE.reShMiniscriptAnchored)) { + //isSegwit false because we know it's a P2SH of a miniscript and not a + //P2SH that embeds a witness payment. + isSegwit = false; + miniscript = canonicalExpression.match(RE.reShMiniscriptAnchored)?.[1]; //[1]-> whatever is found sh(->HERE<-) + if (!miniscript) + throw new Error(`Error: could not get miniscript in ${descriptor}`); + if (allowMiniscriptInP2SH === false && + //These top-level expressions within sh are allowed within sh. + //They can be parsed with miniscript2Script, but first we must make sure + //that other expressions are not accepted (unless forced with allowMiniscriptInP2SH). + miniscript.search(/^(pk\(|pkh\(|wpkh\(|combo\(|multi\(|sortedmulti\(|multi_a\(|sortedmulti_a\()/) !== 0) { + throw new Error(`Error: Miniscript expressions can only be used in wsh`); + } + ({ expandedMiniscript, expansionMap } = expandMiniscript({ + miniscript, + isSegwit, + network + })); + expandedExpression = `sh(${expandedMiniscript})`; + if (!isCanonicalRanged) { + const script = (0, miniscript_1.miniscript2Script)({ expandedMiniscript, expansionMap }); + redeemScript = script; + if (script.byteLength > MAX_SCRIPT_ELEMENT_SIZE) { + throw new Error(`Error: P2SH script is too large, ${script.byteLength} bytes is larger than ${MAX_SCRIPT_ELEMENT_SIZE} bytes`); + } + const nonPushOnlyOps = countNonPushOnlyOPs(script); + if (nonPushOnlyOps > MAX_OPS_PER_SCRIPT) { + throw new Error(`Error: too many non-push ops, ${nonPushOnlyOps} non-push ops is larger than ${MAX_OPS_PER_SCRIPT}`); + } + payment = p2sh({ redeem: { output: script, network }, network }); + } + } + //wsh(miniscript) + else if (canonicalExpression.match(RE.reWshMiniscriptAnchored)) { + isSegwit = true; + miniscript = canonicalExpression.match(RE.reWshMiniscriptAnchored)?.[1]; //[1]-> whatever is found wsh(->HERE<-) + if (!miniscript) + throw new Error(`Error: could not get miniscript in ${descriptor}`); + ({ expandedMiniscript, expansionMap } = expandMiniscript({ + miniscript, + isSegwit, + network + })); + expandedExpression = `wsh(${expandedMiniscript})`; + if (!isCanonicalRanged) { + const script = (0, miniscript_1.miniscript2Script)({ expandedMiniscript, expansionMap }); + witnessScript = script; + if (script.byteLength > MAX_STANDARD_P2WSH_SCRIPT_SIZE) { + throw new Error(`Error: script is too large, ${script.byteLength} bytes is larger than ${MAX_STANDARD_P2WSH_SCRIPT_SIZE} bytes`); + } + const nonPushOnlyOps = countNonPushOnlyOPs(script); + if (nonPushOnlyOps > MAX_OPS_PER_SCRIPT) { + throw new Error(`Error: too many non-push ops, ${nonPushOnlyOps} non-push ops is larger than ${MAX_OPS_PER_SCRIPT}`); + } + payment = p2wsh({ redeem: { output: script, network }, network }); + } + } + else { + throw new Error(`Error: Could not parse descriptor ${descriptor}`); + } + return { + ...(payment !== undefined ? { payment } : {}), + ...(expandedExpression !== undefined ? { expandedExpression } : {}), + ...(miniscript !== undefined ? { miniscript } : {}), + ...(expansionMap !== undefined ? { expansionMap } : {}), + ...(isSegwit !== undefined ? { isSegwit } : {}), + ...(expandedMiniscript !== undefined ? { expandedMiniscript } : {}), + ...(redeemScript !== undefined ? { redeemScript } : {}), + ...(witnessScript !== undefined ? { witnessScript } : {}), + isRanged, + canonicalExpression + }; } - }; - - this.init = function (key) { - - const extractedKey = extractKey(key); - - extractedKey.slice(0, 16).copy(this.I[0]); - multBlock(2, this.I[0], this.I[1]); - - extractedKey.slice(16, 32).copy(this.J[0]); - multBlock(2, this.J[0], this.J[1]); - multBlock(2, this.J[1], this.J[2]); - - extractedKey.slice(32, 48).copy(this.L[1]); - multBlock(2, this.L[1], this.L[2]); - xorBytes1x16(this.L[2], this.L[1], this.L[3]); - multBlock(2, this.L[2], this.L[4]); - xorBytes1x16(this.L[4], this.L[1], this.L[5]); - multBlock(2, this.L[3], this.L[6]); - xorBytes1x16(this.L[6], this.L[1], this.L[7]); - - this.aes = new AESRound(extractedKey); - }; - - this.aezHash = function (nonce, ad, tau) { - const [buf, sum, I, J] = [mkBlock(), mkBlock(), mkBlock(), mkBlock()]; - - buf.writeInt32BE(uint32(tau), 12); - xorBytes1x16(this.J[0], this.J[1], J); - this.aes.AES4(J, this.I[1], this.L[1], buf, sum); - - const empty = !nonce || nonce.length === 0; - let n = nonce; - let nBytes = empty ? 0 : nonce.length; - this.I[1].copy(I); - for (let i = 1; nBytes >= BLOCK_SIZE; i++, nBytes -= BLOCK_SIZE) { - this.aes.AES4(this.J[2], I, this.L[i % 8], n.slice(0, BLOCK_SIZE), buf); - xorBytes1x16(sum, buf, sum); - n = n.slice(BLOCK_SIZE); - if (i % 8 === 0) { - doubleBlock(I); - } + /** + * Expand a miniscript to a generalized form using variables instead of key + * expressions. Variables will be of this form: @0, @1, ... + * This is done so that it can be compiled with compileMiniscript and + * satisfied with satisfier. + * Also compute pubkeys from descriptors to use them later. + */ + function expandMiniscript({ miniscript, isSegwit, network = bitcoinjs_lib_1.networks.bitcoin }) { + return (0, miniscript_1.expandMiniscript)({ + miniscript, + isSegwit, + network, + BIP32, + ECPair + }); } - - if (nBytes > 0 || empty) { - buf.fill(0); - if (!empty) { - n.copy(buf); - } - buf[nBytes] = 0x80; - this.aes.AES4(this.J[2], this.I[0], this.L[0], buf, buf); - xorBytes1x16(sum, buf, sum); + /** + * The `Output` class is the central component for managing descriptors. + * It facilitates the creation of outputs to receive funds and enables the + * signing and finalization of PSBTs (Partially Signed Bitcoin Transactions) + * for spending UTXOs (Unspent Transaction Outputs). + */ + class Output { + /** + * @param options + * @throws {Error} - when descriptor is invalid + */ + constructor({ descriptor, index, checksumRequired = false, allowMiniscriptInP2SH = false, network = bitcoinjs_lib_1.networks.bitcoin, preimages = [], signersPubKeys }) { + _Output_instances.add(this); + _Output_payment.set(this, void 0); + _Output_preimages.set(this, []); + _Output_signersPubKeys.set(this, void 0); + _Output_miniscript.set(this, void 0); + _Output_witnessScript.set(this, void 0); + _Output_redeemScript.set(this, void 0); + //isSegwit true if witnesses are needed to the spend coins sent to this descriptor. + //may be unset because we may get addr(P2SH) which we don't know if they have segwit. + _Output_isSegwit.set(this, void 0); + _Output_expandedExpression.set(this, void 0); + _Output_expandedMiniscript.set(this, void 0); + _Output_expansionMap.set(this, void 0); + _Output_network.set(this, void 0); + __classPrivateFieldSet(this, _Output_network, network, "f"); + __classPrivateFieldSet(this, _Output_preimages, preimages, "f"); + if (typeof descriptor !== 'string') + throw new Error(`Error: invalid descriptor type`); + const expandedResult = expand({ + descriptor, + ...(index !== undefined ? { index } : {}), + checksumRequired, + network, + allowMiniscriptInP2SH + }); + if (expandedResult.isRanged && index === undefined) + throw new Error(`Error: index was not provided for ranged descriptor`); + if (!expandedResult.payment) + throw new Error(`Error: could not extract a payment from ${descriptor}`); + __classPrivateFieldSet(this, _Output_payment, expandedResult.payment, "f"); + if (expandedResult.expandedExpression !== undefined) + __classPrivateFieldSet(this, _Output_expandedExpression, expandedResult.expandedExpression, "f"); + if (expandedResult.miniscript !== undefined) + __classPrivateFieldSet(this, _Output_miniscript, expandedResult.miniscript, "f"); + if (expandedResult.expansionMap !== undefined) + __classPrivateFieldSet(this, _Output_expansionMap, expandedResult.expansionMap, "f"); + if (expandedResult.isSegwit !== undefined) + __classPrivateFieldSet(this, _Output_isSegwit, expandedResult.isSegwit, "f"); + if (expandedResult.expandedMiniscript !== undefined) + __classPrivateFieldSet(this, _Output_expandedMiniscript, expandedResult.expandedMiniscript, "f"); + if (expandedResult.redeemScript !== undefined) + __classPrivateFieldSet(this, _Output_redeemScript, expandedResult.redeemScript, "f"); + if (expandedResult.witnessScript !== undefined) + __classPrivateFieldSet(this, _Output_witnessScript, expandedResult.witnessScript, "f"); + if (signersPubKeys) { + __classPrivateFieldSet(this, _Output_signersPubKeys, signersPubKeys, "f"); + } + else { + if (__classPrivateFieldGet(this, _Output_expansionMap, "f")) { + __classPrivateFieldSet(this, _Output_signersPubKeys, Object.values(__classPrivateFieldGet(this, _Output_expansionMap, "f")).map(keyInfo => { + const pubkey = keyInfo.pubkey; + if (!pubkey) + throw new Error(`Error: could not extract a pubkey from ${descriptor}`); + return pubkey; + }), "f"); + } + else { + //We should only miss expansionMap in addr() expressions: + if (!expandedResult.canonicalExpression.match(RE.reAddrAnchored)) { + throw new Error(`Error: expansionMap not available for expression ${descriptor} that is not an address`); + } + __classPrivateFieldSet(this, _Output_signersPubKeys, [this.getScriptPubKey()], "f"); + } + } + this.getSequence = (0, lodash_memoize_1.default)(this.getSequence); + this.getLockTime = (0, lodash_memoize_1.default)(this.getLockTime); + const getSignaturesKey = (signatures) => signatures === 'DANGEROUSLY_USE_FAKE_SIGNATURES' + ? signatures + : signatures + .map(s => `${s.pubkey.toString('hex')}-${s.signature.toString('hex')}`) + .join('|'); + this.getScriptSatisfaction = (0, lodash_memoize_1.default)(this.getScriptSatisfaction, + // resolver function: + getSignaturesKey); + this.guessOutput = (0, lodash_memoize_1.default)(this.guessOutput); + this.inputWeight = (0, lodash_memoize_1.default)(this.inputWeight, + // resolver function: + (isSegwitTx, signatures) => { + const segwitKey = isSegwitTx ? 'segwit' : 'non-segwit'; + const signaturesKey = getSignaturesKey(signatures); + return `${segwitKey}-${signaturesKey}`; + }); + this.outputWeight = (0, lodash_memoize_1.default)(this.outputWeight); + } + /** + * Creates and returns an instance of bitcoinjs-lib + * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`. + */ + getPayment() { + return __classPrivateFieldGet(this, _Output_payment, "f"); + } + /** + * Returns the Bitcoin Address of this `Output`. + */ + getAddress() { + if (!__classPrivateFieldGet(this, _Output_payment, "f").address) + throw new Error(`Error: could extract an address from the payment`); + return __classPrivateFieldGet(this, _Output_payment, "f").address; + } + /** + * Returns this `Output`'s scriptPubKey. + */ + getScriptPubKey() { + if (!__classPrivateFieldGet(this, _Output_payment, "f").output) + throw new Error(`Error: could extract output.script from the payment`); + return __classPrivateFieldGet(this, _Output_payment, "f").output; + } + /** + * Returns the compiled Script Satisfaction if this `Output` was created + * using a miniscript-based descriptor. + * + * The Satisfaction is the unlocking script that fulfills + * (satisfies) this `Output` and it is derived using the Safisfier algorithm + * [described here](https://bitcoin.sipa.be/miniscript/). + * + * Important: As mentioned above, note that this function only applies to + * miniscript descriptors. + */ + getScriptSatisfaction( + /** + * An array with all the signatures needed to + * build the Satisfaction of this miniscript-based `Output`. + * + * `signatures` must be passed using this format (pairs of `pubKey/signature`): + * `interface PartialSig { pubkey: Buffer; signature: Buffer; }` + * + * * Alternatively, if you do not have the signatures, you can use the option + * `'DANGEROUSLY_USE_FAKE_SIGNATURES'`. This will generate script satisfactions + * using 72-byte zero-padded signatures. While this can be useful in + * modules like coinselector that require estimating transaction size before + * signing, it is critical to understand the risks: + * - Using this option generales invalid unlocking scripts. + * - It should NEVER be used with real transactions. + * - Its primary use is for testing and size estimation purposes only. + * + * ⚠️ Warning: Misuse of 'DANGEROUSLY_USE_FAKE_SIGNATURES' can lead to security + * vulnerabilities, including but not limited to invalid transaction generation. + * Ensure you fully understand the implications before use. + * + */ + signatures) { + if (signatures === 'DANGEROUSLY_USE_FAKE_SIGNATURES') + signatures = __classPrivateFieldGet(this, _Output_signersPubKeys, "f").map(pubkey => ({ + pubkey, + // https://transactionfee.info/charts/bitcoin-script-ecdsa-length/ + signature: Buffer.alloc(72, 0) + })); + const miniscript = __classPrivateFieldGet(this, _Output_miniscript, "f"); + const expandedMiniscript = __classPrivateFieldGet(this, _Output_expandedMiniscript, "f"); + const expansionMap = __classPrivateFieldGet(this, _Output_expansionMap, "f"); + if (miniscript === undefined || + expandedMiniscript === undefined || + expansionMap === undefined) + throw new Error(`Error: cannot get satisfaction from not expanded miniscript ${miniscript}`); + //Note that we pass the nLockTime and nSequence that is deduced + //using preimages and signersPubKeys. + //satisfyMiniscript will make sure + //that the actual solution given, using real signatures, still meets the + //same nLockTime and nSequence constraints + const scriptSatisfaction = (0, miniscript_1.satisfyMiniscript)({ + expandedMiniscript, + expansionMap, + signatures, + preimages: __classPrivateFieldGet(this, _Output_preimages, "f"), + //Here we pass the TimeConstraints obtained using signersPubKeys to + //verify that the solutions found using the final signatures have not + //changed + timeConstraints: { + nLockTime: this.getLockTime(), + nSequence: this.getSequence() + } + }).scriptSatisfaction; + if (!scriptSatisfaction) + throw new Error(`Error: could not produce a valid satisfaction`); + return scriptSatisfaction; + } + /** + * Gets the nSequence required to fulfill this `Output`. + */ + getSequence() { + return __classPrivateFieldGet(this, _Output_instances, "m", _Output_getTimeConstraints).call(this)?.nSequence; + } + /** + * Gets the nLockTime required to fulfill this `Output`. + */ + getLockTime() { + return __classPrivateFieldGet(this, _Output_instances, "m", _Output_getTimeConstraints).call(this)?.nLockTime; + } + /** + * Gets the witnessScript required to fulfill this `Output`. Only applies to + * Segwit outputs. + */ + getWitnessScript() { + return __classPrivateFieldGet(this, _Output_witnessScript, "f"); + } + /** + * Gets the redeemScript required to fullfill this `Output`. Only applies to + * SH outputs: sh(wpkh), sh(wsh), sh(lockingScript). + */ + getRedeemScript() { + return __classPrivateFieldGet(this, _Output_redeemScript, "f"); + } + /** + * Gets the bitcoinjs-lib [`network`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/networks.ts) used to create this `Output`. + */ + getNetwork() { + return __classPrivateFieldGet(this, _Output_network, "f"); + } + /** + * Whether this `Output` is Segwit. + * + * *NOTE:* When the descriptor in an input is `addr(address)`, it is assumed + * that any `addr(SH_TYPE_ADDRESS)` is in fact a Segwit `SH_WPKH` + * (Script Hash-Witness Public Key Hash). + * For inputs using arbitrary scripts (not standard addresses), + * use a descriptor in the format `sh(MINISCRIPT)`. + * + */ + isSegwit() { + return __classPrivateFieldGet(this, _Output_isSegwit, "f"); + } + /** + * Returns the tuple: `{ isPKH: boolean; isWPKH: boolean; isSH: boolean; }` + * for this Output. + */ + guessOutput() { + function guessSH(output) { + try { + bitcoinjs_lib_1.payments.p2sh({ output }); + return true; + } + catch (err) { + return false; + } + } + function guessWPKH(output) { + try { + bitcoinjs_lib_1.payments.p2wpkh({ output }); + return true; + } + catch (err) { + return false; + } + } + function guessPKH(output) { + try { + bitcoinjs_lib_1.payments.p2pkh({ output }); + return true; + } + catch (err) { + return false; + } + } + const isPKH = guessPKH(this.getScriptPubKey()); + const isWPKH = guessWPKH(this.getScriptPubKey()); + const isSH = guessSH(this.getScriptPubKey()); + if ([isPKH, isWPKH, isSH].filter(Boolean).length > 1) + throw new Error('Cannot have multiple output types.'); + return { isPKH, isWPKH, isSH }; + } + // References for inputWeight & outputWeight: + // https://gist.github.com/junderw/b43af3253ea5865ed52cb51c200ac19c + // https://bitcoinops.org/en/tools/calc-size/ + // Look for byteLength: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/transaction.ts + // https://github.com/bitcoinjs/coinselect/blob/master/utils.js + /** + * Computes the Weight Unit contributions of this Output as if it were the + * input in a tx. + * + * *NOTE:* When the descriptor in an input is `addr(address)`, it is assumed + * that any `addr(SH_TYPE_ADDRESS)` is in fact a Segwit `SH_WPKH` + * (Script Hash-Witness Public Key Hash). + * For inputs using arbitrary scripts (not standard addresses), + * use a descriptor in the format `sh(MINISCRIPT)`. + */ + inputWeight( + /** + * Indicates if the transaction is a Segwit transaction. + * If a transaction isSegwitTx, a single byte is then also required for + * non-witness inputs to encode the length of the empty witness stack: + * encodeLength(0) + 0 = 1 + * Read more: + * https://gist.github.com/junderw/b43af3253ea5865ed52cb51c200ac19c?permalink_comment_id=4760512#gistcomment-4760512 + */ + isSegwitTx, + /* + * Array of `PartialSig`. Each `PartialSig` includes + * a public key and its corresponding signature. This parameter + * enables the accurate calculation of signature sizes. + * Pass 'DANGEROUSLY_USE_FAKE_SIGNATURES' to assume 72 bytes in length. + * Mainly used for testing. + */ + signatures) { + if (this.isSegwit() && !isSegwitTx) + throw new Error(`a tx is segwit if at least one input is segwit`); + const errorMsg = 'Input type not implemented. Currently supported: pkh(KEY), wpkh(KEY), \ + sh(wpkh(KEY)), sh(wsh(MINISCRIPT)), sh(MINISCRIPT), wsh(MINISCRIPT), \ + addr(PKH_ADDRESS), addr(WPKH_ADDRESS), addr(SH_WPKH_ADDRESS).'; + //expand any miniscript-based descriptor. If not miniscript-based, then it's + //an addr() descriptor. For those, we can only guess their type. + const expansion = this.expand().expandedExpression; + const { isPKH, isWPKH, isSH } = this.guessOutput(); + if (!expansion && !isPKH && !isWPKH && !isSH) + throw new Error(errorMsg); + const firstSignature = signatures && typeof signatures[0] === 'object' + ? signatures[0] + : 'DANGEROUSLY_USE_FAKE_SIGNATURES'; + if (expansion ? expansion.startsWith('pkh(') : isPKH) { + return ( + // Non-segwit: (txid:32) + (vout:4) + (sequence:4) + (script_len:1) + (sig:73) + (pubkey:34) + (32 + 4 + 4 + 1 + signatureSize(firstSignature) + 34) * 4 + + //Segwit: + (isSegwitTx ? 1 : 0)); + } + else if (expansion ? expansion.startsWith('wpkh(') : isWPKH) { + if (!isSegwitTx) + throw new Error('Should be SegwitTx'); + return ( + // Non-segwit: (txid:32) + (vout:4) + (sequence:4) + (script_len:1) + 41 * 4 + + // Segwit: (push_count:1) + (sig:73) + (pubkey:34) + (1 + signatureSize(firstSignature) + 34)); + } + else if (expansion ? expansion.startsWith('sh(wpkh(') : isSH) { + if (!isSegwitTx) + throw new Error('Should be SegwitTx'); + return ( + // Non-segwit: (txid:32) + (vout:4) + (sequence:4) + (script_len:1) + (p2wpkh:23) + // -> p2wpkh_script: OP_0 OP_PUSH20 + // -> p2wpkh: (script_len:1) + (script:22) + 64 * 4 + + // Segwit: (push_count:1) + (sig:73) + (pubkey:34) + (1 + signatureSize(firstSignature) + 34)); + } + else if (expansion?.startsWith('sh(wsh(')) { + if (!isSegwitTx) + throw new Error('Should be SegwitTx'); + const witnessScript = this.getWitnessScript(); + if (!witnessScript) + throw new Error('sh(wsh) must provide witnessScript'); + const payment = bitcoinjs_lib_1.payments.p2sh({ + redeem: bitcoinjs_lib_1.payments.p2wsh({ + redeem: { + input: this.getScriptSatisfaction(signatures || 'DANGEROUSLY_USE_FAKE_SIGNATURES'), + output: witnessScript + } + }) + }); + if (!payment || !payment.input || !payment.witness) + throw new Error('Could not create payment'); + return ( + //Non-segwit + 4 * (40 + varSliceSize(payment.input)) + + //Segwit + vectorSize(payment.witness)); + } + else if (expansion?.startsWith('sh(')) { + const redeemScript = this.getRedeemScript(); + if (!redeemScript) + throw new Error('sh() must provide redeemScript'); + const payment = bitcoinjs_lib_1.payments.p2sh({ + redeem: { + input: this.getScriptSatisfaction(signatures || 'DANGEROUSLY_USE_FAKE_SIGNATURES'), + output: redeemScript + } + }); + if (!payment || !payment.input) + throw new Error('Could not create payment'); + if (payment.witness?.length) + throw new Error('A legacy p2sh payment should not cointain a witness'); + return ( + //Non-segwit + 4 * (40 + varSliceSize(payment.input)) + + //Segwit: + (isSegwitTx ? 1 : 0)); + } + else if (expansion?.startsWith('wsh(')) { + const witnessScript = this.getWitnessScript(); + if (!witnessScript) + throw new Error('wsh must provide witnessScript'); + const payment = bitcoinjs_lib_1.payments.p2wsh({ + redeem: { + input: this.getScriptSatisfaction(signatures || 'DANGEROUSLY_USE_FAKE_SIGNATURES'), + output: witnessScript + } + }); + if (!payment || !payment.input || !payment.witness) + throw new Error('Could not create payment'); + return ( + //Non-segwit + 4 * (40 + varSliceSize(payment.input)) + + //Segwit + vectorSize(payment.witness)); + } + else { + throw new Error(errorMsg); + } + } + /** + * Computes the Weight Unit contributions of this Output as if it were the + * output in a tx. + */ + outputWeight() { + const errorMsg = 'Output type not implemented. Currently supported: pkh(KEY), wpkh(KEY), \ + sh(ANYTHING), wsh(ANYTHING), addr(PKH_ADDRESS), addr(WPKH_ADDRESS), \ + addr(SH_WPKH_ADDRESS)'; + //expand any miniscript-based descriptor. If not miniscript-based, then it's + //an addr() descriptor. For those, we can only guess their type. + const expansion = this.expand().expandedExpression; + const { isPKH, isWPKH, isSH } = this.guessOutput(); + if (!expansion && !isPKH && !isWPKH && !isSH) + throw new Error(errorMsg); + if (expansion ? expansion.startsWith('pkh(') : isPKH) { + // (p2pkh:26) + (amount:8) + return 34 * 4; + } + else if (expansion ? expansion.startsWith('wpkh(') : isWPKH) { + // (p2wpkh:23) + (amount:8) + return 31 * 4; + } + else if (expansion ? expansion.startsWith('sh(') : isSH) { + // (p2sh:24) + (amount:8) + return 32 * 4; + } + else if (expansion?.startsWith('wsh(')) { + // (p2wsh:35) + (amount:8) + return 43 * 4; + } + else { + throw new Error(errorMsg); + } + } + /** @deprecated - Use updatePsbtAsInput instead + * @hidden + */ + updatePsbt(params) { + this.updatePsbtAsInput(params); + return params.psbt.data.inputs.length - 1; + } + /** + * Sets this output as an input of the provided `psbt` and updates the + * `psbt` locktime if required by the descriptor. + * + * `psbt` and `vout` are mandatory. Include `txHex` as well. The pair + * `vout` and `txHex` define the transaction and output number this instance + * pertains to. + * + * Though not advised, for Segwit inputs you can pass `txId` and `value` + * in lieu of `txHex`. If doing so, ensure `value` accuracy to avoid + * potential fee attacks - + * [See this issue](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1625). + * + * Note: Hardware wallets need the [full `txHex` for Segwit](https://blog.trezor.io/details-of-firmware-updates-for-trezor-one-version-1-9-1-and-trezor-model-t-version-2-3-1-1eba8f60f2dd). + * + * When unsure, always use `txHex`, and skip `txId` and `value` for safety. + * + * Use `rbf` to mark whether this tx can be replaced with another with + * higher fee while being in the mempool. Note that a tx will automatically + * be marked as replacable if a single input requests it. + * Note that any transaction using a relative timelock (nSequence < 0x80000000) + * also falls within the RBF range (nSequence < 0xFFFFFFFE), making it + * inherently replaceable. So don't set `rbf` to false if this is tx uses + * relative time locks. + * + * @returns A finalizer function to be used after signing the `psbt`. + * This function ensures that this input is properly finalized. + * The finalizer has this signature: + * + * `( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void` + * + */ + updatePsbtAsInput({ psbt, txHex, txId, value, vout, //vector output index + rbf = true }) { + if (txHex === undefined) { + console.warn(`Warning: missing txHex may allow fee attacks`); + } + const isSegwit = this.isSegwit(); + if (isSegwit === undefined) { + //This should only happen when using addr() expressions + throw new Error(`Error: could not determine whether this is a segwit descriptor`); + } + const index = (0, psbt_1.updatePsbt)({ + psbt, + vout, + ...(txHex !== undefined ? { txHex } : {}), + ...(txId !== undefined ? { txId } : {}), + ...(value !== undefined ? { value } : {}), + sequence: this.getSequence(), + locktime: this.getLockTime(), + keysInfo: __classPrivateFieldGet(this, _Output_expansionMap, "f") ? Object.values(__classPrivateFieldGet(this, _Output_expansionMap, "f")) : [], + scriptPubKey: this.getScriptPubKey(), + isSegwit, + witnessScript: this.getWitnessScript(), + redeemScript: this.getRedeemScript(), + rbf + }); + const finalizer = ({ psbt, validate = true }) => this.finalizePsbtInput({ index, psbt, validate }); + return finalizer; + } + /** + * Adds this output as an output of the provided `psbt` with the given + * value. + * + * @param psbt - The Partially Signed Bitcoin Transaction. + * @param value - The value for the output in satoshis. + */ + updatePsbtAsOutput({ psbt, value }) { + psbt.addOutput({ script: this.getScriptPubKey(), value }); + } + /** + * Finalizes a PSBT input by adding the necessary unlocking script that satisfies this `Output`'s + * spending conditions. + * + * 🔴 IMPORTANT 🔴 + * It is STRONGLY RECOMMENDED to use the finalizer function returned by + * {@link _Internal_.Output.updatePsbtAsInput | `updatePsbtAsInput`} instead + * of calling this method directly. + * This approach eliminates the need to manage the `Output` instance and the + * input's index, simplifying the process. + * + * The `finalizePsbtInput` method completes a PSBT input by adding the + * unlocking script (`scriptWitness` or `scriptSig`) that satisfies + * this `Output`'s spending conditions. Bear in mind that both + * `scriptSig` and `scriptWitness` incorporate signatures. As such, you + * should complete all necessary signing operations before calling this + * method. + * + * For each unspent output from a previous transaction that you're + * referencing in a `psbt` as an input to be spent, apply this method as + * follows: `output.finalizePsbtInput({ index, psbt })`. + * + * It's essential to specify the exact position (or `index`) of the input in + * the `psbt` that references this unspent `Output`. This `index` should + * align with the value returned by the `updatePsbtAsInput` method. + * Note: + * The `index` corresponds to the position of the input in the `psbt`. + * To get this index, right after calling `updatePsbtAsInput()`, use: + * `index = psbt.data.inputs.length - 1`. + */ + finalizePsbtInput({ index, psbt, validate = true }) { + if (validate && + !psbt.validateSignaturesOfInput(index, signatureValidator)) { + throw new Error(`Error: invalid signatures on input ${index}`); + } + //An index must be passed since finding the index in the psbt cannot be + //done: + //Imagine the case where you received money twice to + //the same miniscript-based address. You would have the same scriptPubKey, + //same sequences, ... The descriptor does not store the hash of the previous + //transaction since it is a general Descriptor object. Indices must be kept + //out of the scope of this class and then passed. + const signatures = psbt.data.inputs[index]?.partialSig; + if (!signatures) + throw new Error(`Error: cannot finalize without signatures`); + __classPrivateFieldGet(this, _Output_instances, "m", _Output_assertPsbtInput).call(this, { index, psbt }); + if (!__classPrivateFieldGet(this, _Output_miniscript, "f")) { + //Use standard finalizers + psbt.finalizeInput(index); + } + else { + const scriptSatisfaction = this.getScriptSatisfaction(signatures); + psbt.finalizeInput(index, (0, psbt_1.finalScriptsFuncFactory)(scriptSatisfaction, __classPrivateFieldGet(this, _Output_network, "f"))); + } + } + /** + * Decomposes the descriptor used to form this `Output` into its elemental + * parts. See {@link ExpansionMap ExpansionMap} for a detailed explanation. + */ + expand() { + return { + ...(__classPrivateFieldGet(this, _Output_expandedExpression, "f") !== undefined + ? { expandedExpression: __classPrivateFieldGet(this, _Output_expandedExpression, "f") } + : {}), + ...(__classPrivateFieldGet(this, _Output_miniscript, "f") !== undefined + ? { miniscript: __classPrivateFieldGet(this, _Output_miniscript, "f") } + : {}), + ...(__classPrivateFieldGet(this, _Output_expandedMiniscript, "f") !== undefined + ? { expandedMiniscript: __classPrivateFieldGet(this, _Output_expandedMiniscript, "f") } + : {}), + ...(__classPrivateFieldGet(this, _Output_expansionMap, "f") !== undefined + ? { expansionMap: __classPrivateFieldGet(this, _Output_expansionMap, "f") } + : {}) + }; + } + } + _Output_payment = new WeakMap(), _Output_preimages = new WeakMap(), _Output_signersPubKeys = new WeakMap(), _Output_miniscript = new WeakMap(), _Output_witnessScript = new WeakMap(), _Output_redeemScript = new WeakMap(), _Output_isSegwit = new WeakMap(), _Output_expandedExpression = new WeakMap(), _Output_expandedMiniscript = new WeakMap(), _Output_expansionMap = new WeakMap(), _Output_network = new WeakMap(), _Output_instances = new WeakSet(), _Output_getTimeConstraints = function _Output_getTimeConstraints() { + const miniscript = __classPrivateFieldGet(this, _Output_miniscript, "f"); + const preimages = __classPrivateFieldGet(this, _Output_preimages, "f"); + const expandedMiniscript = __classPrivateFieldGet(this, _Output_expandedMiniscript, "f"); + const expansionMap = __classPrivateFieldGet(this, _Output_expansionMap, "f"); + const signersPubKeys = __classPrivateFieldGet(this, _Output_signersPubKeys, "f"); + //Create a method. solvePreimages to solve them. + if (miniscript) { + if (expandedMiniscript === undefined || expansionMap === undefined) + throw new Error(`Error: cannot get time constraints from not expanded miniscript ${miniscript}`); + //We create some fakeSignatures since we may not have them yet. + //We only want to retrieve the nLockTime and nSequence of the satisfaction and + //signatures don't matter + const fakeSignatures = signersPubKeys.map(pubkey => ({ + pubkey, + // https://transactionfee.info/charts/bitcoin-script-ecdsa-length/ + signature: Buffer.alloc(72, 0) + })); + const { nLockTime, nSequence } = (0, miniscript_1.satisfyMiniscript)({ + expandedMiniscript, + expansionMap, + signatures: fakeSignatures, + preimages + }); + return { nLockTime, nSequence }; + } + else + return undefined; + }, _Output_assertPsbtInput = function _Output_assertPsbtInput({ psbt, index }) { + const input = psbt.data.inputs[index]; + const txInput = psbt.txInputs[index]; + if (!input || !txInput) + throw new Error(`Error: invalid input or txInput`); + const { sequence: inputSequence, index: vout } = txInput; + let scriptPubKey; + if (input.witnessUtxo) + scriptPubKey = input.witnessUtxo.script; + else { + if (!input.nonWitnessUtxo) + throw new Error(`Error: input should have either witnessUtxo or nonWitnessUtxo`); + const tx = bitcoinjs_lib_1.Transaction.fromBuffer(input.nonWitnessUtxo); + const out = tx.outs[vout]; + if (!out) + throw new Error(`Error: utxo should exist`); + scriptPubKey = out.script; + } + const locktime = this.getLockTime() || 0; + const sequence = this.getSequence(); + //We don't know whether the user opted for RBF or not. So check that + //at least one of the 2 sequences matches. + const sequenceNoRBF = sequence !== undefined + ? sequence + : locktime === 0 + ? 0xffffffff + : 0xfffffffe; + const sequenceRBF = sequence !== undefined ? sequence : 0xfffffffd; + const eqBuffers = (buf1, buf2) => buf1 instanceof Buffer && buf2 instanceof Buffer + ? Buffer.compare(buf1, buf2) === 0 + : buf1 === buf2; + if (Buffer.compare(scriptPubKey, this.getScriptPubKey()) !== 0 || + (sequenceRBF !== inputSequence && sequenceNoRBF !== inputSequence) || + locktime !== psbt.locktime || + !eqBuffers(this.getWitnessScript(), input.witnessScript) || + !eqBuffers(this.getRedeemScript(), input.redeemScript)) { + throw new Error(`Error: cannot finalize psbt index ${index} since it does not correspond to this descriptor`); + } + }; + /** + * @hidden + * @deprecated Use `Output` instead + */ + class Descriptor extends Output { + constructor({ expression, ...rest }) { + super({ descriptor: expression, ...rest }); + } } + return { + // deprecated TAG must also be below so it is exported to descriptors.d.ts + /** @deprecated */ Descriptor, + Output, + parseKeyExpression, + expand, + ECPair, + BIP32 + }; +} +exports.DescriptorsFactory = DescriptorsFactory; - const self = this; - ad.forEach((p, k) => { - const empty = !p || p.length === 0; - let bytes = empty ? 0 : p.length; - self.I[1].copy(I); - multBlock(5 + k, self.J[0], J); - for (let i = 1; bytes >= BLOCK_SIZE; i++, bytes -= BLOCK_SIZE) { - self.aes.AES4(J, I, self.L[i % 8], p.slice(0, BLOCK_SIZE), buf); - xorBytes1x16(sum, buf, sum); - p = p.slice(BLOCK_SIZE); - if (i % 8 === 0) { - doubleBlock(I); +}).call(this)}).call(this,require("buffer").Buffer) +},{"./checksum":2,"./keyExpressions":5,"./miniscript":7,"./psbt":8,"./re":9,"bip32":45,"bitcoinjs-lib":53,"buffer":249,"ecpair":271,"lodash.memoize":431,"varuint-bitcoin":528}],4:[function(require,module,exports){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ledger = exports.scriptExpressions = exports.keyExpressionLedger = exports.keyExpressionBIP32 = exports.finalizePsbt = exports.signers = exports.checksum = exports.DescriptorsFactory = void 0; +var descriptors_1 = require("./descriptors"); +Object.defineProperty(exports, "DescriptorsFactory", { enumerable: true, get: function () { return descriptors_1.DescriptorsFactory; } }); +var checksum_1 = require("./checksum"); +Object.defineProperty(exports, "checksum", { enumerable: true, get: function () { return checksum_1.DescriptorChecksum; } }); +const signers = __importStar(require("./signers")); +exports.signers = signers; +/** + * @hidden + * To be removed in v3.0 and replaced by the version with the signature that + * does not accept descriptors + */ +function finalizePsbt({ psbt, outputs, descriptors, validate = true }) { + if (descriptors && outputs) + throw new Error(`descriptors param has been deprecated`); + outputs = descriptors || outputs; + if (!outputs) + throw new Error(`outputs not provided`); + outputs.forEach((output, inputIndex) => output.finalizePsbtInput({ index: inputIndex, psbt, validate })); +} +exports.finalizePsbt = finalizePsbt; +var keyExpressions_1 = require("./keyExpressions"); +Object.defineProperty(exports, "keyExpressionBIP32", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionBIP32; } }); +Object.defineProperty(exports, "keyExpressionLedger", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionLedger; } }); +const scriptExpressions = __importStar(require("./scriptExpressions")); +exports.scriptExpressions = scriptExpressions; +const ledger_1 = require("./ledger"); +exports.ledger = { + getLedgerMasterFingerPrint: ledger_1.getLedgerMasterFingerPrint, + getLedgerXpub: ledger_1.getLedgerXpub, + registerLedgerWallet: ledger_1.registerLedgerWallet, + assertLedgerApp: ledger_1.assertLedgerApp +}; + +},{"./checksum":2,"./descriptors":3,"./keyExpressions":5,"./ledger":6,"./scriptExpressions":10,"./signers":11}],5:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.keyExpressionBIP32 = exports.keyExpressionLedger = exports.parseKeyExpression = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const ledger_1 = require("./ledger"); +const RE = __importStar(require("./re")); +const derivePath = (node, path) => { + if (typeof path !== 'string') { + throw new Error(`Error: invalid derivation path ${path}`); + } + const parsedPath = path.replaceAll('H', "'").replaceAll('h', "'").slice(1); + const splitPath = parsedPath.split('/'); + for (const element of splitPath) { + const unhardened = element.endsWith("'") ? element.slice(0, -1) : element; + if (!Number.isInteger(Number(unhardened)) || + Number(unhardened) >= 0x80000000) + throw new Error(`Error: BIP 32 path element overflow`); + } + return node.derivePath(parsedPath); +}; +/** + * Parses a key expression (xpub, xprv, pubkey or wif) into {@link KeyInfo | `KeyInfo`}. + * + * For example, given this `keyExpression`: `"[d34db33f/49'/0'/0']tpubDCdxmvzJ5QBjTN8oCjjyT2V58AyZvA1fkmCeZRC75QMoaHcVP2m45Bv3hmnR7ttAwkb2UNYyoXdHVt4gwBqRrJqLUU2JrM43HippxiWpHra/1/2/3/4/*"`, this is its parsed result: + * + * ```javascript + * { + * keyExpression: + * "[d34db33f/49'/0'/0']tpubDCdxmvzJ5QBjTN8oCjjyT2V58AyZvA1fkmCeZRC75QMoaHcVP2m45Bv3hmnR7ttAwkb2UNYyoXdHVt4gwBqRrJqLUU2JrM43HippxiWpHra/1/2/3/4/*", + * keyPath: '/1/2/3/4/*', + * originPath: "/49'/0'/0'", + * path: "m/49'/0'/0'/1/2/3/4/*", + * // Other relevant properties of the type `KeyInfo`: `pubkey`, `ecpair` & `bip32` interfaces, `masterFingerprint`, etc. + * } + * ``` + */ +function parseKeyExpression({ keyExpression, isSegwit, ECPair, BIP32, network = bitcoinjs_lib_1.networks.bitcoin }) { + let pubkey; //won't be computed for ranged keyExpressions + let ecpair; + let bip32; + let masterFingerprint; + let originPath; + let keyPath; + let path; + const isRanged = keyExpression.indexOf('*') !== -1; + //Validate the keyExpression: + const keyExpressions = keyExpression.match(RE.reKeyExp); + if (keyExpressions === null || keyExpressions[0] !== keyExpression) { + throw new Error(`Error: expected a keyExpression but got ${keyExpression}`); + } + const reOriginAnchoredStart = RegExp(String.raw `^(${RE.reOrigin})?`); //starts with ^origin + const mOrigin = keyExpression.match(reOriginAnchoredStart); + if (mOrigin) { + const bareOrigin = mOrigin[0].replace(/[[\]]/g, ''); //strip the "[" and "]" in [origin] + const reMasterFingerprintAnchoredStart = String.raw `^(${RE.reMasterFingerprint})`; + const mMasterFingerprint = bareOrigin.match(reMasterFingerprintAnchoredStart); + const masterFingerprintHex = mMasterFingerprint + ? mMasterFingerprint[0] + : ''; + originPath = bareOrigin.replace(masterFingerprintHex, ''); + if (masterFingerprintHex.length > 0) { + if (masterFingerprintHex.length !== 8) + throw new Error(`Error: masterFingerprint ${masterFingerprintHex} invalid for keyExpression: ${keyExpression}`); + masterFingerprint = Buffer.from(masterFingerprintHex, 'hex'); } - } - if (bytes > 0 || empty) { - buf.fill(0); - if (!empty) { - p.copy(buf); + } + //Remove the origin (if it exists) and store result in actualKey + const actualKey = keyExpression.replace(reOriginAnchoredStart, ''); + let mPubKey, mWIF, mXpubKey, mXprvKey; + //match pubkey: + if ((mPubKey = actualKey.match(RE.anchorStartAndEnd(RE.rePubKey))) !== null) { + pubkey = Buffer.from(mPubKey[0], 'hex'); + ecpair = ECPair.fromPublicKey(pubkey, { network }); + //Validate the pubkey (compressed or uncompressed) + if (!ECPair.isPoint(pubkey) || + !(pubkey.length === 33 || pubkey.length === 65)) { + throw new Error(`Error: invalid pubkey`); } - buf[bytes] = 0x80; - self.aes.AES4(J, self.I[0], self.L[0], buf, buf); - xorBytes1x16(sum, buf, sum); - } + //Do an extra check in case we know this pubkey refers to a segwit input + if (typeof isSegwit === 'boolean' && + isSegwit && + pubkey.length !== 33 //Inside wpkh and wsh, only compressed public keys are permitted. + ) { + throw new Error(`Error: invalid pubkey`); + } + //match WIF: + } + else if ((mWIF = actualKey.match(RE.anchorStartAndEnd(RE.reWIF))) !== null) { + ecpair = ECPair.fromWIF(mWIF[0], network); + //fromWIF will throw if the wif is not valid + pubkey = ecpair.publicKey; + //match xpub: + } + else if ((mXpubKey = actualKey.match(RE.anchorStartAndEnd(RE.reXpubKey))) !== null) { + const xPubKey = mXpubKey[0]; + const xPub = xPubKey.match(RE.reXpub)?.[0]; + if (!xPub) + throw new Error(`Error: xpub could not be matched`); + bip32 = BIP32.fromBase58(xPub, network); + const mPath = xPubKey.match(RE.rePath); + if (mPath !== null) { + keyPath = xPubKey.match(RE.rePath)?.[0]; + if (!keyPath) + throw new Error(`Error: could not extract a path`); + //fromBase58 and derivePath will throw if xPub or path are not valid + if (!isRanged) + pubkey = derivePath(bip32, keyPath).publicKey; + } + else { + pubkey = bip32.publicKey; + } + //match xprv: + } + else if ((mXprvKey = actualKey.match(RE.anchorStartAndEnd(RE.reXprvKey))) !== null) { + const xPrvKey = mXprvKey[0]; + const xPrv = xPrvKey.match(RE.reXprv)?.[0]; + if (!xPrv) + throw new Error(`Error: xprv could not be matched`); + bip32 = BIP32.fromBase58(xPrv, network); + const mPath = xPrvKey.match(RE.rePath); + if (mPath !== null) { + keyPath = xPrvKey.match(RE.rePath)?.[0]; + if (!keyPath) + throw new Error(`Error: could not extract a path`); + //fromBase58 and derivePath will throw if xPrv or path are not valid + if (!isRanged) + pubkey = derivePath(bip32, keyPath).publicKey; + } + else { + pubkey = bip32.publicKey; + } + } + else { + throw new Error(`Error: could not get pubkey for keyExpression ${keyExpression}`); + } + if (originPath || keyPath) { + path = `m${originPath ?? ''}${keyPath ?? ''}`; + } + return { + keyExpression, + ...(pubkey !== undefined ? { pubkey } : {}), + ...(ecpair !== undefined ? { ecpair } : {}), + ...(bip32 !== undefined ? { bip32 } : {}), + ...(masterFingerprint !== undefined ? { masterFingerprint } : {}), + ...(originPath !== undefined && originPath !== '' ? { originPath } : {}), + ...(keyPath !== undefined && keyPath !== '' ? { keyPath } : {}), + ...(path !== undefined ? { path } : {}) + }; +} +exports.parseKeyExpression = parseKeyExpression; +function assertChangeIndexKeyPath({ change, index, keyPath }) { + if (!((change === undefined && index === undefined) || + (change !== undefined && index !== undefined))) + throw new Error(`Error: Pass change and index or neither`); + if ((change !== undefined) === (keyPath !== undefined)) + throw new Error(`Error: Pass either change and index or a keyPath`); +} +/** @hidden */ +async function keyExpressionLedger({ ledgerClient, ledgerState, ledgerManager, originPath, keyPath, change, index }) { + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`ledgerClient and ledgerState have been deprecated`); + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient || !ledgerState) + throw new Error(`Could not retrieve ledgerClient or ledgerState`); + assertChangeIndexKeyPath({ change, index, keyPath }); + const masterFingerprint = await (0, ledger_1.getLedgerMasterFingerPrint)({ + ledgerClient, + ledgerState }); + const origin = `[${masterFingerprint.toString('hex')}${originPath}]`; + const xpub = await (0, ledger_1.getLedgerXpub)({ originPath, ledgerClient, ledgerState }); + const keyRoot = `${origin}${xpub}`; + if (keyPath !== undefined) + return `${keyRoot}${keyPath}`; + else + return `${keyRoot}/${change}/${index}`; +} +exports.keyExpressionLedger = keyExpressionLedger; +/** + * Constructs a key expression string from its constituent components. + * + * This function essentially performs the reverse operation of + * {@link _Internal_.ParseKeyExpression | ParseKeyExpression}. For detailed + * explanations and examples of the terms used here, refer to + * {@link _Internal_.ParseKeyExpression | ParseKeyExpression}. + */ +function keyExpressionBIP32({ masterNode, originPath, keyPath, change, index, isPublic = true }) { + assertChangeIndexKeyPath({ change, index, keyPath }); + const masterFingerprint = masterNode.fingerprint; + const origin = `[${masterFingerprint.toString('hex')}${originPath}]`; + const xpub = isPublic + ? masterNode.derivePath(`m${originPath}`).neutered().toBase58().toString() + : masterNode.derivePath(`m${originPath}`).toBase58().toString(); + const keyRoot = `${origin}${xpub}`; + if (keyPath !== undefined) + return `${keyRoot}${keyPath}`; + else + return `${keyRoot}/${change}/${index}`; +} +exports.keyExpressionBIP32 = keyExpressionBIP32; - return sum; - }; - - this.aezPRF = function (delta, tau, dst) { - const [buf, ctr] = [mkBlock(), mkBlock()]; - - let off = 0; - while (tau >= BLOCK_SIZE) { - xorBytes1x16(delta, ctr, buf); - this.aes.AES10(this.L[3], buf, buf); - buf.copy(dst, off); - - let i = 15; - while (true) { - ctr[i]++; - i--; - if (ctr[i + 1] !== 0) { - break; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./ledger":6,"./re":9,"bitcoinjs-lib":53,"buffer":249}],6:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ledgerPolicyFromState = exports.comparePolicies = exports.ledgerPolicyFromStandard = exports.registerLedgerWallet = exports.ledgerPolicyFromOutput = exports.ledgerPolicyFromPsbtInput = exports.getLedgerXpub = exports.getLedgerMasterFingerPrint = exports.assertLedgerApp = exports.importAndValidateLedgerBitcoin = void 0; +/* + * Notes on Ledger implementation: + * + * Ledger assumes as external all keyRoots that do not have origin information. + * + * Some known Ledger Limitations (based on my tests as of Febr 2023): + * + * 1) All keyExpressions must be expanded into @i. In other words, + * this template is not valid: + * wsh(and_v(v:pk(03ed0b41d808b012b3a77dd7f6a30c4180dfbcab604133d90ce7593ec7f3e4037b),and_v(v:sha256(6c60f404f8167a38fc70eaf8aa17ac351023bef86bcb9d1086a19afe95bd5333),and_v(and_v(v:pk(@0/**),v:pk(@1/**)),older(5))))) + * (note the fixed 03ed0b41d808b012b3a77dd7f6a30c4180dfbcab604133d90ce7593ec7f3e4037b pubkey) + * + * 2) All elements in the keyRoot vector must be xpub-type (no xprv-type, no pubkey-type, ...) + * + * 3) All originPaths of the expressions in the keyRoot vector must be the same. + * On the other hand, an empty originPath is permitted for external keys. + * + * 4) Since all originPaths must be the same and originPaths for the Ledger are + * necessary, a Ledger device can only sign at most 1 key per policy and input. + * + * All the conditions above are checked in function ledgerPolicyFromOutput. + */ +const descriptors_1 = require("./descriptors"); +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const re_1 = require("./re"); +/** + * Dynamically imports the 'ledger-bitcoin' module and, if provided, checks if `ledgerClient` is an instance of `AppClient`. + * + * @async + * @param {unknown} ledgerClient - An optional parameter that, if provided, is checked to see if it's an instance of `AppClient`. + * @throws {Error} Throws an error if `ledgerClient` is provided but is not an instance of `AppClient`. + * @throws {Error} Throws an error if the 'ledger-bitcoin' module cannot be imported. This typically indicates that the 'ledger-bitcoin' peer dependency is not installed. + * @returns {Promise} Returns a promise that resolves with the entire 'ledger-bitcoin' module if it can be successfully imported. We force it to return an unknown type so that the declaration of this function won't break projects that don't use ledger-bitcoin as dependency + * + * @example + * + * importAndValidateLedgerBitcoin(ledgerClient) + * .then((module) => { + * const { AppClient, PsbtV2, DefaultWalletPolicy, WalletPolicy, DefaultDescriptorTemplate, PartialSignature } = module; + * // Use the imported objects... + * }) + * .catch((error) => console.error(error)); + */ +async function importAndValidateLedgerBitcoin(ledgerClient) { + let ledgerBitcoinModule; + try { + // Originally, the code used dynamic imports: + // ledgerBitcoinModule = await import('ledger-bitcoin'); + // However, in React Native with the Metro bundler, there's an issue with + // recognizing dynamic imports inside try-catch blocks. For details, refer to: + // https://github.com/react-native-community/discussions-and-proposals/issues/120 + // The dynamic import gets transpiled to: + // ledgerBitcoinModule = Promise.resolve().then(() => __importStar(require('ledger-bitcoin'))); + // Metro bundler fails to recognize the above as conditional. Hence, it tries + // to require 'ledger-bitcoin' unconditionally, leading to potential errors if + // 'ledger-bitcoin' is not installed (given it's an optional peerDependency). + // To bypass this, we directly use require: + ledgerBitcoinModule = require('ledger-bitcoin'); + } + catch (error) { + throw new Error('Could not import "ledger-bitcoin". This is a peer dependency and needs to be installed explicitly. Please run "npm install ledger-bitcoin" to use Ledger Hardware Wallet functionality.'); + } + const { AppClient } = ledgerBitcoinModule; + if (ledgerClient !== undefined && !(ledgerClient instanceof AppClient)) { + throw new Error('Error: invalid AppClient instance'); + } + return ledgerBitcoinModule; +} +exports.importAndValidateLedgerBitcoin = importAndValidateLedgerBitcoin; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +async function ledgerAppInfo(transport) { + const r = await transport.send(0xb0, 0x01, 0x00, 0x00); + let i = 0; + const format = r[i++]; + const nameLength = r[i++]; + const name = r.slice(i, (i += nameLength)).toString('ascii'); + const versionLength = r[i++]; + const version = r.slice(i, (i += versionLength)).toString('ascii'); + const flagLength = r[i++]; + const flags = r.slice(i, (i += flagLength)); + return { name, version, flags, format }; +} +/** + * Verifies if the Ledger device is connected, if the required Bitcoin App is opened, + * and if the version of the app meets the minimum requirements. + * + * @throws Will throw an error if the Ledger device is not connected, the required + * Bitcoin App is not opened, or if the version is below the required number. + * + * @returns Promise - A promise that resolves if all assertions pass, or throws otherwise. + */ +async function assertLedgerApp({ transport, name, minVersion }) { + const { name: openName, version } = await ledgerAppInfo(transport); + if (openName !== name) { + throw new Error(`Open the ${name} app and try again`); + } + else { + const [mVmajor, mVminor, mVpatch] = minVersion.split('.').map(Number); + const [major, minor, patch] = version.split('.').map(Number); + if (mVmajor === undefined || + mVminor === undefined || + mVpatch === undefined) { + throw new Error(`Pass a minVersion using semver notation: major.minor.patch`); } - } - - tau -= BLOCK_SIZE; - off += BLOCK_SIZE; + if (major < mVmajor || + (major === mVmajor && minor < mVminor) || + (major === mVmajor && minor === mVminor && patch < mVpatch)) + throw new Error(`Error: please upgrade ${name} to version ${minVersion}`); } - if (tau > 0) { - xorBytes1x16(delta, ctr, buf); - this.aes.AES10(this.L[3], buf, buf); - buf.copy(dst, off); +} +exports.assertLedgerApp = assertLedgerApp; +function isLedgerStandard({ ledgerTemplate, keyRoots, network = bitcoinjs_lib_1.networks.bitcoin }) { + if (keyRoots.length !== 1) + return false; + const originPath = keyRoots[0]?.match(re_1.reOriginPath)?.[1]; + if (!originPath) + return false; + //Network is the 6th character: /44'/0' + if (originPath[5] !== (network === bitcoinjs_lib_1.networks.bitcoin ? '0' : '1')) + return false; + if ((ledgerTemplate === 'pkh(@0/**)' && + originPath.match(/^\/44'\/[01]'\/(\d+)'$/)) || + (ledgerTemplate === 'wpkh(@0/**)' && + originPath.match(/^\/84'\/[01]'\/(\d+)'$/)) || + (ledgerTemplate === 'sh(wpkh(@0/**))' && + originPath.match(/^\/49'\/[01]'\/(\d+)'$/)) || + (ledgerTemplate === 'tr(@0/**)' && + originPath.match(/^\/86'\/[01]'\/(\d+)'$/))) + return true; + return false; +} +/** @hidden */ +async function getLedgerMasterFingerPrint({ ledgerClient, ledgerState, ledgerManager }) { + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`ledgerClient and ledgerState have been deprecated`); + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient || !ledgerState) + throw new Error(`Could not retrieve ledgerClient or ledgerState`); + const { AppClient } = (await importAndValidateLedgerBitcoin(ledgerClient)); + if (!(ledgerClient instanceof AppClient)) + throw new Error(`Error: pass a valid ledgerClient`); + let masterFingerprint = ledgerState.masterFingerprint; + if (!masterFingerprint) { + masterFingerprint = Buffer.from(await ledgerClient.getMasterFingerprint(), 'hex'); + ledgerState.masterFingerprint = masterFingerprint; + } + return masterFingerprint; +} +exports.getLedgerMasterFingerPrint = getLedgerMasterFingerPrint; +/** @hidden */ +async function getLedgerXpub({ originPath, ledgerClient, ledgerState, ledgerManager }) { + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`ledgerClient and ledgerState have been deprecated`); + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient || !ledgerState) + throw new Error(`Could not retrieve ledgerClient or ledgerState`); + const { AppClient } = (await importAndValidateLedgerBitcoin(ledgerClient)); + if (!(ledgerClient instanceof AppClient)) + throw new Error(`Error: pass a valid ledgerClient`); + if (!ledgerState.xpubs) + ledgerState.xpubs = {}; + let xpub = ledgerState.xpubs[originPath]; + if (!xpub) { + try { + //Try getting the xpub without user confirmation + xpub = await ledgerClient.getExtendedPubkey(`m${originPath}`, false); + } + catch (err) { + xpub = await ledgerClient.getExtendedPubkey(`m${originPath}`, true); + } + if (typeof xpub !== 'string') + throw new Error(`Error: ledgerClient did not return a valid xpub`); + ledgerState.xpubs[originPath] = xpub; } - }; - - this.encipher = function (delta, input, dst) { - if (!input || input.length === 0) { - return; + return xpub; +} +exports.getLedgerXpub = getLedgerXpub; +/** + * Checks whether there is a policy in ledgerState that the ledger + * could use to sign this psbt input. + * + * It found return the policy, otherwise, return undefined + * + * All considerations in the header of this file are applied + */ +async function ledgerPolicyFromPsbtInput({ ledgerManager, psbt, index }) { + const { ledgerState, ledgerClient, ecc, network } = ledgerManager; + const { Output } = (0, descriptors_1.DescriptorsFactory)(ecc); + const input = psbt.data.inputs[index]; + if (!input) + throw new Error(`Input numer ${index} not set.`); + let scriptPubKey; + if (input.nonWitnessUtxo) { + const vout = psbt.txInputs[index]?.index; + if (vout === undefined) + throw new Error(`Could not extract vout from nonWitnessUtxo for input ${index}.`); + scriptPubKey = bitcoinjs_lib_1.Transaction.fromBuffer(input.nonWitnessUtxo).outs[vout] + ?.script; + } + else if (input.witnessUtxo) { + scriptPubKey = input.witnessUtxo.script; + } + if (!scriptPubKey) + throw new Error(`Could not retrieve scriptPubKey for input ${index}.`); + const bip32Derivations = input.bip32Derivation; + if (!bip32Derivations || !bip32Derivations.length) + throw new Error(`Input ${index} does not contain bip32 derivations.`); + const ledgerMasterFingerprint = await getLedgerMasterFingerPrint({ + ledgerManager + }); + for (const bip32Derivation of bip32Derivations) { + //get the keyRoot and keyPath. If it matches one of our policies then + //we are still not sure this is the policy that must be used yet + //So we must use the template and the keyRoot of each policy and compute the + //scriptPubKey: + if (Buffer.compare(bip32Derivation.masterFingerprint, ledgerMasterFingerprint) === 0) { + // Match /m followed by n consecutive hardened levels and then 2 consecutive unhardened levels: + const match = bip32Derivation.path.match(/m((\/\d+['hH])*)(\/\d+\/\d+)?/); + const originPath = match ? match[1] : undefined; //n consecutive hardened levels + const keyPath = match ? match[3] : undefined; //2 unhardened levels or undefined + if (originPath && keyPath) { + const [, strChange, strIndex] = keyPath.split('/'); + if (!strChange || !strIndex) + throw new Error(`keyPath ${keyPath} incorrectly extracted`); + const change = parseInt(strChange, 10); + const index = parseInt(strIndex, 10); + const coinType = network === bitcoinjs_lib_1.networks.bitcoin ? 0 : 1; + //standard policy candidate. This policy will be added to the pool + //of policies below and check if it produces the correct scriptPubKey + let standardPolicy; + if (change === 0 || change === 1) { + const standardTemplate = originPath.match(new RegExp(`^/44'/${coinType}'/(\\d+)'$`)) + ? 'pkh(@0/**)' + : originPath.match(new RegExp(`^/84'/${coinType}'/(\\d+)'$`)) + ? 'wpkh(@0/**)' + : originPath.match(new RegExp(`^/49'/${coinType}'/(\\d+)'$`)) + ? 'sh(wpkh(@0/**))' + : originPath.match(new RegExp(`^/86'/${coinType}'/(\\d+)'$`)) + ? 'tr(@0/**)' + : undefined; + if (standardTemplate) { + const xpub = await getLedgerXpub({ + originPath, + ledgerClient, + ledgerState + }); + standardPolicy = { + ledgerTemplate: standardTemplate, + keyRoots: [ + `[${ledgerMasterFingerprint.toString('hex')}${originPath}]${xpub}` + ] + }; + } + } + const policies = [...(ledgerState.policies || [])]; + if (standardPolicy) + policies.push(standardPolicy); + for (const policy of policies) { + //Build the descriptor from the ledgerTemplate + keyRoots + //then get the scriptPubKey + let descriptor = policy.ledgerTemplate; + // Replace change (making sure the value in the change level for the + // template of the policy meets the change in bip32Derivation): + descriptor = descriptor.replace(/\/\*\*/g, `/<0;1>/*`); + const regExpMN = new RegExp(`/<(\\d+);(\\d+)>`, 'g'); + let matchMN; + while (descriptor && (matchMN = regExpMN.exec(descriptor)) !== null) { + const [M, N] = [ + parseInt(matchMN[1], 10), + parseInt(matchMN[2], 10) + ]; + if (M === change || N === change) + descriptor = descriptor.replace(`/<${M};${N}>`, `/${change}`); + else + descriptor = undefined; + } + if (descriptor) { + // Replace index: + descriptor = descriptor.replace(/\/\*/g, `/${index}`); + // Replace origin in reverse order to prevent + // misreplacements, e.g., @10 being mistaken for @1 and leaving a 0. + for (let i = policy.keyRoots.length - 1; i >= 0; i--) { + const keyRoot = policy.keyRoots[i]; + if (!keyRoot) + throw new Error(`keyRoot ${keyRoot} invalidly extracted.`); + const match = keyRoot.match(/\[([^]+)\]/); + const keyRootOrigin = match && match[1]; + if (keyRootOrigin) { + const [, ...arrKeyRootOriginPath] = keyRootOrigin.split('/'); + const keyRootOriginPath = '/' + arrKeyRootOriginPath.join('/'); + //We check all origins to be the same even if they do not + //belong to the ledger (read the header in this file) + if (descriptor && keyRootOriginPath === originPath) + descriptor = descriptor.replace(new RegExp(`@${i}`, 'g'), keyRoot); + else + descriptor = undefined; + } + else + descriptor = undefined; + } + //verify the scriptPubKey from the input vs. the one obtained from + //the policy after having filled in the keyPath in the template + if (descriptor) { + const policyScriptPubKey = new Output({ + descriptor, + network + }).getScriptPubKey(); + if (Buffer.compare(policyScriptPubKey, scriptPubKey) === 0) { + return policy; + } + } + } + } + } + } } - - if (input.length < 32) { - this.aezTiny(delta, input, 0, dst); - } else { - this.aezCore(delta, input, 0, dst); + return; +} +exports.ledgerPolicyFromPsbtInput = ledgerPolicyFromPsbtInput; +/** + * Given an output, it extracts its descriptor and converts it to a Ledger + * Wallet Policy, that is, its keyRoots and template. + * + * keyRoots and template follow Ledger's specifications: + * https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md + * + * keyRoots and template are a generalization of a descriptor and serve to + * describe internal and external addresses and any index. + * + * So, this function starts from a descriptor and obtains generalized Ledger + * wallet policy. + * + * keyRoots is an array of strings, encoding xpub-type key expressions up to the origin. + * F.ex.: [76223a6e/48'/1'/0'/2']tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF + * + * Template encodes the descriptor script expression, where its key + * expressions are represented using variables for each keyRoot and finished with "/**" + * (for change 1 or 0 and any index). F.ex.: + * wsh(sortedmulti(2,@0/**,@1/**)), where @0 corresponds the first element in the keyRoots array. + * + * If this descriptor does not contain any key that can be signed with the ledger + * (non-matching masterFingerprint), then this function returns null. + * + * This function takes into account all the considerations regarding Ledger + * policy implementation details expressed in the header of this file. + */ +async function ledgerPolicyFromOutput({ output, ledgerClient, ledgerState }) { + const expandedExpression = output.expand().expandedExpression; + const expansionMap = output.expand().expansionMap; + if (!expandedExpression || !expansionMap) + throw new Error(`Error: invalid output`); + const ledgerMasterFingerprint = await getLedgerMasterFingerPrint({ + ledgerClient, + ledgerState + }); + //It's important to have keys sorted in ascii order. keys + //are of this type: @0, @1, @2, .... and they also appear in the expandedExpression + //in ascending ascii order. Note that Object.keys(expansionMap ) does not ensure + //that the order is respected and so we force it. + const allKeys = Object.keys(expansionMap).sort(); + const ledgerKeys = allKeys.filter(key => { + const masterFingerprint = expansionMap[key]?.masterFingerprint; + return (masterFingerprint && + Buffer.compare(masterFingerprint, ledgerMasterFingerprint) === 0); + }); + if (ledgerKeys.length === 0) + return null; + if (ledgerKeys.length > 1) + throw new Error(`Error: descriptor ${expandedExpression} does not contain exactly 1 ledger key`); + const ledgerKey = ledgerKeys[0]; + const masterFingerprint = expansionMap[ledgerKey].masterFingerprint; + const originPath = expansionMap[ledgerKey].originPath; + const keyPath = expansionMap[ledgerKey].keyPath; + const bip32 = expansionMap[ledgerKey].bip32; + if (!masterFingerprint || !originPath || !keyPath || !bip32) { + throw new Error(`Error: Ledger key expression must have a valid masterFingerprint: ${masterFingerprint}, originPath: ${originPath}, keyPath: ${keyPath} and a valid bip32 node`); + } + if (!/^\/[01]\/\d+$/.test(keyPath)) + throw new Error(`Error: key paths must be /<1;0>/index, where change is 1 or 0 and index >= 0`); + const keyRoots = []; + let ledgerTemplate = expandedExpression; + allKeys.forEach(key => { + if (key !== ledgerKey) { + //This block here only does data integrity assertions: + const otherKeyInfo = expansionMap[key]; + if (!otherKeyInfo.bip32) { + throw new Error(`Error: ledger only allows xpub-type key expressions`); + } + if (otherKeyInfo.originPath) { + if (otherKeyInfo.originPath !== originPath) { + throw new Error(`Error: all originPaths must be the same for Ledger being able to sign. On the other hand, you can leave the origin info empty for external keys: ${otherKeyInfo.originPath} !== ${originPath}`); + } + } + if (otherKeyInfo.keyPath !== keyPath) { + throw new Error(`Error: all keyPaths must be the same for Ledger being able to sign: ${otherKeyInfo.keyPath} !== ${keyPath}`); + } + } + ledgerTemplate = ledgerTemplate.replaceAll(key, `@${keyRoots.length}/**`); + const keyInfo = expansionMap[key]; + if (keyInfo.masterFingerprint && keyInfo.originPath) + keyRoots.push(`[${keyInfo.masterFingerprint?.toString('hex')}${keyInfo.originPath}]${keyInfo?.bip32?.neutered().toBase58()}`); + else + keyRoots.push(`${keyInfo?.bip32?.neutered().toBase58()}`); + }); + return { ledgerTemplate, keyRoots }; +} +exports.ledgerPolicyFromOutput = ledgerPolicyFromOutput; +/** + * To be removed in v3.0 and replaced by a version that does not accept + * descriptors + * @hidden + **/ +async function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, ledgerManager, policyName }) { + if (typeof descriptor !== 'string' && ledgerManager) + throw new Error(`Invalid usage: descriptor must be a string`); + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`Invalid usage: either ledgerManager or ledgerClient + ledgerState`); + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient) + throw new Error(`ledgerManager not provided`); + if (!ledgerState) + throw new Error(`ledgerManager not provided`); + const { WalletPolicy, AppClient } = (await importAndValidateLedgerBitcoin(ledgerClient)); + if (!(ledgerClient instanceof AppClient)) + throw new Error(`Error: pass a valid ledgerClient`); + let output; + if (typeof descriptor === 'string') { + if (!ledgerManager) + throw new Error(`ledgerManager not provided`); + const { Output } = (0, descriptors_1.DescriptorsFactory)(ledgerManager.ecc); + output = new Output({ + descriptor, + ...(descriptor.includes('*') ? { index: 0 } : {}), + network: ledgerManager.network + }); } - }; - - this.decipher = function (delta, input, dst) { - if (!input || input.length === 0) { - return; + else + output = descriptor; + if (await ledgerPolicyFromStandard({ output, ledgerClient, ledgerState })) + return; + const result = await ledgerPolicyFromOutput({ + output, + ledgerClient, + ledgerState + }); + if (await ledgerPolicyFromStandard({ output, ledgerClient, ledgerState })) + return; + if (!result) + throw new Error(`Error: output does not have a ledger input`); + const { ledgerTemplate, keyRoots } = result; + if (!ledgerState.policies) + ledgerState.policies = []; + let walletPolicy, policyHmac; + //Search in ledgerState first + const policy = await ledgerPolicyFromState({ + output, + ledgerClient, + ledgerState + }); + if (policy) { + if (policy.policyName !== policyName) + throw new Error(`Error: policy was already registered with a different name: ${policy.policyName}`); + //It already existed. No need to register it again. } - - if (input.length < 32) { - this.aezTiny(delta, input, 1, dst); - } else { - this.aezCore(delta, input, 1, dst); + else { + walletPolicy = new WalletPolicy(policyName, ledgerTemplate, keyRoots); + let policyId; + [policyId, policyHmac] = await ledgerClient.registerWallet(walletPolicy); + const policy = { + policyName, + ledgerTemplate, + keyRoots, + policyId, + policyHmac + }; + ledgerState.policies.push(policy); } - }; - - this.aezTiny = function (delta, input, d, dst) { - const inBytes = input.length; - const buf = mkBlock(2 * BLOCK_SIZE); - const [L, R, tmp] = [mkBlock(), mkBlock(), mkBlock()]; - let mask = 0x00; - let pad = 0x80; - let rounds, i, j, step; - - i = 7; - if (inBytes === 1) { - rounds = 24; - } else if (inBytes === 2) { - rounds = 16; - } else if (inBytes < 16) { - rounds = 10; - } else { - i = 6; - rounds = 8; +} +exports.registerLedgerWallet = registerLedgerWallet; +/** + * Retrieve a standard ledger policy or null if it does correspond. + **/ +async function ledgerPolicyFromStandard({ output, ledgerClient, ledgerState }) { + const result = await ledgerPolicyFromOutput({ + output, + ledgerClient, + ledgerState + }); + if (!result) + throw new Error(`Error: descriptor does not have a ledger input`); + const { ledgerTemplate, keyRoots } = result; + if (isLedgerStandard({ + ledgerTemplate, + keyRoots, + network: output.getNetwork() + })) + return { ledgerTemplate, keyRoots }; + return null; +} +exports.ledgerPolicyFromStandard = ledgerPolicyFromStandard; +function compareKeyRoots(arr1, arr2) { + if (arr1.length !== arr2.length) { + return false; } - - input.slice(0, (inBytes + 1) / 2).copy(L); - input.slice(inBytes / 2, (inBytes / 2) + ((inBytes + 1) / 2)).copy(R); - if (inBytes & 1 !== 0) { - for (let k = 0; k < (inBytes / 2); k++) { - R[k] = (R[k] << 4) | (R[k + 1] >> 4); - } - R[inBytes / 2] = R[inBytes / 2] << 4; - pad = 0x08; - mask = 0xf0; + for (let i = 0; i < arr1.length; i++) { + if (arr1[i] !== arr2[i]) { + return false; + } } - - if (d !== 0) { - if (inBytes < 16) { - input.slice(0, BLOCK_SIZE).copy(buf); - buf[0] |= 0x80; - xorBytes1x16(delta, buf, buf); - this.aes.AES4(ZERO, this.I[1], this.L[3], buf, tmp); - L[0] ^= (tmp[0] & 0x80); - } - j = rounds - 1; - step = -1; - } else { - j = 0; - step = 1; + return true; +} +function comparePolicies(policyA, policyB) { + return (compareKeyRoots(policyA.keyRoots, policyB.keyRoots) && + policyA.ledgerTemplate === policyB.ledgerTemplate); +} +exports.comparePolicies = comparePolicies; +/** + * Retrieve a ledger policy from ledgerState or null if it does not exist yet. + **/ +async function ledgerPolicyFromState({ output, ledgerClient, ledgerState }) { + const result = await ledgerPolicyFromOutput({ + output, + ledgerClient, + ledgerState + }); + if (!result) + throw new Error(`Error: output does not have a ledger input`); + const { ledgerTemplate, keyRoots } = result; + if (!ledgerState.policies) + ledgerState.policies = []; + //Search in ledgerState: + const policies = ledgerState.policies.filter(policy => comparePolicies(policy, { ledgerTemplate, keyRoots })); + if (policies.length > 1) + throw new Error(`Error: duplicated policy`); + if (policies.length === 1) { + return policies[0]; } - - for (let k = 0; k < rounds / 2; k++, j += step * 2) { - buf.fill(0, 0, BLOCK_SIZE); - R.slice(0, (inBytes + 1) / 2).copy(buf); - buf[floor(inBytes / 2)] = (buf[floor(inBytes / 2)] & mask) | pad; - xorBytes1x16(buf, delta, buf); - buf[15] ^= j; - this.aes.AES4(ZERO, this.I[1], this.L[i], buf, tmp); - xorBytes1x16(L, tmp, L); - - buf.fill(0, 0, BLOCK_SIZE); - L.slice(0, (inBytes + 1) / 2).copy(buf); - buf[floor(inBytes / 2)] = (buf[floor(inBytes / 2)] & mask) | pad; - xorBytes1x16(buf, delta, buf); - buf[15] ^= j + step; - this.aes.AES4(ZERO, this.I[1], this.L[i], buf, tmp); - xorBytes1x16(R, tmp, R); + else { + return null; } +} +exports.ledgerPolicyFromState = ledgerPolicyFromState; - R.slice(0, floor(inBytes / 2)).copy(buf); - L.slice(0, floor((inBytes + 1) / 2)).copy(buf, floor(inBytes / 2)); - if (inBytes & 1 !== 0) { - for (let k = inBytes - 1; k > inBytes / 2; k--) { - buf[k] = (buf[k] >> 4) | (buf[k - 1] << 4); - } - buf[floor(inBytes / 2)] = (L[0] >> 4) | (R[floor(inBytes / 2)] & 0xf0); +}).call(this)}).call(this,require("buffer").Buffer) +},{"./descriptors":3,"./re":9,"bitcoinjs-lib":53,"buffer":249,"ledger-bitcoin":356}],7:[function(require,module,exports){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.numberEncodeAsm = exports.satisfyMiniscript = exports.miniscript2Script = exports.expandMiniscript = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const keyExpressions_1 = require("./keyExpressions"); +const RE = __importStar(require("./re")); +const miniscript_1 = require("@bitcoinerlab/miniscript"); +/** + * Expand a miniscript to a generalized form using variables instead of key + * expressions. Variables will be of this form: @0, @1, ... + * This is done so that it can be compiled with compileMiniscript and + * satisfied with satisfier. + * Also compute pubkeys from descriptors to use them later. + */ +function expandMiniscript({ miniscript, isSegwit, network = bitcoinjs_lib_1.networks.bitcoin, ECPair, BIP32 }) { + const expansionMap = {}; + const expandedMiniscript = miniscript.replace(RegExp(RE.reKeyExp, 'g'), (keyExpression) => { + const key = '@' + Object.keys(expansionMap).length; + expansionMap[key] = (0, keyExpressions_1.parseKeyExpression)({ + keyExpression, + isSegwit, + network, + ECPair, + BIP32 + }); + return key; + }); + //Do some assertions. Miniscript must not have duplicate keys, also all + //keyExpressions must produce a valid pubkey (unless it's ranged and we want + //to expand a generalized form, then we don't check) + const pubkeysHex = Object.values(expansionMap) + .filter(keyInfo => keyInfo.keyExpression.indexOf('*') === -1) + .map(keyInfo => { + if (!keyInfo.pubkey) + throw new Error(`Error: keyExpression ${keyInfo.keyExpression} does not have a pubkey`); + return keyInfo.pubkey.toString('hex'); + }); + if (new Set(pubkeysHex).size !== pubkeysHex.length) { + throw new Error(`Error: miniscript ${miniscript} is not sane: contains duplicate public keys.`); } - - buf.slice(0, inBytes).copy(dst); - if (inBytes < 16 && d === 0) { - buf.fill(0, inBytes, BLOCK_SIZE); - buf[0] |= 0x80; - xorBytes1x16(delta, buf, buf); - this.aes.AES4(ZERO, this.I[1], this.L[3], buf, tmp); - dst[0] ^= tmp[0] & 0x80; + return { expandedMiniscript, expansionMap }; +} +exports.expandMiniscript = expandMiniscript; +/** + * Particularize an expanded ASM expression using the variables in + * expansionMap. + * This is the kind of the opposite to what expandMiniscript does. + * Signatures and preimages are already subsituted by the satisfier calling + * this function. + */ +function substituteAsm({ expandedAsm, expansionMap }) { + //Replace back variables into the pubkeys previously computed. + let asm = Object.keys(expansionMap).reduce((accAsm, key) => { + const pubkey = expansionMap[key]?.pubkey; + if (!pubkey) { + throw new Error(`Error: invalid expansionMap for ${key}`); + } + return accAsm + .replaceAll(`<${key}>`, `<${pubkey.toString('hex')}>`) + .replaceAll(``, `<${bitcoinjs_lib_1.crypto.hash160(pubkey).toString('hex')}>`); + }, expandedAsm); + //Now clean it and prepare it so that fromASM can be called: + asm = asm + .trim() + //Replace one or more consecutive whitespace characters (spaces, tabs, + //or line breaks) with a single space. + .replace(/\s+/g, ' ') + //Now encode numbers to little endian hex. Note that numbers are not + //enclosed in <>, since <> represents hex code already encoded. + //The regex below will match one or more digits within a string, + //except if the sequence is surrounded by "<" and ">" + .replace(/(<\d+>)|\b\d+\b/g, match => match.startsWith('<') ? match : numberEncodeAsm(Number(match))) + //we don't have numbers anymore, now it's safe to remove < and > since we + //know that every remaining is either an op_code or a hex encoded number + .replace(/[<>]/g, ''); + return asm; +} +function miniscript2Script({ expandedMiniscript, expansionMap }) { + const compiled = (0, miniscript_1.compileMiniscript)(expandedMiniscript); + if (compiled.issane !== true) { + throw new Error(`Error: Miniscript ${expandedMiniscript} is not sane`); + } + return bitcoinjs_lib_1.script.fromASM(substituteAsm({ expandedAsm: compiled.asm, expansionMap })); +} +exports.miniscript2Script = miniscript2Script; +/** + * Assumptions: + * The attacker does not have access to any of the private keys of public keys + * that participate in the Script. + * + * The attacker only has access to hash preimages that honest users have access + * to as well. + * + * Pass timeConstraints to search for the first solution with this nLockTime and + * nSequence. Throw if no solution is possible using these constraints. + * + * Don't pass timeConstraints (this is the default) if you want to get the + * smallest size solution altogether. + * + * If a solution is not found this function throws. + */ +function satisfyMiniscript({ expandedMiniscript, expansionMap, signatures = [], preimages = [], timeConstraints }) { + //convert 'sha256(6c...33)' to: { ['']: '10...5f'} + const preimageMap = {}; + preimages.forEach(preimage => { + preimageMap['<' + preimage.digest.replace('(', '_preimage(') + '>'] = + '<' + preimage.preimage + '>'; + }); + //convert the pubkeys in signatures into [{['']: '30450221'}, ...] + //get the keyExpressions: @0, @1 from the keys in expansionMap + const expandedSignatureMap = {}; + signatures.forEach(signature => { + const pubkeyHex = signature.pubkey.toString('hex'); + const keyExpression = Object.keys(expansionMap).find(k => expansionMap[k]?.pubkey?.toString('hex') === pubkeyHex); + expandedSignatureMap[''] = + '<' + signature.signature.toString('hex') + '>'; + }); + const expandedKnownsMap = { ...preimageMap, ...expandedSignatureMap }; + const knowns = Object.keys(expandedKnownsMap); + //satisfier verifies again internally whether expandedKnownsMap with given knowns is sane + const { nonMalleableSats } = (0, miniscript_1.satisfier)(expandedMiniscript, { knowns }); + if (!Array.isArray(nonMalleableSats) || !nonMalleableSats[0]) + throw new Error(`Error: unresolvable miniscript ${expandedMiniscript}`); + let sat; + if (!timeConstraints) { + sat = nonMalleableSats[0]; } - }; - - this.aezCore = function (delta, input, d, dst) { - const inBytes = input.length; - let fragBytes = inBytes % 32; - - const initialBytes = inBytes - fragBytes - 32; - const [tmp, X, Y, S] = [mkBlock(), mkBlock(), mkBlock(), mkBlock()]; - - const outOrig = dst; - const inOrig = input; - - // Compute X and store intermediate results - if (inBytes >= 64) { - this.aezCorePass1(input, dst, X); + else { + sat = nonMalleableSats.find(nonMalleableSat => nonMalleableSat.nSequence === timeConstraints.nSequence && + nonMalleableSat.nLockTime === timeConstraints.nLockTime); + if (sat === undefined) { + throw new Error(`Error: unresolvable miniscript ${expandedMiniscript}. Could not find solutions for sequence ${timeConstraints.nSequence} & locktime=${timeConstraints.nLockTime}. Signatures are applied to a hash that depends on sequence and locktime. Did you provide all the signatures wrt the signers keys declared and include all preimages?`); + } } - - // Finish X calculation - input = input.slice(initialBytes); - if (fragBytes >= BLOCK_SIZE) { - this.aes.AES4(ZERO, this.I[1], this.L[4], input, tmp); - xorBytes1x16(X, tmp, X); - oneZeroPad(input.slice(BLOCK_SIZE), fragBytes - BLOCK_SIZE, tmp); - this.aes.AES4(ZERO, this.I[1], this.L[5], tmp, tmp); - xorBytes1x16(X, tmp, X); - } else if (fragBytes > 0) { - oneZeroPad(input, fragBytes, tmp); - this.aes.AES4(ZERO, this.I[1], this.L[4], tmp, tmp); - xorBytes1x16(X, tmp, X); + //substitute signatures and preimages: + let expandedAsm = sat.asm; + //replace in expandedAsm all the and + //to <304...01> and <107...5f> ... + for (const search in expandedKnownsMap) { + const replace = expandedKnownsMap[search]; + if (!replace || replace === '<>') + throw new Error(`Error: invalid expandedKnownsMap`); + expandedAsm = expandedAsm.replaceAll(search, replace); + } + const scriptSatisfaction = bitcoinjs_lib_1.script.fromASM(substituteAsm({ expandedAsm, expansionMap })); + return { + scriptSatisfaction, + nLockTime: sat.nLockTime, + nSequence: sat.nSequence + }; +} +exports.satisfyMiniscript = satisfyMiniscript; +/** + * + * Use this function instead of bitcoinjs-lib's equivalent `script.number.encode` + * when encoding numbers to be compiled with `fromASM` to avoid problems. + * + * Motivation: + * + * Numbers in Bitcoin assembly code are represented in hex and in Little Endian. + * Decimal: 32766 - Big endian: 0x7FFE - Little Endian: 0xFE7F. + * + * This function takes an integer and encodes it so that bitcoinjs-lib `fromASM` + * can compile it. This is basically what bitcoinjs-lib's `script.number.encode` + * does. + * + * Note that `fromASM` already converts integers from 1 to 16 to + * OP_1 ... OP_16 {@link https://github.com/bitcoinjs/bitcoinjs-lib/blob/59b21162a2c4645c64271ca004c7a3755a3d72fb/src/script.js#L33 here}. + * This is done in Bitcoin to save some bits. + * + * Neither this function nor `script.number.encode` convert numbers to + * their op code equivalent since this is done later in `fromASM`. + * + * Both functions simply convert numbers to Little Endian. + * + * However, the `0` number is an edge case that we specially handle with this + * function. + * + * bitcoinjs-lib's `bscript.number.encode(0)` produces an empty Buffer. + * This is what the Bitcoin interpreter does and it is what `script.number.encode` was + * implemented to do. + * + * The problem is `bscript.number.encode(0).toString('hex')` produces an + * empty string and thus it should not be used to serialize number zero before `fromASM`. + * + * A zero should produce the OP_0 ASM symbolic code (corresponding to a `0` when + * compiled). + * + * So, this function will produce a string in hex format in Little Endian + * encoding for integers not equal to `0` and it will return `OP_0` for `0`. + * + * Read more about the this {@link https://github.com/bitcoinjs/bitcoinjs-lib/issues/1799#issuecomment-1122591738 here}. + * + * Use it in combination with `fromASM` like this: + * + * ```javascript + * //To produce "0 1 OP_ADD": + * fromASM( + * `${numberEncodeAsm(0)} ${numberEncodeAsm(1)} OP_ADD` + * .trim().replace(/\s+/g, ' ') + * ) + * ``` + * + * @param {number} number An integer. + * @returns {string} Returns `"OP_0"` for `number === 0` and a hex string representing other numbers in Little Endian encoding. + */ +function numberEncodeAsm(number) { + if (Number.isSafeInteger(number) === false) { + throw new Error(`Error: invalid number ${number}`); } - - // Calculate S - dst = outOrig.slice(inOrig.length - 32); - input = inOrig.slice(inOrig.length - 32); - this.aes.AES4(ZERO, this.I[1], this.L[(1 + d) % 8], input.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); - xorBytes4x16(X, input, delta, tmp, dst); - this.aes.AES10(this.L[(1 + d) % 8], dst, tmp); - xorBytes1x16(input.slice(BLOCK_SIZE), tmp, dst.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); - xorBytes1x16(dst, dst.slice(BLOCK_SIZE), S); - - // Pass 2 over intermediate values in dst[32..]. Final values written - dst = outOrig; - input = inOrig; - if (input.length >= 64) { - this.aezCorePass2(input, dst, Y, S); + if (number === 0) { + return 'OP_0'; } + else + return bitcoinjs_lib_1.script.number.encode(number).toString('hex'); +} +exports.numberEncodeAsm = numberEncodeAsm; - // Finish Y calculation and finish encryption of fragment bytes - dst = dst.slice(initialBytes); - input = input.slice(initialBytes); - if (fragBytes >= BLOCK_SIZE) { - this.aes.AES10(this.L[4], S, tmp); - xorBytes1x16(input, tmp, dst); - this.aes.AES4(ZERO, this.I[1], this.L[4], dst, tmp); - xorBytes1x16(Y, tmp, Y); - - dst = dst.slice(BLOCK_SIZE); - input = input.slice(BLOCK_SIZE); - fragBytes -= BLOCK_SIZE; - - this.aes.AES10(this.L[5], S, tmp); - xorBytes(input, tmp, tmp.slice(0, fragBytes)); - tmp.slice(0, fragBytes).copy(dst); - tmp.slice(fragBytes).fill(0); - tmp[fragBytes] = 0x80; - this.aes.AES4(ZERO, this.I[1], this.L[5], tmp, tmp); - xorBytes1x16(Y, tmp, Y); - } else if (fragBytes > 0) { - this.aes.AES10(this.L[4], S, tmp); - xorBytes(input, tmp, tmp.slice(0, fragBytes)); - tmp.slice(0, fragBytes).copy(dst); - tmp.slice(fragBytes).fill(0); - tmp[fragBytes] = 0x80; - this.aes.AES4(ZERO, this.I[1], this.L[4], tmp, tmp); - xorBytes1x16(Y, tmp, Y); +},{"./keyExpressions":5,"./re":9,"@bitcoinerlab/miniscript":80,"bitcoinjs-lib":53}],8:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updatePsbt = exports.finalScriptsFuncFactory = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const varuint_bitcoin_1 = require("varuint-bitcoin"); +function reverseBuffer(buffer) { + if (buffer.length < 1) + return buffer; + let j = buffer.length - 1; + let tmp = 0; + for (let i = 0; i < buffer.length / 2; i++) { + tmp = buffer[i]; + buffer[i] = buffer[j]; + buffer[j] = tmp; + j--; } + return buffer; +} +function witnessStackToScriptWitness(witness) { + let buffer = Buffer.allocUnsafe(0); + function writeSlice(slice) { + buffer = Buffer.concat([buffer, Buffer.from(slice)]); + } + function writeVarInt(i) { + const currentLen = buffer.length; + const varintLen = (0, varuint_bitcoin_1.encodingLength)(i); + buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]); + (0, varuint_bitcoin_1.encode)(i, buffer, currentLen); + } + function writeVarSlice(slice) { + writeVarInt(slice.length); + writeSlice(slice); + } + function writeVector(vector) { + writeVarInt(vector.length); + vector.forEach(writeVarSlice); + } + writeVector(witness); + return buffer; +} +function finalScriptsFuncFactory(scriptSatisfaction, network) { + const finalScriptsFunc = (_index, _input, lockingScript /*witnessScript or redeemScript*/, isSegwit, isP2SH, _isP2WSH) => { + let finalScriptWitness; + let finalScriptSig; + //p2wsh + if (isSegwit && !isP2SH) { + const payment = bitcoinjs_lib_1.payments.p2wsh({ + redeem: { input: scriptSatisfaction, output: lockingScript }, + network + }); + if (!payment.witness) + throw new Error(`Error: p2wsh failed producing a witness`); + finalScriptWitness = witnessStackToScriptWitness(payment.witness); + } + //p2sh-p2wsh + else if (isSegwit && isP2SH) { + const payment = bitcoinjs_lib_1.payments.p2sh({ + redeem: bitcoinjs_lib_1.payments.p2wsh({ + redeem: { input: scriptSatisfaction, output: lockingScript }, + network + }), + network + }); + if (!payment.witness) + throw new Error(`Error: p2sh-p2wsh failed producing a witness`); + finalScriptWitness = witnessStackToScriptWitness(payment.witness); + finalScriptSig = payment.input; + } + //p2sh + else { + finalScriptSig = bitcoinjs_lib_1.payments.p2sh({ + redeem: { input: scriptSatisfaction, output: lockingScript }, + network + }).input; + } + return { + finalScriptWitness, + finalScriptSig + }; + }; + return finalScriptsFunc; +} +exports.finalScriptsFuncFactory = finalScriptsFuncFactory; +/** + * Important: Read comments on descriptor.updatePsbt regarding not passing txHex + */ +function updatePsbt({ psbt, vout, txHex, txId, value, sequence, locktime, keysInfo, scriptPubKey, isSegwit, witnessScript, redeemScript, rbf }) { + //Some data-sanity checks: + if (sequence !== undefined && rbf && sequence > 0xfffffffd) + throw new Error(`Error: incompatible sequence and rbf settings`); + if (!isSegwit && txHex === undefined) + throw new Error(`Error: txHex is mandatory for Non-Segwit inputs`); + if (isSegwit && + txHex === undefined && + (txId === undefined || value === undefined)) + throw new Error(`Error: pass txHex or txId+value for Segwit inputs`); + if (txHex !== undefined) { + const tx = bitcoinjs_lib_1.Transaction.fromHex(txHex); + const out = tx?.outs?.[vout]; + if (!out) + throw new Error(`Error: tx ${txHex} does not have vout ${vout}`); + const outputScript = out.script; + if (!outputScript) + throw new Error(`Error: could not extract outputScript for txHex ${txHex} and vout ${vout}`); + if (Buffer.compare(outputScript, scriptPubKey) !== 0) + throw new Error(`Error: txHex ${txHex} for vout ${vout} does not correspond to scriptPubKey ${scriptPubKey}`); + if (txId !== undefined) { + if (tx.getId() !== txId) + throw new Error(`Error: txId for ${txHex} and vout ${vout} does not correspond to ${txId}`); + } + else { + txId = tx.getId(); + } + if (value !== undefined) { + if (out.value !== value) + throw new Error(`Error: value for ${txHex} and vout ${vout} does not correspond to ${value}`); + } + else { + value = out.value; + } + } + if (txId === undefined || !value) + throw new Error(`Error: txHex+vout required. Alternatively, but ONLY for Segwit inputs, txId+value can also be passed.`); + if (locktime) { + if (psbt.locktime && psbt.locktime !== locktime) + throw new Error(`Error: transaction locktime was already set with a different value: ${locktime} != ${psbt.locktime}`); + // nLockTime only works if at least one of the transaction inputs has an + // nSequence value that is below 0xffffffff. Let's make sure that at least + // this input's sequence < 0xffffffff + if (sequence === undefined) { + //NOTE: if sequence is undefined, bitcoinjs-lib uses 0xffffffff as default + sequence = rbf ? 0xfffffffd : 0xfffffffe; + } + else if (sequence > 0xfffffffe) { + throw new Error(`Error: incompatible sequence: ${sequence} and locktime: ${locktime}`); + } + if (sequence === undefined && rbf) + sequence = 0xfffffffd; + psbt.setLocktime(locktime); + } + else { + if (sequence === undefined) { + if (rbf) + sequence = 0xfffffffd; + else + sequence = 0xffffffff; + } + } + const input = { + hash: reverseBuffer(Buffer.from(txId, 'hex')), + index: vout + }; + if (txHex !== undefined) { + input.nonWitnessUtxo = bitcoinjs_lib_1.Transaction.fromHex(txHex).toBuffer(); + } + const bip32Derivation = keysInfo + .filter((keyInfo) => keyInfo.pubkey && keyInfo.masterFingerprint && keyInfo.path) + .map((keyInfo) => { + const pubkey = keyInfo.pubkey; + if (!pubkey) + throw new Error(`key ${keyInfo.keyExpression} missing pubkey`); + return { + masterFingerprint: keyInfo.masterFingerprint, + pubkey, + path: keyInfo.path + }; + }); + if (bip32Derivation.length) + input.bip32Derivation = bip32Derivation; + if (isSegwit && txHex !== undefined) { + //There's no need to put both witnessUtxo and nonWitnessUtxo + input.witnessUtxo = { script: scriptPubKey, value }; + } + if (sequence !== undefined) + input.sequence = sequence; + if (witnessScript) + input.witnessScript = witnessScript; + if (redeemScript) + input.redeemScript = redeemScript; + psbt.addInput(input); + return psbt.data.inputs.length - 1; +} +exports.updatePsbt = updatePsbt; + +}).call(this)}).call(this,require("buffer").Buffer) +},{"bitcoinjs-lib":53,"buffer":249,"varuint-bitcoin":528}],9:[function(require,module,exports){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +Object.defineProperty(exports, "__esModule", { value: true }); +exports.reWshMiniscriptAnchored = exports.reShWshMiniscriptAnchored = exports.reShMiniscriptAnchored = exports.reShWpkhAnchored = exports.reWpkhAnchored = exports.rePkhAnchored = exports.reAddrAnchored = exports.rePkAnchored = exports.anchorStartAndEnd = exports.reKeyExp = exports.reXprvKey = exports.reXpubKey = exports.rePath = exports.reXprv = exports.reXpub = exports.reWIF = exports.rePubKey = exports.reChecksum = exports.reOrigin = exports.reMasterFingerprint = exports.reOriginPath = void 0; +const checksum_1 = require("./checksum"); +//Regular expressions cheat sheet: +//https://www.keycdn.com/support/regex-cheat-sheet +//hardened characters +const reHardened = String.raw `(['hH])`; +//a level is a series of integers followed (optional) by a hardener char +const reLevel = String.raw `(\d+${reHardened}?)`; +//a path component is a level followed by a slash "/" char +const rePathComponent = String.raw `(${reLevel}\/)`; +//A path formed by a series of path components that can be hardened: /2'/23H/23 +exports.reOriginPath = String.raw `(\/${rePathComponent}*${reLevel})`; //The "*" means: "match 0 or more of the previous" +//an origin is something like this: [d34db33f/44'/0'/0'] where the path is optional. The fingerPrint is 8 chars hex +exports.reMasterFingerprint = String.raw `[0-9a-fA-F]{8}`; +exports.reOrigin = String.raw `(\[${exports.reMasterFingerprint}(${exports.reOriginPath})?\])`; +exports.reChecksum = String.raw `(#[${checksum_1.CHECKSUM_CHARSET}]{8})`; +//Something like this: 0252972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2 +//as explained here: github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md#reference +const reCompressedPubKey = String.raw `((02|03)[0-9a-fA-F]{64})`; +const reUncompressedPubKey = String.raw `(04[0-9a-fA-F]{128})`; +exports.rePubKey = String.raw `(${reCompressedPubKey}|${reUncompressedPubKey})`; +//https://learnmeabitcoin.com/technical/wif +//5, K, L for mainnet, 5: uncompressed, {K, L}: compressed +//c, 9, testnet, c: compressed, 9: uncompressed +exports.reWIF = String.raw `([5KLc9][1-9A-HJ-NP-Za-km-z]{50,51})`; +//x for mainnet, t for testnet +exports.reXpub = String.raw `([xXtT]pub[1-9A-HJ-NP-Za-km-z]{79,108})`; +exports.reXprv = String.raw `([xXtT]prv[1-9A-HJ-NP-Za-km-z]{79,108})`; +//reRangeLevel is like reLevel but using a wildcard "*" +const reRangeLevel = String.raw `(\*(${reHardened})?)`; +//A path can be finished with stuff like this: /23 or /23h or /* or /*' +exports.rePath = String.raw `(\/(${rePathComponent})*(${reRangeLevel}|${reLevel}))`; +//rePath is optional (note the "zero"): Followed by zero or more /NUM or /NUM' path elements to indicate unhardened or hardened derivation steps between the fingerprint and the key or xpub/xprv root that follows +exports.reXpubKey = String.raw `(${exports.reXpub})(${exports.rePath})?`; +exports.reXprvKey = String.raw `(${exports.reXprv})(${exports.rePath})?`; +//actualKey is the keyExpression without optional origin +const reActualKey = String.raw `(${exports.reXpubKey}|${exports.reXprvKey}|${exports.rePubKey}|${exports.reWIF})`; +//reOrigin is optional: Optionally, key origin information, consisting of: +//Matches a key expression: wif, xpub, xprv or pubkey: +exports.reKeyExp = String.raw `(${exports.reOrigin})?(${reActualKey})`; +const rePk = String.raw `pk\((.*?)\)`; //Matches anything. We assert later in the code that the pubkey is valid. +const reAddr = String.raw `addr\((.*?)\)`; //Matches anything. We assert later in the code that the address is valid. +const rePkh = String.raw `pkh\(${exports.reKeyExp}\)`; +const reWpkh = String.raw `wpkh\(${exports.reKeyExp}\)`; +const reShWpkh = String.raw `sh\(wpkh\(${exports.reKeyExp}\)\)`; +const reMiniscript = String.raw `(.*?)`; //Matches anything. We assert later in the code that miniscripts are valid and sane. +//RegExp makers: +const makeReSh = (re) => String.raw `sh\(${re}\)`; +const makeReWsh = (re) => String.raw `wsh\(${re}\)`; +const makeReShWsh = (re) => makeReSh(makeReWsh(re)); +const anchorStartAndEnd = (re) => String.raw `^${re}$`; //starts and finishes like re (not composable) +exports.anchorStartAndEnd = anchorStartAndEnd; +const composeChecksum = (re) => String.raw `${re}(${exports.reChecksum})?`; //it's optional (note the "?") +exports.rePkAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(rePk)); +exports.reAddrAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reAddr)); +exports.rePkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(rePkh)); +exports.reWpkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reWpkh)); +exports.reShWpkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reShWpkh)); +exports.reShMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReSh(reMiniscript))); +exports.reShWshMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReShWsh(reMiniscript))); +exports.reWshMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReWsh(reMiniscript))); + +},{"./checksum":2}],10:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.wpkhLedger = exports.shWpkhLedger = exports.pkhLedger = exports.wpkhBIP32 = exports.shWpkhBIP32 = exports.pkhBIP32 = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const keyExpressions_1 = require("./keyExpressions"); +function assertStandardKeyPath(keyPath) { + // Regular expression to match "/change/index" or "/change/*" format + const regex = /^\/[01]\/(\d+|\*)$/; + if (!regex.test(keyPath)) { + throw new Error("Error: Key path must be in the format '/change/index', where change is either 0 or 1 and index is a non-negative integer."); + } +} +function standardExpressionsBIP32Maker(purpose, scriptTemplate) { + /** + * Computes the standard descriptor based on given parameters. + * + * You can define the output location either by: + * - Providing the full `keyPath` (e.g., "/0/2"). + * OR + * - Specifying the `change` and `index` values separately (e.g., `{change:0, index:2}`). + * + * For ranged indexing, the `index` can be set as a wildcard '*'. For example: + * - `keyPath="/0/*"` + * OR + * - `{change:0, index:'*'}`. + */ + function standardScriptExpressionBIP32({ masterNode, network = bitcoinjs_lib_1.networks.bitcoin, keyPath, account, change, index, isPublic = true }) { + const originPath = `/${purpose}'/${network === bitcoinjs_lib_1.networks.bitcoin ? 0 : 1}'/${account}'`; + if (keyPath !== undefined) + assertStandardKeyPath(keyPath); + const keyExpression = (0, keyExpressions_1.keyExpressionBIP32)({ + masterNode, + originPath, + keyPath, + change, + index, + isPublic + }); + return scriptTemplate.replace('KEYEXPRESSION', keyExpression); + } + return standardScriptExpressionBIP32; +} +exports.pkhBIP32 = standardExpressionsBIP32Maker(44, 'pkh(KEYEXPRESSION)'); +exports.shWpkhBIP32 = standardExpressionsBIP32Maker(49, 'sh(wpkh(KEYEXPRESSION))'); +exports.wpkhBIP32 = standardExpressionsBIP32Maker(84, 'wpkh(KEYEXPRESSION)'); +function standardExpressionsLedgerMaker(purpose, scriptTemplate) { + /** @hidden */ + async function standardScriptExpressionLedger({ ledgerClient, ledgerState, ledgerManager, network, account, keyPath, change, index }) { + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`ledgerClient and ledgerState have been deprecated`); + if (ledgerManager && network) + throw new Error(`ledgerManager already includes the network object`); + if (!ledgerManager && !network) + network = bitcoinjs_lib_1.networks.bitcoin; + if (ledgerManager) + ({ ledgerClient, ledgerState, network } = ledgerManager); + if (!ledgerClient || !ledgerState) + throw new Error(`Could not retrieve ledgerClient or ledgerState`); + const originPath = `/${purpose}'/${network === bitcoinjs_lib_1.networks.bitcoin ? 0 : 1}'/${account}'`; + if (keyPath !== undefined) + assertStandardKeyPath(keyPath); + const keyExpression = await (0, keyExpressions_1.keyExpressionLedger)({ + ledgerClient, + ledgerState, + originPath, + keyPath, + change, + index + }); + return scriptTemplate.replace('KEYEXPRESSION', keyExpression); + } + return standardScriptExpressionLedger; +} +exports.pkhLedger = standardExpressionsLedgerMaker(44, 'pkh(KEYEXPRESSION)'); +exports.shWpkhLedger = standardExpressionsLedgerMaker(49, 'sh(wpkh(KEYEXPRESSION))'); +exports.wpkhLedger = standardExpressionsLedgerMaker(84, 'wpkh(KEYEXPRESSION)'); - // Finish encryption of last two blocks - dst = outOrig.slice(inOrig.length - 32); - this.aes.AES10(this.L[(2 - d) % 8], dst.slice(BLOCK_SIZE), tmp); - xorBytes1x16(dst, tmp, dst); - this.aes.AES4(ZERO, this.I[1], this.L[(2 - d) % 8], dst, tmp); - xorBytes4x16(tmp, dst.slice(BLOCK_SIZE), delta, Y, dst.slice(BLOCK_SIZE)); - dst.slice(0, BLOCK_SIZE).copy(tmp); - dst.slice(BLOCK_SIZE).copy(dst.slice(0, BLOCK_SIZE)); - tmp.copy(dst.slice(BLOCK_SIZE)); - }; - - this.aezCorePass1 = function (input, output, X) { - const [tmp, I] = [mkBlock(), mkBlock()]; - - this.I[1].copy(I); - for (let i = 1, inBytes = input.length; inBytes >= 64; i++, inBytes -= 32) { - this.aes.AES4(this.J[0], I, this.L[i % 8], input.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); - xorBytes1x16(input, tmp, output); - - this.aes.AES4(ZERO, this.I[0], this.L[0], output, tmp); - xorBytes1x16(input.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); - xorBytes1x16(output.slice(BLOCK_SIZE), X, X); +},{"./keyExpressions":5,"bitcoinjs-lib":53}],11:[function(require,module,exports){ +"use strict"; +// Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com +// Distributed under the MIT software license +Object.defineProperty(exports, "__esModule", { value: true }); +exports.signLedger = exports.signInputLedger = exports.signBIP32 = exports.signInputBIP32 = exports.signECPair = exports.signInputECPair = void 0; +const ledger_1 = require("./ledger"); +function signInputECPair({ psbt, index, ecpair }) { + psbt.signInput(index, ecpair); +} +exports.signInputECPair = signInputECPair; +function signECPair({ psbt, ecpair }) { + psbt.signAllInputs(ecpair); +} +exports.signECPair = signECPair; +function signInputBIP32({ psbt, index, node }) { + psbt.signInputHD(index, node); +} +exports.signInputBIP32 = signInputBIP32; +function signBIP32({ psbt, masterNode }) { + psbt.signAllInputsHD(masterNode); +} +exports.signBIP32 = signBIP32; +const ledgerSignaturesForInputIndex = (index, ledgerSignatures) => ledgerSignatures + .filter(([i]) => i === index) + .map(([_i, partialSignature]) => ({ + pubkey: partialSignature.pubkey, + signature: partialSignature.signature +})); +/** + * To be removed in v3.0 and replaced by a version that does not accept + * descriptor + * @hidden + */ +async function signInputLedger({ psbt, index, descriptor, ledgerClient, ledgerState, ledgerManager }) { + if (!descriptor && !ledgerManager) + throw new Error(`ledgerManager not provided`); + if (descriptor && ledgerManager) + throw new Error(`Invalid usage: don't pass descriptor`); + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`Invalid usage: either ledgerManager or ledgerClient + ledgerState`); + const output = descriptor; + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient) + throw new Error(`ledgerManager not provided`); + if (!ledgerState) + throw new Error(`ledgerManager not provided`); + const { PsbtV2, DefaultWalletPolicy, WalletPolicy, AppClient } = (await (0, ledger_1.importAndValidateLedgerBitcoin)(ledgerClient)); + if (!(ledgerClient instanceof AppClient)) + throw new Error(`Error: pass a valid ledgerClient`); + let ledgerSignatures; + if (ledgerManager) { + const policy = await (0, ledger_1.ledgerPolicyFromPsbtInput)({ + psbt, + index, + ledgerManager + }); + if (!policy) + throw new Error(`Error: the ledger cannot sign this pstb input`); + if (policy.policyName && policy.policyHmac && policy.policyId) { + //non-standard policy + const walletPolicy = new WalletPolicy(policy.policyName, policy.ledgerTemplate, policy.keyRoots); + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), walletPolicy, policy.policyHmac); + } + else { + //standard policy + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), new DefaultWalletPolicy(policy.ledgerTemplate, policy.keyRoots[0]), null); + } + } + else { + if (!output) + throw new Error(`outputs not provided`); + const result = await (0, ledger_1.ledgerPolicyFromOutput)({ + output, + ledgerClient, + ledgerState + }); + if (!result) + throw new Error(`Error: output does not have a ledger input`); + const { ledgerTemplate, keyRoots } = result; + const standardPolicy = await (0, ledger_1.ledgerPolicyFromStandard)({ + output, + ledgerClient, + ledgerState + }); + if (standardPolicy) { + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), new DefaultWalletPolicy(ledgerTemplate, keyRoots[0]), null); + } + else { + const policy = await (0, ledger_1.ledgerPolicyFromState)({ + output, + ledgerClient, + ledgerState + }); + if (!policy || !policy.policyName || !policy.policyHmac) + throw new Error(`Error: the descriptor's policy is not registered`); + const walletPolicy = new WalletPolicy(policy.policyName, ledgerTemplate, keyRoots); + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), walletPolicy, policy.policyHmac); + } + } + //Add the signatures to the Psbt object using PartialSig format: + psbt.updateInput(index, { + partialSig: ledgerSignaturesForInputIndex(index, ledgerSignatures) + }); +} +exports.signInputLedger = signInputLedger; +/** + * To be removed in v3.0 and replaced by a version that does not accept + * descriptors + * @hidden + */ +async function signLedger({ psbt, descriptors, ledgerClient, ledgerState, ledgerManager }) { + if (!descriptors && !ledgerManager) + throw new Error(`ledgerManager not provided`); + if (descriptors && ledgerManager) + throw new Error(`Invalid usage: don't pass descriptors`); + if (ledgerManager && (ledgerClient || ledgerState)) + throw new Error(`Invalid usage: either ledgerManager or ledgerClient + ledgerState`); + const outputs = descriptors; + if (ledgerManager) + ({ ledgerClient, ledgerState } = ledgerManager); + if (!ledgerClient) + throw new Error(`ledgerManager not provided`); + if (!ledgerState) + throw new Error(`ledgerManager not provided`); + const { PsbtV2, DefaultWalletPolicy, WalletPolicy, AppClient } = (await (0, ledger_1.importAndValidateLedgerBitcoin)(ledgerClient)); + if (!(ledgerClient instanceof AppClient)) + throw new Error(`Error: pass a valid ledgerClient`); + const ledgerPolicies = []; + if (ledgerManager) + for (let index = 0; index < psbt.data.inputs.length; index++) { + const policy = await (0, ledger_1.ledgerPolicyFromPsbtInput)({ + psbt, + index, + ledgerManager + }); + if (policy) + ledgerPolicies.push(policy); + } + else { + if (!outputs) + throw new Error(`outputs not provided`); + for (const output of outputs) { + const policy = (await (0, ledger_1.ledgerPolicyFromState)({ output, ledgerClient, ledgerState })) || + (await (0, ledger_1.ledgerPolicyFromStandard)({ output, ledgerClient, ledgerState })); + if (policy) + ledgerPolicies.push(policy); + } + if (ledgerPolicies.length === 0) + throw new Error(`Error: there are no inputs which could be signed`); + } + //cluster unique LedgerPolicies + const uniquePolicies = []; + for (const policy of ledgerPolicies) { + if (!uniquePolicies.find((uniquePolicy) => (0, ledger_1.comparePolicies)(uniquePolicy, policy))) + uniquePolicies.push(policy); + } + for (const uniquePolicy of uniquePolicies) { + let ledgerSignatures; + if (uniquePolicy.policyName && + uniquePolicy.policyHmac && + uniquePolicy.policyId) { + //non-standard policy + const walletPolicy = new WalletPolicy(uniquePolicy.policyName, uniquePolicy.ledgerTemplate, uniquePolicy.keyRoots); + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), walletPolicy, uniquePolicy.policyHmac); + } + else { + //standard policy + ledgerSignatures = await ledgerClient.signPsbt(new PsbtV2().fromBitcoinJS(psbt), new DefaultWalletPolicy(uniquePolicy.ledgerTemplate, uniquePolicy.keyRoots[0]), null); + } + for (const [index, ,] of ledgerSignatures) { + psbt.updateInput(index, { + partialSig: ledgerSignaturesForInputIndex(index, ledgerSignatures) + }); + } + } +} +exports.signLedger = signLedger; - input = input.slice(32); - output = output.slice(32); - if (i % 8 === 0) { - doubleBlock(I); +},{"./ledger":6}],12:[function(require,module,exports){ +'use strict' +// base-x encoding / decoding +// Copyright (c) 2018 base-x contributors +// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp) +// Distributed under the MIT software license, see the accompanying +// file LICENSE or http://www.opensource.org/licenses/mit-license.php. +function base (ALPHABET) { + if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') } + var BASE_MAP = new Uint8Array(256) + for (var j = 0; j < BASE_MAP.length; j++) { + BASE_MAP[j] = 255 + } + for (var i = 0; i < ALPHABET.length; i++) { + var x = ALPHABET.charAt(i) + var xc = x.charCodeAt(0) + if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') } + BASE_MAP[xc] = i + } + var BASE = ALPHABET.length + var LEADER = ALPHABET.charAt(0) + var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up + var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up + function encode (source) { + if (source instanceof Uint8Array) { + } else if (ArrayBuffer.isView(source)) { + source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength) + } else if (Array.isArray(source)) { + source = Uint8Array.from(source) + } + if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') } + if (source.length === 0) { return '' } + // Skip & count leading zeroes. + var zeroes = 0 + var length = 0 + var pbegin = 0 + var pend = source.length + while (pbegin !== pend && source[pbegin] === 0) { + pbegin++ + zeroes++ + } + // Allocate enough space in big-endian base58 representation. + var size = ((pend - pbegin) * iFACTOR + 1) >>> 0 + var b58 = new Uint8Array(size) + // Process the bytes. + while (pbegin !== pend) { + var carry = source[pbegin] + // Apply "b58 = b58 * 256 + ch". + var i = 0 + for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) { + carry += (256 * b58[it1]) >>> 0 + b58[it1] = (carry % BASE) >>> 0 + carry = (carry / BASE) >>> 0 } + if (carry !== 0) { throw new Error('Non-zero carry') } + length = i + pbegin++ } - }; - - this.aezCorePass2 = function (input, output, Y, S) { - const [tmp, I] = [mkBlock(), mkBlock()]; - - this.I[1].copy(I); - for (let i = 1, inBytes = input.length; inBytes >= 64; i++, inBytes -= 32) { - this.aes.AES4(this.J[1], I, this.L[i % 8], S, tmp); - xorBytes1x16(output, tmp, output); - xorBytes1x16(output.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); - xorBytes1x16(output, Y, Y); - - this.aes.AES4(ZERO, this.I[0], this.L[0], output.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); - xorBytes1x16(output, tmp, output); - - this.aes.AES4(this.J[0], I, this.L[i % 8], output, tmp); - xorBytes1x16(output.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); - - output.copy(tmp); - output.slice(BLOCK_SIZE).copy(output.slice(0, BLOCK_SIZE)); - tmp.copy(output.slice(BLOCK_SIZE)); - - input = input.slice(32); - output = output.slice(32); - if (i % 8 === 0) { - doubleBlock(I); + // Skip leading zeroes in base58 result. + var it2 = size - length + while (it2 !== size && b58[it2] === 0) { + it2++ + } + // Translate the result into a string. + var str = LEADER.repeat(zeroes) + for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) } + return str + } + function decodeUnsafe (source) { + if (typeof source !== 'string') { throw new TypeError('Expected String') } + if (source.length === 0) { return new Uint8Array() } + var psz = 0 + // Skip and count leading '1's. + var zeroes = 0 + var length = 0 + while (source[psz] === LEADER) { + zeroes++ + psz++ + } + // Allocate enough space in big-endian base256 representation. + var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up. + var b256 = new Uint8Array(size) + // Process the characters. + while (source[psz]) { + // Decode character + var carry = BASE_MAP[source.charCodeAt(psz)] + // Invalid character + if (carry === 255) { return } + var i = 0 + for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) { + carry += (BASE * b256[it3]) >>> 0 + b256[it3] = (carry % 256) >>> 0 + carry = (carry / 256) >>> 0 } + if (carry !== 0) { throw new Error('Non-zero carry') } + length = i + psz++ } - }; -}; - -module.exports = AEZState; - -},{"./aes_round":2,"./functions":5,"safe-buffer":280}],5:[function(require,module,exports){ -const Buffer = require('safe-buffer').Buffer; -const blake = require('blakejs'); - -const BLOCK_SIZE = 16; -const EXTRACTED_KEY_SIZE = 3 * 16; - -function mkBlock(size) { - return Buffer.alloc((size === undefined ? BLOCK_SIZE : size), 0); -} - -function xorBytes1x16(a, b, dst) { - for (let i = 0; i < BLOCK_SIZE; i++) { - dst[i] = a[i] ^ b[i]; + // Skip leading zeroes in b256. + var it4 = size - length + while (it4 !== size && b256[it4] === 0) { + it4++ + } + var vch = new Uint8Array(zeroes + (size - it4)) + var j = zeroes + while (it4 !== size) { + vch[j++] = b256[it4++] + } + return vch + } + function decode (string) { + var buffer = decodeUnsafe(string) + if (buffer) { return buffer } + throw new Error('Non-base' + BASE + ' character') + } + return { + encode: encode, + decodeUnsafe: decodeUnsafe, + decode: decode } } +module.exports = base -function xorBytes4x16(a, b, c, d, dst) { - for (let i = 0; i < BLOCK_SIZE; i++) { - dst[i] = a[i] ^ b[i] ^ c[i] ^ d[i]; +},{}],13:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const parser_1 = require('../parser'); +function combine(psbts) { + const self = psbts[0]; + const selfKeyVals = parser_1.psbtToKeyVals(self); + const others = psbts.slice(1); + if (others.length === 0) throw new Error('Combine: Nothing to combine'); + const selfTx = getTx(self); + if (selfTx === undefined) { + throw new Error('Combine: Self missing transaction'); + } + const selfGlobalSet = getKeySet(selfKeyVals.globalKeyVals); + const selfInputSets = selfKeyVals.inputKeyVals.map(getKeySet); + const selfOutputSets = selfKeyVals.outputKeyVals.map(getKeySet); + for (const other of others) { + const otherTx = getTx(other); + if ( + otherTx === undefined || + !otherTx.toBuffer().equals(selfTx.toBuffer()) + ) { + throw new Error( + 'Combine: One of the Psbts does not have the same transaction.', + ); + } + const otherKeyVals = parser_1.psbtToKeyVals(other); + const otherGlobalSet = getKeySet(otherKeyVals.globalKeyVals); + otherGlobalSet.forEach( + keyPusher( + selfGlobalSet, + selfKeyVals.globalKeyVals, + otherKeyVals.globalKeyVals, + ), + ); + const otherInputSets = otherKeyVals.inputKeyVals.map(getKeySet); + otherInputSets.forEach((inputSet, idx) => + inputSet.forEach( + keyPusher( + selfInputSets[idx], + selfKeyVals.inputKeyVals[idx], + otherKeyVals.inputKeyVals[idx], + ), + ), + ); + const otherOutputSets = otherKeyVals.outputKeyVals.map(getKeySet); + otherOutputSets.forEach((outputSet, idx) => + outputSet.forEach( + keyPusher( + selfOutputSets[idx], + selfKeyVals.outputKeyVals[idx], + otherKeyVals.outputKeyVals[idx], + ), + ), + ); } + return parser_1.psbtFromKeyVals(selfTx, { + globalMapKeyVals: selfKeyVals.globalKeyVals, + inputKeyVals: selfKeyVals.inputKeyVals, + outputKeyVals: selfKeyVals.outputKeyVals, + }); +} +exports.combine = combine; +function keyPusher(selfSet, selfKeyVals, otherKeyVals) { + return key => { + if (selfSet.has(key)) return; + const newKv = otherKeyVals.filter(kv => kv.key.toString('hex') === key)[0]; + selfKeyVals.push(newKv); + selfSet.add(key); + }; +} +function getTx(psbt) { + return psbt.globalMap.unsignedTx; +} +function getKeySet(keyVals) { + const set = new Set(); + keyVals.forEach(keyVal => { + const hex = keyVal.key.toString('hex'); + if (set.has(hex)) + throw new Error('Combine: KeyValue Map keys should be unique'); + set.add(hex); + }); + return set; } -function xorBytes(a, b, dst) { - if (a.length < dst.length || b.length < dst.length) { - throw new Error('aez: xorBytes: len'); +},{"../parser":38}],14:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +const range = n => [...Array(n).keys()]; +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.GlobalTypes.GLOBAL_XPUB) { + throw new Error( + 'Decode Error: could not decode globalXpub with key 0x' + + keyVal.key.toString('hex'), + ); } - for (let i = 0; i < dst.length; i++) { - dst[i] = a[i] ^ b[i] + if (keyVal.key.length !== 79 || ![2, 3].includes(keyVal.key[46])) { + throw new Error( + 'Decode Error: globalXpub has invalid extended pubkey in key 0x' + + keyVal.key.toString('hex'), + ); + } + if ((keyVal.value.length / 4) % 1 !== 0) { + throw new Error( + 'Decode Error: Global GLOBAL_XPUB value length should be multiple of 4', + ); + } + const extendedPubkey = keyVal.key.slice(1); + const data = { + masterFingerprint: keyVal.value.slice(0, 4), + extendedPubkey, + path: 'm', + }; + for (const i of range(keyVal.value.length / 4 - 1)) { + const val = keyVal.value.readUInt32LE(i * 4 + 4); + const isHard = !!(val & 0x80000000); + const idx = val & 0x7fffffff; + data.path += '/' + idx.toString(10) + (isHard ? "'" : ''); } + return data; } - -function uint32(i) { - return i >>> 0; +exports.decode = decode; +function encode(data) { + const head = Buffer.from([typeFields_1.GlobalTypes.GLOBAL_XPUB]); + const key = Buffer.concat([head, data.extendedPubkey]); + const splitPath = data.path.split('/'); + const value = Buffer.allocUnsafe(splitPath.length * 4); + data.masterFingerprint.copy(value, 0); + let offset = 4; + splitPath.slice(1).forEach(level => { + const isHard = level.slice(-1) === "'"; + let num = 0x7fffffff & parseInt(isHard ? level.slice(0, -1) : level, 10); + if (isHard) num += 0x80000000; + value.writeUInt32LE(num, offset); + offset += 4; + }); + return { + key, + value, + }; +} +exports.encode = encode; +exports.expected = + '{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }'; +function check(data) { + const epk = data.extendedPubkey; + const mfp = data.masterFingerprint; + const p = data.path; + return ( + Buffer.isBuffer(epk) && + epk.length === 78 && + [2, 3].indexOf(epk[45]) > -1 && + Buffer.isBuffer(mfp) && + mfp.length === 4 && + typeof p === 'string' && + !!p.match(/^m(\/\d+'?)*$/) + ); +} +exports.check = check; +function canAddToArray(array, item, dupeSet) { + const dupeString = item.extendedPubkey.toString('hex'); + if (dupeSet.has(dupeString)) return false; + dupeSet.add(dupeString); + return ( + array.filter(v => v.extendedPubkey.equals(item.extendedPubkey)).length === 0 + ); } +exports.canAddToArray = canAddToArray; -function uint8(i) { - return 0x000000ff & i; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],15:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function encode(data) { + return { + key: Buffer.from([typeFields_1.GlobalTypes.UNSIGNED_TX]), + value: data.toBuffer(), + }; } +exports.encode = encode; -function extractKey(k) { - if (k && k.length && k.length === EXTRACTED_KEY_SIZE) { - return k; - } else { - const context = blake.blake2bInit(EXTRACTED_KEY_SIZE); - blake.blake2bUpdate(context, k); - return Buffer.from(blake.blake2bFinal(context)); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],16:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../typeFields'); +const globalXpub = require('./global/globalXpub'); +const unsignedTx = require('./global/unsignedTx'); +const finalScriptSig = require('./input/finalScriptSig'); +const finalScriptWitness = require('./input/finalScriptWitness'); +const nonWitnessUtxo = require('./input/nonWitnessUtxo'); +const partialSig = require('./input/partialSig'); +const porCommitment = require('./input/porCommitment'); +const sighashType = require('./input/sighashType'); +const tapKeySig = require('./input/tapKeySig'); +const tapLeafScript = require('./input/tapLeafScript'); +const tapMerkleRoot = require('./input/tapMerkleRoot'); +const tapScriptSig = require('./input/tapScriptSig'); +const witnessUtxo = require('./input/witnessUtxo'); +const tapTree = require('./output/tapTree'); +const bip32Derivation = require('./shared/bip32Derivation'); +const checkPubkey = require('./shared/checkPubkey'); +const redeemScript = require('./shared/redeemScript'); +const tapBip32Derivation = require('./shared/tapBip32Derivation'); +const tapInternalKey = require('./shared/tapInternalKey'); +const witnessScript = require('./shared/witnessScript'); +const globals = { + unsignedTx, + globalXpub, + // pass an Array of key bytes that require pubkey beside the key + checkPubkey: checkPubkey.makeChecker([]), +}; +exports.globals = globals; +const inputs = { + nonWitnessUtxo, + partialSig, + sighashType, + finalScriptSig, + finalScriptWitness, + porCommitment, + witnessUtxo, + bip32Derivation: bip32Derivation.makeConverter( + typeFields_1.InputTypes.BIP32_DERIVATION, + ), + redeemScript: redeemScript.makeConverter( + typeFields_1.InputTypes.REDEEM_SCRIPT, + ), + witnessScript: witnessScript.makeConverter( + typeFields_1.InputTypes.WITNESS_SCRIPT, + ), + checkPubkey: checkPubkey.makeChecker([ + typeFields_1.InputTypes.PARTIAL_SIG, + typeFields_1.InputTypes.BIP32_DERIVATION, + ]), + tapKeySig, + tapScriptSig, + tapLeafScript, + tapBip32Derivation: tapBip32Derivation.makeConverter( + typeFields_1.InputTypes.TAP_BIP32_DERIVATION, + ), + tapInternalKey: tapInternalKey.makeConverter( + typeFields_1.InputTypes.TAP_INTERNAL_KEY, + ), + tapMerkleRoot, +}; +exports.inputs = inputs; +const outputs = { + bip32Derivation: bip32Derivation.makeConverter( + typeFields_1.OutputTypes.BIP32_DERIVATION, + ), + redeemScript: redeemScript.makeConverter( + typeFields_1.OutputTypes.REDEEM_SCRIPT, + ), + witnessScript: witnessScript.makeConverter( + typeFields_1.OutputTypes.WITNESS_SCRIPT, + ), + checkPubkey: checkPubkey.makeChecker([ + typeFields_1.OutputTypes.BIP32_DERIVATION, + ]), + tapBip32Derivation: tapBip32Derivation.makeConverter( + typeFields_1.OutputTypes.TAP_BIP32_DERIVATION, + ), + tapTree, + tapInternalKey: tapInternalKey.makeConverter( + typeFields_1.OutputTypes.TAP_INTERNAL_KEY, + ), +}; +exports.outputs = outputs; + +},{"../typeFields":41,"./global/globalXpub":14,"./global/unsignedTx":15,"./input/finalScriptSig":17,"./input/finalScriptWitness":18,"./input/nonWitnessUtxo":19,"./input/partialSig":20,"./input/porCommitment":21,"./input/sighashType":22,"./input/tapKeySig":23,"./input/tapLeafScript":24,"./input/tapMerkleRoot":25,"./input/tapScriptSig":26,"./input/witnessUtxo":27,"./output/tapTree":28,"./shared/bip32Derivation":29,"./shared/checkPubkey":30,"./shared/redeemScript":31,"./shared/tapBip32Derivation":32,"./shared/tapInternalKey":33,"./shared/witnessScript":34}],17:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.FINAL_SCRIPTSIG) { + throw new Error( + 'Decode Error: could not decode finalScriptSig with key 0x' + + keyVal.key.toString('hex'), + ); } + return keyVal.value; } +exports.decode = decode; +function encode(data) { + const key = Buffer.from([typeFields_1.InputTypes.FINAL_SCRIPTSIG]); + return { + key, + value: data, + }; +} +exports.encode = encode; +exports.expected = 'Buffer'; +function check(data) { + return Buffer.isBuffer(data); +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.finalScriptSig === undefined; +} +exports.canAdd = canAdd; -function multBlock(x, src, dst) { - const [t, r] = [mkBlock(), mkBlock()]; - - src.copy(t); - - while (x !== 0) { - if (x & 1 !== 0) { - xorBytes1x16(r, t, r); - } - doubleBlock(t); - x >>= 1 +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],18:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.FINAL_SCRIPTWITNESS) { + throw new Error( + 'Decode Error: could not decode finalScriptWitness with key 0x' + + keyVal.key.toString('hex'), + ); } - - r.copy(dst); + return keyVal.value; +} +exports.decode = decode; +function encode(data) { + const key = Buffer.from([typeFields_1.InputTypes.FINAL_SCRIPTWITNESS]); + return { + key, + value: data, + }; } +exports.encode = encode; +exports.expected = 'Buffer'; +function check(data) { + return Buffer.isBuffer(data); +} +exports.check = check; +function canAdd(currentData, newData) { + return ( + !!currentData && !!newData && currentData.finalScriptWitness === undefined + ); +} +exports.canAdd = canAdd; -function doubleBlock(p) { - const tmp = p[0]; - for (let i = 0; i < 15; i++) { - p[i] = (p[i] << 1) | (p[i + 1] >> 7); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],19:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.NON_WITNESS_UTXO) { + throw new Error( + 'Decode Error: could not decode nonWitnessUtxo with key 0x' + + keyVal.key.toString('hex'), + ); } - p[15] = (p[15] << 1) ^ ((tmp >> 7) ? 135 : 0); + return keyVal.value; } - -function oneZeroPad(src, size, dst) { - dst.fill(0); - src.slice(0, size).copy(dst); - dst[size] = 0x80; +exports.decode = decode; +function encode(data) { + return { + key: Buffer.from([typeFields_1.InputTypes.NON_WITNESS_UTXO]), + value: data, + }; } +exports.encode = encode; +exports.expected = 'Buffer'; +function check(data) { + return Buffer.isBuffer(data); +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.nonWitnessUtxo === undefined; +} +exports.canAdd = canAdd; -module.exports = { - BLOCK_SIZE, - EXTRACTED_KEY_SIZE, - mkBlock, - xorBytes1x16, - xorBytes4x16, - xorBytes, - uint32, - uint8, - extractKey, - multBlock, - doubleBlock, - oneZeroPad, -}; - -},{"blakejs":101,"safe-buffer":280}],6:[function(require,module,exports){ -const aez = require('./aez'); - -module.exports = { - VERSION: aez.VERSION, - encrypt: aez.encrypt, - decrypt: aez.decrypt, -}; - -},{"./aez":3}],7:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],20:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.PARTIAL_SIG) { + throw new Error( + 'Decode Error: could not decode partialSig with key 0x' + + keyVal.key.toString('hex'), + ); + } + if ( + !(keyVal.key.length === 34 || keyVal.key.length === 66) || + ![2, 3, 4].includes(keyVal.key[1]) + ) { + throw new Error( + 'Decode Error: partialSig has invalid pubkey in key 0x' + + keyVal.key.toString('hex'), + ); + } + const pubkey = keyVal.key.slice(1); + return { + pubkey, + signature: keyVal.value, + }; +} +exports.decode = decode; +function encode(pSig) { + const head = Buffer.from([typeFields_1.InputTypes.PARTIAL_SIG]); + return { + key: Buffer.concat([head, pSig.pubkey]), + value: pSig.signature, + }; +} +exports.encode = encode; +exports.expected = '{ pubkey: Buffer; signature: Buffer; }'; +function check(data) { + return ( + Buffer.isBuffer(data.pubkey) && + Buffer.isBuffer(data.signature) && + [33, 65].includes(data.pubkey.length) && + [2, 3, 4].includes(data.pubkey[0]) && + isDerSigWithSighash(data.signature) + ); +} +exports.check = check; +function isDerSigWithSighash(buf) { + if (!Buffer.isBuffer(buf) || buf.length < 9) return false; + if (buf[0] !== 0x30) return false; + if (buf.length !== buf[1] + 3) return false; + if (buf[2] !== 0x02) return false; + const rLen = buf[3]; + if (rLen > 33 || rLen < 1) return false; + if (buf[3 + rLen + 1] !== 0x02) return false; + const sLen = buf[3 + rLen + 2]; + if (sLen > 33 || sLen < 1) return false; + if (buf.length !== 3 + rLen + 2 + sLen + 2) return false; + return true; +} +function canAddToArray(array, item, dupeSet) { + const dupeString = item.pubkey.toString('hex'); + if (dupeSet.has(dupeString)) return false; + dupeSet.add(dupeString); + return array.filter(v => v.pubkey.equals(item.pubkey)).length === 0; +} +exports.canAddToArray = canAddToArray; -const asn1 = exports; - -asn1.bignum = require('bn.js'); - -asn1.define = require('./asn1/api').define; -asn1.base = require('./asn1/base'); -asn1.constants = require('./asn1/constants'); -asn1.decoders = require('./asn1/decoders'); -asn1.encoders = require('./asn1/encoders'); - -},{"./asn1/api":8,"./asn1/base":10,"./asn1/constants":14,"./asn1/decoders":16,"./asn1/encoders":19,"bn.js":103}],8:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],21:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -const encoders = require('./encoders'); -const decoders = require('./decoders'); -const inherits = require('inherits'); - -const api = exports; - -api.define = function define(name, body) { - return new Entity(name, body); -}; - -function Entity(name, body) { - this.name = name; - this.body = body; - - this.decoders = {}; - this.encoders = {}; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.POR_COMMITMENT) { + throw new Error( + 'Decode Error: could not decode porCommitment with key 0x' + + keyVal.key.toString('hex'), + ); + } + return keyVal.value.toString('utf8'); } +exports.decode = decode; +function encode(data) { + const key = Buffer.from([typeFields_1.InputTypes.POR_COMMITMENT]); + return { + key, + value: Buffer.from(data, 'utf8'), + }; +} +exports.encode = encode; +exports.expected = 'string'; +function check(data) { + return typeof data === 'string'; +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.porCommitment === undefined; +} +exports.canAdd = canAdd; -Entity.prototype._createNamed = function createNamed(Base) { - const name = this.name; - - function Generated(entity) { - this._initNamed(entity, name); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],22:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.SIGHASH_TYPE) { + throw new Error( + 'Decode Error: could not decode sighashType with key 0x' + + keyVal.key.toString('hex'), + ); } - inherits(Generated, Base); - Generated.prototype._initNamed = function _initNamed(entity, name) { - Base.call(this, entity, name); + return keyVal.value.readUInt32LE(0); +} +exports.decode = decode; +function encode(data) { + const key = Buffer.from([typeFields_1.InputTypes.SIGHASH_TYPE]); + const value = Buffer.allocUnsafe(4); + value.writeUInt32LE(data, 0); + return { + key, + value, }; +} +exports.encode = encode; +exports.expected = 'number'; +function check(data) { + return typeof data === 'number'; +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.sighashType === undefined; +} +exports.canAdd = canAdd; - return new Generated(this); -}; - -Entity.prototype._getDecoder = function _getDecoder(enc) { - enc = enc || 'der'; - // Lazily create decoder - if (!this.decoders.hasOwnProperty(enc)) - this.decoders[enc] = this._createNamed(decoders[enc]); - return this.decoders[enc]; -}; - -Entity.prototype.decode = function decode(data, enc, options) { - return this._getDecoder(enc).decode(data, options); -}; - -Entity.prototype._getEncoder = function _getEncoder(enc) { - enc = enc || 'der'; - // Lazily create encoder - if (!this.encoders.hasOwnProperty(enc)) - this.encoders[enc] = this._createNamed(encoders[enc]); - return this.encoders[enc]; -}; - -Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) { - return this._getEncoder(enc).encode(data, reporter); -}; - -},{"./decoders":16,"./encoders":19,"inherits":230}],9:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],23:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -const inherits = require('inherits'); -const Reporter = require('../base/reporter').Reporter; -const Buffer = require('safer-buffer').Buffer; - -function DecoderBuffer(base, options) { - Reporter.call(this, options); - if (!Buffer.isBuffer(base)) { - this.error('Input not Buffer'); - return; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if ( + keyVal.key[0] !== typeFields_1.InputTypes.TAP_KEY_SIG || + keyVal.key.length !== 1 + ) { + throw new Error( + 'Decode Error: could not decode tapKeySig with key 0x' + + keyVal.key.toString('hex'), + ); } - - this.base = base; - this.offset = 0; - this.length = base.length; + if (!check(keyVal.value)) { + throw new Error( + 'Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature', + ); + } + return keyVal.value; } -inherits(DecoderBuffer, Reporter); -exports.DecoderBuffer = DecoderBuffer; +exports.decode = decode; +function encode(value) { + const key = Buffer.from([typeFields_1.InputTypes.TAP_KEY_SIG]); + return { key, value }; +} +exports.encode = encode; +exports.expected = 'Buffer'; +function check(data) { + return Buffer.isBuffer(data) && (data.length === 64 || data.length === 65); +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.tapKeySig === undefined; +} +exports.canAdd = canAdd; -DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) { - if (data instanceof DecoderBuffer) { - return true; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],24:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.TAP_LEAF_SCRIPT) { + throw new Error( + 'Decode Error: could not decode tapLeafScript with key 0x' + + keyVal.key.toString('hex'), + ); } - - // Or accept compatible API - const isCompatible = typeof data === 'object' && - Buffer.isBuffer(data.base) && - data.constructor.name === 'DecoderBuffer' && - typeof data.offset === 'number' && - typeof data.length === 'number' && - typeof data.save === 'function' && - typeof data.restore === 'function' && - typeof data.isEmpty === 'function' && - typeof data.readUInt8 === 'function' && - typeof data.skip === 'function' && - typeof data.raw === 'function'; - - return isCompatible; -}; - -DecoderBuffer.prototype.save = function save() { - return { offset: this.offset, reporter: Reporter.prototype.save.call(this) }; -}; - -DecoderBuffer.prototype.restore = function restore(save) { - // Return skipped data - const res = new DecoderBuffer(this.base); - res.offset = save.offset; - res.length = this.offset; - - this.offset = save.offset; - Reporter.prototype.restore.call(this, save.reporter); - - return res; -}; - -DecoderBuffer.prototype.isEmpty = function isEmpty() { - return this.offset === this.length; -}; - -DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) { - if (this.offset + 1 <= this.length) - return this.base.readUInt8(this.offset++, true); - else - return this.error(fail || 'DecoderBuffer overrun'); -}; - -DecoderBuffer.prototype.skip = function skip(bytes, fail) { - if (!(this.offset + bytes <= this.length)) - return this.error(fail || 'DecoderBuffer overrun'); - - const res = new DecoderBuffer(this.base); - - // Share reporter state - res._reporterState = this._reporterState; - - res.offset = this.offset; - res.length = this.offset + bytes; - this.offset += bytes; - return res; -}; - -DecoderBuffer.prototype.raw = function raw(save) { - return this.base.slice(save ? save.offset : this.offset, this.length); -}; - -function EncoderBuffer(value, reporter) { - if (Array.isArray(value)) { - this.length = 0; - this.value = value.map(function(item) { - if (!EncoderBuffer.isEncoderBuffer(item)) - item = new EncoderBuffer(item, reporter); - this.length += item.length; - return item; - }, this); - } else if (typeof value === 'number') { - if (!(0 <= value && value <= 0xff)) - return reporter.error('non-byte EncoderBuffer value'); - this.value = value; - this.length = 1; - } else if (typeof value === 'string') { - this.value = value; - this.length = Buffer.byteLength(value); - } else if (Buffer.isBuffer(value)) { - this.value = value; - this.length = value.length; - } else { - return reporter.error('Unsupported type: ' + typeof value); + if ((keyVal.key.length - 2) % 32 !== 0) { + throw new Error( + 'Decode Error: tapLeafScript has invalid control block in key 0x' + + keyVal.key.toString('hex'), + ); } + const leafVersion = keyVal.value[keyVal.value.length - 1]; + if ((keyVal.key[1] & 0xfe) !== leafVersion) { + throw new Error( + 'Decode Error: tapLeafScript bad leaf version in key 0x' + + keyVal.key.toString('hex'), + ); + } + const script = keyVal.value.slice(0, -1); + const controlBlock = keyVal.key.slice(1); + return { controlBlock, script, leafVersion }; } -exports.EncoderBuffer = EncoderBuffer; +exports.decode = decode; +function encode(tScript) { + const head = Buffer.from([typeFields_1.InputTypes.TAP_LEAF_SCRIPT]); + const verBuf = Buffer.from([tScript.leafVersion]); + return { + key: Buffer.concat([head, tScript.controlBlock]), + value: Buffer.concat([tScript.script, verBuf]), + }; +} +exports.encode = encode; +exports.expected = + '{ controlBlock: Buffer; leafVersion: number, script: Buffer; }'; +function check(data) { + return ( + Buffer.isBuffer(data.controlBlock) && + (data.controlBlock.length - 1) % 32 === 0 && + (data.controlBlock[0] & 0xfe) === data.leafVersion && + Buffer.isBuffer(data.script) + ); +} +exports.check = check; +function canAddToArray(array, item, dupeSet) { + const dupeString = item.controlBlock.toString('hex'); + if (dupeSet.has(dupeString)) return false; + dupeSet.add(dupeString); + return ( + array.filter(v => v.controlBlock.equals(item.controlBlock)).length === 0 + ); +} +exports.canAddToArray = canAddToArray; -EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) { - if (data instanceof EncoderBuffer) { - return true; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],25:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if ( + keyVal.key[0] !== typeFields_1.InputTypes.TAP_MERKLE_ROOT || + keyVal.key.length !== 1 + ) { + throw new Error( + 'Decode Error: could not decode tapMerkleRoot with key 0x' + + keyVal.key.toString('hex'), + ); } + if (!check(keyVal.value)) { + throw new Error('Decode Error: tapMerkleRoot not a 32-byte hash'); + } + return keyVal.value; +} +exports.decode = decode; +function encode(value) { + const key = Buffer.from([typeFields_1.InputTypes.TAP_MERKLE_ROOT]); + return { key, value }; +} +exports.encode = encode; +exports.expected = 'Buffer'; +function check(data) { + return Buffer.isBuffer(data) && data.length === 32; +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.tapMerkleRoot === undefined; +} +exports.canAdd = canAdd; - // Or accept compatible API - const isCompatible = typeof data === 'object' && - data.constructor.name === 'EncoderBuffer' && - typeof data.length === 'number' && - typeof data.join === 'function'; - - return isCompatible; -}; - -EncoderBuffer.prototype.join = function join(out, offset) { - if (!out) - out = Buffer.alloc(this.length); - if (!offset) - offset = 0; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],26:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.TAP_SCRIPT_SIG) { + throw new Error( + 'Decode Error: could not decode tapScriptSig with key 0x' + + keyVal.key.toString('hex'), + ); + } + if (keyVal.key.length !== 65) { + throw new Error( + 'Decode Error: tapScriptSig has invalid key 0x' + + keyVal.key.toString('hex'), + ); + } + if (keyVal.value.length !== 64 && keyVal.value.length !== 65) { + throw new Error( + 'Decode Error: tapScriptSig has invalid signature in key 0x' + + keyVal.key.toString('hex'), + ); + } + const pubkey = keyVal.key.slice(1, 33); + const leafHash = keyVal.key.slice(33); + return { + pubkey, + leafHash, + signature: keyVal.value, + }; +} +exports.decode = decode; +function encode(tSig) { + const head = Buffer.from([typeFields_1.InputTypes.TAP_SCRIPT_SIG]); + return { + key: Buffer.concat([head, tSig.pubkey, tSig.leafHash]), + value: tSig.signature, + }; +} +exports.encode = encode; +exports.expected = '{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }'; +function check(data) { + return ( + Buffer.isBuffer(data.pubkey) && + Buffer.isBuffer(data.leafHash) && + Buffer.isBuffer(data.signature) && + data.pubkey.length === 32 && + data.leafHash.length === 32 && + (data.signature.length === 64 || data.signature.length === 65) + ); +} +exports.check = check; +function canAddToArray(array, item, dupeSet) { + const dupeString = + item.pubkey.toString('hex') + item.leafHash.toString('hex'); + if (dupeSet.has(dupeString)) return false; + dupeSet.add(dupeString); + return ( + array.filter( + v => v.pubkey.equals(item.pubkey) && v.leafHash.equals(item.leafHash), + ).length === 0 + ); +} +exports.canAddToArray = canAddToArray; - if (this.length === 0) - return out; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"buffer":249}],27:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +const tools_1 = require('../tools'); +const varuint = require('../varint'); +function decode(keyVal) { + if (keyVal.key[0] !== typeFields_1.InputTypes.WITNESS_UTXO) { + throw new Error( + 'Decode Error: could not decode witnessUtxo with key 0x' + + keyVal.key.toString('hex'), + ); + } + const value = tools_1.readUInt64LE(keyVal.value, 0); + let _offset = 8; + const scriptLen = varuint.decode(keyVal.value, _offset); + _offset += varuint.encodingLength(scriptLen); + const script = keyVal.value.slice(_offset); + if (script.length !== scriptLen) { + throw new Error('Decode Error: WITNESS_UTXO script is not proper length'); + } + return { + script, + value, + }; +} +exports.decode = decode; +function encode(data) { + const { script, value } = data; + const varintLen = varuint.encodingLength(script.length); + const result = Buffer.allocUnsafe(8 + varintLen + script.length); + tools_1.writeUInt64LE(result, value, 0); + varuint.encode(script.length, result, 8); + script.copy(result, 8 + varintLen); + return { + key: Buffer.from([typeFields_1.InputTypes.WITNESS_UTXO]), + value: result, + }; +} +exports.encode = encode; +exports.expected = '{ script: Buffer; value: number; }'; +function check(data) { + return Buffer.isBuffer(data.script) && typeof data.value === 'number'; +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.witnessUtxo === undefined; +} +exports.canAdd = canAdd; - if (Array.isArray(this.value)) { - this.value.forEach(function(item) { - item.join(out, offset); - offset += item.length; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"../tools":35,"../varint":36,"buffer":249}],28:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const typeFields_1 = require('../../typeFields'); +const varuint = require('../varint'); +function decode(keyVal) { + if ( + keyVal.key[0] !== typeFields_1.OutputTypes.TAP_TREE || + keyVal.key.length !== 1 + ) { + throw new Error( + 'Decode Error: could not decode tapTree with key 0x' + + keyVal.key.toString('hex'), + ); + } + let _offset = 0; + const data = []; + while (_offset < keyVal.value.length) { + const depth = keyVal.value[_offset++]; + const leafVersion = keyVal.value[_offset++]; + const scriptLen = varuint.decode(keyVal.value, _offset); + _offset += varuint.encodingLength(scriptLen); + data.push({ + depth, + leafVersion, + script: keyVal.value.slice(_offset, _offset + scriptLen), }); - } else { - if (typeof this.value === 'number') - out[offset] = this.value; - else if (typeof this.value === 'string') - out.write(this.value, offset); - else if (Buffer.isBuffer(this.value)) - this.value.copy(out, offset); - offset += this.length; + _offset += scriptLen; } + return { leaves: data }; +} +exports.decode = decode; +function encode(tree) { + const key = Buffer.from([typeFields_1.OutputTypes.TAP_TREE]); + const bufs = [].concat( + ...tree.leaves.map(tapLeaf => [ + Buffer.of(tapLeaf.depth, tapLeaf.leafVersion), + varuint.encode(tapLeaf.script.length), + tapLeaf.script, + ]), + ); + return { + key, + value: Buffer.concat(bufs), + }; +} +exports.encode = encode; +exports.expected = + '{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }'; +function check(data) { + return ( + Array.isArray(data.leaves) && + data.leaves.every( + tapLeaf => + tapLeaf.depth >= 0 && + tapLeaf.depth <= 128 && + (tapLeaf.leafVersion & 0xfe) === tapLeaf.leafVersion && + Buffer.isBuffer(tapLeaf.script), + ) + ); +} +exports.check = check; +function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.tapTree === undefined; +} +exports.canAdd = canAdd; - return out; -}; - -},{"../base/reporter":12,"inherits":230,"safer-buffer":281}],10:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../typeFields":41,"../varint":36,"buffer":249}],29:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const range = n => [...Array(n).keys()]; +const isValidDERKey = pubkey => + (pubkey.length === 33 && [2, 3].includes(pubkey[0])) || + (pubkey.length === 65 && 4 === pubkey[0]); +function makeConverter(TYPE_BYTE, isValidPubkey = isValidDERKey) { + function decode(keyVal) { + if (keyVal.key[0] !== TYPE_BYTE) { + throw new Error( + 'Decode Error: could not decode bip32Derivation with key 0x' + + keyVal.key.toString('hex'), + ); + } + const pubkey = keyVal.key.slice(1); + if (!isValidPubkey(pubkey)) { + throw new Error( + 'Decode Error: bip32Derivation has invalid pubkey in key 0x' + + keyVal.key.toString('hex'), + ); + } + if ((keyVal.value.length / 4) % 1 !== 0) { + throw new Error( + 'Decode Error: Input BIP32_DERIVATION value length should be multiple of 4', + ); + } + const data = { + masterFingerprint: keyVal.value.slice(0, 4), + pubkey, + path: 'm', + }; + for (const i of range(keyVal.value.length / 4 - 1)) { + const val = keyVal.value.readUInt32LE(i * 4 + 4); + const isHard = !!(val & 0x80000000); + const idx = val & 0x7fffffff; + data.path += '/' + idx.toString(10) + (isHard ? "'" : ''); + } + return data; + } + function encode(data) { + const head = Buffer.from([TYPE_BYTE]); + const key = Buffer.concat([head, data.pubkey]); + const splitPath = data.path.split('/'); + const value = Buffer.allocUnsafe(splitPath.length * 4); + data.masterFingerprint.copy(value, 0); + let offset = 4; + splitPath.slice(1).forEach(level => { + const isHard = level.slice(-1) === "'"; + let num = 0x7fffffff & parseInt(isHard ? level.slice(0, -1) : level, 10); + if (isHard) num += 0x80000000; + value.writeUInt32LE(num, offset); + offset += 4; + }); + return { + key, + value, + }; + } + const expected = + '{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }'; + function check(data) { + return ( + Buffer.isBuffer(data.pubkey) && + Buffer.isBuffer(data.masterFingerprint) && + typeof data.path === 'string' && + isValidPubkey(data.pubkey) && + data.masterFingerprint.length === 4 + ); + } + function canAddToArray(array, item, dupeSet) { + const dupeString = item.pubkey.toString('hex'); + if (dupeSet.has(dupeString)) return false; + dupeSet.add(dupeString); + return array.filter(v => v.pubkey.equals(item.pubkey)).length === 0; + } + return { + decode, + encode, + check, + expected, + canAddToArray, + }; +} +exports.makeConverter = makeConverter; -const base = exports; - -base.Reporter = require('./reporter').Reporter; -base.DecoderBuffer = require('./buffer').DecoderBuffer; -base.EncoderBuffer = require('./buffer').EncoderBuffer; -base.Node = require('./node'); - -},{"./buffer":9,"./node":11,"./reporter":12}],11:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],30:[function(require,module,exports){ 'use strict'; - -const Reporter = require('../base/reporter').Reporter; -const EncoderBuffer = require('../base/buffer').EncoderBuffer; -const DecoderBuffer = require('../base/buffer').DecoderBuffer; -const assert = require('minimalistic-assert'); - -// Supported tags -const tags = [ - 'seq', 'seqof', 'set', 'setof', 'objid', 'bool', - 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc', - 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str', - 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr' -]; - -// Public methods list -const methods = [ - 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', - 'any', 'contains' -].concat(tags); - -// Overrided methods list -const overrided = [ - '_peekTag', '_decodeTag', '_use', - '_decodeStr', '_decodeObjid', '_decodeTime', - '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', - - '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', - '_encodeNull', '_encodeInt', '_encodeBool' -]; - -function Node(enc, parent, name) { - const state = {}; - this._baseState = state; - - state.name = name; - state.enc = enc; - - state.parent = parent || null; - state.children = null; - - // State - state.tag = null; - state.args = null; - state.reverseArgs = null; - state.choice = null; - state.optional = false; - state.any = false; - state.obj = false; - state.use = null; - state.useDecoder = null; - state.key = null; - state['default'] = null; - state.explicit = null; - state.implicit = null; - state.contains = null; - - // Should create new instance on each method - if (!state.parent) { - state.children = []; - this._wrap(); +Object.defineProperty(exports, '__esModule', { value: true }); +function makeChecker(pubkeyTypes) { + return checkPubkey; + function checkPubkey(keyVal) { + let pubkey; + if (pubkeyTypes.includes(keyVal.key[0])) { + pubkey = keyVal.key.slice(1); + if ( + !(pubkey.length === 33 || pubkey.length === 65) || + ![2, 3, 4].includes(pubkey[0]) + ) { + throw new Error( + 'Format Error: invalid pubkey in key 0x' + keyVal.key.toString('hex'), + ); + } + } + return pubkey; } } -module.exports = Node; - -const stateProps = [ - 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', - 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', - 'implicit', 'contains' -]; - -Node.prototype.clone = function clone() { - const state = this._baseState; - const cstate = {}; - stateProps.forEach(function(prop) { - cstate[prop] = state[prop]; - }); - const res = new this.constructor(cstate.parent); - res._baseState = cstate; - return res; -}; +exports.makeChecker = makeChecker; -Node.prototype._wrap = function wrap() { - const state = this._baseState; - methods.forEach(function(method) { - this[method] = function _wrappedMethod() { - const clone = new this.constructor(this); - state.children.push(clone); - return clone[method].apply(clone, arguments); +},{}],31:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +function makeConverter(TYPE_BYTE) { + function decode(keyVal) { + if (keyVal.key[0] !== TYPE_BYTE) { + throw new Error( + 'Decode Error: could not decode redeemScript with key 0x' + + keyVal.key.toString('hex'), + ); + } + return keyVal.value; + } + function encode(data) { + const key = Buffer.from([TYPE_BYTE]); + return { + key, + value: data, }; - }, this); -}; - -Node.prototype._init = function init(body) { - const state = this._baseState; - - assert(state.parent === null); - body.call(this); - - // Filter children - state.children = state.children.filter(function(child) { - return child._baseState.parent === this; - }, this); - assert.equal(state.children.length, 1, 'Root node can have only one child'); -}; - -Node.prototype._useArgs = function useArgs(args) { - const state = this._baseState; - - // Filter children and args - const children = args.filter(function(arg) { - return arg instanceof this.constructor; - }, this); - args = args.filter(function(arg) { - return !(arg instanceof this.constructor); - }, this); - - if (children.length !== 0) { - assert(state.children === null); - state.children = children; - - // Replace parent to maintain backward link - children.forEach(function(child) { - child._baseState.parent = this; - }, this); } - if (args.length !== 0) { - assert(state.args === null); - state.args = args; - state.reverseArgs = args.map(function(arg) { - if (typeof arg !== 'object' || arg.constructor !== Object) - return arg; + const expected = 'Buffer'; + function check(data) { + return Buffer.isBuffer(data); + } + function canAdd(currentData, newData) { + return !!currentData && !!newData && currentData.redeemScript === undefined; + } + return { + decode, + encode, + check, + expected, + canAdd, + }; +} +exports.makeConverter = makeConverter; - const res = {}; - Object.keys(arg).forEach(function(key) { - if (key == (key | 0)) - key |= 0; - const value = arg[key]; - res[value] = key; - }); - return res; +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],32:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const varuint = require('../varint'); +const bip32Derivation = require('./bip32Derivation'); +const isValidBIP340Key = pubkey => pubkey.length === 32; +function makeConverter(TYPE_BYTE) { + const parent = bip32Derivation.makeConverter(TYPE_BYTE, isValidBIP340Key); + function decode(keyVal) { + const nHashes = varuint.decode(keyVal.value); + const nHashesLen = varuint.encodingLength(nHashes); + const base = parent.decode({ + key: keyVal.key, + value: keyVal.value.slice(nHashesLen + nHashes * 32), }); + const leafHashes = new Array(nHashes); + for (let i = 0, _offset = nHashesLen; i < nHashes; i++, _offset += 32) { + leafHashes[i] = keyVal.value.slice(_offset, _offset + 32); + } + return Object.assign({}, base, { leafHashes }); + } + function encode(data) { + const base = parent.encode(data); + const nHashesLen = varuint.encodingLength(data.leafHashes.length); + const nHashesBuf = Buffer.allocUnsafe(nHashesLen); + varuint.encode(data.leafHashes.length, nHashesBuf); + const value = Buffer.concat([nHashesBuf, ...data.leafHashes, base.value]); + return Object.assign({}, base, { value }); + } + const expected = + '{ ' + + 'masterFingerprint: Buffer; ' + + 'pubkey: Buffer; ' + + 'path: string; ' + + 'leafHashes: Buffer[]; ' + + '}'; + function check(data) { + return ( + Array.isArray(data.leafHashes) && + data.leafHashes.every( + leafHash => Buffer.isBuffer(leafHash) && leafHash.length === 32, + ) && + parent.check(data) + ); } -}; - -// -// Overrided methods -// - -overrided.forEach(function(method) { - Node.prototype[method] = function _overrided() { - const state = this._baseState; - throw new Error(method + ' not implemented for encoding: ' + state.enc); + return { + decode, + encode, + check, + expected, + canAddToArray: parent.canAddToArray, }; -}); - -// -// Public methods -// - -tags.forEach(function(tag) { - Node.prototype[tag] = function _tagMethod() { - const state = this._baseState; - const args = Array.prototype.slice.call(arguments); - - assert(state.tag === null); - state.tag = tag; - - this._useArgs(args); +} +exports.makeConverter = makeConverter; - return this; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../varint":36,"./bip32Derivation":29,"buffer":249}],33:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +function makeConverter(TYPE_BYTE) { + function decode(keyVal) { + if (keyVal.key[0] !== TYPE_BYTE || keyVal.key.length !== 1) { + throw new Error( + 'Decode Error: could not decode tapInternalKey with key 0x' + + keyVal.key.toString('hex'), + ); + } + if (keyVal.value.length !== 32) { + throw new Error( + 'Decode Error: tapInternalKey not a 32-byte x-only pubkey', + ); + } + return keyVal.value; + } + function encode(value) { + const key = Buffer.from([TYPE_BYTE]); + return { key, value }; + } + const expected = 'Buffer'; + function check(data) { + return Buffer.isBuffer(data) && data.length === 32; + } + function canAdd(currentData, newData) { + return ( + !!currentData && !!newData && currentData.tapInternalKey === undefined + ); + } + return { + decode, + encode, + check, + expected, + canAdd, }; -}); - -Node.prototype.use = function use(item) { - assert(item); - const state = this._baseState; - - assert(state.use === null); - state.use = item; - - return this; -}; - -Node.prototype.optional = function optional() { - const state = this._baseState; +} +exports.makeConverter = makeConverter; - state.optional = true; - - return this; -}; - -Node.prototype.def = function def(val) { - const state = this._baseState; - - assert(state['default'] === null); - state['default'] = val; - state.optional = true; - - return this; -}; - -Node.prototype.explicit = function explicit(num) { - const state = this._baseState; - - assert(state.explicit === null && state.implicit === null); - state.explicit = num; - - return this; -}; - -Node.prototype.implicit = function implicit(num) { - const state = this._baseState; - - assert(state.explicit === null && state.implicit === null); - state.implicit = num; - - return this; -}; - -Node.prototype.obj = function obj() { - const state = this._baseState; - const args = Array.prototype.slice.call(arguments); - - state.obj = true; - - if (args.length !== 0) - this._useArgs(args); - - return this; -}; - -Node.prototype.key = function key(newKey) { - const state = this._baseState; - - assert(state.key === null); - state.key = newKey; - - return this; -}; - -Node.prototype.any = function any() { - const state = this._baseState; - - state.any = true; - - return this; -}; - -Node.prototype.choice = function choice(obj) { - const state = this._baseState; - - assert(state.choice === null); - state.choice = obj; - this._useArgs(Object.keys(obj).map(function(key) { - return obj[key]; - })); - - return this; -}; - -Node.prototype.contains = function contains(item) { - const state = this._baseState; - - assert(state.use === null); - state.contains = item; - - return this; -}; - -// -// Decoding -// - -Node.prototype._decode = function decode(input, options) { - const state = this._baseState; - - // Decode root node - if (state.parent === null) - return input.wrapResult(state.children[0]._decode(input, options)); - - let result = state['default']; - let present = true; +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],34:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +function makeConverter(TYPE_BYTE) { + function decode(keyVal) { + if (keyVal.key[0] !== TYPE_BYTE) { + throw new Error( + 'Decode Error: could not decode witnessScript with key 0x' + + keyVal.key.toString('hex'), + ); + } + return keyVal.value; + } + function encode(data) { + const key = Buffer.from([TYPE_BYTE]); + return { + key, + value: data, + }; + } + const expected = 'Buffer'; + function check(data) { + return Buffer.isBuffer(data); + } + function canAdd(currentData, newData) { + return ( + !!currentData && !!newData && currentData.witnessScript === undefined + ); + } + return { + decode, + encode, + check, + expected, + canAdd, + }; +} +exports.makeConverter = makeConverter; - let prevKey = null; - if (state.key !== null) - prevKey = input.enterKey(state.key); +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],35:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const varuint = require('./varint'); +exports.range = n => [...Array(n).keys()]; +function reverseBuffer(buffer) { + if (buffer.length < 1) return buffer; + let j = buffer.length - 1; + let tmp = 0; + for (let i = 0; i < buffer.length / 2; i++) { + tmp = buffer[i]; + buffer[i] = buffer[j]; + buffer[j] = tmp; + j--; + } + return buffer; +} +exports.reverseBuffer = reverseBuffer; +function keyValsToBuffer(keyVals) { + const buffers = keyVals.map(keyValToBuffer); + buffers.push(Buffer.from([0])); + return Buffer.concat(buffers); +} +exports.keyValsToBuffer = keyValsToBuffer; +function keyValToBuffer(keyVal) { + const keyLen = keyVal.key.length; + const valLen = keyVal.value.length; + const keyVarIntLen = varuint.encodingLength(keyLen); + const valVarIntLen = varuint.encodingLength(valLen); + const buffer = Buffer.allocUnsafe( + keyVarIntLen + keyLen + valVarIntLen + valLen, + ); + varuint.encode(keyLen, buffer, 0); + keyVal.key.copy(buffer, keyVarIntLen); + varuint.encode(valLen, buffer, keyVarIntLen + keyLen); + keyVal.value.copy(buffer, keyVarIntLen + keyLen + valVarIntLen); + return buffer; +} +exports.keyValToBuffer = keyValToBuffer; +// https://github.com/feross/buffer/blob/master/index.js#L1127 +function verifuint(value, max) { + if (typeof value !== 'number') + throw new Error('cannot write a non-number as a number'); + if (value < 0) + throw new Error('specified a negative value for writing an unsigned value'); + if (value > max) throw new Error('RangeError: value out of range'); + if (Math.floor(value) !== value) + throw new Error('value has a fractional component'); +} +function readUInt64LE(buffer, offset) { + const a = buffer.readUInt32LE(offset); + let b = buffer.readUInt32LE(offset + 4); + b *= 0x100000000; + verifuint(b + a, 0x001fffffffffffff); + return b + a; +} +exports.readUInt64LE = readUInt64LE; +function writeUInt64LE(buffer, value, offset) { + verifuint(value, 0x001fffffffffffff); + buffer.writeInt32LE(value & -1, offset); + buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4); + return offset + 8; +} +exports.writeUInt64LE = writeUInt64LE; - // Check if tag is there - if (state.optional) { - let tag = null; - if (state.explicit !== null) - tag = state.explicit; - else if (state.implicit !== null) - tag = state.implicit; - else if (state.tag !== null) - tag = state.tag; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./varint":36,"buffer":249}],36:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +// Number.MAX_SAFE_INTEGER +const MAX_SAFE_INTEGER = 9007199254740991; +function checkUInt53(n) { + if (n < 0 || n > MAX_SAFE_INTEGER || n % 1 !== 0) + throw new RangeError('value out of range'); +} +function encode(_number, buffer, offset) { + checkUInt53(_number); + if (!buffer) buffer = Buffer.allocUnsafe(encodingLength(_number)); + if (!Buffer.isBuffer(buffer)) + throw new TypeError('buffer must be a Buffer instance'); + if (!offset) offset = 0; + // 8 bit + if (_number < 0xfd) { + buffer.writeUInt8(_number, offset); + Object.assign(encode, { bytes: 1 }); + // 16 bit + } else if (_number <= 0xffff) { + buffer.writeUInt8(0xfd, offset); + buffer.writeUInt16LE(_number, offset + 1); + Object.assign(encode, { bytes: 3 }); + // 32 bit + } else if (_number <= 0xffffffff) { + buffer.writeUInt8(0xfe, offset); + buffer.writeUInt32LE(_number, offset + 1); + Object.assign(encode, { bytes: 5 }); + // 64 bit + } else { + buffer.writeUInt8(0xff, offset); + buffer.writeUInt32LE(_number >>> 0, offset + 1); + buffer.writeUInt32LE((_number / 0x100000000) | 0, offset + 5); + Object.assign(encode, { bytes: 9 }); + } + return buffer; +} +exports.encode = encode; +function decode(buffer, offset) { + if (!Buffer.isBuffer(buffer)) + throw new TypeError('buffer must be a Buffer instance'); + if (!offset) offset = 0; + const first = buffer.readUInt8(offset); + // 8 bit + if (first < 0xfd) { + Object.assign(decode, { bytes: 1 }); + return first; + // 16 bit + } else if (first === 0xfd) { + Object.assign(decode, { bytes: 3 }); + return buffer.readUInt16LE(offset + 1); + // 32 bit + } else if (first === 0xfe) { + Object.assign(decode, { bytes: 5 }); + return buffer.readUInt32LE(offset + 1); + // 64 bit + } else { + Object.assign(decode, { bytes: 9 }); + const lo = buffer.readUInt32LE(offset + 1); + const hi = buffer.readUInt32LE(offset + 5); + const _number = hi * 0x0100000000 + lo; + checkUInt53(_number); + return _number; + } +} +exports.decode = decode; +function encodingLength(_number) { + checkUInt53(_number); + return _number < 0xfd + ? 1 + : _number <= 0xffff + ? 3 + : _number <= 0xffffffff + ? 5 + : 9; +} +exports.encodingLength = encodingLength; - if (tag === null && !state.any) { - // Trial and Error - const save = input.save(); - try { - if (state.choice === null) - this._decodeGeneric(state.tag, input, options); - else - this._decodeChoice(input, options); - present = true; - } catch (e) { - present = false; +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],37:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const convert = require('../converter'); +const tools_1 = require('../converter/tools'); +const varuint = require('../converter/varint'); +const typeFields_1 = require('../typeFields'); +function psbtFromBuffer(buffer, txGetter) { + let offset = 0; + function varSlice() { + const keyLen = varuint.decode(buffer, offset); + offset += varuint.encodingLength(keyLen); + const key = buffer.slice(offset, offset + keyLen); + offset += keyLen; + return key; + } + function readUInt32BE() { + const num = buffer.readUInt32BE(offset); + offset += 4; + return num; + } + function readUInt8() { + const num = buffer.readUInt8(offset); + offset += 1; + return num; + } + function getKeyValue() { + const key = varSlice(); + const value = varSlice(); + return { + key, + value, + }; + } + function checkEndOfKeyValPairs() { + if (offset >= buffer.length) { + throw new Error('Format Error: Unexpected End of PSBT'); + } + const isEnd = buffer.readUInt8(offset) === 0; + if (isEnd) { + offset++; + } + return isEnd; + } + if (readUInt32BE() !== 0x70736274) { + throw new Error('Format Error: Invalid Magic Number'); + } + if (readUInt8() !== 0xff) { + throw new Error( + 'Format Error: Magic Number must be followed by 0xff separator', + ); + } + const globalMapKeyVals = []; + const globalKeyIndex = {}; + while (!checkEndOfKeyValPairs()) { + const keyVal = getKeyValue(); + const hexKey = keyVal.key.toString('hex'); + if (globalKeyIndex[hexKey]) { + throw new Error( + 'Format Error: Keys must be unique for global keymap: key ' + hexKey, + ); + } + globalKeyIndex[hexKey] = 1; + globalMapKeyVals.push(keyVal); + } + const unsignedTxMaps = globalMapKeyVals.filter( + keyVal => keyVal.key[0] === typeFields_1.GlobalTypes.UNSIGNED_TX, + ); + if (unsignedTxMaps.length !== 1) { + throw new Error('Format Error: Only one UNSIGNED_TX allowed'); + } + const unsignedTx = txGetter(unsignedTxMaps[0].value); + // Get input and output counts to loop the respective fields + const { inputCount, outputCount } = unsignedTx.getInputOutputCounts(); + const inputKeyVals = []; + const outputKeyVals = []; + // Get input fields + for (const index of tools_1.range(inputCount)) { + const inputKeyIndex = {}; + const input = []; + while (!checkEndOfKeyValPairs()) { + const keyVal = getKeyValue(); + const hexKey = keyVal.key.toString('hex'); + if (inputKeyIndex[hexKey]) { + throw new Error( + 'Format Error: Keys must be unique for each input: ' + + 'input index ' + + index + + ' key ' + + hexKey, + ); } - input.restore(save); - } else { - present = this._peekTag(input, tag, state.any); - - if (input.isError(present)) - return present; + inputKeyIndex[hexKey] = 1; + input.push(keyVal); + } + inputKeyVals.push(input); + } + for (const index of tools_1.range(outputCount)) { + const outputKeyIndex = {}; + const output = []; + while (!checkEndOfKeyValPairs()) { + const keyVal = getKeyValue(); + const hexKey = keyVal.key.toString('hex'); + if (outputKeyIndex[hexKey]) { + throw new Error( + 'Format Error: Keys must be unique for each output: ' + + 'output index ' + + index + + ' key ' + + hexKey, + ); + } + outputKeyIndex[hexKey] = 1; + output.push(keyVal); } + outputKeyVals.push(output); } - - // Push object on stack - let prevObj; - if (state.obj && present) - prevObj = input.enterObject(); - - if (present) { - // Unwrap explicit values - if (state.explicit !== null) { - const explicit = this._decodeTag(input, state.explicit); - if (input.isError(explicit)) - return explicit; - input = explicit; + return psbtFromKeyVals(unsignedTx, { + globalMapKeyVals, + inputKeyVals, + outputKeyVals, + }); +} +exports.psbtFromBuffer = psbtFromBuffer; +function checkKeyBuffer(type, keyBuf, keyNum) { + if (!keyBuf.equals(Buffer.from([keyNum]))) { + throw new Error( + `Format Error: Invalid ${type} key: ${keyBuf.toString('hex')}`, + ); + } +} +exports.checkKeyBuffer = checkKeyBuffer; +function psbtFromKeyVals( + unsignedTx, + { globalMapKeyVals, inputKeyVals, outputKeyVals }, +) { + // That was easy :-) + const globalMap = { + unsignedTx, + }; + let txCount = 0; + for (const keyVal of globalMapKeyVals) { + // If a globalMap item needs pubkey, uncomment + // const pubkey = convert.globals.checkPubkey(keyVal); + switch (keyVal.key[0]) { + case typeFields_1.GlobalTypes.UNSIGNED_TX: + checkKeyBuffer( + 'global', + keyVal.key, + typeFields_1.GlobalTypes.UNSIGNED_TX, + ); + if (txCount > 0) { + throw new Error('Format Error: GlobalMap has multiple UNSIGNED_TX'); + } + txCount++; + break; + case typeFields_1.GlobalTypes.GLOBAL_XPUB: + if (globalMap.globalXpub === undefined) { + globalMap.globalXpub = []; + } + globalMap.globalXpub.push(convert.globals.globalXpub.decode(keyVal)); + break; + default: + // This will allow inclusion during serialization. + if (!globalMap.unknownKeyVals) globalMap.unknownKeyVals = []; + globalMap.unknownKeyVals.push(keyVal); + } + } + // Get input and output counts to loop the respective fields + const inputCount = inputKeyVals.length; + const outputCount = outputKeyVals.length; + const inputs = []; + const outputs = []; + // Get input fields + for (const index of tools_1.range(inputCount)) { + const input = {}; + for (const keyVal of inputKeyVals[index]) { + convert.inputs.checkPubkey(keyVal); + switch (keyVal.key[0]) { + case typeFields_1.InputTypes.NON_WITNESS_UTXO: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.NON_WITNESS_UTXO, + ); + if (input.nonWitnessUtxo !== undefined) { + throw new Error( + 'Format Error: Input has multiple NON_WITNESS_UTXO', + ); + } + input.nonWitnessUtxo = convert.inputs.nonWitnessUtxo.decode(keyVal); + break; + case typeFields_1.InputTypes.WITNESS_UTXO: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.WITNESS_UTXO, + ); + if (input.witnessUtxo !== undefined) { + throw new Error('Format Error: Input has multiple WITNESS_UTXO'); + } + input.witnessUtxo = convert.inputs.witnessUtxo.decode(keyVal); + break; + case typeFields_1.InputTypes.PARTIAL_SIG: + if (input.partialSig === undefined) { + input.partialSig = []; + } + input.partialSig.push(convert.inputs.partialSig.decode(keyVal)); + break; + case typeFields_1.InputTypes.SIGHASH_TYPE: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.SIGHASH_TYPE, + ); + if (input.sighashType !== undefined) { + throw new Error('Format Error: Input has multiple SIGHASH_TYPE'); + } + input.sighashType = convert.inputs.sighashType.decode(keyVal); + break; + case typeFields_1.InputTypes.REDEEM_SCRIPT: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.REDEEM_SCRIPT, + ); + if (input.redeemScript !== undefined) { + throw new Error('Format Error: Input has multiple REDEEM_SCRIPT'); + } + input.redeemScript = convert.inputs.redeemScript.decode(keyVal); + break; + case typeFields_1.InputTypes.WITNESS_SCRIPT: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.WITNESS_SCRIPT, + ); + if (input.witnessScript !== undefined) { + throw new Error('Format Error: Input has multiple WITNESS_SCRIPT'); + } + input.witnessScript = convert.inputs.witnessScript.decode(keyVal); + break; + case typeFields_1.InputTypes.BIP32_DERIVATION: + if (input.bip32Derivation === undefined) { + input.bip32Derivation = []; + } + input.bip32Derivation.push( + convert.inputs.bip32Derivation.decode(keyVal), + ); + break; + case typeFields_1.InputTypes.FINAL_SCRIPTSIG: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.FINAL_SCRIPTSIG, + ); + input.finalScriptSig = convert.inputs.finalScriptSig.decode(keyVal); + break; + case typeFields_1.InputTypes.FINAL_SCRIPTWITNESS: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.FINAL_SCRIPTWITNESS, + ); + input.finalScriptWitness = convert.inputs.finalScriptWitness.decode( + keyVal, + ); + break; + case typeFields_1.InputTypes.POR_COMMITMENT: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.POR_COMMITMENT, + ); + input.porCommitment = convert.inputs.porCommitment.decode(keyVal); + break; + case typeFields_1.InputTypes.TAP_KEY_SIG: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.TAP_KEY_SIG, + ); + input.tapKeySig = convert.inputs.tapKeySig.decode(keyVal); + break; + case typeFields_1.InputTypes.TAP_SCRIPT_SIG: + if (input.tapScriptSig === undefined) { + input.tapScriptSig = []; + } + input.tapScriptSig.push(convert.inputs.tapScriptSig.decode(keyVal)); + break; + case typeFields_1.InputTypes.TAP_LEAF_SCRIPT: + if (input.tapLeafScript === undefined) { + input.tapLeafScript = []; + } + input.tapLeafScript.push(convert.inputs.tapLeafScript.decode(keyVal)); + break; + case typeFields_1.InputTypes.TAP_BIP32_DERIVATION: + if (input.tapBip32Derivation === undefined) { + input.tapBip32Derivation = []; + } + input.tapBip32Derivation.push( + convert.inputs.tapBip32Derivation.decode(keyVal), + ); + break; + case typeFields_1.InputTypes.TAP_INTERNAL_KEY: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.TAP_INTERNAL_KEY, + ); + input.tapInternalKey = convert.inputs.tapInternalKey.decode(keyVal); + break; + case typeFields_1.InputTypes.TAP_MERKLE_ROOT: + checkKeyBuffer( + 'input', + keyVal.key, + typeFields_1.InputTypes.TAP_MERKLE_ROOT, + ); + input.tapMerkleRoot = convert.inputs.tapMerkleRoot.decode(keyVal); + break; + default: + // This will allow inclusion during serialization. + if (!input.unknownKeyVals) input.unknownKeyVals = []; + input.unknownKeyVals.push(keyVal); + } } - - const start = input.offset; - - // Unwrap implicit and normal values - if (state.use === null && state.choice === null) { - let save; - if (state.any) - save = input.save(); - const body = this._decodeTag( - input, - state.implicit !== null ? state.implicit : state.tag, - state.any - ); - if (input.isError(body)) - return body; - - if (state.any) - result = input.raw(save); - else - input = body; + inputs.push(input); + } + for (const index of tools_1.range(outputCount)) { + const output = {}; + for (const keyVal of outputKeyVals[index]) { + convert.outputs.checkPubkey(keyVal); + switch (keyVal.key[0]) { + case typeFields_1.OutputTypes.REDEEM_SCRIPT: + checkKeyBuffer( + 'output', + keyVal.key, + typeFields_1.OutputTypes.REDEEM_SCRIPT, + ); + if (output.redeemScript !== undefined) { + throw new Error('Format Error: Output has multiple REDEEM_SCRIPT'); + } + output.redeemScript = convert.outputs.redeemScript.decode(keyVal); + break; + case typeFields_1.OutputTypes.WITNESS_SCRIPT: + checkKeyBuffer( + 'output', + keyVal.key, + typeFields_1.OutputTypes.WITNESS_SCRIPT, + ); + if (output.witnessScript !== undefined) { + throw new Error('Format Error: Output has multiple WITNESS_SCRIPT'); + } + output.witnessScript = convert.outputs.witnessScript.decode(keyVal); + break; + case typeFields_1.OutputTypes.BIP32_DERIVATION: + if (output.bip32Derivation === undefined) { + output.bip32Derivation = []; + } + output.bip32Derivation.push( + convert.outputs.bip32Derivation.decode(keyVal), + ); + break; + case typeFields_1.OutputTypes.TAP_INTERNAL_KEY: + checkKeyBuffer( + 'output', + keyVal.key, + typeFields_1.OutputTypes.TAP_INTERNAL_KEY, + ); + output.tapInternalKey = convert.outputs.tapInternalKey.decode(keyVal); + break; + case typeFields_1.OutputTypes.TAP_TREE: + checkKeyBuffer( + 'output', + keyVal.key, + typeFields_1.OutputTypes.TAP_TREE, + ); + output.tapTree = convert.outputs.tapTree.decode(keyVal); + break; + case typeFields_1.OutputTypes.TAP_BIP32_DERIVATION: + if (output.tapBip32Derivation === undefined) { + output.tapBip32Derivation = []; + } + output.tapBip32Derivation.push( + convert.outputs.tapBip32Derivation.decode(keyVal), + ); + break; + default: + if (!output.unknownKeyVals) output.unknownKeyVals = []; + output.unknownKeyVals.push(keyVal); + } } + outputs.push(output); + } + return { globalMap, inputs, outputs }; +} +exports.psbtFromKeyVals = psbtFromKeyVals; - if (options && options.track && state.tag !== null) - options.track(input.path(), start, input.length, 'tagged'); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../converter":16,"../converter/tools":35,"../converter/varint":36,"../typeFields":41,"buffer":249}],38:[function(require,module,exports){ +'use strict'; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, '__esModule', { value: true }); +__export(require('./fromBuffer')); +__export(require('./toBuffer')); - if (options && options.track && state.tag !== null) - options.track(input.path(), input.offset, input.length, 'content'); +},{"./fromBuffer":37,"./toBuffer":39}],39:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const convert = require('../converter'); +const tools_1 = require('../converter/tools'); +function psbtToBuffer({ globalMap, inputs, outputs }) { + const { globalKeyVals, inputKeyVals, outputKeyVals } = psbtToKeyVals({ + globalMap, + inputs, + outputs, + }); + const globalBuffer = tools_1.keyValsToBuffer(globalKeyVals); + const keyValsOrEmptyToBuffer = keyVals => + keyVals.length === 0 + ? [Buffer.from([0])] + : keyVals.map(tools_1.keyValsToBuffer); + const inputBuffers = keyValsOrEmptyToBuffer(inputKeyVals); + const outputBuffers = keyValsOrEmptyToBuffer(outputKeyVals); + const header = Buffer.allocUnsafe(5); + header.writeUIntBE(0x70736274ff, 0, 5); + return Buffer.concat( + [header, globalBuffer].concat(inputBuffers, outputBuffers), + ); +} +exports.psbtToBuffer = psbtToBuffer; +const sortKeyVals = (a, b) => { + return a.key.compare(b.key); +}; +function keyValsFromMap(keyValMap, converterFactory) { + const keyHexSet = new Set(); + const keyVals = Object.entries(keyValMap).reduce((result, [key, value]) => { + if (key === 'unknownKeyVals') return result; + // We are checking for undefined anyways. So ignore TS error + // @ts-ignore + const converter = converterFactory[key]; + if (converter === undefined) return result; + const encodedKeyVals = (Array.isArray(value) ? value : [value]).map( + converter.encode, + ); + const keyHexes = encodedKeyVals.map(kv => kv.key.toString('hex')); + keyHexes.forEach(hex => { + if (keyHexSet.has(hex)) + throw new Error('Serialize Error: Duplicate key: ' + hex); + keyHexSet.add(hex); + }); + return result.concat(encodedKeyVals); + }, []); + // Get other keyVals that have not yet been gotten + const otherKeyVals = keyValMap.unknownKeyVals + ? keyValMap.unknownKeyVals.filter(keyVal => { + return !keyHexSet.has(keyVal.key.toString('hex')); + }) + : []; + return keyVals.concat(otherKeyVals).sort(sortKeyVals); +} +function psbtToKeyVals({ globalMap, inputs, outputs }) { + // First parse the global keyVals + // Get any extra keyvals to pass along + return { + globalKeyVals: keyValsFromMap(globalMap, convert.globals), + inputKeyVals: inputs.map(i => keyValsFromMap(i, convert.inputs)), + outputKeyVals: outputs.map(o => keyValsFromMap(o, convert.outputs)), + }; +} +exports.psbtToKeyVals = psbtToKeyVals; - // Select proper method for tag - if (state.any) { - // no-op - } else if (state.choice === null) { - result = this._decodeGeneric(state.tag, input, options); - } else { - result = this._decodeChoice(input, options); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../converter":16,"../converter/tools":35,"buffer":249}],40:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const combiner_1 = require('./combiner'); +const parser_1 = require('./parser'); +const typeFields_1 = require('./typeFields'); +const utils_1 = require('./utils'); +class Psbt { + constructor(tx) { + this.inputs = []; + this.outputs = []; + this.globalMap = { + unsignedTx: tx, + }; + } + static fromBase64(data, txFromBuffer) { + const buffer = Buffer.from(data, 'base64'); + return this.fromBuffer(buffer, txFromBuffer); + } + static fromHex(data, txFromBuffer) { + const buffer = Buffer.from(data, 'hex'); + return this.fromBuffer(buffer, txFromBuffer); + } + static fromBuffer(buffer, txFromBuffer) { + const results = parser_1.psbtFromBuffer(buffer, txFromBuffer); + const psbt = new this(results.globalMap.unsignedTx); + Object.assign(psbt, results); + return psbt; + } + toBase64() { + const buffer = this.toBuffer(); + return buffer.toString('base64'); + } + toHex() { + const buffer = this.toBuffer(); + return buffer.toString('hex'); + } + toBuffer() { + return parser_1.psbtToBuffer(this); + } + updateGlobal(updateData) { + utils_1.updateGlobal(updateData, this.globalMap); + return this; + } + updateInput(inputIndex, updateData) { + const input = utils_1.checkForInput(this.inputs, inputIndex); + utils_1.updateInput(updateData, input); + return this; + } + updateOutput(outputIndex, updateData) { + const output = utils_1.checkForOutput(this.outputs, outputIndex); + utils_1.updateOutput(updateData, output); + return this; + } + addUnknownKeyValToGlobal(keyVal) { + utils_1.checkHasKey( + keyVal, + this.globalMap.unknownKeyVals, + utils_1.getEnumLength(typeFields_1.GlobalTypes), + ); + if (!this.globalMap.unknownKeyVals) this.globalMap.unknownKeyVals = []; + this.globalMap.unknownKeyVals.push(keyVal); + return this; + } + addUnknownKeyValToInput(inputIndex, keyVal) { + const input = utils_1.checkForInput(this.inputs, inputIndex); + utils_1.checkHasKey( + keyVal, + input.unknownKeyVals, + utils_1.getEnumLength(typeFields_1.InputTypes), + ); + if (!input.unknownKeyVals) input.unknownKeyVals = []; + input.unknownKeyVals.push(keyVal); + return this; + } + addUnknownKeyValToOutput(outputIndex, keyVal) { + const output = utils_1.checkForOutput(this.outputs, outputIndex); + utils_1.checkHasKey( + keyVal, + output.unknownKeyVals, + utils_1.getEnumLength(typeFields_1.OutputTypes), + ); + if (!output.unknownKeyVals) output.unknownKeyVals = []; + output.unknownKeyVals.push(keyVal); + return this; + } + addInput(inputData) { + this.globalMap.unsignedTx.addInput(inputData); + this.inputs.push({ + unknownKeyVals: [], + }); + const addKeyVals = inputData.unknownKeyVals || []; + const inputIndex = this.inputs.length - 1; + if (!Array.isArray(addKeyVals)) { + throw new Error('unknownKeyVals must be an Array'); } - - if (input.isError(result)) - return result; - - // Decode children - if (!state.any && state.choice === null && state.children !== null) { - state.children.forEach(function decodeChildren(child) { - // NOTE: We are ignoring errors here, to let parser continue with other - // parts of encoded data - child._decode(input, options); - }); + addKeyVals.forEach(keyVal => + this.addUnknownKeyValToInput(inputIndex, keyVal), + ); + utils_1.addInputAttributes(this.inputs, inputData); + return this; + } + addOutput(outputData) { + this.globalMap.unsignedTx.addOutput(outputData); + this.outputs.push({ + unknownKeyVals: [], + }); + const addKeyVals = outputData.unknownKeyVals || []; + const outputIndex = this.outputs.length - 1; + if (!Array.isArray(addKeyVals)) { + throw new Error('unknownKeyVals must be an Array'); } - - // Decode contained/encoded by schema, only in bit or octet strings - if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) { - const data = new DecoderBuffer(result); - result = this._getUse(state.contains, input._reporterState.obj) - ._decode(data, options); + addKeyVals.forEach(keyVal => + this.addUnknownKeyValToOutput(outputIndex, keyVal), + ); + utils_1.addOutputAttributes(this.outputs, outputData); + return this; + } + clearFinalizedInput(inputIndex) { + const input = utils_1.checkForInput(this.inputs, inputIndex); + utils_1.inputCheckUncleanFinalized(inputIndex, input); + for (const key of Object.keys(input)) { + if ( + ![ + 'witnessUtxo', + 'nonWitnessUtxo', + 'finalScriptSig', + 'finalScriptWitness', + 'unknownKeyVals', + ].includes(key) + ) { + // @ts-ignore + delete input[key]; + } } + return this; } - - // Pop object - if (state.obj && present) - result = input.leaveObject(prevObj); - - // Set key - if (state.key !== null && (result !== null || present === true)) - input.leaveKey(prevKey, state.key, result); - else if (prevKey !== null) - input.exitKey(prevKey); - - return result; -}; - -Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) { - const state = this._baseState; - - if (tag === 'seq' || tag === 'set') - return null; - if (tag === 'seqof' || tag === 'setof') - return this._decodeList(input, tag, state.args[0], options); - else if (/str$/.test(tag)) - return this._decodeStr(input, tag, options); - else if (tag === 'objid' && state.args) - return this._decodeObjid(input, state.args[0], state.args[1], options); - else if (tag === 'objid') - return this._decodeObjid(input, null, null, options); - else if (tag === 'gentime' || tag === 'utctime') - return this._decodeTime(input, tag, options); - else if (tag === 'null_') - return this._decodeNull(input, options); - else if (tag === 'bool') - return this._decodeBool(input, options); - else if (tag === 'objDesc') - return this._decodeStr(input, tag, options); - else if (tag === 'int' || tag === 'enum') - return this._decodeInt(input, state.args && state.args[0], options); - - if (state.use !== null) { - return this._getUse(state.use, input._reporterState.obj) - ._decode(input, options); - } else { - return input.error('unknown tag: ' + tag); + combine(...those) { + // Combine this with those. + // Return self for chaining. + const result = combiner_1.combine([this].concat(those)); + Object.assign(this, result); + return this; } -}; - -Node.prototype._getUse = function _getUse(entity, obj) { - - const state = this._baseState; - // Create altered use decoder if implicit is set - state.useDecoder = this._use(entity, obj); - assert(state.useDecoder._baseState.parent === null); - state.useDecoder = state.useDecoder._baseState.children[0]; - if (state.implicit !== state.useDecoder._baseState.implicit) { - state.useDecoder = state.useDecoder.clone(); - state.useDecoder._baseState.implicit = state.implicit; + getTransaction() { + return this.globalMap.unsignedTx.toBuffer(); } - return state.useDecoder; -}; - -Node.prototype._decodeChoice = function decodeChoice(input, options) { - const state = this._baseState; - let result = null; - let match = false; +} +exports.Psbt = Psbt; - Object.keys(state.choice).some(function(key) { - const save = input.save(); - const node = state.choice[key]; - try { - const value = node._decode(input, options); - if (input.isError(value)) - return false; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./combiner":13,"./parser":38,"./typeFields":41,"./utils":42,"buffer":249}],41:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var GlobalTypes; +(function(GlobalTypes) { + GlobalTypes[(GlobalTypes['UNSIGNED_TX'] = 0)] = 'UNSIGNED_TX'; + GlobalTypes[(GlobalTypes['GLOBAL_XPUB'] = 1)] = 'GLOBAL_XPUB'; +})((GlobalTypes = exports.GlobalTypes || (exports.GlobalTypes = {}))); +exports.GLOBAL_TYPE_NAMES = ['unsignedTx', 'globalXpub']; +var InputTypes; +(function(InputTypes) { + InputTypes[(InputTypes['NON_WITNESS_UTXO'] = 0)] = 'NON_WITNESS_UTXO'; + InputTypes[(InputTypes['WITNESS_UTXO'] = 1)] = 'WITNESS_UTXO'; + InputTypes[(InputTypes['PARTIAL_SIG'] = 2)] = 'PARTIAL_SIG'; + InputTypes[(InputTypes['SIGHASH_TYPE'] = 3)] = 'SIGHASH_TYPE'; + InputTypes[(InputTypes['REDEEM_SCRIPT'] = 4)] = 'REDEEM_SCRIPT'; + InputTypes[(InputTypes['WITNESS_SCRIPT'] = 5)] = 'WITNESS_SCRIPT'; + InputTypes[(InputTypes['BIP32_DERIVATION'] = 6)] = 'BIP32_DERIVATION'; + InputTypes[(InputTypes['FINAL_SCRIPTSIG'] = 7)] = 'FINAL_SCRIPTSIG'; + InputTypes[(InputTypes['FINAL_SCRIPTWITNESS'] = 8)] = 'FINAL_SCRIPTWITNESS'; + InputTypes[(InputTypes['POR_COMMITMENT'] = 9)] = 'POR_COMMITMENT'; + InputTypes[(InputTypes['TAP_KEY_SIG'] = 19)] = 'TAP_KEY_SIG'; + InputTypes[(InputTypes['TAP_SCRIPT_SIG'] = 20)] = 'TAP_SCRIPT_SIG'; + InputTypes[(InputTypes['TAP_LEAF_SCRIPT'] = 21)] = 'TAP_LEAF_SCRIPT'; + InputTypes[(InputTypes['TAP_BIP32_DERIVATION'] = 22)] = + 'TAP_BIP32_DERIVATION'; + InputTypes[(InputTypes['TAP_INTERNAL_KEY'] = 23)] = 'TAP_INTERNAL_KEY'; + InputTypes[(InputTypes['TAP_MERKLE_ROOT'] = 24)] = 'TAP_MERKLE_ROOT'; +})((InputTypes = exports.InputTypes || (exports.InputTypes = {}))); +exports.INPUT_TYPE_NAMES = [ + 'nonWitnessUtxo', + 'witnessUtxo', + 'partialSig', + 'sighashType', + 'redeemScript', + 'witnessScript', + 'bip32Derivation', + 'finalScriptSig', + 'finalScriptWitness', + 'porCommitment', + 'tapKeySig', + 'tapScriptSig', + 'tapLeafScript', + 'tapBip32Derivation', + 'tapInternalKey', + 'tapMerkleRoot', +]; +var OutputTypes; +(function(OutputTypes) { + OutputTypes[(OutputTypes['REDEEM_SCRIPT'] = 0)] = 'REDEEM_SCRIPT'; + OutputTypes[(OutputTypes['WITNESS_SCRIPT'] = 1)] = 'WITNESS_SCRIPT'; + OutputTypes[(OutputTypes['BIP32_DERIVATION'] = 2)] = 'BIP32_DERIVATION'; + OutputTypes[(OutputTypes['TAP_INTERNAL_KEY'] = 5)] = 'TAP_INTERNAL_KEY'; + OutputTypes[(OutputTypes['TAP_TREE'] = 6)] = 'TAP_TREE'; + OutputTypes[(OutputTypes['TAP_BIP32_DERIVATION'] = 7)] = + 'TAP_BIP32_DERIVATION'; +})((OutputTypes = exports.OutputTypes || (exports.OutputTypes = {}))); +exports.OUTPUT_TYPE_NAMES = [ + 'redeemScript', + 'witnessScript', + 'bip32Derivation', + 'tapInternalKey', + 'tapTree', + 'tapBip32Derivation', +]; - result = { type: key, value: value }; - match = true; - } catch (e) { - input.restore(save); - return false; - } - return true; - }, this); - - if (!match) - return input.error('Choice not matched'); - - return result; -}; - -// -// Encoding -// - -Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) { - return new EncoderBuffer(data, this.reporter); -}; - -Node.prototype._encode = function encode(data, reporter, parent) { - const state = this._baseState; - if (state['default'] !== null && state['default'] === data) - return; - - const result = this._encodeValue(data, reporter, parent); - if (result === undefined) - return; - - if (this._skipDefault(result, reporter, parent)) - return; - - return result; -}; - -Node.prototype._encodeValue = function encode(data, reporter, parent) { - const state = this._baseState; - - // Decode root node - if (state.parent === null) - return state.children[0]._encode(data, reporter || new Reporter()); - - let result = null; - - // Set reporter to share it with a child class - this.reporter = reporter; - - // Check if data is there - if (state.optional && data === undefined) { - if (state['default'] !== null) - data = state['default']; - else - return; - } - - // Encode children first - let content = null; - let primitive = false; - if (state.any) { - // Anything that was given is translated to buffer - result = this._createEncoderBuffer(data); - } else if (state.choice) { - result = this._encodeChoice(data, reporter); - } else if (state.contains) { - content = this._getUse(state.contains, parent)._encode(data, reporter); - primitive = true; - } else if (state.children) { - content = state.children.map(function(child) { - if (child._baseState.tag === 'null_') - return child._encode(null, reporter, data); - - if (child._baseState.key === null) - return reporter.error('Child should have a key'); - const prevKey = reporter.enterKey(child._baseState.key); - - if (typeof data !== 'object') - return reporter.error('Child expected, but input is not object'); - - const res = child._encode(data[child._baseState.key], reporter, data); - reporter.leaveKey(prevKey); - - return res; - }, this).filter(function(child) { - return child; - }); - content = this._createEncoderBuffer(content); - } else { - if (state.tag === 'seqof' || state.tag === 'setof') { - // TODO(indutny): this should be thrown on DSL level - if (!(state.args && state.args.length === 1)) - return reporter.error('Too many args for : ' + state.tag); - - if (!Array.isArray(data)) - return reporter.error('seqof/setof, but data is not Array'); - - const child = this.clone(); - child._baseState.implicit = null; - content = this._createEncoderBuffer(data.map(function(item) { - const state = this._baseState; - - return this._getUse(state.args[0], data)._encode(item, reporter); - }, child)); - } else if (state.use !== null) { - result = this._getUse(state.use, parent)._encode(data, reporter); - } else { - content = this._encodePrimitive(state.tag, data); - primitive = true; +},{}],42:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const converter = require('./converter'); +function checkForInput(inputs, inputIndex) { + const input = inputs[inputIndex]; + if (input === undefined) throw new Error(`No input #${inputIndex}`); + return input; +} +exports.checkForInput = checkForInput; +function checkForOutput(outputs, outputIndex) { + const output = outputs[outputIndex]; + if (output === undefined) throw new Error(`No output #${outputIndex}`); + return output; +} +exports.checkForOutput = checkForOutput; +function checkHasKey(checkKeyVal, keyVals, enumLength) { + if (checkKeyVal.key[0] < enumLength) { + throw new Error( + `Use the method for your specific key instead of addUnknownKeyVal*`, + ); + } + if ( + keyVals && + keyVals.filter(kv => kv.key.equals(checkKeyVal.key)).length !== 0 + ) { + throw new Error(`Duplicate Key: ${checkKeyVal.key.toString('hex')}`); + } +} +exports.checkHasKey = checkHasKey; +function getEnumLength(myenum) { + let count = 0; + Object.keys(myenum).forEach(val => { + if (Number(isNaN(Number(val)))) { + count++; } + }); + return count; +} +exports.getEnumLength = getEnumLength; +function inputCheckUncleanFinalized(inputIndex, input) { + let result = false; + if (input.nonWitnessUtxo || input.witnessUtxo) { + const needScriptSig = !!input.redeemScript; + const needWitnessScript = !!input.witnessScript; + const scriptSigOK = !needScriptSig || !!input.finalScriptSig; + const witnessScriptOK = !needWitnessScript || !!input.finalScriptWitness; + const hasOneFinal = !!input.finalScriptSig || !!input.finalScriptWitness; + result = scriptSigOK && witnessScriptOK && hasOneFinal; + } + if (result === false) { + throw new Error( + `Input #${inputIndex} has too much or too little data to clean`, + ); } - - // Encode data itself - if (!state.any && state.choice === null) { - const tag = state.implicit !== null ? state.implicit : state.tag; - const cls = state.implicit === null ? 'universal' : 'context'; - - if (tag === null) { - if (state.use === null) - reporter.error('Tag could be omitted only for .use()'); - } else { - if (state.use === null) - result = this._encodeComposite(tag, primitive, cls, content); +} +exports.inputCheckUncleanFinalized = inputCheckUncleanFinalized; +function throwForUpdateMaker(typeName, name, expected, data) { + throw new Error( + `Data for ${typeName} key ${name} is incorrect: Expected ` + + `${expected} and got ${JSON.stringify(data)}`, + ); +} +function updateMaker(typeName) { + return (updateData, mainData) => { + for (const name of Object.keys(updateData)) { + // @ts-ignore + const data = updateData[name]; + // @ts-ignore + const { canAdd, canAddToArray, check, expected } = + // @ts-ignore + converter[typeName + 's'][name] || {}; + const isArray = !!canAddToArray; + // If unknown data. ignore and do not add + if (check) { + if (isArray) { + if ( + !Array.isArray(data) || + // @ts-ignore + (mainData[name] && !Array.isArray(mainData[name])) + ) { + throw new Error(`Key type ${name} must be an array`); + } + if (!data.every(check)) { + throwForUpdateMaker(typeName, name, expected, data); + } + // @ts-ignore + const arr = mainData[name] || []; + const dupeCheckSet = new Set(); + if (!data.every(v => canAddToArray(arr, v, dupeCheckSet))) { + throw new Error('Can not add duplicate data to array'); + } + // @ts-ignore + mainData[name] = arr.concat(data); + } else { + if (!check(data)) { + throwForUpdateMaker(typeName, name, expected, data); + } + if (!canAdd(mainData, data)) { + throw new Error(`Can not add duplicate data to ${typeName}`); + } + // @ts-ignore + mainData[name] = data; + } + } } + }; +} +exports.updateGlobal = updateMaker('global'); +exports.updateInput = updateMaker('input'); +exports.updateOutput = updateMaker('output'); +function addInputAttributes(inputs, data) { + const index = inputs.length - 1; + const input = checkForInput(inputs, index); + exports.updateInput(data, input); +} +exports.addInputAttributes = addInputAttributes; +function addOutputAttributes(outputs, data) { + const index = outputs.length - 1; + const output = checkForOutput(outputs, index); + exports.updateOutput(data, output); +} +exports.addOutputAttributes = addOutputAttributes; +function defaultVersionSetter(version, txBuf) { + if (!Buffer.isBuffer(txBuf) || txBuf.length < 4) { + throw new Error('Set Version: Invalid Transaction'); } - - // Wrap in explicit - if (state.explicit !== null) - result = this._encodeComposite(state.explicit, false, 'context', result); - - return result; -}; - -Node.prototype._encodeChoice = function encodeChoice(data, reporter) { - const state = this._baseState; - - const node = state.choice[data.type]; - if (!node) { - assert( - false, - data.type + ' not found in ' + - JSON.stringify(Object.keys(state.choice))); + txBuf.writeUInt32LE(version, 0); + return txBuf; +} +exports.defaultVersionSetter = defaultVersionSetter; +function defaultLocktimeSetter(locktime, txBuf) { + if (!Buffer.isBuffer(txBuf) || txBuf.length < 4) { + throw new Error('Set Locktime: Invalid Transaction'); } - return node._encode(data.value, reporter); -}; - -Node.prototype._encodePrimitive = function encodePrimitive(tag, data) { - const state = this._baseState; + txBuf.writeUInt32LE(locktime, txBuf.length - 4); + return txBuf; +} +exports.defaultLocktimeSetter = defaultLocktimeSetter; - if (/str$/.test(tag)) - return this._encodeStr(data, tag); - else if (tag === 'objid' && state.args) - return this._encodeObjid(data, state.reverseArgs[0], state.args[1]); - else if (tag === 'objid') - return this._encodeObjid(data, null, null); - else if (tag === 'gentime' || tag === 'utctime') - return this._encodeTime(data, tag); - else if (tag === 'null_') - return this._encodeNull(); - else if (tag === 'int' || tag === 'enum') - return this._encodeInt(data, state.args && state.reverseArgs[0]); - else if (tag === 'bool') - return this._encodeBool(data); - else if (tag === 'objDesc') - return this._encodeStr(data, tag); - else - throw new Error('Unsupported tag: ' + tag); -}; +}).call(this)}).call(this,{"isBuffer":require("../../../../../../is-buffer/index.js")}) +},{"../../../../../../is-buffer/index.js":351,"./converter":16}],43:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BIP32Factory = void 0; +const crypto = require("./crypto"); +const testecc_1 = require("./testecc"); +const base_1 = require("@scure/base"); +const sha256_1 = require("@noble/hashes/sha256"); +const typeforce = require('typeforce'); +const wif = require('wif'); +const _bs58check = (0, base_1.base58check)(sha256_1.sha256); +const bs58check = { + encode: (data) => _bs58check.encode(Uint8Array.from(data)), + decode: (str) => Buffer.from(_bs58check.decode(str)), +}; +function BIP32Factory(ecc) { + (0, testecc_1.testEcc)(ecc); + const UINT256_TYPE = typeforce.BufferN(32); + const NETWORK_TYPE = typeforce.compile({ + wif: typeforce.UInt8, + bip32: { + public: typeforce.UInt32, + private: typeforce.UInt32, + }, + }); + const BITCOIN = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'bc', + bip32: { + public: 0x0488b21e, + private: 0x0488ade4, + }, + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80, + }; + const HIGHEST_BIT = 0x80000000; + const UINT31_MAX = Math.pow(2, 31) - 1; + function BIP32Path(value) { + return (typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null); + } + function UInt31(value) { + return typeforce.UInt32(value) && value <= UINT31_MAX; + } + function toXOnly(pubKey) { + return pubKey.length === 32 ? pubKey : pubKey.slice(1, 33); + } + class Bip32Signer { + constructor(__D, __Q) { + this.__D = __D; + this.__Q = __Q; + this.lowR = false; + } + get publicKey() { + if (this.__Q === undefined) + this.__Q = Buffer.from(ecc.pointFromScalar(this.__D, true)); + return this.__Q; + } + get privateKey() { + return this.__D; + } + sign(hash, lowR) { + if (!this.privateKey) + throw new Error('Missing private key'); + if (lowR === undefined) + lowR = this.lowR; + if (lowR === false) { + return Buffer.from(ecc.sign(hash, this.privateKey)); + } + else { + let sig = Buffer.from(ecc.sign(hash, this.privateKey)); + const extraData = Buffer.alloc(32, 0); + let counter = 0; + // if first try is lowR, skip the loop + // for second try and on, add extra entropy counting up + while (sig[0] > 0x7f) { + counter++; + extraData.writeUIntLE(counter, 0, 6); + sig = Buffer.from(ecc.sign(hash, this.privateKey, extraData)); + } + return sig; + } + } + signSchnorr(hash) { + if (!this.privateKey) + throw new Error('Missing private key'); + if (!ecc.signSchnorr) + throw new Error('signSchnorr not supported by ecc library'); + return Buffer.from(ecc.signSchnorr(hash, this.privateKey)); + } + verify(hash, signature) { + return ecc.verify(hash, this.publicKey, signature); + } + verifySchnorr(hash, signature) { + if (!ecc.verifySchnorr) + throw new Error('verifySchnorr not supported by ecc library'); + return ecc.verifySchnorr(hash, this.publicKey.subarray(1, 33), signature); + } + } + class BIP32 extends Bip32Signer { + constructor(__D, __Q, chainCode, network, __DEPTH = 0, __INDEX = 0, __PARENT_FINGERPRINT = 0x00000000) { + super(__D, __Q); + this.chainCode = chainCode; + this.network = network; + this.__DEPTH = __DEPTH; + this.__INDEX = __INDEX; + this.__PARENT_FINGERPRINT = __PARENT_FINGERPRINT; + typeforce(NETWORK_TYPE, network); + } + get depth() { + return this.__DEPTH; + } + get index() { + return this.__INDEX; + } + get parentFingerprint() { + return this.__PARENT_FINGERPRINT; + } + get identifier() { + return crypto.hash160(this.publicKey); + } + get fingerprint() { + return this.identifier.slice(0, 4); + } + get compressed() { + return true; + } + // Private === not neutered + // Public === neutered + isNeutered() { + return this.__D === undefined; + } + neutered() { + return fromPublicKeyLocal(this.publicKey, this.chainCode, this.network, this.depth, this.index, this.parentFingerprint); + } + toBase58() { + const network = this.network; + const version = !this.isNeutered() + ? network.bip32.private + : network.bip32.public; + const buffer = Buffer.allocUnsafe(78); + // 4 bytes: version bytes + buffer.writeUInt32BE(version, 0); + // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... + buffer.writeUInt8(this.depth, 4); + // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) + buffer.writeUInt32BE(this.parentFingerprint, 5); + // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. + // This is encoded in big endian. (0x00000000 if master key) + buffer.writeUInt32BE(this.index, 9); + // 32 bytes: the chain code + this.chainCode.copy(buffer, 13); + // 33 bytes: the public key or private key data + if (!this.isNeutered()) { + // 0x00 + k for private keys + buffer.writeUInt8(0, 45); + this.privateKey.copy(buffer, 46); + // 33 bytes: the public key + } + else { + // X9.62 encoding for public keys + this.publicKey.copy(buffer, 45); + } + return bs58check.encode(buffer); + } + toWIF() { + if (!this.privateKey) + throw new TypeError('Missing private key'); + return wif.encode(this.network.wif, this.privateKey, true); + } + // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions + derive(index) { + typeforce(typeforce.UInt32, index); + const isHardened = index >= HIGHEST_BIT; + const data = Buffer.allocUnsafe(37); + // Hardened child + if (isHardened) { + if (this.isNeutered()) + throw new TypeError('Missing private key for hardened child key'); + // data = 0x00 || ser256(kpar) || ser32(index) + data[0] = 0x00; + this.privateKey.copy(data, 1); + data.writeUInt32BE(index, 33); + // Normal child + } + else { + // data = serP(point(kpar)) || ser32(index) + // = serP(Kpar) || ser32(index) + this.publicKey.copy(data, 0); + data.writeUInt32BE(index, 33); + } + const I = crypto.hmacSHA512(this.chainCode, data); + const IL = I.slice(0, 32); + const IR = I.slice(32); + // if parse256(IL) >= n, proceed with the next value for i + if (!ecc.isPrivate(IL)) + return this.derive(index + 1); + // Private parent key -> private child key + let hd; + if (!this.isNeutered()) { + // ki = parse256(IL) + kpar (mod n) + const ki = Buffer.from(ecc.privateAdd(this.privateKey, IL)); + // In case ki == 0, proceed with the next value for i + if (ki == null) + return this.derive(index + 1); + hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); + // Public parent key -> public child key + } + else { + // Ki = point(parse256(IL)) + Kpar + // = G*IL + Kpar + const Ki = Buffer.from(ecc.pointAddScalar(this.publicKey, IL, true)); + // In case Ki is the point at infinity, proceed with the next value for i + if (Ki === null) + return this.derive(index + 1); + hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); + } + return hd; + } + deriveHardened(index) { + typeforce(UInt31, index); + // Only derives hardened private keys by default + return this.derive(index + HIGHEST_BIT); + } + derivePath(path) { + typeforce(BIP32Path, path); + let splitPath = path.split('/'); + if (splitPath[0] === 'm') { + if (this.parentFingerprint) + throw new TypeError('Expected master, got child'); + splitPath = splitPath.slice(1); + } + return splitPath.reduce((prevHd, indexStr) => { + let index; + if (indexStr.slice(-1) === `'`) { + index = parseInt(indexStr.slice(0, -1), 10); + return prevHd.deriveHardened(index); + } + else { + index = parseInt(indexStr, 10); + return prevHd.derive(index); + } + }, this); + } + tweak(t) { + if (this.privateKey) + return this.tweakFromPrivateKey(t); + return this.tweakFromPublicKey(t); + } + tweakFromPublicKey(t) { + const xOnlyPubKey = toXOnly(this.publicKey); + if (!ecc.xOnlyPointAddTweak) + throw new Error('xOnlyPointAddTweak not supported by ecc library'); + const tweakedPublicKey = ecc.xOnlyPointAddTweak(xOnlyPubKey, t); + if (!tweakedPublicKey || tweakedPublicKey.xOnlyPubkey === null) + throw new Error('Cannot tweak public key!'); + const parityByte = Buffer.from([ + tweakedPublicKey.parity === 0 ? 0x02 : 0x03, + ]); + const tweakedPublicKeyCompresed = Buffer.concat([ + parityByte, + tweakedPublicKey.xOnlyPubkey, + ]); + return new Bip32Signer(undefined, tweakedPublicKeyCompresed); + } + tweakFromPrivateKey(t) { + const hasOddY = this.publicKey[0] === 3 || + (this.publicKey[0] === 4 && (this.publicKey[64] & 1) === 1); + const privateKey = (() => { + if (!hasOddY) + return this.privateKey; + else if (!ecc.privateNegate) + throw new Error('privateNegate not supported by ecc library'); + else + return ecc.privateNegate(this.privateKey); + })(); + const tweakedPrivateKey = ecc.privateAdd(privateKey, t); + if (!tweakedPrivateKey) + throw new Error('Invalid tweaked private key!'); + return new Bip32Signer(Buffer.from(tweakedPrivateKey), undefined); + } + } + function fromBase58(inString, network) { + const buffer = bs58check.decode(inString); + if (buffer.length !== 78) + throw new TypeError('Invalid buffer length'); + network = network || BITCOIN; + // 4 bytes: version bytes + const version = buffer.readUInt32BE(0); + if (version !== network.bip32.private && version !== network.bip32.public) + throw new TypeError('Invalid network version'); + // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ... + const depth = buffer[4]; + // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) + const parentFingerprint = buffer.readUInt32BE(5); + if (depth === 0) { + if (parentFingerprint !== 0x00000000) + throw new TypeError('Invalid parent fingerprint'); + } + // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. + // This is encoded in MSB order. (0x00000000 if master key) + const index = buffer.readUInt32BE(9); + if (depth === 0 && index !== 0) + throw new TypeError('Invalid index'); + // 32 bytes: the chain code + const chainCode = buffer.slice(13, 45); + let hd; + // 33 bytes: private key data (0x00 + k) + if (version === network.bip32.private) { + if (buffer.readUInt8(45) !== 0x00) + throw new TypeError('Invalid private key'); + const k = buffer.slice(46, 78); + hd = fromPrivateKeyLocal(k, chainCode, network, depth, index, parentFingerprint); + // 33 bytes: public key data (0x02 + X or 0x03 + X) + } + else { + const X = buffer.slice(45, 78); + hd = fromPublicKeyLocal(X, chainCode, network, depth, index, parentFingerprint); + } + return hd; + } + function fromPrivateKey(privateKey, chainCode, network) { + return fromPrivateKeyLocal(privateKey, chainCode, network); + } + function fromPrivateKeyLocal(privateKey, chainCode, network, depth, index, parentFingerprint) { + typeforce({ + privateKey: UINT256_TYPE, + chainCode: UINT256_TYPE, + }, { privateKey, chainCode }); + network = network || BITCOIN; + if (!ecc.isPrivate(privateKey)) + throw new TypeError('Private key not in range [1, n)'); + return new BIP32(privateKey, undefined, chainCode, network, depth, index, parentFingerprint); + } + function fromPublicKey(publicKey, chainCode, network) { + return fromPublicKeyLocal(publicKey, chainCode, network); + } + function fromPublicKeyLocal(publicKey, chainCode, network, depth, index, parentFingerprint) { + typeforce({ + publicKey: typeforce.BufferN(33), + chainCode: UINT256_TYPE, + }, { publicKey, chainCode }); + network = network || BITCOIN; + // verify the X coordinate is a point on the curve + if (!ecc.isPoint(publicKey)) + throw new TypeError('Point is not on the curve'); + return new BIP32(undefined, publicKey, chainCode, network, depth, index, parentFingerprint); + } + function fromSeed(seed, network) { + typeforce(typeforce.Buffer, seed); + if (seed.length < 16) + throw new TypeError('Seed should be at least 128 bits'); + if (seed.length > 64) + throw new TypeError('Seed should be at most 512 bits'); + network = network || BITCOIN; + const I = crypto.hmacSHA512(Buffer.from('Bitcoin seed', 'utf8'), seed); + const IL = I.slice(0, 32); + const IR = I.slice(32); + return fromPrivateKey(IL, IR, network); + } + return { + fromSeed, + fromBase58, + fromPublicKey, + fromPrivateKey, + }; +} +exports.BIP32Factory = BIP32Factory; -Node.prototype._isNumstr = function isNumstr(str) { - return /^[0-9 ]*$/.test(str); -}; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./crypto":44,"./testecc":46,"@noble/hashes/sha256":89,"@scure/base":93,"buffer":249,"typeforce":521,"wif":530}],44:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hmacSHA512 = exports.hash160 = void 0; +const hmac_1 = require("@noble/hashes/hmac"); +const ripemd160_1 = require("@noble/hashes/ripemd160"); +const sha256_1 = require("@noble/hashes/sha256"); +const sha512_1 = require("@noble/hashes/sha512"); +function hash160(buffer) { + const sha256Hash = (0, sha256_1.sha256)(Uint8Array.from(buffer)); + return Buffer.from((0, ripemd160_1.ripemd160)(sha256Hash)); +} +exports.hash160 = hash160; +function hmacSHA512(key, data) { + return Buffer.from((0, hmac_1.hmac)(sha512_1.sha512, key, data)); +} +exports.hmacSHA512 = hmacSHA512; -Node.prototype._isPrintstr = function isPrintstr(str) { - return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str); -}; +}).call(this)}).call(this,require("buffer").Buffer) +},{"@noble/hashes/hmac":86,"@noble/hashes/ripemd160":87,"@noble/hashes/sha256":89,"@noble/hashes/sha512":90,"buffer":249}],45:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BIP32Factory = exports.default = void 0; +var bip32_1 = require("./bip32"); +Object.defineProperty(exports, "default", { enumerable: true, get: function () { return bip32_1.BIP32Factory; } }); +Object.defineProperty(exports, "BIP32Factory", { enumerable: true, get: function () { return bip32_1.BIP32Factory; } }); -},{"../base/buffer":9,"../base/reporter":12,"minimalistic-assert":238}],12:[function(require,module,exports){ +},{"./bip32":43}],46:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.testEcc = void 0; +const h = (hex) => Buffer.from(hex, 'hex'); +function testEcc(ecc) { + assert(ecc.isPoint(h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'))); + assert(!ecc.isPoint(h('030000000000000000000000000000000000000000000000000000000000000005'))); + assert(ecc.isPrivate(h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'))); + // order - 1 + assert(ecc.isPrivate(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'))); + // 0 + assert(!ecc.isPrivate(h('0000000000000000000000000000000000000000000000000000000000000000'))); + // order + assert(!ecc.isPrivate(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'))); + // order + 1 + assert(!ecc.isPrivate(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142'))); + assert(Buffer.from(ecc.pointFromScalar(h('b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af'))).equals(h('02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99'))); + if (ecc.xOnlyPointAddTweak) { + assert(ecc.xOnlyPointAddTweak(h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140')) === null); + let xOnlyRes = ecc.xOnlyPointAddTweak(h('1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b'), h('a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac')); + assert(Buffer.from(xOnlyRes.xOnlyPubkey).equals(h('e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf')) && xOnlyRes.parity === 1); + xOnlyRes = ecc.xOnlyPointAddTweak(h('2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991'), h('823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47')); + } + assert(Buffer.from(ecc.pointAddScalar(h('0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), h('0000000000000000000000000000000000000000000000000000000000000003'))).equals(h('02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5'))); + assert(Buffer.from(ecc.privateAdd(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e'), h('0000000000000000000000000000000000000000000000000000000000000002'))).equals(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'))); + if (ecc.privateNegate) { + assert(Buffer.from(ecc.privateNegate(h('0000000000000000000000000000000000000000000000000000000000000001'))).equals(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'))); + assert(Buffer.from(ecc.privateNegate(h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e'))).equals(h('0000000000000000000000000000000000000000000000000000000000000003'))); + assert(Buffer.from(ecc.privateNegate(h('b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af'))).equals(h('4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792'))); + } + assert(Buffer.from(ecc.sign(h('5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed'), h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'))).equals(h('54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5'))); + assert(ecc.verify(h('5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed'), h('0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), h('54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5'))); + if (ecc.signSchnorr) { + assert(Buffer.from(ecc.signSchnorr(h('7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c'), h('c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9'), h('c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906'))).equals(h('5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7'))); + } + if (ecc.verifySchnorr) { + assert(ecc.verifySchnorr(h('7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c'), h('dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8'), h('5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7'))); + } +} +exports.testEcc = testEcc; +function assert(bool) { + if (!bool) + throw new Error('ecc library invalid'); +} + +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],47:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -const inherits = require('inherits'); - -function Reporter(options) { - this._reporterState = { - obj: null, - path: [], - options: options || {}, - errors: [] - }; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.toOutputScript = + exports.fromOutputScript = + exports.toBech32 = + exports.toBase58Check = + exports.fromBech32 = + exports.fromBase58Check = + void 0; +const networks = require('./networks'); +const payments = require('./payments'); +const bscript = require('./script'); +const types_1 = require('./types'); +const bech32_1 = require('bech32'); +const bs58check = require('bs58check'); +const FUTURE_SEGWIT_MAX_SIZE = 40; +const FUTURE_SEGWIT_MIN_SIZE = 2; +const FUTURE_SEGWIT_MAX_VERSION = 16; +const FUTURE_SEGWIT_MIN_VERSION = 2; +const FUTURE_SEGWIT_VERSION_DIFF = 0x50; +const FUTURE_SEGWIT_VERSION_WARNING = + 'WARNING: Sending to a future segwit version address can lead to loss of funds. ' + + 'End users MUST be warned carefully in the GUI and asked if they wish to proceed ' + + 'with caution. Wallets should verify the segwit version from the output of fromBech32, ' + + 'then decide when it is safe to use which version of segwit.'; +function _toFutureSegwitAddress(output, network) { + const data = output.slice(2); + if ( + data.length < FUTURE_SEGWIT_MIN_SIZE || + data.length > FUTURE_SEGWIT_MAX_SIZE + ) + throw new TypeError('Invalid program length for segwit address'); + const version = output[0] - FUTURE_SEGWIT_VERSION_DIFF; + if ( + version < FUTURE_SEGWIT_MIN_VERSION || + version > FUTURE_SEGWIT_MAX_VERSION + ) + throw new TypeError('Invalid version for segwit address'); + if (output[1] !== data.length) + throw new TypeError('Invalid script for segwit address'); + console.warn(FUTURE_SEGWIT_VERSION_WARNING); + return toBech32(data, version, network.bech32); } -exports.Reporter = Reporter; - -Reporter.prototype.isError = function isError(obj) { - return obj instanceof ReporterError; -}; - -Reporter.prototype.save = function save() { - const state = this._reporterState; - - return { obj: state.obj, pathLen: state.path.length }; -}; - -Reporter.prototype.restore = function restore(data) { - const state = this._reporterState; - - state.obj = data.obj; - state.path = state.path.slice(0, data.pathLen); -}; - -Reporter.prototype.enterKey = function enterKey(key) { - return this._reporterState.path.push(key); -}; - -Reporter.prototype.exitKey = function exitKey(index) { - const state = this._reporterState; - - state.path = state.path.slice(0, index - 1); -}; - -Reporter.prototype.leaveKey = function leaveKey(index, key, value) { - const state = this._reporterState; - - this.exitKey(index); - if (state.obj !== null) - state.obj[key] = value; -}; - -Reporter.prototype.path = function path() { - return this._reporterState.path.join('/'); -}; - -Reporter.prototype.enterObject = function enterObject() { - const state = this._reporterState; - - const prev = state.obj; - state.obj = {}; - return prev; -}; - -Reporter.prototype.leaveObject = function leaveObject(prev) { - const state = this._reporterState; - - const now = state.obj; - state.obj = prev; - return now; -}; - -Reporter.prototype.error = function error(msg) { - let err; - const state = this._reporterState; - - const inherited = msg instanceof ReporterError; - if (inherited) { - err = msg; +/** + * decode address with base58 specification, return address version and address hash if valid + */ +function fromBase58Check(address) { + const payload = Buffer.from(bs58check.decode(address)); + // TODO: 4.0.0, move to "toOutputScript" + if (payload.length < 21) throw new TypeError(address + ' is too short'); + if (payload.length > 21) throw new TypeError(address + ' is too long'); + const version = payload.readUInt8(0); + const hash = payload.slice(1); + return { version, hash }; +} +exports.fromBase58Check = fromBase58Check; +/** + * decode address with bech32 specification, return address version、address prefix and address data if valid + */ +function fromBech32(address) { + let result; + let version; + try { + result = bech32_1.bech32.decode(address); + } catch (e) {} + if (result) { + version = result.words[0]; + if (version !== 0) throw new TypeError(address + ' uses wrong encoding'); } else { - err = new ReporterError(state.path.map(function(elem) { - return '[' + JSON.stringify(elem) + ']'; - }).join(''), msg.message || msg, msg.stack); + result = bech32_1.bech32m.decode(address); + version = result.words[0]; + if (version === 0) throw new TypeError(address + ' uses wrong encoding'); } - - if (!state.options.partial) - throw err; - - if (!inherited) - state.errors.push(err); - - return err; -}; - -Reporter.prototype.wrapResult = function wrapResult(result) { - const state = this._reporterState; - if (!state.options.partial) - return result; - + const data = bech32_1.bech32.fromWords(result.words.slice(1)); return { - result: this.isError(result) ? null : result, - errors: state.errors + version, + prefix: result.prefix, + data: Buffer.from(data), }; -}; - -function ReporterError(path, msg) { - this.path = path; - this.rethrow(msg); } -inherits(ReporterError, Error); - -ReporterError.prototype.rethrow = function rethrow(msg) { - this.message = msg + ' at: ' + (this.path || '(shallow)'); - if (Error.captureStackTrace) - Error.captureStackTrace(this, ReporterError); - - if (!this.stack) { +exports.fromBech32 = fromBech32; +/** + * encode address hash to base58 address with version + */ +function toBase58Check(hash, version) { + (0, types_1.typeforce)( + (0, types_1.tuple)(types_1.Hash160bit, types_1.UInt8), + arguments, + ); + const payload = Buffer.allocUnsafe(21); + payload.writeUInt8(version, 0); + hash.copy(payload, 1); + return bs58check.encode(payload); +} +exports.toBase58Check = toBase58Check; +/** + * encode address hash to bech32 address with version and prefix + */ +function toBech32(data, version, prefix) { + const words = bech32_1.bech32.toWords(data); + words.unshift(version); + return version === 0 + ? bech32_1.bech32.encode(prefix, words) + : bech32_1.bech32m.encode(prefix, words); +} +exports.toBech32 = toBech32; +/** + * decode address from output script with network, return address if matched + */ +function fromOutputScript(output, network) { + // TODO: Network + network = network || networks.bitcoin; + try { + return payments.p2pkh({ output, network }).address; + } catch (e) {} + try { + return payments.p2sh({ output, network }).address; + } catch (e) {} + try { + return payments.p2wpkh({ output, network }).address; + } catch (e) {} + try { + return payments.p2wsh({ output, network }).address; + } catch (e) {} + try { + return payments.p2tr({ output, network }).address; + } catch (e) {} + try { + return _toFutureSegwitAddress(output, network); + } catch (e) {} + throw new Error(bscript.toASM(output) + ' has no matching Address'); +} +exports.fromOutputScript = fromOutputScript; +/** + * encodes address to output script with network, return output script if address matched + */ +function toOutputScript(address, network) { + network = network || networks.bitcoin; + let decodeBase58; + let decodeBech32; + try { + decodeBase58 = fromBase58Check(address); + } catch (e) {} + if (decodeBase58) { + if (decodeBase58.version === network.pubKeyHash) + return payments.p2pkh({ hash: decodeBase58.hash }).output; + if (decodeBase58.version === network.scriptHash) + return payments.p2sh({ hash: decodeBase58.hash }).output; + } else { try { - // IE only adds stack when thrown - throw new Error(this.message); - } catch (e) { - this.stack = e.stack; + decodeBech32 = fromBech32(address); + } catch (e) {} + if (decodeBech32) { + if (decodeBech32.prefix !== network.bech32) + throw new Error(address + ' has an invalid prefix'); + if (decodeBech32.version === 0) { + if (decodeBech32.data.length === 20) + return payments.p2wpkh({ hash: decodeBech32.data }).output; + if (decodeBech32.data.length === 32) + return payments.p2wsh({ hash: decodeBech32.data }).output; + } else if (decodeBech32.version === 1) { + if (decodeBech32.data.length === 32) + return payments.p2tr({ pubkey: decodeBech32.data }).output; + } else if ( + decodeBech32.version >= FUTURE_SEGWIT_MIN_VERSION && + decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION && + decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE && + decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE + ) { + console.warn(FUTURE_SEGWIT_VERSION_WARNING); + return bscript.compile([ + decodeBech32.version + FUTURE_SEGWIT_VERSION_DIFF, + decodeBech32.data, + ]); + } } } - return this; -}; + throw new Error(address + ' has no matching Script'); +} +exports.toOutputScript = toOutputScript; -},{"inherits":230}],13:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./networks":55,"./payments":59,"./script":72,"./types":76,"bech32":120,"bs58check":79,"buffer":249}],48:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -// Helper -function reverse(map) { - const res = {}; - - Object.keys(map).forEach(function(key) { - // Convert key to integer if it is stringified - if ((key | 0) == key) - key = key | 0; - - const value = map[key]; - res[value] = key; - }); - - return res; +// Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki +// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] +// NOTE: SIGHASH byte ignored AND restricted, truncate before use +Object.defineProperty(exports, '__esModule', { value: true }); +exports.encode = exports.decode = exports.check = void 0; +function check(buffer) { + if (buffer.length < 8) return false; + if (buffer.length > 72) return false; + if (buffer[0] !== 0x30) return false; + if (buffer[1] !== buffer.length - 2) return false; + if (buffer[2] !== 0x02) return false; + const lenR = buffer[3]; + if (lenR === 0) return false; + if (5 + lenR >= buffer.length) return false; + if (buffer[4 + lenR] !== 0x02) return false; + const lenS = buffer[5 + lenR]; + if (lenS === 0) return false; + if (6 + lenR + lenS !== buffer.length) return false; + if (buffer[4] & 0x80) return false; + if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5] & 0x80)) return false; + if (buffer[lenR + 6] & 0x80) return false; + if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80)) + return false; + return true; } - -exports.tagClass = { - 0: 'universal', - 1: 'application', - 2: 'context', - 3: 'private' -}; -exports.tagClassByName = reverse(exports.tagClass); - -exports.tag = { - 0x00: 'end', - 0x01: 'bool', - 0x02: 'int', - 0x03: 'bitstr', - 0x04: 'octstr', - 0x05: 'null_', - 0x06: 'objid', - 0x07: 'objDesc', - 0x08: 'external', - 0x09: 'real', - 0x0a: 'enum', - 0x0b: 'embed', - 0x0c: 'utf8str', - 0x0d: 'relativeOid', - 0x10: 'seq', - 0x11: 'set', - 0x12: 'numstr', - 0x13: 'printstr', - 0x14: 't61str', - 0x15: 'videostr', - 0x16: 'ia5str', - 0x17: 'utctime', - 0x18: 'gentime', - 0x19: 'graphstr', - 0x1a: 'iso646str', - 0x1b: 'genstr', - 0x1c: 'unistr', - 0x1d: 'charstr', - 0x1e: 'bmpstr' -}; -exports.tagByName = reverse(exports.tag); - -},{}],14:[function(require,module,exports){ -'use strict'; - -const constants = exports; - -// Helper -constants._reverse = function reverse(map) { - const res = {}; - - Object.keys(map).forEach(function(key) { - // Convert key to integer if it is stringified - if ((key | 0) == key) - key = key | 0; - - const value = map[key]; - res[value] = key; - }); - - return res; -}; - -constants.der = require('./der'); - -},{"./der":13}],15:[function(require,module,exports){ -'use strict'; - -const inherits = require('inherits'); - -const bignum = require('bn.js'); -const DecoderBuffer = require('../base/buffer').DecoderBuffer; -const Node = require('../base/node'); - -// Import DER constants -const der = require('../constants/der'); - -function DERDecoder(entity) { - this.enc = 'der'; - this.name = entity.name; - this.entity = entity; - - // Construct base tree - this.tree = new DERNode(); - this.tree._init(entity.body); +exports.check = check; +function decode(buffer) { + if (buffer.length < 8) throw new Error('DER sequence length is too short'); + if (buffer.length > 72) throw new Error('DER sequence length is too long'); + if (buffer[0] !== 0x30) throw new Error('Expected DER sequence'); + if (buffer[1] !== buffer.length - 2) + throw new Error('DER sequence length is invalid'); + if (buffer[2] !== 0x02) throw new Error('Expected DER integer'); + const lenR = buffer[3]; + if (lenR === 0) throw new Error('R length is zero'); + if (5 + lenR >= buffer.length) throw new Error('R length is too long'); + if (buffer[4 + lenR] !== 0x02) throw new Error('Expected DER integer (2)'); + const lenS = buffer[5 + lenR]; + if (lenS === 0) throw new Error('S length is zero'); + if (6 + lenR + lenS !== buffer.length) throw new Error('S length is invalid'); + if (buffer[4] & 0x80) throw new Error('R value is negative'); + if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5] & 0x80)) + throw new Error('R value excessively padded'); + if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative'); + if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80)) + throw new Error('S value excessively padded'); + // non-BIP66 - extract R, S values + return { + r: buffer.slice(4, 4 + lenR), + s: buffer.slice(6 + lenR), + }; } -module.exports = DERDecoder; - -DERDecoder.prototype.decode = function decode(data, options) { - if (!DecoderBuffer.isDecoderBuffer(data)) { - data = new DecoderBuffer(data, options); - } - - return this.tree._decode(data, options); -}; - -// Tree methods - -function DERNode(parent) { - Node.call(this, 'der', parent); +exports.decode = decode; +/* + * Expects r and s to be positive DER integers. + * + * The DER format uses the most significant bit as a sign bit (& 0x80). + * If the significant bit is set AND the integer is positive, a 0x00 is prepended. + * + * Examples: + * + * 0 => 0x00 + * 1 => 0x01 + * -1 => 0xff + * 127 => 0x7f + * -127 => 0x81 + * 128 => 0x0080 + * -128 => 0x80 + * 255 => 0x00ff + * -255 => 0xff01 + * 16300 => 0x3fac + * -16300 => 0xc054 + * 62300 => 0x00f35c + * -62300 => 0xff0ca4 + */ +function encode(r, s) { + const lenR = r.length; + const lenS = s.length; + if (lenR === 0) throw new Error('R length is zero'); + if (lenS === 0) throw new Error('S length is zero'); + if (lenR > 33) throw new Error('R length is too long'); + if (lenS > 33) throw new Error('S length is too long'); + if (r[0] & 0x80) throw new Error('R value is negative'); + if (s[0] & 0x80) throw new Error('S value is negative'); + if (lenR > 1 && r[0] === 0x00 && !(r[1] & 0x80)) + throw new Error('R value excessively padded'); + if (lenS > 1 && s[0] === 0x00 && !(s[1] & 0x80)) + throw new Error('S value excessively padded'); + const signature = Buffer.allocUnsafe(6 + lenR + lenS); + // 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] + signature[0] = 0x30; + signature[1] = signature.length - 2; + signature[2] = 0x02; + signature[3] = r.length; + r.copy(signature, 4); + signature[4 + lenR] = 0x02; + signature[5 + lenR] = s.length; + s.copy(signature, 6 + lenR); + return signature; } -inherits(DERNode, Node); - -DERNode.prototype._peekTag = function peekTag(buffer, tag, any) { - if (buffer.isEmpty()) - return false; - - const state = buffer.save(); - const decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"'); - if (buffer.isError(decodedTag)) - return decodedTag; - - buffer.restore(state); - - return decodedTag.tag === tag || decodedTag.tagStr === tag || - (decodedTag.tagStr + 'of') === tag || any; -}; - -DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) { - const decodedTag = derDecodeTag(buffer, - 'Failed to decode tag of "' + tag + '"'); - if (buffer.isError(decodedTag)) - return decodedTag; - - let len = derDecodeLen(buffer, - decodedTag.primitive, - 'Failed to get length of "' + tag + '"'); - - // Failure - if (buffer.isError(len)) - return len; +exports.encode = encode; - if (!any && - decodedTag.tag !== tag && - decodedTag.tagStr !== tag && - decodedTag.tagStr + 'of' !== tag) { - return buffer.error('Failed to match tag: "' + tag + '"'); +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],49:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.Block = void 0; +const bufferutils_1 = require('./bufferutils'); +const bcrypto = require('./crypto'); +const merkle_1 = require('./merkle'); +const transaction_1 = require('./transaction'); +const types = require('./types'); +const { typeforce } = types; +const errorMerkleNoTxes = new TypeError( + 'Cannot compute merkle root for zero transactions', +); +const errorWitnessNotSegwit = new TypeError( + 'Cannot compute witness commit for non-segwit block', +); +class Block { + constructor() { + this.version = 1; + this.prevHash = undefined; + this.merkleRoot = undefined; + this.timestamp = 0; + this.witnessCommit = undefined; + this.bits = 0; + this.nonce = 0; + this.transactions = undefined; } - - if (decodedTag.primitive || len !== null) - return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); - - // Indefinite length... find END tag - const state = buffer.save(); - const res = this._skipUntilEnd( - buffer, - 'Failed to skip indefinite length body: "' + this.tag + '"'); - if (buffer.isError(res)) - return res; - - len = buffer.offset - state.offset; - buffer.restore(state); - return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); -}; - -DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) { - for (;;) { - const tag = derDecodeTag(buffer, fail); - if (buffer.isError(tag)) - return tag; - const len = derDecodeLen(buffer, tag.primitive, fail); - if (buffer.isError(len)) - return len; - - let res; - if (tag.primitive || len !== null) - res = buffer.skip(len); - else - res = this._skipUntilEnd(buffer, fail); - - // Failure - if (buffer.isError(res)) - return res; - - if (tag.tagStr === 'end') - break; + static fromBuffer(buffer) { + if (buffer.length < 80) throw new Error('Buffer too small (< 80 bytes)'); + const bufferReader = new bufferutils_1.BufferReader(buffer); + const block = new Block(); + block.version = bufferReader.readInt32(); + block.prevHash = bufferReader.readSlice(32); + block.merkleRoot = bufferReader.readSlice(32); + block.timestamp = bufferReader.readUInt32(); + block.bits = bufferReader.readUInt32(); + block.nonce = bufferReader.readUInt32(); + if (buffer.length === 80) return block; + const readTransaction = () => { + const tx = transaction_1.Transaction.fromBuffer( + bufferReader.buffer.slice(bufferReader.offset), + true, + ); + bufferReader.offset += tx.byteLength(); + return tx; + }; + const nTransactions = bufferReader.readVarInt(); + block.transactions = []; + for (let i = 0; i < nTransactions; ++i) { + const tx = readTransaction(); + block.transactions.push(tx); + } + const witnessCommit = block.getWitnessCommit(); + // This Block contains a witness commit + if (witnessCommit) block.witnessCommit = witnessCommit; + return block; } -}; - -DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, - options) { - const result = []; - while (!buffer.isEmpty()) { - const possibleEnd = this._peekTag(buffer, 'end'); - if (buffer.isError(possibleEnd)) - return possibleEnd; - - const res = decoder.decode(buffer, 'der', options); - if (buffer.isError(res) && possibleEnd) - break; - result.push(res); + static fromHex(hex) { + return Block.fromBuffer(Buffer.from(hex, 'hex')); } - return result; -}; - -DERNode.prototype._decodeStr = function decodeStr(buffer, tag) { - if (tag === 'bitstr') { - const unused = buffer.readUInt8(); - if (buffer.isError(unused)) - return unused; - return { unused: unused, data: buffer.raw() }; - } else if (tag === 'bmpstr') { - const raw = buffer.raw(); - if (raw.length % 2 === 1) - return buffer.error('Decoding of string type: bmpstr length mismatch'); - - let str = ''; - for (let i = 0; i < raw.length / 2; i++) { - str += String.fromCharCode(raw.readUInt16BE(i * 2)); - } - return str; - } else if (tag === 'numstr') { - const numstr = buffer.raw().toString('ascii'); - if (!this._isNumstr(numstr)) { - return buffer.error('Decoding of string type: ' + - 'numstr unsupported characters'); - } - return numstr; - } else if (tag === 'octstr') { - return buffer.raw(); - } else if (tag === 'objDesc') { - return buffer.raw(); - } else if (tag === 'printstr') { - const printstr = buffer.raw().toString('ascii'); - if (!this._isPrintstr(printstr)) { - return buffer.error('Decoding of string type: ' + - 'printstr unsupported characters'); - } - return printstr; - } else if (/str$/.test(tag)) { - return buffer.raw().toString(); - } else { - return buffer.error('Decoding of string type: ' + tag + ' unsupported'); + static calculateTarget(bits) { + const exponent = ((bits & 0xff000000) >> 24) - 3; + const mantissa = bits & 0x007fffff; + const target = Buffer.alloc(32, 0); + target.writeUIntBE(mantissa, 29 - exponent, 3); + return target; } -}; - -DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) { - let result; - const identifiers = []; - let ident = 0; - let subident = 0; - while (!buffer.isEmpty()) { - subident = buffer.readUInt8(); - ident <<= 7; - ident |= subident & 0x7f; - if ((subident & 0x80) === 0) { - identifiers.push(ident); - ident = 0; - } + static calculateMerkleRoot(transactions, forWitness) { + typeforce([{ getHash: types.Function }], transactions); + if (transactions.length === 0) throw errorMerkleNoTxes; + if (forWitness && !txesHaveWitnessCommit(transactions)) + throw errorWitnessNotSegwit; + const hashes = transactions.map(transaction => + transaction.getHash(forWitness), + ); + const rootHash = (0, merkle_1.fastMerkleRoot)(hashes, bcrypto.hash256); + return forWitness + ? bcrypto.hash256( + Buffer.concat([rootHash, transactions[0].ins[0].witness[0]]), + ) + : rootHash; } - if (subident & 0x80) - identifiers.push(ident); - - const first = (identifiers[0] / 40) | 0; - const second = identifiers[0] % 40; - - if (relative) - result = identifiers; - else - result = [first, second].concat(identifiers.slice(1)); - - if (values) { - let tmp = values[result.join(' ')]; - if (tmp === undefined) - tmp = values[result.join('.')]; - if (tmp !== undefined) - result = tmp; + getWitnessCommit() { + if (!txesHaveWitnessCommit(this.transactions)) return null; + // The merkle root for the witness data is in an OP_RETURN output. + // There is no rule for the index of the output, so use filter to find it. + // The root is prepended with 0xaa21a9ed so check for 0x6a24aa21a9ed + // If multiple commits are found, the output with highest index is assumed. + const witnessCommits = this.transactions[0].outs + .filter(out => + out.script.slice(0, 6).equals(Buffer.from('6a24aa21a9ed', 'hex')), + ) + .map(out => out.script.slice(6, 38)); + if (witnessCommits.length === 0) return null; + // Use the commit with the highest output (should only be one though) + const result = witnessCommits[witnessCommits.length - 1]; + if (!(result instanceof Buffer && result.length === 32)) return null; + return result; } - - return result; -}; - -DERNode.prototype._decodeTime = function decodeTime(buffer, tag) { - const str = buffer.raw().toString(); - - let year; - let mon; - let day; - let hour; - let min; - let sec; - if (tag === 'gentime') { - year = str.slice(0, 4) | 0; - mon = str.slice(4, 6) | 0; - day = str.slice(6, 8) | 0; - hour = str.slice(8, 10) | 0; - min = str.slice(10, 12) | 0; - sec = str.slice(12, 14) | 0; - } else if (tag === 'utctime') { - year = str.slice(0, 2) | 0; - mon = str.slice(2, 4) | 0; - day = str.slice(4, 6) | 0; - hour = str.slice(6, 8) | 0; - min = str.slice(8, 10) | 0; - sec = str.slice(10, 12) | 0; - if (year < 70) - year = 2000 + year; - else - year = 1900 + year; - } else { - return buffer.error('Decoding ' + tag + ' time is not supported yet'); + hasWitnessCommit() { + if ( + this.witnessCommit instanceof Buffer && + this.witnessCommit.length === 32 + ) + return true; + if (this.getWitnessCommit() !== null) return true; + return false; } - - return Date.UTC(year, mon - 1, day, hour, min, sec, 0); -}; - -DERNode.prototype._decodeNull = function decodeNull() { - return null; -}; - -DERNode.prototype._decodeBool = function decodeBool(buffer) { - const res = buffer.readUInt8(); - if (buffer.isError(res)) - return res; - else - return res !== 0; -}; - -DERNode.prototype._decodeInt = function decodeInt(buffer, values) { - // Bigint, return as it is (assume big endian) - const raw = buffer.raw(); - let res = new bignum(raw); - - if (values) - res = values[res.toString(10)] || res; - - return res; -}; - -DERNode.prototype._use = function use(entity, obj) { - if (typeof entity === 'function') - entity = entity(obj); - return entity._getDecoder('der').tree; -}; - -// Utility methods - -function derDecodeTag(buf, fail) { - let tag = buf.readUInt8(fail); - if (buf.isError(tag)) - return tag; - - const cls = der.tagClass[tag >> 6]; - const primitive = (tag & 0x20) === 0; - - // Multi-octet tag - load - if ((tag & 0x1f) === 0x1f) { - let oct = tag; - tag = 0; - while ((oct & 0x80) === 0x80) { - oct = buf.readUInt8(fail); - if (buf.isError(oct)) - return oct; - - tag <<= 7; - tag |= oct & 0x7f; - } - } else { - tag &= 0x1f; + hasWitness() { + return anyTxHasWitness(this.transactions); } - const tagStr = der.tag[tag]; - - return { - cls: cls, - primitive: primitive, - tag: tag, - tagStr: tagStr - }; -} - -function derDecodeLen(buf, primitive, fail) { - let len = buf.readUInt8(fail); - if (buf.isError(len)) - return len; - - // Indefinite form - if (!primitive && len === 0x80) - return null; - - // Definite form - if ((len & 0x80) === 0) { - // Short form - return len; + weight() { + const base = this.byteLength(false, false); + const total = this.byteLength(false, true); + return base * 3 + total; } - - // Long form - const num = len & 0x7f; - if (num > 4) - return buf.error('length octect is too long'); - - len = 0; - for (let i = 0; i < num; i++) { - len <<= 8; - const j = buf.readUInt8(fail); - if (buf.isError(j)) - return j; - len |= j; + byteLength(headersOnly, allowWitness = true) { + if (headersOnly || !this.transactions) return 80; + return ( + 80 + + bufferutils_1.varuint.encodingLength(this.transactions.length) + + this.transactions.reduce((a, x) => a + x.byteLength(allowWitness), 0) + ); } - - return len; -} - -},{"../base/buffer":9,"../base/node":11,"../constants/der":13,"bn.js":103,"inherits":230}],16:[function(require,module,exports){ -'use strict'; - -const decoders = exports; - -decoders.der = require('./der'); -decoders.pem = require('./pem'); - -},{"./der":15,"./pem":17}],17:[function(require,module,exports){ -'use strict'; - -const inherits = require('inherits'); -const Buffer = require('safer-buffer').Buffer; - -const DERDecoder = require('./der'); - -function PEMDecoder(entity) { - DERDecoder.call(this, entity); - this.enc = 'pem'; -} -inherits(PEMDecoder, DERDecoder); -module.exports = PEMDecoder; - -PEMDecoder.prototype.decode = function decode(data, options) { - const lines = data.toString().split(/[\r\n]+/g); - - const label = options.label.toUpperCase(); - - const re = /^-----(BEGIN|END) ([^-]+)-----$/; - let start = -1; - let end = -1; - for (let i = 0; i < lines.length; i++) { - const match = lines[i].match(re); - if (match === null) - continue; - - if (match[2] !== label) - continue; - - if (start === -1) { - if (match[1] !== 'BEGIN') - break; - start = i; - } else { - if (match[1] !== 'END') - break; - end = i; - break; - } + getHash() { + return bcrypto.hash256(this.toBuffer(true)); } - if (start === -1 || end === -1) - throw new Error('PEM section not found for: ' + label); - - const base64 = lines.slice(start + 1, end).join(''); - // Remove excessive symbols - base64.replace(/[^a-z0-9+/=]+/gi, ''); - - const input = Buffer.from(base64, 'base64'); - return DERDecoder.prototype.decode.call(this, input, options); -}; + getId() { + return (0, bufferutils_1.reverseBuffer)(this.getHash()).toString('hex'); + } + getUTCDate() { + const date = new Date(0); // epoch + date.setUTCSeconds(this.timestamp); + return date; + } + // TODO: buffer, offset compatibility + toBuffer(headersOnly) { + const buffer = Buffer.allocUnsafe(this.byteLength(headersOnly)); + const bufferWriter = new bufferutils_1.BufferWriter(buffer); + bufferWriter.writeInt32(this.version); + bufferWriter.writeSlice(this.prevHash); + bufferWriter.writeSlice(this.merkleRoot); + bufferWriter.writeUInt32(this.timestamp); + bufferWriter.writeUInt32(this.bits); + bufferWriter.writeUInt32(this.nonce); + if (headersOnly || !this.transactions) return buffer; + bufferutils_1.varuint.encode( + this.transactions.length, + buffer, + bufferWriter.offset, + ); + bufferWriter.offset += bufferutils_1.varuint.encode.bytes; + this.transactions.forEach(tx => { + const txSize = tx.byteLength(); // TODO: extract from toBuffer? + tx.toBuffer(buffer, bufferWriter.offset); + bufferWriter.offset += txSize; + }); + return buffer; + } + toHex(headersOnly) { + return this.toBuffer(headersOnly).toString('hex'); + } + checkTxRoots() { + // If the Block has segwit transactions but no witness commit, + // there's no way it can be valid, so fail the check. + const hasWitnessCommit = this.hasWitnessCommit(); + if (!hasWitnessCommit && this.hasWitness()) return false; + return ( + this.__checkMerkleRoot() && + (hasWitnessCommit ? this.__checkWitnessCommit() : true) + ); + } + checkProofOfWork() { + const hash = (0, bufferutils_1.reverseBuffer)(this.getHash()); + const target = Block.calculateTarget(this.bits); + return hash.compare(target) <= 0; + } + __checkMerkleRoot() { + if (!this.transactions) throw errorMerkleNoTxes; + const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions); + return this.merkleRoot.compare(actualMerkleRoot) === 0; + } + __checkWitnessCommit() { + if (!this.transactions) throw errorMerkleNoTxes; + if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit; + const actualWitnessCommit = Block.calculateMerkleRoot( + this.transactions, + true, + ); + return this.witnessCommit.compare(actualWitnessCommit) === 0; + } +} +exports.Block = Block; +function txesHaveWitnessCommit(transactions) { + return ( + transactions instanceof Array && + transactions[0] && + transactions[0].ins && + transactions[0].ins instanceof Array && + transactions[0].ins[0] && + transactions[0].ins[0].witness && + transactions[0].ins[0].witness instanceof Array && + transactions[0].ins[0].witness.length > 0 + ); +} +function anyTxHasWitness(transactions) { + return ( + transactions instanceof Array && + transactions.some( + tx => + typeof tx === 'object' && + tx.ins instanceof Array && + tx.ins.some( + input => + typeof input === 'object' && + input.witness instanceof Array && + input.witness.length > 0, + ), + ) + ); +} -},{"./der":15,"inherits":230,"safer-buffer":281}],18:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bufferutils":50,"./crypto":51,"./merkle":54,"./transaction":75,"./types":76,"buffer":249}],50:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -const inherits = require('inherits'); -const Buffer = require('safer-buffer').Buffer; -const Node = require('../base/node'); - -// Import DER constants -const der = require('../constants/der'); - -function DEREncoder(entity) { - this.enc = 'der'; - this.name = entity.name; - this.entity = entity; - - // Construct base tree - this.tree = new DERNode(); - this.tree._init(entity.body); +Object.defineProperty(exports, '__esModule', { value: true }); +exports.BufferReader = + exports.BufferWriter = + exports.cloneBuffer = + exports.reverseBuffer = + exports.writeUInt64LE = + exports.readUInt64LE = + exports.varuint = + void 0; +const types = require('./types'); +const { typeforce } = types; +const varuint = require('varuint-bitcoin'); +exports.varuint = varuint; +// https://github.com/feross/buffer/blob/master/index.js#L1127 +function verifuint(value, max) { + if (typeof value !== 'number') + throw new Error('cannot write a non-number as a number'); + if (value < 0) + throw new Error('specified a negative value for writing an unsigned value'); + if (value > max) throw new Error('RangeError: value out of range'); + if (Math.floor(value) !== value) + throw new Error('value has a fractional component'); } -module.exports = DEREncoder; - -DEREncoder.prototype.encode = function encode(data, reporter) { - return this.tree._encode(data, reporter).join(); -}; - -// Tree methods - -function DERNode(parent) { - Node.call(this, 'der', parent); +function readUInt64LE(buffer, offset) { + const a = buffer.readUInt32LE(offset); + let b = buffer.readUInt32LE(offset + 4); + b *= 0x100000000; + verifuint(b + a, 0x001fffffffffffff); + return b + a; } -inherits(DERNode, Node); - -DERNode.prototype._encodeComposite = function encodeComposite(tag, - primitive, - cls, - content) { - const encodedTag = encodeTag(tag, primitive, cls, this.reporter); - - // Short form - if (content.length < 0x80) { - const header = Buffer.alloc(2); - header[0] = encodedTag; - header[1] = content.length; - return this._createEncoderBuffer([ header, content ]); +exports.readUInt64LE = readUInt64LE; +/** + * Writes a 64-bit unsigned integer in little-endian format to the specified buffer at the given offset. + * + * @param buffer - The buffer to write the value to. + * @param value - The 64-bit unsigned integer value to write. + * @param offset - The offset in the buffer where the value should be written. + * @returns The new offset after writing the value. + */ +function writeUInt64LE(buffer, value, offset) { + verifuint(value, 0x001fffffffffffff); + buffer.writeInt32LE(value & -1, offset); + buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4); + return offset + 8; +} +exports.writeUInt64LE = writeUInt64LE; +/** + * Reverses the order of bytes in a buffer. + * @param buffer - The buffer to reverse. + * @returns A new buffer with the bytes reversed. + */ +function reverseBuffer(buffer) { + if (buffer.length < 1) return buffer; + let j = buffer.length - 1; + let tmp = 0; + for (let i = 0; i < buffer.length / 2; i++) { + tmp = buffer[i]; + buffer[i] = buffer[j]; + buffer[j] = tmp; + j--; } - - // Long form - // Count octets required to store length - let lenOctets = 1; - for (let i = content.length; i >= 0x100; i >>= 8) - lenOctets++; - - const header = Buffer.alloc(1 + 1 + lenOctets); - header[0] = encodedTag; - header[1] = 0x80 | lenOctets; - - for (let i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) - header[i] = j & 0xff; - - return this._createEncoderBuffer([ header, content ]); -}; - -DERNode.prototype._encodeStr = function encodeStr(str, tag) { - if (tag === 'bitstr') { - return this._createEncoderBuffer([ str.unused | 0, str.data ]); - } else if (tag === 'bmpstr') { - const buf = Buffer.alloc(str.length * 2); - for (let i = 0; i < str.length; i++) { - buf.writeUInt16BE(str.charCodeAt(i), i * 2); - } - return this._createEncoderBuffer(buf); - } else if (tag === 'numstr') { - if (!this._isNumstr(str)) { - return this.reporter.error('Encoding of string type: numstr supports ' + - 'only digits and space'); - } - return this._createEncoderBuffer(str); - } else if (tag === 'printstr') { - if (!this._isPrintstr(str)) { - return this.reporter.error('Encoding of string type: printstr supports ' + - 'only latin upper and lower case letters, ' + - 'digits, space, apostrophe, left and rigth ' + - 'parenthesis, plus sign, comma, hyphen, ' + - 'dot, slash, colon, equal sign, ' + - 'question mark'); - } - return this._createEncoderBuffer(str); - } else if (/str$/.test(tag)) { - return this._createEncoderBuffer(str); - } else if (tag === 'objDesc') { - return this._createEncoderBuffer(str); - } else { - return this.reporter.error('Encoding of string type: ' + tag + - ' unsupported'); + return buffer; +} +exports.reverseBuffer = reverseBuffer; +function cloneBuffer(buffer) { + const clone = Buffer.allocUnsafe(buffer.length); + buffer.copy(clone); + return clone; +} +exports.cloneBuffer = cloneBuffer; +/** + * Helper class for serialization of bitcoin data types into a pre-allocated buffer. + */ +class BufferWriter { + static withCapacity(size) { + return new BufferWriter(Buffer.alloc(size)); } -}; - -DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) { - if (typeof id === 'string') { - if (!values) - return this.reporter.error('string objid given, but no values map found'); - if (!values.hasOwnProperty(id)) - return this.reporter.error('objid not found in values map'); - id = values[id].split(/[\s.]+/g); - for (let i = 0; i < id.length; i++) - id[i] |= 0; - } else if (Array.isArray(id)) { - id = id.slice(); - for (let i = 0; i < id.length; i++) - id[i] |= 0; + constructor(buffer, offset = 0) { + this.buffer = buffer; + this.offset = offset; + typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); } - - if (!Array.isArray(id)) { - return this.reporter.error('objid() should be either array or string, ' + - 'got: ' + JSON.stringify(id)); + writeUInt8(i) { + this.offset = this.buffer.writeUInt8(i, this.offset); } - - if (!relative) { - if (id[1] >= 40) - return this.reporter.error('Second objid identifier OOB'); - id.splice(0, 2, id[0] * 40 + id[1]); + writeInt32(i) { + this.offset = this.buffer.writeInt32LE(i, this.offset); } - - // Count number of octets - let size = 0; - for (let i = 0; i < id.length; i++) { - let ident = id[i]; - for (size++; ident >= 0x80; ident >>= 7) - size++; + writeUInt32(i) { + this.offset = this.buffer.writeUInt32LE(i, this.offset); } - - const objid = Buffer.alloc(size); - let offset = objid.length - 1; - for (let i = id.length - 1; i >= 0; i--) { - let ident = id[i]; - objid[offset--] = ident & 0x7f; - while ((ident >>= 7) > 0) - objid[offset--] = 0x80 | (ident & 0x7f); + writeUInt64(i) { + this.offset = writeUInt64LE(this.buffer, i, this.offset); } - - return this._createEncoderBuffer(objid); -}; - -function two(num) { - if (num < 10) - return '0' + num; - else - return num; -} - -DERNode.prototype._encodeTime = function encodeTime(time, tag) { - let str; - const date = new Date(time); - - if (tag === 'gentime') { - str = [ - two(date.getUTCFullYear()), - two(date.getUTCMonth() + 1), - two(date.getUTCDate()), - two(date.getUTCHours()), - two(date.getUTCMinutes()), - two(date.getUTCSeconds()), - 'Z' - ].join(''); - } else if (tag === 'utctime') { - str = [ - two(date.getUTCFullYear() % 100), - two(date.getUTCMonth() + 1), - two(date.getUTCDate()), - two(date.getUTCHours()), - two(date.getUTCMinutes()), - two(date.getUTCSeconds()), - 'Z' - ].join(''); - } else { - this.reporter.error('Encoding ' + tag + ' time is not supported yet'); + writeVarInt(i) { + varuint.encode(i, this.buffer, this.offset); + this.offset += varuint.encode.bytes; } - - return this._encodeStr(str, 'octstr'); -}; - -DERNode.prototype._encodeNull = function encodeNull() { - return this._createEncoderBuffer(''); -}; - -DERNode.prototype._encodeInt = function encodeInt(num, values) { - if (typeof num === 'string') { - if (!values) - return this.reporter.error('String int or enum given, but no values map'); - if (!values.hasOwnProperty(num)) { - return this.reporter.error('Values map doesn\'t contain: ' + - JSON.stringify(num)); + writeSlice(slice) { + if (this.buffer.length < this.offset + slice.length) { + throw new Error('Cannot write slice out of bounds'); } - num = values[num]; + this.offset += slice.copy(this.buffer, this.offset); } - - // Bignum, assume big endian - if (typeof num !== 'number' && !Buffer.isBuffer(num)) { - const numArray = num.toArray(); - if (!num.sign && numArray[0] & 0x80) { - numArray.unshift(0); + writeVarSlice(slice) { + this.writeVarInt(slice.length); + this.writeSlice(slice); + } + writeVector(vector) { + this.writeVarInt(vector.length); + vector.forEach(buf => this.writeVarSlice(buf)); + } + end() { + if (this.buffer.length === this.offset) { + return this.buffer; } - num = Buffer.from(numArray); + throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`); } - - if (Buffer.isBuffer(num)) { - let size = num.length; - if (num.length === 0) - size++; - - const out = Buffer.alloc(size); - num.copy(out); - if (num.length === 0) - out[0] = 0; - return this._createEncoderBuffer(out); +} +exports.BufferWriter = BufferWriter; +/** + * Helper class for reading of bitcoin data types from a buffer. + */ +class BufferReader { + constructor(buffer, offset = 0) { + this.buffer = buffer; + this.offset = offset; + typeforce(types.tuple(types.Buffer, types.UInt32), [buffer, offset]); } - - if (num < 0x80) - return this._createEncoderBuffer(num); - - if (num < 0x100) - return this._createEncoderBuffer([0, num]); - - let size = 1; - for (let i = num; i >= 0x100; i >>= 8) - size++; - - const out = new Array(size); - for (let i = out.length - 1; i >= 0; i--) { - out[i] = num & 0xff; - num >>= 8; + readUInt8() { + const result = this.buffer.readUInt8(this.offset); + this.offset++; + return result; } - if(out[0] & 0x80) { - out.unshift(0); + readInt32() { + const result = this.buffer.readInt32LE(this.offset); + this.offset += 4; + return result; } + readUInt32() { + const result = this.buffer.readUInt32LE(this.offset); + this.offset += 4; + return result; + } + readUInt64() { + const result = readUInt64LE(this.buffer, this.offset); + this.offset += 8; + return result; + } + readVarInt() { + const vi = varuint.decode(this.buffer, this.offset); + this.offset += varuint.decode.bytes; + return vi; + } + readSlice(n) { + if (this.buffer.length < this.offset + n) { + throw new Error('Cannot read slice out of bounds'); + } + const result = this.buffer.slice(this.offset, this.offset + n); + this.offset += n; + return result; + } + readVarSlice() { + return this.readSlice(this.readVarInt()); + } + readVector() { + const count = this.readVarInt(); + const vector = []; + for (let i = 0; i < count; i++) vector.push(this.readVarSlice()); + return vector; + } +} +exports.BufferReader = BufferReader; - return this._createEncoderBuffer(Buffer.from(out)); -}; - -DERNode.prototype._encodeBool = function encodeBool(value) { - return this._createEncoderBuffer(value ? 0xff : 0); -}; - -DERNode.prototype._use = function use(entity, obj) { - if (typeof entity === 'function') - entity = entity(obj); - return entity._getEncoder('der').tree; -}; - -DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) { - const state = this._baseState; - let i; - if (state['default'] === null) - return false; - - const data = dataBuffer.join(); - if (state.defaultBuffer === undefined) - state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join(); - - if (data.length !== state.defaultBuffer.length) - return false; - - for (i=0; i < data.length; i++) - if (data[i] !== state.defaultBuffer[i]) - return false; - - return true; -}; - -// Utility methods - -function encodeTag(tag, primitive, cls, reporter) { - let res; - - if (tag === 'seqof') - tag = 'seq'; - else if (tag === 'setof') - tag = 'set'; - - if (der.tagByName.hasOwnProperty(tag)) - res = der.tagByName[tag]; - else if (typeof tag === 'number' && (tag | 0) === tag) - res = tag; - else - return reporter.error('Unknown tag: ' + tag); - - if (res >= 0x1f) - return reporter.error('Multi-octet tag encoding unsupported'); - - if (!primitive) - res |= 0x20; - - res |= (der.tagClassByName[cls || 'universal'] << 6); - - return res; -} - -},{"../base/node":11,"../constants/der":13,"inherits":230,"safer-buffer":281}],19:[function(require,module,exports){ -'use strict'; - -const encoders = exports; - -encoders.der = require('./der'); -encoders.pem = require('./pem'); - -},{"./der":18,"./pem":20}],20:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./types":76,"buffer":249,"varuint-bitcoin":528}],51:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -const inherits = require('inherits'); - -const DEREncoder = require('./der'); - -function PEMEncoder(entity) { - DEREncoder.call(this, entity); - this.enc = 'pem'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.taggedHash = + exports.TAGGED_HASH_PREFIXES = + exports.TAGS = + exports.hash256 = + exports.hash160 = + exports.sha256 = + exports.sha1 = + exports.ripemd160 = + void 0; +/** + * A module for hashing functions. + * include ripemd160、sha1、sha256、hash160、hash256、taggedHash + * + * @packageDocumentation + */ +const ripemd160_1 = require('@noble/hashes/ripemd160'); +const sha1_1 = require('@noble/hashes/sha1'); +const sha256_1 = require('@noble/hashes/sha256'); +function ripemd160(buffer) { + return Buffer.from((0, ripemd160_1.ripemd160)(Uint8Array.from(buffer))); } -inherits(PEMEncoder, DEREncoder); -module.exports = PEMEncoder; - -PEMEncoder.prototype.encode = function encode(data, options) { - const buf = DEREncoder.prototype.encode.call(this, data); - - const p = buf.toString('base64'); - const out = [ '-----BEGIN ' + options.label + '-----' ]; - for (let i = 0; i < p.length; i += 64) - out.push(p.slice(i, i + 64)); - out.push('-----END ' + options.label + '-----'); - return out.join('\n'); -}; - -},{"./der":18,"inherits":230}],21:[function(require,module,exports){ -(function (global){ +exports.ripemd160 = ripemd160; +function sha1(buffer) { + return Buffer.from((0, sha1_1.sha1)(Uint8Array.from(buffer))); +} +exports.sha1 = sha1; +function sha256(buffer) { + return Buffer.from((0, sha256_1.sha256)(Uint8Array.from(buffer))); +} +exports.sha256 = sha256; +function hash160(buffer) { + return Buffer.from( + (0, ripemd160_1.ripemd160)((0, sha256_1.sha256)(Uint8Array.from(buffer))), + ); +} +exports.hash160 = hash160; +function hash256(buffer) { + return Buffer.from( + (0, sha256_1.sha256)((0, sha256_1.sha256)(Uint8Array.from(buffer))), + ); +} +exports.hash256 = hash256; +exports.TAGS = [ + 'BIP0340/challenge', + 'BIP0340/aux', + 'BIP0340/nonce', + 'TapLeaf', + 'TapBranch', + 'TapSighash', + 'TapTweak', + 'KeyAgg list', + 'KeyAgg coefficient', +]; +/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */ +/** + * Defines the tagged hash prefixes used in the crypto module. + */ +exports.TAGGED_HASH_PREFIXES = { + 'BIP0340/challenge': Buffer.from([ + 123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130, + 210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124, + 123, 181, 45, 122, 159, 239, 88, 50, 62, 177, 191, 122, 64, 125, 179, 130, + 210, 243, 242, 216, 27, 177, 34, 79, 73, 254, 81, 143, 109, 72, 211, 124, + ]), + 'BIP0340/aux': Buffer.from([ + 241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160, + 105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144, + 241, 239, 78, 94, 192, 99, 202, 218, 109, 148, 202, 250, 157, 152, 126, 160, + 105, 38, 88, 57, 236, 193, 31, 151, 45, 119, 165, 46, 216, 193, 204, 144, + ]), + 'BIP0340/nonce': Buffer.from([ + 7, 73, 119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244, + 52, 215, 62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47, 7, 73, + 119, 52, 167, 155, 203, 53, 91, 155, 140, 125, 3, 79, 18, 28, 244, 52, 215, + 62, 247, 45, 218, 25, 135, 0, 97, 251, 82, 191, 235, 47, + ]), + TapLeaf: Buffer.from([ + 174, 234, 143, 220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211, + 95, 28, 181, 64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238, 174, 234, 143, + 220, 66, 8, 152, 49, 5, 115, 75, 88, 8, 29, 30, 38, 56, 211, 95, 28, 181, + 64, 8, 212, 211, 87, 202, 3, 190, 120, 233, 238, + ]), + TapBranch: Buffer.from([ + 25, 65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247, + 33, 111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21, 25, + 65, 161, 242, 229, 110, 185, 95, 162, 169, 241, 148, 190, 92, 1, 247, 33, + 111, 51, 237, 130, 176, 145, 70, 52, 144, 208, 91, 245, 22, 160, 21, + ]), + TapSighash: Buffer.from([ + 244, 10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61, + 149, 253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49, 244, + 10, 72, 223, 75, 42, 112, 200, 180, 146, 75, 242, 101, 70, 97, 237, 61, 149, + 253, 102, 163, 19, 235, 135, 35, 117, 151, 198, 40, 228, 160, 49, + ]), + TapTweak: Buffer.from([ + 232, 15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66, + 156, 188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233, 232, + 15, 225, 99, 156, 156, 160, 80, 227, 175, 27, 57, 193, 67, 198, 62, 66, 156, + 188, 235, 21, 217, 64, 251, 181, 197, 161, 244, 175, 87, 197, 233, + ]), + 'KeyAgg list': Buffer.from([ + 72, 28, 151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126, + 215, 49, 156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240, 72, 28, + 151, 28, 60, 11, 70, 215, 240, 178, 117, 174, 89, 141, 78, 44, 126, 215, 49, + 156, 89, 74, 92, 110, 199, 158, 160, 212, 153, 2, 148, 240, + ]), + 'KeyAgg coefficient': Buffer.from([ + 191, 201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100, + 130, 78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129, 191, + 201, 4, 3, 77, 28, 136, 232, 200, 14, 34, 229, 61, 36, 86, 109, 100, 130, + 78, 214, 66, 114, 129, 192, 145, 0, 249, 77, 205, 82, 201, 129, + ]), +}; +function taggedHash(prefix, data) { + return sha256(Buffer.concat([exports.TAGGED_HASH_PREFIXES[prefix], data])); +} +exports.taggedHash = taggedHash; + +}).call(this)}).call(this,require("buffer").Buffer) +},{"@noble/hashes/ripemd160":87,"@noble/hashes/sha1":88,"@noble/hashes/sha256":89,"buffer":249}],52:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; - -var objectAssign = require('object-assign'); - -// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js -// original notice: - -/*! - * The buffer module from node.js, for the browser. +Object.defineProperty(exports, '__esModule', { value: true }); +exports.getEccLib = exports.initEccLib = void 0; +const _ECCLIB_CACHE = {}; +/** + * Initializes the ECC library with the provided instance. + * If `eccLib` is `undefined`, the library will be cleared. + * If `eccLib` is a new instance, it will be verified before setting it as the active library. * - * @author Feross Aboukhadijeh - * @license MIT + * @param eccLib The instance of the ECC library to initialize. */ -function compare(a, b) { - if (a === b) { - return 0; - } - - var x = a.length; - var y = b.length; - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; - } - } - - if (x < y) { - return -1; - } - if (y < x) { - return 1; +function initEccLib(eccLib) { + if (!eccLib) { + // allow clearing the library + _ECCLIB_CACHE.eccLib = eccLib; + } else if (eccLib !== _ECCLIB_CACHE.eccLib) { + // new instance, verify it + verifyEcc(eccLib); + _ECCLIB_CACHE.eccLib = eccLib; } - return 0; } -function isBuffer(b) { - if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { - return global.Buffer.isBuffer(b); - } - return !!(b != null && b._isBuffer); +exports.initEccLib = initEccLib; +/** + * Retrieves the ECC Library instance. + * Throws an error if the ECC Library is not provided. + * You must call initEccLib() with a valid TinySecp256k1Interface instance before calling this function. + * @returns The ECC Library instance. + * @throws Error if the ECC Library is not provided. + */ +function getEccLib() { + if (!_ECCLIB_CACHE.eccLib) + throw new Error( + 'No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance', + ); + return _ECCLIB_CACHE.eccLib; } - -// based on node assert, original notice: -// NB: The URL to the CommonJS spec is kept just for tradition. -// node-assert has evolved a lot since then, both in API and behavior. - -// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 -// -// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! -// -// Originally from narwhal.js (http://narwhaljs.org) -// Copyright (c) 2009 Thomas Robinson <280north.com> -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -var util = require('util/'); -var hasOwn = Object.prototype.hasOwnProperty; -var pSlice = Array.prototype.slice; -var functionsHaveNames = (function () { - return function foo() {}.name === 'foo'; -}()); -function pToString (obj) { - return Object.prototype.toString.call(obj); +exports.getEccLib = getEccLib; +const h = hex => Buffer.from(hex, 'hex'); +/** + * Verifies the ECC functionality. + * + * @param ecc - The TinySecp256k1Interface object. + */ +function verifyEcc(ecc) { + assert(typeof ecc.isXOnlyPoint === 'function'); + assert( + ecc.isXOnlyPoint( + h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + ), + ); + assert( + ecc.isXOnlyPoint( + h('fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e'), + ), + ); + assert( + ecc.isXOnlyPoint( + h('f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9'), + ), + ); + assert( + ecc.isXOnlyPoint( + h('0000000000000000000000000000000000000000000000000000000000000001'), + ), + ); + assert( + !ecc.isXOnlyPoint( + h('0000000000000000000000000000000000000000000000000000000000000000'), + ), + ); + assert( + !ecc.isXOnlyPoint( + h('fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'), + ), + ); + assert(typeof ecc.xOnlyPointAddTweak === 'function'); + tweakAddVectors.forEach(t => { + const r = ecc.xOnlyPointAddTweak(h(t.pubkey), h(t.tweak)); + if (t.result === null) { + assert(r === null); + } else { + assert(r !== null); + assert(r.parity === t.parity); + assert(Buffer.from(r.xOnlyPubkey).equals(h(t.result))); + } + }); } -function isView(arrbuf) { - if (isBuffer(arrbuf)) { - return false; - } - if (typeof global.ArrayBuffer !== 'function') { - return false; - } - if (typeof ArrayBuffer.isView === 'function') { - return ArrayBuffer.isView(arrbuf); - } - if (!arrbuf) { - return false; - } - if (arrbuf instanceof DataView) { - return true; - } - if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { - return true; - } - return false; +function assert(bool) { + if (!bool) throw new Error('ecc library invalid'); } -// 1. The assert module provides functions that throw -// AssertionError's when particular conditions are not met. The -// assert module must conform to the following interface. - -var assert = module.exports = ok; +const tweakAddVectors = [ + { + pubkey: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', + tweak: 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140', + parity: -1, + result: null, + }, + { + pubkey: '1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b', + tweak: 'a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac', + parity: 1, + result: 'e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf', + }, + { + pubkey: '2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991', + tweak: '823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47', + parity: 0, + result: '9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c', + }, +]; -// 2. The AssertionError is defined in assert. -// new assert.AssertionError({ message: message, -// actual: actual, -// expected: expected }) +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],53:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.initEccLib = + exports.Transaction = + exports.opcodes = + exports.Psbt = + exports.Block = + exports.script = + exports.payments = + exports.networks = + exports.crypto = + exports.address = + void 0; +const address = require('./address'); +exports.address = address; +const crypto = require('./crypto'); +exports.crypto = crypto; +const networks = require('./networks'); +exports.networks = networks; +const payments = require('./payments'); +exports.payments = payments; +const script = require('./script'); +exports.script = script; +var block_1 = require('./block'); +Object.defineProperty(exports, 'Block', { + enumerable: true, + get: function () { + return block_1.Block; + }, +}); +var psbt_1 = require('./psbt'); +Object.defineProperty(exports, 'Psbt', { + enumerable: true, + get: function () { + return psbt_1.Psbt; + }, +}); +/** @hidden */ +var ops_1 = require('./ops'); +Object.defineProperty(exports, 'opcodes', { + enumerable: true, + get: function () { + return ops_1.OPS; + }, +}); +var transaction_1 = require('./transaction'); +Object.defineProperty(exports, 'Transaction', { + enumerable: true, + get: function () { + return transaction_1.Transaction; + }, +}); +var ecc_lib_1 = require('./ecc_lib'); +Object.defineProperty(exports, 'initEccLib', { + enumerable: true, + get: function () { + return ecc_lib_1.initEccLib; + }, +}); -var regex = /\s*function\s+([^\(\s]*)\s*/; -// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js -function getName(func) { - if (!util.isFunction(func)) { - return; - } - if (functionsHaveNames) { - return func.name; +},{"./address":47,"./block":49,"./crypto":51,"./ecc_lib":52,"./networks":55,"./ops":56,"./payments":59,"./psbt":68,"./script":72,"./transaction":75}],54:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.fastMerkleRoot = void 0; +/** + * Calculates the Merkle root of an array of buffers using a specified digest function. + * + * @param values - The array of buffers. + * @param digestFn - The digest function used to calculate the hash of the concatenated buffers. + * @returns The Merkle root as a buffer. + * @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function. + */ +function fastMerkleRoot(values, digestFn) { + if (!Array.isArray(values)) throw TypeError('Expected values Array'); + if (typeof digestFn !== 'function') + throw TypeError('Expected digest Function'); + let length = values.length; + const results = values.concat(); + while (length > 1) { + let j = 0; + for (let i = 0; i < length; i += 2, ++j) { + const left = results[i]; + const right = i + 1 === length ? left : results[i + 1]; + const data = Buffer.concat([left, right]); + results[j] = digestFn(data); + } + length = j; } - var str = func.toString(); - var match = str.match(regex); - return match && match[1]; + return results[0]; } -assert.AssertionError = function AssertionError(options) { - this.name = 'AssertionError'; - this.actual = options.actual; - this.expected = options.expected; - this.operator = options.operator; - if (options.message) { - this.message = options.message; - this.generatedMessage = false; - } else { - this.message = getMessage(this); - this.generatedMessage = true; - } - var stackStartFunction = options.stackStartFunction || fail; - if (Error.captureStackTrace) { - Error.captureStackTrace(this, stackStartFunction); - } else { - // non v8 browsers so we can have a stacktrace - var err = new Error(); - if (err.stack) { - var out = err.stack; +exports.fastMerkleRoot = fastMerkleRoot; - // try to strip useless frames - var fn_name = getName(stackStartFunction); - var idx = out.indexOf('\n' + fn_name); - if (idx >= 0) { - // once we have located the function frame - // we need to strip out everything before it (and its line) - var next_line = out.indexOf('\n', idx + 1); - out = out.substring(next_line + 1); - } - - this.stack = out; - } - } +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],55:[function(require,module,exports){ +'use strict'; +// https://en.bitcoin.it/wiki/List_of_address_prefixes +// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731 +Object.defineProperty(exports, '__esModule', { value: true }); +exports.testnet = exports.regtest = exports.bitcoin = void 0; +/** + * Represents the Bitcoin network configuration. + */ +exports.bitcoin = { + /** + * The message prefix used for signing Bitcoin messages. + */ + messagePrefix: '\x18Bitcoin Signed Message:\n', + /** + * The Bech32 prefix used for Bitcoin addresses. + */ + bech32: 'bc', + /** + * The BIP32 key prefixes for Bitcoin. + */ + bip32: { + /** + * The public key prefix for BIP32 extended public keys. + */ + public: 0x0488b21e, + /** + * The private key prefix for BIP32 extended private keys. + */ + private: 0x0488ade4, + }, + /** + * The prefix for Bitcoin public key hashes. + */ + pubKeyHash: 0x00, + /** + * The prefix for Bitcoin script hashes. + */ + scriptHash: 0x05, + /** + * The prefix for Bitcoin Wallet Import Format (WIF) private keys. + */ + wif: 0x80, +}; +/** + * Represents the regtest network configuration. + */ +exports.regtest = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'bcrt', + bip32: { + public: 0x043587cf, + private: 0x04358394, + }, + pubKeyHash: 0x6f, + scriptHash: 0xc4, + wif: 0xef, +}; +/** + * Represents the testnet network configuration. + */ +exports.testnet = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'tb', + bip32: { + public: 0x043587cf, + private: 0x04358394, + }, + pubKeyHash: 0x6f, + scriptHash: 0xc4, + wif: 0xef, }; -// assert.AssertionError instanceof Error -util.inherits(assert.AssertionError, Error); - -function truncate(s, n) { - if (typeof s === 'string') { - return s.length < n ? s : s.slice(0, n); - } else { - return s; +},{}],56:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.REVERSE_OPS = exports.OPS = void 0; +const OPS = { + OP_FALSE: 0, + OP_0: 0, + OP_PUSHDATA1: 76, + OP_PUSHDATA2: 77, + OP_PUSHDATA4: 78, + OP_1NEGATE: 79, + OP_RESERVED: 80, + OP_TRUE: 81, + OP_1: 81, + OP_2: 82, + OP_3: 83, + OP_4: 84, + OP_5: 85, + OP_6: 86, + OP_7: 87, + OP_8: 88, + OP_9: 89, + OP_10: 90, + OP_11: 91, + OP_12: 92, + OP_13: 93, + OP_14: 94, + OP_15: 95, + OP_16: 96, + OP_NOP: 97, + OP_VER: 98, + OP_IF: 99, + OP_NOTIF: 100, + OP_VERIF: 101, + OP_VERNOTIF: 102, + OP_ELSE: 103, + OP_ENDIF: 104, + OP_VERIFY: 105, + OP_RETURN: 106, + OP_TOALTSTACK: 107, + OP_FROMALTSTACK: 108, + OP_2DROP: 109, + OP_2DUP: 110, + OP_3DUP: 111, + OP_2OVER: 112, + OP_2ROT: 113, + OP_2SWAP: 114, + OP_IFDUP: 115, + OP_DEPTH: 116, + OP_DROP: 117, + OP_DUP: 118, + OP_NIP: 119, + OP_OVER: 120, + OP_PICK: 121, + OP_ROLL: 122, + OP_ROT: 123, + OP_SWAP: 124, + OP_TUCK: 125, + OP_CAT: 126, + OP_SUBSTR: 127, + OP_LEFT: 128, + OP_RIGHT: 129, + OP_SIZE: 130, + OP_INVERT: 131, + OP_AND: 132, + OP_OR: 133, + OP_XOR: 134, + OP_EQUAL: 135, + OP_EQUALVERIFY: 136, + OP_RESERVED1: 137, + OP_RESERVED2: 138, + OP_1ADD: 139, + OP_1SUB: 140, + OP_2MUL: 141, + OP_2DIV: 142, + OP_NEGATE: 143, + OP_ABS: 144, + OP_NOT: 145, + OP_0NOTEQUAL: 146, + OP_ADD: 147, + OP_SUB: 148, + OP_MUL: 149, + OP_DIV: 150, + OP_MOD: 151, + OP_LSHIFT: 152, + OP_RSHIFT: 153, + OP_BOOLAND: 154, + OP_BOOLOR: 155, + OP_NUMEQUAL: 156, + OP_NUMEQUALVERIFY: 157, + OP_NUMNOTEQUAL: 158, + OP_LESSTHAN: 159, + OP_GREATERTHAN: 160, + OP_LESSTHANOREQUAL: 161, + OP_GREATERTHANOREQUAL: 162, + OP_MIN: 163, + OP_MAX: 164, + OP_WITHIN: 165, + OP_RIPEMD160: 166, + OP_SHA1: 167, + OP_SHA256: 168, + OP_HASH160: 169, + OP_HASH256: 170, + OP_CODESEPARATOR: 171, + OP_CHECKSIG: 172, + OP_CHECKSIGVERIFY: 173, + OP_CHECKMULTISIG: 174, + OP_CHECKMULTISIGVERIFY: 175, + OP_NOP1: 176, + OP_NOP2: 177, + OP_CHECKLOCKTIMEVERIFY: 177, + OP_NOP3: 178, + OP_CHECKSEQUENCEVERIFY: 178, + OP_NOP4: 179, + OP_NOP5: 180, + OP_NOP6: 181, + OP_NOP7: 182, + OP_NOP8: 183, + OP_NOP9: 184, + OP_NOP10: 185, + OP_CHECKSIGADD: 186, + OP_PUBKEYHASH: 253, + OP_PUBKEY: 254, + OP_INVALIDOPCODE: 255, +}; +exports.OPS = OPS; +const REVERSE_OPS = {}; +exports.REVERSE_OPS = REVERSE_OPS; +for (const op of Object.keys(OPS)) { + const code = OPS[op]; + REVERSE_OPS[code] = op; +} + +},{}],57:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.tweakKey = + exports.tapTweakHash = + exports.tapleafHash = + exports.findScriptPath = + exports.toHashTree = + exports.rootHashFromPath = + exports.MAX_TAPTREE_DEPTH = + exports.LEAF_VERSION_TAPSCRIPT = + void 0; +const buffer_1 = require('buffer'); +const ecc_lib_1 = require('../ecc_lib'); +const bcrypto = require('../crypto'); +const bufferutils_1 = require('../bufferutils'); +const types_1 = require('../types'); +exports.LEAF_VERSION_TAPSCRIPT = 0xc0; +exports.MAX_TAPTREE_DEPTH = 128; +const isHashBranch = ht => 'left' in ht && 'right' in ht; +/** + * Calculates the root hash from a given control block and leaf hash. + * @param controlBlock - The control block buffer. + * @param leafHash - The leaf hash buffer. + * @returns The root hash buffer. + * @throws {TypeError} If the control block length is less than 33. + */ +function rootHashFromPath(controlBlock, leafHash) { + if (controlBlock.length < 33) + throw new TypeError( + `The control-block length is too small. Got ${controlBlock.length}, expected min 33.`, + ); + const m = (controlBlock.length - 33) / 32; + let kj = leafHash; + for (let j = 0; j < m; j++) { + const ej = controlBlock.slice(33 + 32 * j, 65 + 32 * j); + if (kj.compare(ej) < 0) { + kj = tapBranchHash(kj, ej); + } else { + kj = tapBranchHash(ej, kj); + } } + return kj; } -function inspect(something) { - if (functionsHaveNames || !util.isFunction(something)) { - return util.inspect(something); +exports.rootHashFromPath = rootHashFromPath; +/** + * Build a hash tree of merkle nodes from the scripts binary tree. + * @param scriptTree - the tree of scripts to pairwise hash. + */ +function toHashTree(scriptTree) { + if ((0, types_1.isTapleaf)(scriptTree)) + return { hash: tapleafHash(scriptTree) }; + const hashes = [toHashTree(scriptTree[0]), toHashTree(scriptTree[1])]; + hashes.sort((a, b) => a.hash.compare(b.hash)); + const [left, right] = hashes; + return { + hash: tapBranchHash(left.hash, right.hash), + left, + right, + }; +} +exports.toHashTree = toHashTree; +/** + * Given a HashTree, finds the path from a particular hash to the root. + * @param node - the root of the tree + * @param hash - the hash to search for + * @returns - array of sibling hashes, from leaf (inclusive) to root + * (exclusive) needed to prove inclusion of the specified hash. undefined if no + * path is found + */ +function findScriptPath(node, hash) { + if (isHashBranch(node)) { + const leftPath = findScriptPath(node.left, hash); + if (leftPath !== undefined) return [...leftPath, node.right.hash]; + const rightPath = findScriptPath(node.right, hash); + if (rightPath !== undefined) return [...rightPath, node.left.hash]; + } else if (node.hash.equals(hash)) { + return []; } - var rawname = getName(something); - var name = rawname ? ': ' + rawname : ''; - return '[Function' + name + ']'; + return undefined; +} +exports.findScriptPath = findScriptPath; +function tapleafHash(leaf) { + const version = leaf.version || exports.LEAF_VERSION_TAPSCRIPT; + return bcrypto.taggedHash( + 'TapLeaf', + buffer_1.Buffer.concat([ + buffer_1.Buffer.from([version]), + serializeScript(leaf.output), + ]), + ); } -function getMessage(self) { - return truncate(inspect(self.actual), 128) + ' ' + - self.operator + ' ' + - truncate(inspect(self.expected), 128); +exports.tapleafHash = tapleafHash; +function tapTweakHash(pubKey, h) { + return bcrypto.taggedHash( + 'TapTweak', + buffer_1.Buffer.concat(h ? [pubKey, h] : [pubKey]), + ); } - -// At present only the three keys mentioned above are used and -// understood by the spec. Implementations or sub modules can pass -// other keys to the AssertionError's constructor - they will be -// ignored. - -// 3. All of the following functions must throw an AssertionError -// when a corresponding condition is not met, with a message that -// may be undefined if not provided. All assertion methods provide -// both the actual and expected values to the assertion error for -// display purposes. - -function fail(actual, expected, message, operator, stackStartFunction) { - throw new assert.AssertionError({ - message: message, - actual: actual, - expected: expected, - operator: operator, - stackStartFunction: stackStartFunction - }); +exports.tapTweakHash = tapTweakHash; +function tweakKey(pubKey, h) { + if (!buffer_1.Buffer.isBuffer(pubKey)) return null; + if (pubKey.length !== 32) return null; + if (h && h.length !== 32) return null; + const tweakHash = tapTweakHash(pubKey, h); + const res = (0, ecc_lib_1.getEccLib)().xOnlyPointAddTweak(pubKey, tweakHash); + if (!res || res.xOnlyPubkey === null) return null; + return { + parity: res.parity, + x: buffer_1.Buffer.from(res.xOnlyPubkey), + }; } - -// EXTENSION! allows for well behaved errors defined elsewhere. -assert.fail = fail; - -// 4. Pure assertion tests whether a value is truthy, as determined -// by !!guard. -// assert.ok(guard, message_opt); -// This statement is equivalent to assert.equal(true, !!guard, -// message_opt);. To test strictly for the value true, use -// assert.strictEqual(true, guard, message_opt);. - -function ok(value, message) { - if (!value) fail(value, true, message, '==', assert.ok); +exports.tweakKey = tweakKey; +function tapBranchHash(a, b) { + return bcrypto.taggedHash('TapBranch', buffer_1.Buffer.concat([a, b])); +} +function serializeScript(s) { + const varintLen = bufferutils_1.varuint.encodingLength(s.length); + const buffer = buffer_1.Buffer.allocUnsafe(varintLen); // better + bufferutils_1.varuint.encode(s.length, buffer); + return buffer_1.Buffer.concat([buffer, s]); } -assert.ok = ok; - -// 5. The equality assertion tests shallow, coercive equality with -// ==. -// assert.equal(actual, expected, message_opt); - -assert.equal = function equal(actual, expected, message) { - if (actual != expected) fail(actual, expected, message, '==', assert.equal); -}; - -// 6. The non-equality assertion tests for whether two objects are not equal -// with != assert.notEqual(actual, expected, message_opt); -assert.notEqual = function notEqual(actual, expected, message) { - if (actual == expected) { - fail(actual, expected, message, '!=', assert.notEqual); +},{"../bufferutils":50,"../crypto":51,"../ecc_lib":52,"../types":76,"buffer":249}],58:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2data = void 0; +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const OPS = bscript.OPS; +// output: OP_RETURN ... +/** + * Embeds data in a Bitcoin payment. + * @param a - The payment object. + * @param opts - Optional payment options. + * @returns The modified payment object. + * @throws {TypeError} If there is not enough data or if the output is invalid. + */ +function p2data(a, opts) { + if (!a.data && !a.output) throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + data: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }, + a, + ); + const network = a.network || networks_1.bitcoin; + const o = { name: 'embed', network }; + lazy.prop(o, 'output', () => { + if (!a.data) return; + return bscript.compile([OPS.OP_RETURN].concat(a.data)); + }); + lazy.prop(o, 'data', () => { + if (!a.output) return; + return bscript.decompile(a.output).slice(1); + }); + // extended validation + if (opts.validate) { + if (a.output) { + const chunks = bscript.decompile(a.output); + if (chunks[0] !== OPS.OP_RETURN) throw new TypeError('Output is invalid'); + if (!chunks.slice(1).every(types_1.typeforce.Buffer)) + throw new TypeError('Output is invalid'); + if (a.data && !(0, types_1.stacksEqual)(a.data, o.data)) + throw new TypeError('Data mismatch'); + } } -}; + return Object.assign(o, a); +} +exports.p2data = p2data; -// 7. The equivalence assertion tests a deep equality relation. -// assert.deepEqual(actual, expected, message_opt); +},{"../networks":55,"../script":72,"../types":76,"./lazy":60}],59:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2tr = + exports.p2wsh = + exports.p2wpkh = + exports.p2sh = + exports.p2pkh = + exports.p2pk = + exports.p2ms = + exports.embed = + void 0; +const embed_1 = require('./embed'); +Object.defineProperty(exports, 'embed', { + enumerable: true, + get: function () { + return embed_1.p2data; + }, +}); +const p2ms_1 = require('./p2ms'); +Object.defineProperty(exports, 'p2ms', { + enumerable: true, + get: function () { + return p2ms_1.p2ms; + }, +}); +const p2pk_1 = require('./p2pk'); +Object.defineProperty(exports, 'p2pk', { + enumerable: true, + get: function () { + return p2pk_1.p2pk; + }, +}); +const p2pkh_1 = require('./p2pkh'); +Object.defineProperty(exports, 'p2pkh', { + enumerable: true, + get: function () { + return p2pkh_1.p2pkh; + }, +}); +const p2sh_1 = require('./p2sh'); +Object.defineProperty(exports, 'p2sh', { + enumerable: true, + get: function () { + return p2sh_1.p2sh; + }, +}); +const p2wpkh_1 = require('./p2wpkh'); +Object.defineProperty(exports, 'p2wpkh', { + enumerable: true, + get: function () { + return p2wpkh_1.p2wpkh; + }, +}); +const p2wsh_1 = require('./p2wsh'); +Object.defineProperty(exports, 'p2wsh', { + enumerable: true, + get: function () { + return p2wsh_1.p2wsh; + }, +}); +const p2tr_1 = require('./p2tr'); +Object.defineProperty(exports, 'p2tr', { + enumerable: true, + get: function () { + return p2tr_1.p2tr; + }, +}); +// TODO +// witness commitment -assert.deepEqual = function deepEqual(actual, expected, message) { - if (!_deepEqual(actual, expected, false)) { - fail(actual, expected, message, 'deepEqual', assert.deepEqual); - } -}; - -assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { - if (!_deepEqual(actual, expected, true)) { - fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); - } -}; - -function _deepEqual(actual, expected, strict, memos) { - // 7.1. All identical values are equivalent, as determined by ===. - if (actual === expected) { - return true; - } else if (isBuffer(actual) && isBuffer(expected)) { - return compare(actual, expected) === 0; - - // 7.2. If the expected value is a Date object, the actual value is - // equivalent if it is also a Date object that refers to the same time. - } else if (util.isDate(actual) && util.isDate(expected)) { - return actual.getTime() === expected.getTime(); - - // 7.3 If the expected value is a RegExp object, the actual value is - // equivalent if it is also a RegExp object with the same source and - // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). - } else if (util.isRegExp(actual) && util.isRegExp(expected)) { - return actual.source === expected.source && - actual.global === expected.global && - actual.multiline === expected.multiline && - actual.lastIndex === expected.lastIndex && - actual.ignoreCase === expected.ignoreCase; - - // 7.4. Other pairs that do not both pass typeof value == 'object', - // equivalence is determined by ==. - } else if ((actual === null || typeof actual !== 'object') && - (expected === null || typeof expected !== 'object')) { - return strict ? actual === expected : actual == expected; - - // If both values are instances of typed arrays, wrap their underlying - // ArrayBuffers in a Buffer each to increase performance - // This optimization requires the arrays to have the same type as checked by - // Object.prototype.toString (aka pToString). Never perform binary - // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their - // bit patterns are not identical. - } else if (isView(actual) && isView(expected) && - pToString(actual) === pToString(expected) && - !(actual instanceof Float32Array || - actual instanceof Float64Array)) { - return compare(new Uint8Array(actual.buffer), - new Uint8Array(expected.buffer)) === 0; - - // 7.5 For all other Object pairs, including Array objects, equivalence is - // determined by having the same number of owned properties (as verified - // with Object.prototype.hasOwnProperty.call), the same set of keys - // (although not necessarily the same order), equivalent values for every - // corresponding key, and an identical 'prototype' property. Note: this - // accounts for both named and indexed properties on Arrays. - } else if (isBuffer(actual) !== isBuffer(expected)) { - return false; - } else { - memos = memos || {actual: [], expected: []}; - - var actualIndex = memos.actual.indexOf(actual); - if (actualIndex !== -1) { - if (actualIndex === memos.expected.indexOf(expected)) { - return true; - } - } - - memos.actual.push(actual); - memos.expected.push(expected); - - return objEquiv(actual, expected, strict, memos); - } +},{"./embed":58,"./p2ms":61,"./p2pk":62,"./p2pkh":63,"./p2sh":64,"./p2tr":65,"./p2wpkh":66,"./p2wsh":67}],60:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.value = exports.prop = void 0; +function prop(object, name, f) { + Object.defineProperty(object, name, { + configurable: true, + enumerable: true, + get() { + const _value = f.call(this); + this[name] = _value; + return _value; + }, + set(_value) { + Object.defineProperty(this, name, { + configurable: true, + enumerable: true, + value: _value, + writable: true, + }); + }, + }); } - -function isArguments(object) { - return Object.prototype.toString.call(object) == '[object Arguments]'; +exports.prop = prop; +function value(f) { + let _value; + return () => { + if (_value !== undefined) return _value; + _value = f(); + return _value; + }; } +exports.value = value; -function objEquiv(a, b, strict, actualVisitedObjects) { - if (a === null || a === undefined || b === null || b === undefined) - return false; - // if one is a primitive, the other must be same - if (util.isPrimitive(a) || util.isPrimitive(b)) - return a === b; - if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) - return false; - var aIsArgs = isArguments(a); - var bIsArgs = isArguments(b); - if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) - return false; - if (aIsArgs) { - a = pSlice.call(a); - b = pSlice.call(b); - return _deepEqual(a, b, strict); +},{}],61:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2ms = void 0; +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const OPS = bscript.OPS; +const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1 +// input: OP_0 [signatures ...] +// output: m [pubKeys ...] n OP_CHECKMULTISIG +/** + * Represents a function that creates a Pay-to-Multisig (P2MS) payment object. + * @param a - The payment object. + * @param opts - Optional payment options. + * @returns The created payment object. + * @throws {TypeError} If the provided data is not valid. + */ +function p2ms(a, opts) { + if ( + !a.input && + !a.output && + !(a.pubkeys && a.m !== undefined) && + !a.signatures + ) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + function isAcceptableSignature(x) { + return ( + bscript.isCanonicalScriptSignature(x) || + (opts.allowIncomplete && x === OPS.OP_0) !== undefined + ); } - var ka = objectKeys(a); - var kb = objectKeys(b); - var key, i; - // having the same number of owned properties (keys incorporates - // hasOwnProperty) - if (ka.length !== kb.length) - return false; - //the same set of keys (although not necessarily the same order), - ka.sort(); - kb.sort(); - //~~~cheap key test - for (i = ka.length - 1; i >= 0; i--) { - if (ka[i] !== kb[i]) - return false; + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + m: types_1.typeforce.maybe(types_1.typeforce.Number), + n: types_1.typeforce.maybe(types_1.typeforce.Number), + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + pubkeys: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.isPoint), + ), + signatures: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(isAcceptableSignature), + ), + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + }, + a, + ); + const network = a.network || networks_1.bitcoin; + const o = { network }; + let chunks = []; + let decoded = false; + function decode(output) { + if (decoded) return; + decoded = true; + chunks = bscript.decompile(output); + o.m = chunks[0] - OP_INT_BASE; + o.n = chunks[chunks.length - 2] - OP_INT_BASE; + o.pubkeys = chunks.slice(1, -2); } - //equivalent values for every corresponding key, and - //~~~possibly expensive deep test - for (i = ka.length - 1; i >= 0; i--) { - key = ka[i]; - if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) - return false; + lazy.prop(o, 'output', () => { + if (!a.m) return; + if (!o.n) return; + if (!a.pubkeys) return; + return bscript.compile( + [].concat( + OP_INT_BASE + a.m, + a.pubkeys, + OP_INT_BASE + o.n, + OPS.OP_CHECKMULTISIG, + ), + ); + }); + lazy.prop(o, 'm', () => { + if (!o.output) return; + decode(o.output); + return o.m; + }); + lazy.prop(o, 'n', () => { + if (!o.pubkeys) return; + return o.pubkeys.length; + }); + lazy.prop(o, 'pubkeys', () => { + if (!a.output) return; + decode(a.output); + return o.pubkeys; + }); + lazy.prop(o, 'signatures', () => { + if (!a.input) return; + return bscript.decompile(a.input).slice(1); + }); + lazy.prop(o, 'input', () => { + if (!a.signatures) return; + return bscript.compile([OPS.OP_0].concat(a.signatures)); + }); + lazy.prop(o, 'witness', () => { + if (!o.input) return; + return []; + }); + lazy.prop(o, 'name', () => { + if (!o.m || !o.n) return; + return `p2ms(${o.m} of ${o.n})`; + }); + // extended validation + if (opts.validate) { + if (a.output) { + decode(a.output); + if (!types_1.typeforce.Number(chunks[0])) + throw new TypeError('Output is invalid'); + if (!types_1.typeforce.Number(chunks[chunks.length - 2])) + throw new TypeError('Output is invalid'); + if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) + throw new TypeError('Output is invalid'); + if (o.m <= 0 || o.n > 16 || o.m > o.n || o.n !== chunks.length - 3) + throw new TypeError('Output is invalid'); + if (!o.pubkeys.every(x => (0, types_1.isPoint)(x))) + throw new TypeError('Output is invalid'); + if (a.m !== undefined && a.m !== o.m) throw new TypeError('m mismatch'); + if (a.n !== undefined && a.n !== o.n) throw new TypeError('n mismatch'); + if (a.pubkeys && !(0, types_1.stacksEqual)(a.pubkeys, o.pubkeys)) + throw new TypeError('Pubkeys mismatch'); + } + if (a.pubkeys) { + if (a.n !== undefined && a.n !== a.pubkeys.length) + throw new TypeError('Pubkey count mismatch'); + o.n = a.pubkeys.length; + if (o.n < o.m) throw new TypeError('Pubkey count cannot be less than m'); + } + if (a.signatures) { + if (a.signatures.length < o.m) + throw new TypeError('Not enough signatures provided'); + if (a.signatures.length > o.m) + throw new TypeError('Too many signatures provided'); + } + if (a.input) { + if (a.input[0] !== OPS.OP_0) throw new TypeError('Input is invalid'); + if ( + o.signatures.length === 0 || + !o.signatures.every(isAcceptableSignature) + ) + throw new TypeError('Input has invalid signature(s)'); + if (a.signatures && !(0, types_1.stacksEqual)(a.signatures, o.signatures)) + throw new TypeError('Signature mismatch'); + if (a.m !== undefined && a.m !== a.signatures.length) + throw new TypeError('Signature count mismatch'); + } } - return true; + return Object.assign(o, a); } +exports.p2ms = p2ms; -// 8. The non-equivalence assertion tests for any deep inequality. -// assert.notDeepEqual(actual, expected, message_opt); - -assert.notDeepEqual = function notDeepEqual(actual, expected, message) { - if (_deepEqual(actual, expected, false)) { - fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); - } -}; - -assert.notDeepStrictEqual = notDeepStrictEqual; -function notDeepStrictEqual(actual, expected, message) { - if (_deepEqual(actual, expected, true)) { - fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); +},{"../networks":55,"../script":72,"../types":76,"./lazy":60}],62:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2pk = void 0; +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const OPS = bscript.OPS; +// input: {signature} +// output: {pubKey} OP_CHECKSIG +/** + * Creates a pay-to-public-key (P2PK) payment object. + * + * @param a - The payment object containing the necessary data. + * @param opts - Optional payment options. + * @returns The P2PK payment object. + * @throws {TypeError} If the required data is not provided or if the data is invalid. + */ +function p2pk(a, opts) { + if (!a.input && !a.output && !a.pubkey && !a.input && !a.signature) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + pubkey: types_1.typeforce.maybe(types_1.isPoint), + signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + }, + a, + ); + const _chunks = lazy.value(() => { + return bscript.decompile(a.input); + }); + const network = a.network || networks_1.bitcoin; + const o = { name: 'p2pk', network }; + lazy.prop(o, 'output', () => { + if (!a.pubkey) return; + return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]); + }); + lazy.prop(o, 'pubkey', () => { + if (!a.output) return; + return a.output.slice(1, -1); + }); + lazy.prop(o, 'signature', () => { + if (!a.input) return; + return _chunks()[0]; + }); + lazy.prop(o, 'input', () => { + if (!a.signature) return; + return bscript.compile([a.signature]); + }); + lazy.prop(o, 'witness', () => { + if (!o.input) return; + return []; + }); + // extended validation + if (opts.validate) { + if (a.output) { + if (a.output[a.output.length - 1] !== OPS.OP_CHECKSIG) + throw new TypeError('Output is invalid'); + if (!(0, types_1.isPoint)(o.pubkey)) + throw new TypeError('Output pubkey is invalid'); + if (a.pubkey && !a.pubkey.equals(o.pubkey)) + throw new TypeError('Pubkey mismatch'); + } + if (a.signature) { + if (a.input && !a.input.equals(o.input)) + throw new TypeError('Signature mismatch'); + } + if (a.input) { + if (_chunks().length !== 1) throw new TypeError('Input is invalid'); + if (!bscript.isCanonicalScriptSignature(o.signature)) + throw new TypeError('Input has invalid signature'); + } } + return Object.assign(o, a); } +exports.p2pk = p2pk; - -// 9. The strict equality assertion tests strict equality, as determined by ===. -// assert.strictEqual(actual, expected, message_opt); - -assert.strictEqual = function strictEqual(actual, expected, message) { - if (actual !== expected) { - fail(actual, expected, message, '===', assert.strictEqual); - } -}; - -// 10. The strict non-equality assertion tests for strict inequality, as -// determined by !==. assert.notStrictEqual(actual, expected, message_opt); - -assert.notStrictEqual = function notStrictEqual(actual, expected, message) { - if (actual === expected) { - fail(actual, expected, message, '!==', assert.notStrictEqual); - } -}; - -function expectedException(actual, expected) { - if (!actual || !expected) { - return false; - } - - if (Object.prototype.toString.call(expected) == '[object RegExp]') { - return expected.test(actual); - } - - try { - if (actual instanceof expected) { - return true; +},{"../networks":55,"../script":72,"../types":76,"./lazy":60}],63:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2pkh = void 0; +const bcrypto = require('../crypto'); +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const bs58check = require('bs58check'); +const OPS = bscript.OPS; +// input: {signature} {pubkey} +// output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG +/** + * Creates a Pay-to-Public-Key-Hash (P2PKH) payment object. + * + * @param a - The payment object containing the necessary data. + * @param opts - Optional payment options. + * @returns The P2PKH payment object. + * @throws {TypeError} If the required data is not provided or if the data is invalid. + */ +function p2pkh(a, opts) { + if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + address: types_1.typeforce.maybe(types_1.typeforce.String), + hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), + output: types_1.typeforce.maybe(types_1.typeforce.BufferN(25)), + pubkey: types_1.typeforce.maybe(types_1.isPoint), + signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + }, + a, + ); + const _address = lazy.value(() => { + const payload = Buffer.from(bs58check.decode(a.address)); + const version = payload.readUInt8(0); + const hash = payload.slice(1); + return { version, hash }; + }); + const _chunks = lazy.value(() => { + return bscript.decompile(a.input); + }); + const network = a.network || networks_1.bitcoin; + const o = { name: 'p2pkh', network }; + lazy.prop(o, 'address', () => { + if (!o.hash) return; + const payload = Buffer.allocUnsafe(21); + payload.writeUInt8(network.pubKeyHash, 0); + o.hash.copy(payload, 1); + return bs58check.encode(payload); + }); + lazy.prop(o, 'hash', () => { + if (a.output) return a.output.slice(3, 23); + if (a.address) return _address().hash; + if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey); + }); + lazy.prop(o, 'output', () => { + if (!o.hash) return; + return bscript.compile([ + OPS.OP_DUP, + OPS.OP_HASH160, + o.hash, + OPS.OP_EQUALVERIFY, + OPS.OP_CHECKSIG, + ]); + }); + lazy.prop(o, 'pubkey', () => { + if (!a.input) return; + return _chunks()[1]; + }); + lazy.prop(o, 'signature', () => { + if (!a.input) return; + return _chunks()[0]; + }); + lazy.prop(o, 'input', () => { + if (!a.pubkey) return; + if (!a.signature) return; + return bscript.compile([a.signature, a.pubkey]); + }); + lazy.prop(o, 'witness', () => { + if (!o.input) return; + return []; + }); + // extended validation + if (opts.validate) { + let hash = Buffer.from([]); + if (a.address) { + if (_address().version !== network.pubKeyHash) + throw new TypeError('Invalid version or Network mismatch'); + if (_address().hash.length !== 20) throw new TypeError('Invalid address'); + hash = _address().hash; + } + if (a.hash) { + if (hash.length > 0 && !hash.equals(a.hash)) + throw new TypeError('Hash mismatch'); + else hash = a.hash; + } + if (a.output) { + if ( + a.output.length !== 25 || + a.output[0] !== OPS.OP_DUP || + a.output[1] !== OPS.OP_HASH160 || + a.output[2] !== 0x14 || + a.output[23] !== OPS.OP_EQUALVERIFY || + a.output[24] !== OPS.OP_CHECKSIG + ) + throw new TypeError('Output is invalid'); + const hash2 = a.output.slice(3, 23); + if (hash.length > 0 && !hash.equals(hash2)) + throw new TypeError('Hash mismatch'); + else hash = hash2; + } + if (a.pubkey) { + const pkh = bcrypto.hash160(a.pubkey); + if (hash.length > 0 && !hash.equals(pkh)) + throw new TypeError('Hash mismatch'); + else hash = pkh; + } + if (a.input) { + const chunks = _chunks(); + if (chunks.length !== 2) throw new TypeError('Input is invalid'); + if (!bscript.isCanonicalScriptSignature(chunks[0])) + throw new TypeError('Input has invalid signature'); + if (!(0, types_1.isPoint)(chunks[1])) + throw new TypeError('Input has invalid pubkey'); + if (a.signature && !a.signature.equals(chunks[0])) + throw new TypeError('Signature mismatch'); + if (a.pubkey && !a.pubkey.equals(chunks[1])) + throw new TypeError('Pubkey mismatch'); + const pkh = bcrypto.hash160(chunks[1]); + if (hash.length > 0 && !hash.equals(pkh)) + throw new TypeError('Hash mismatch'); } - } catch (e) { - // Ignore. The instanceof check doesn't work for arrow functions. - } - - if (Error.isPrototypeOf(expected)) { - return false; } - - return expected.call({}, actual) === true; + return Object.assign(o, a); } +exports.p2pkh = p2pkh; -function _tryBlock(block) { - var error; - try { - block(); - } catch (e) { - error = e; - } - return error; -} - -function _throws(shouldThrow, block, expected, message) { - var actual; - - if (typeof block !== 'function') { - throw new TypeError('"block" argument must be a function'); - } - - if (typeof expected === 'string') { - message = expected; - expected = null; - } - - actual = _tryBlock(block); - - message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + - (message ? ' ' + message : '.'); - - if (shouldThrow && !actual) { - fail(actual, expected, 'Missing expected exception' + message); - } - - var userProvidedMessage = typeof message === 'string'; - var isUnwantedException = !shouldThrow && util.isError(actual); - var isUnexpectedException = !shouldThrow && actual && !expected; - - if ((isUnwantedException && - userProvidedMessage && - expectedException(actual, expected)) || - isUnexpectedException) { - fail(actual, expected, 'Got unwanted exception' + message); - } - - if ((shouldThrow && actual && expected && - !expectedException(actual, expected)) || (!shouldThrow && actual)) { - throw actual; - } -} - -// 11. Expected to throw an error: -// assert.throws(block, Error_opt, message_opt); - -assert.throws = function(block, /*optional*/error, /*optional*/message) { - _throws(true, block, error, message); -}; - -// EXTENSION! This is annoying to write outside this module. -assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { - _throws(false, block, error, message); -}; - -assert.ifError = function(err) { if (err) throw err; }; - -// Expose a strict only variant of assert -function strict(value, message) { - if (!value) fail(value, true, message, '==', strict); -} -assert.strict = objectAssign(strict, assert, { - equal: assert.strictEqual, - deepEqual: assert.deepStrictEqual, - notEqual: assert.notStrictEqual, - notDeepEqual: assert.notDeepStrictEqual -}); -assert.strict.strict = assert.strict; - -var objectKeys = Object.keys || function (obj) { - var keys = []; - for (var key in obj) { - if (hasOwn.call(obj, key)) keys.push(key); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":51,"../networks":55,"../script":72,"../types":76,"./lazy":60,"bs58check":79,"buffer":249}],64:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2sh = void 0; +const bcrypto = require('../crypto'); +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const bs58check = require('bs58check'); +const OPS = bscript.OPS; +// input: [redeemScriptSig ...] {redeemScript} +// witness: +// output: OP_HASH160 {hash160(redeemScript)} OP_EQUAL +/** + * Creates a Pay-to-Script-Hash (P2SH) payment object. + * + * @param a - The payment object containing the necessary data. + * @param opts - Optional payment options. + * @returns The P2SH payment object. + * @throws {TypeError} If the required data is not provided or if the data is invalid. + */ +function p2sh(a, opts) { + if (!a.address && !a.hash && !a.output && !a.redeem && !a.input) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + address: types_1.typeforce.maybe(types_1.typeforce.String), + hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), + output: types_1.typeforce.maybe(types_1.typeforce.BufferN(23)), + redeem: types_1.typeforce.maybe({ + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }), + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }, + a, + ); + let network = a.network; + if (!network) { + network = (a.redeem && a.redeem.network) || networks_1.bitcoin; } - return keys; -}; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"object-assign":240,"util/":24}],22:[function(require,module,exports){ -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true + const o = { network }; + const _address = lazy.value(() => { + const payload = Buffer.from(bs58check.decode(a.address)); + const version = payload.readUInt8(0); + const hash = payload.slice(1); + return { version, hash }; + }); + const _chunks = lazy.value(() => { + return bscript.decompile(a.input); + }); + const _redeem = lazy.value(() => { + const chunks = _chunks(); + const lastChunk = chunks[chunks.length - 1]; + return { + network, + output: lastChunk === OPS.OP_FALSE ? Buffer.from([]) : lastChunk, + input: bscript.compile(chunks.slice(0, -1)), + witness: a.witness || [], + }; + }); + // output dependents + lazy.prop(o, 'address', () => { + if (!o.hash) return; + const payload = Buffer.allocUnsafe(21); + payload.writeUInt8(o.network.scriptHash, 0); + o.hash.copy(payload, 1); + return bs58check.encode(payload); + }); + lazy.prop(o, 'hash', () => { + // in order of least effort + if (a.output) return a.output.slice(2, 22); + if (a.address) return _address().hash; + if (o.redeem && o.redeem.output) return bcrypto.hash160(o.redeem.output); + }); + lazy.prop(o, 'output', () => { + if (!o.hash) return; + return bscript.compile([OPS.OP_HASH160, o.hash, OPS.OP_EQUAL]); + }); + // input dependents + lazy.prop(o, 'redeem', () => { + if (!a.input) return; + return _redeem(); + }); + lazy.prop(o, 'input', () => { + if (!a.redeem || !a.redeem.input || !a.redeem.output) return; + return bscript.compile( + [].concat(bscript.decompile(a.redeem.input), a.redeem.output), + ); + }); + lazy.prop(o, 'witness', () => { + if (o.redeem && o.redeem.witness) return o.redeem.witness; + if (o.input) return []; + }); + lazy.prop(o, 'name', () => { + const nameParts = ['p2sh']; + if (o.redeem !== undefined && o.redeem.name !== undefined) + nameParts.push(o.redeem.name); + return nameParts.join('-'); + }); + if (opts.validate) { + let hash = Buffer.from([]); + if (a.address) { + if (_address().version !== network.scriptHash) + throw new TypeError('Invalid version or Network mismatch'); + if (_address().hash.length !== 20) throw new TypeError('Invalid address'); + hash = _address().hash; + } + if (a.hash) { + if (hash.length > 0 && !hash.equals(a.hash)) + throw new TypeError('Hash mismatch'); + else hash = a.hash; + } + if (a.output) { + if ( + a.output.length !== 23 || + a.output[0] !== OPS.OP_HASH160 || + a.output[1] !== 0x14 || + a.output[22] !== OPS.OP_EQUAL + ) + throw new TypeError('Output is invalid'); + const hash2 = a.output.slice(2, 22); + if (hash.length > 0 && !hash.equals(hash2)) + throw new TypeError('Hash mismatch'); + else hash = hash2; + } + // inlined to prevent 'no-inner-declarations' failing + const checkRedeem = redeem => { + // is the redeem output empty/invalid? + if (redeem.output) { + const decompile = bscript.decompile(redeem.output); + if (!decompile || decompile.length < 1) + throw new TypeError('Redeem.output too short'); + if (redeem.output.byteLength > 520) + throw new TypeError( + 'Redeem.output unspendable if larger than 520 bytes', + ); + if (bscript.countNonPushOnlyOPs(decompile) > 201) + throw new TypeError( + 'Redeem.output unspendable with more than 201 non-push ops', + ); + // match hash against other sources + const hash2 = bcrypto.hash160(redeem.output); + if (hash.length > 0 && !hash.equals(hash2)) + throw new TypeError('Hash mismatch'); + else hash = hash2; } - }); - }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor + if (redeem.input) { + const hasInput = redeem.input.length > 0; + const hasWitness = redeem.witness && redeem.witness.length > 0; + if (!hasInput && !hasWitness) throw new TypeError('Empty input'); + if (hasInput && hasWitness) + throw new TypeError('Input and witness provided'); + if (hasInput) { + const richunks = bscript.decompile(redeem.input); + if (!bscript.isPushOnly(richunks)) + throw new TypeError('Non push-only scriptSig'); + } + } + }; + if (a.input) { + const chunks = _chunks(); + if (!chunks || chunks.length < 1) throw new TypeError('Input too short'); + if (!Buffer.isBuffer(_redeem().output)) + throw new TypeError('Input is invalid'); + checkRedeem(_redeem()); + } + if (a.redeem) { + if (a.redeem.network && a.redeem.network !== network) + throw new TypeError('Network mismatch'); + if (a.input) { + const redeem = _redeem(); + if (a.redeem.output && !a.redeem.output.equals(redeem.output)) + throw new TypeError('Redeem.output mismatch'); + if (a.redeem.input && !a.redeem.input.equals(redeem.input)) + throw new TypeError('Redeem.input mismatch'); + } + checkRedeem(a.redeem); + } + if (a.witness) { + if ( + a.redeem && + a.redeem.witness && + !(0, types_1.stacksEqual)(a.redeem.witness, a.witness) + ) + throw new TypeError('Witness and redeem.witness mismatch'); + } } + return Object.assign(o, a); } +exports.p2sh = p2sh; -},{}],23:[function(require,module,exports){ -module.exports = function isBuffer(arg) { - return arg && typeof arg === 'object' - && typeof arg.copy === 'function' - && typeof arg.fill === 'function' - && typeof arg.readUInt8 === 'function'; -} -},{}],24:[function(require,module,exports){ -(function (process,global){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var formatRegExp = /%[sdj%]/g; -exports.format = function(f) { - if (!isString(f)) { - var objects = []; - for (var i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":51,"../networks":55,"../script":72,"../types":76,"./lazy":60,"bs58check":79,"buffer":249}],65:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2tr = void 0; +const buffer_1 = require('buffer'); +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const ecc_lib_1 = require('../ecc_lib'); +const bip341_1 = require('./bip341'); +const lazy = require('./lazy'); +const bech32_1 = require('bech32'); +const address_1 = require('../address'); +const OPS = bscript.OPS; +const TAPROOT_WITNESS_VERSION = 0x01; +const ANNEX_PREFIX = 0x50; +/** + * Creates a Pay-to-Taproot (P2TR) payment object. + * + * @param a - The payment object containing the necessary data for P2TR. + * @param opts - Optional payment options. + * @returns The P2TR payment object. + * @throws {TypeError} If the provided data is invalid or insufficient. + */ +function p2tr(a, opts) { + if ( + !a.address && + !a.output && + !a.pubkey && + !a.internalPubkey && + !(a.witness && a.witness.length > 1) + ) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + address: types_1.typeforce.maybe(types_1.typeforce.String), + input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)), + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.BufferN(34)), + internalPubkey: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)), + hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)), + pubkey: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)), + signature: types_1.typeforce.maybe( + types_1.typeforce.anyOf( + types_1.typeforce.BufferN(64), + types_1.typeforce.BufferN(65), + ), + ), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + scriptTree: types_1.typeforce.maybe(types_1.isTaptree), + redeem: types_1.typeforce.maybe({ + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + redeemVersion: types_1.typeforce.maybe(types_1.typeforce.Number), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }), + redeemVersion: types_1.typeforce.maybe(types_1.typeforce.Number), + }, + a, + ); + const _address = lazy.value(() => { + return (0, address_1.fromBech32)(a.address); + }); + // remove annex if present, ignored by taproot + const _witness = lazy.value(() => { + if (!a.witness || !a.witness.length) return; + if ( + a.witness.length >= 2 && + a.witness[a.witness.length - 1][0] === ANNEX_PREFIX + ) { + return a.witness.slice(0, -1); } - return objects.join(' '); - } - - var i = 1; - var args = arguments; - var len = args.length; - var str = String(f).replace(formatRegExp, function(x) { - if (x === '%%') return '%'; - if (i >= len) return x; - switch (x) { - case '%s': return String(args[i++]); - case '%d': return Number(args[i++]); - case '%j': - try { - return JSON.stringify(args[i++]); - } catch (_) { - return '[Circular]'; - } - default: - return x; + return a.witness.slice(); + }); + const _hashTree = lazy.value(() => { + if (a.scriptTree) return (0, bip341_1.toHashTree)(a.scriptTree); + if (a.hash) return { hash: a.hash }; + return; + }); + const network = a.network || networks_1.bitcoin; + const o = { name: 'p2tr', network }; + lazy.prop(o, 'address', () => { + if (!o.pubkey) return; + const words = bech32_1.bech32m.toWords(o.pubkey); + words.unshift(TAPROOT_WITNESS_VERSION); + return bech32_1.bech32m.encode(network.bech32, words); + }); + lazy.prop(o, 'hash', () => { + const hashTree = _hashTree(); + if (hashTree) return hashTree.hash; + const w = _witness(); + if (w && w.length > 1) { + const controlBlock = w[w.length - 1]; + const leafVersion = controlBlock[0] & types_1.TAPLEAF_VERSION_MASK; + const script = w[w.length - 2]; + const leafHash = (0, bip341_1.tapleafHash)({ + output: script, + version: leafVersion, + }); + return (0, bip341_1.rootHashFromPath)(controlBlock, leafHash); } + return null; }); - for (var x = args[i]; i < len; x = args[++i]) { - if (isNull(x) || !isObject(x)) { - str += ' ' + x; - } else { - str += ' ' + inspect(x); + lazy.prop(o, 'output', () => { + if (!o.pubkey) return; + return bscript.compile([OPS.OP_1, o.pubkey]); + }); + lazy.prop(o, 'redeemVersion', () => { + if (a.redeemVersion) return a.redeemVersion; + if ( + a.redeem && + a.redeem.redeemVersion !== undefined && + a.redeem.redeemVersion !== null + ) { + return a.redeem.redeemVersion; } - } - return str; -}; - - -// Mark that a method should not be used. -// Returns a modified function which warns once by default. -// If --no-deprecation is set, then it is a no-op. -exports.deprecate = function(fn, msg) { - // Allow for deprecating things in the process of starting up. - if (isUndefined(global.process)) { - return function() { - return exports.deprecate(fn, msg).apply(this, arguments); + return bip341_1.LEAF_VERSION_TAPSCRIPT; + }); + lazy.prop(o, 'redeem', () => { + const witness = _witness(); // witness without annex + if (!witness || witness.length < 2) return; + return { + output: witness[witness.length - 2], + witness: witness.slice(0, -2), + redeemVersion: + witness[witness.length - 1][0] & types_1.TAPLEAF_VERSION_MASK, }; - } - - if (process.noDeprecation === true) { - return fn; - } - - var warned = false; - function deprecated() { - if (!warned) { - if (process.throwDeprecation) { - throw new Error(msg); - } else if (process.traceDeprecation) { - console.trace(msg); - } else { - console.error(msg); + }); + lazy.prop(o, 'pubkey', () => { + if (a.pubkey) return a.pubkey; + if (a.output) return a.output.slice(2); + if (a.address) return _address().data; + if (o.internalPubkey) { + const tweakedKey = (0, bip341_1.tweakKey)(o.internalPubkey, o.hash); + if (tweakedKey) return tweakedKey.x; + } + }); + lazy.prop(o, 'internalPubkey', () => { + if (a.internalPubkey) return a.internalPubkey; + const witness = _witness(); + if (witness && witness.length > 1) + return witness[witness.length - 1].slice(1, 33); + }); + lazy.prop(o, 'signature', () => { + if (a.signature) return a.signature; + const witness = _witness(); // witness without annex + if (!witness || witness.length !== 1) return; + return witness[0]; + }); + lazy.prop(o, 'witness', () => { + if (a.witness) return a.witness; + const hashTree = _hashTree(); + if (hashTree && a.redeem && a.redeem.output && a.internalPubkey) { + const leafHash = (0, bip341_1.tapleafHash)({ + output: a.redeem.output, + version: o.redeemVersion, + }); + const path = (0, bip341_1.findScriptPath)(hashTree, leafHash); + if (!path) return; + const outputKey = (0, bip341_1.tweakKey)(a.internalPubkey, hashTree.hash); + if (!outputKey) return; + const controlBock = buffer_1.Buffer.concat( + [ + buffer_1.Buffer.from([o.redeemVersion | outputKey.parity]), + a.internalPubkey, + ].concat(path), + ); + return [a.redeem.output, controlBock]; + } + if (a.signature) return [a.signature]; + }); + // extended validation + if (opts.validate) { + let pubkey = buffer_1.Buffer.from([]); + if (a.address) { + if (network && network.bech32 !== _address().prefix) + throw new TypeError('Invalid prefix or Network mismatch'); + if (_address().version !== TAPROOT_WITNESS_VERSION) + throw new TypeError('Invalid address version'); + if (_address().data.length !== 32) + throw new TypeError('Invalid address data'); + pubkey = _address().data; + } + if (a.pubkey) { + if (pubkey.length > 0 && !pubkey.equals(a.pubkey)) + throw new TypeError('Pubkey mismatch'); + else pubkey = a.pubkey; + } + if (a.output) { + if ( + a.output.length !== 34 || + a.output[0] !== OPS.OP_1 || + a.output[1] !== 0x20 + ) + throw new TypeError('Output is invalid'); + if (pubkey.length > 0 && !pubkey.equals(a.output.slice(2))) + throw new TypeError('Pubkey mismatch'); + else pubkey = a.output.slice(2); + } + if (a.internalPubkey) { + const tweakedKey = (0, bip341_1.tweakKey)(a.internalPubkey, o.hash); + if (pubkey.length > 0 && !pubkey.equals(tweakedKey.x)) + throw new TypeError('Pubkey mismatch'); + else pubkey = tweakedKey.x; + } + if (pubkey && pubkey.length) { + if (!(0, ecc_lib_1.getEccLib)().isXOnlyPoint(pubkey)) + throw new TypeError('Invalid pubkey for p2tr'); + } + const hashTree = _hashTree(); + if (a.hash && hashTree) { + if (!a.hash.equals(hashTree.hash)) throw new TypeError('Hash mismatch'); + } + if (a.redeem && a.redeem.output && hashTree) { + const leafHash = (0, bip341_1.tapleafHash)({ + output: a.redeem.output, + version: o.redeemVersion, + }); + if (!(0, bip341_1.findScriptPath)(hashTree, leafHash)) + throw new TypeError('Redeem script not in tree'); + } + const witness = _witness(); + // compare the provided redeem data with the one computed from witness + if (a.redeem && o.redeem) { + if (a.redeem.redeemVersion) { + if (a.redeem.redeemVersion !== o.redeem.redeemVersion) + throw new TypeError('Redeem.redeemVersion and witness mismatch'); + } + if (a.redeem.output) { + if (bscript.decompile(a.redeem.output).length === 0) + throw new TypeError('Redeem.output is invalid'); + // output redeem is constructed from the witness + if (o.redeem.output && !a.redeem.output.equals(o.redeem.output)) + throw new TypeError('Redeem.output and witness mismatch'); + } + if (a.redeem.witness) { + if ( + o.redeem.witness && + !(0, types_1.stacksEqual)(a.redeem.witness, o.redeem.witness) + ) + throw new TypeError('Redeem.witness and witness mismatch'); } - warned = true; } - return fn.apply(this, arguments); - } - - return deprecated; -}; - - -var debugs = {}; -var debugEnviron; -exports.debuglog = function(set) { - if (isUndefined(debugEnviron)) - debugEnviron = process.env.NODE_DEBUG || ''; - set = set.toUpperCase(); - if (!debugs[set]) { - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { - var pid = process.pid; - debugs[set] = function() { - var msg = exports.format.apply(exports, arguments); - console.error('%s %d: %s', set, pid, msg); - }; - } else { - debugs[set] = function() {}; + if (witness && witness.length) { + if (witness.length === 1) { + // key spending + if (a.signature && !a.signature.equals(witness[0])) + throw new TypeError('Signature mismatch'); + } else { + // script path spending + const controlBlock = witness[witness.length - 1]; + if (controlBlock.length < 33) + throw new TypeError( + `The control-block length is too small. Got ${controlBlock.length}, expected min 33.`, + ); + if ((controlBlock.length - 33) % 32 !== 0) + throw new TypeError( + `The control-block length of ${controlBlock.length} is incorrect!`, + ); + const m = (controlBlock.length - 33) / 32; + if (m > 128) + throw new TypeError( + `The script path is too long. Got ${m}, expected max 128.`, + ); + const internalPubkey = controlBlock.slice(1, 33); + if (a.internalPubkey && !a.internalPubkey.equals(internalPubkey)) + throw new TypeError('Internal pubkey mismatch'); + if (!(0, ecc_lib_1.getEccLib)().isXOnlyPoint(internalPubkey)) + throw new TypeError('Invalid internalPubkey for p2tr witness'); + const leafVersion = controlBlock[0] & types_1.TAPLEAF_VERSION_MASK; + const script = witness[witness.length - 2]; + const leafHash = (0, bip341_1.tapleafHash)({ + output: script, + version: leafVersion, + }); + const hash = (0, bip341_1.rootHashFromPath)(controlBlock, leafHash); + const outputKey = (0, bip341_1.tweakKey)(internalPubkey, hash); + if (!outputKey) + // todo: needs test data + throw new TypeError('Invalid outputKey for p2tr witness'); + if (pubkey.length && !pubkey.equals(outputKey.x)) + throw new TypeError('Pubkey mismatch for p2tr witness'); + if (outputKey.parity !== (controlBlock[0] & 1)) + throw new Error('Incorrect parity'); + } } } - return debugs[set]; -}; - + return Object.assign(o, a); +} +exports.p2tr = p2tr; +},{"../address":47,"../ecc_lib":52,"../networks":55,"../script":72,"../types":76,"./bip341":57,"./lazy":60,"bech32":120,"buffer":249}],66:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2wpkh = void 0; +const bcrypto = require('../crypto'); +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const bech32_1 = require('bech32'); +const OPS = bscript.OPS; +const EMPTY_BUFFER = Buffer.alloc(0); +// witness: {signature} {pubKey} +// input: <> +// output: OP_0 {pubKeyHash} /** - * Echos the value of a value. Trys to print the value out - * in the best way possible given the different types. + * Creates a pay-to-witness-public-key-hash (p2wpkh) payment object. * - * @param {Object} obj The object to print out. - * @param {Object} opts Optional options object that alters the output. + * @param a - The payment object containing the necessary data. + * @param opts - Optional payment options. + * @returns The p2wpkh payment object. + * @throws {TypeError} If the required data is missing or invalid. */ -/* legacy: obj, showHidden, depth, colors*/ -function inspect(obj, opts) { - // default options - var ctx = { - seen: [], - stylize: stylizeNoColor - }; - // legacy... - if (arguments.length >= 3) ctx.depth = arguments[2]; - if (arguments.length >= 4) ctx.colors = arguments[3]; - if (isBoolean(opts)) { - // legacy... - ctx.showHidden = opts; - } else if (opts) { - // got an "options" object - exports._extend(ctx, opts); - } - // set default options - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; - if (isUndefined(ctx.depth)) ctx.depth = 2; - if (isUndefined(ctx.colors)) ctx.colors = false; - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; - if (ctx.colors) ctx.stylize = stylizeWithColor; - return formatValue(ctx, obj, ctx.depth); -} -exports.inspect = inspect; - - -// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics -inspect.colors = { - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [30, 39], - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] -}; - -// Don't use 'blue' not visible on cmd.exe -inspect.styles = { - 'special': 'cyan', - 'number': 'yellow', - 'boolean': 'yellow', - 'undefined': 'grey', - 'null': 'bold', - 'string': 'green', - 'date': 'magenta', - // "name": intentionally not styling - 'regexp': 'red' -}; - - -function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; - - if (style) { - return '\u001b[' + inspect.colors[style][0] + 'm' + str + - '\u001b[' + inspect.colors[style][1] + 'm'; - } else { - return str; +function p2wpkh(a, opts) { + if (!a.address && !a.hash && !a.output && !a.pubkey && !a.witness) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + address: types_1.typeforce.maybe(types_1.typeforce.String), + hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)), + input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)), + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.BufferN(22)), + pubkey: types_1.typeforce.maybe(types_1.isPoint), + signature: types_1.typeforce.maybe(bscript.isCanonicalScriptSignature), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }, + a, + ); + const _address = lazy.value(() => { + const result = bech32_1.bech32.decode(a.address); + const version = result.words.shift(); + const data = bech32_1.bech32.fromWords(result.words); + return { + version, + prefix: result.prefix, + data: Buffer.from(data), + }; + }); + const network = a.network || networks_1.bitcoin; + const o = { name: 'p2wpkh', network }; + lazy.prop(o, 'address', () => { + if (!o.hash) return; + const words = bech32_1.bech32.toWords(o.hash); + words.unshift(0x00); + return bech32_1.bech32.encode(network.bech32, words); + }); + lazy.prop(o, 'hash', () => { + if (a.output) return a.output.slice(2, 22); + if (a.address) return _address().data; + if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey); + }); + lazy.prop(o, 'output', () => { + if (!o.hash) return; + return bscript.compile([OPS.OP_0, o.hash]); + }); + lazy.prop(o, 'pubkey', () => { + if (a.pubkey) return a.pubkey; + if (!a.witness) return; + return a.witness[1]; + }); + lazy.prop(o, 'signature', () => { + if (!a.witness) return; + return a.witness[0]; + }); + lazy.prop(o, 'input', () => { + if (!o.witness) return; + return EMPTY_BUFFER; + }); + lazy.prop(o, 'witness', () => { + if (!a.pubkey) return; + if (!a.signature) return; + return [a.signature, a.pubkey]; + }); + // extended validation + if (opts.validate) { + let hash = Buffer.from([]); + if (a.address) { + if (network && network.bech32 !== _address().prefix) + throw new TypeError('Invalid prefix or Network mismatch'); + if (_address().version !== 0x00) + throw new TypeError('Invalid address version'); + if (_address().data.length !== 20) + throw new TypeError('Invalid address data'); + hash = _address().data; + } + if (a.hash) { + if (hash.length > 0 && !hash.equals(a.hash)) + throw new TypeError('Hash mismatch'); + else hash = a.hash; + } + if (a.output) { + if ( + a.output.length !== 22 || + a.output[0] !== OPS.OP_0 || + a.output[1] !== 0x14 + ) + throw new TypeError('Output is invalid'); + if (hash.length > 0 && !hash.equals(a.output.slice(2))) + throw new TypeError('Hash mismatch'); + else hash = a.output.slice(2); + } + if (a.pubkey) { + const pkh = bcrypto.hash160(a.pubkey); + if (hash.length > 0 && !hash.equals(pkh)) + throw new TypeError('Hash mismatch'); + else hash = pkh; + if (!(0, types_1.isPoint)(a.pubkey) || a.pubkey.length !== 33) + throw new TypeError('Invalid pubkey for p2wpkh'); + } + if (a.witness) { + if (a.witness.length !== 2) throw new TypeError('Witness is invalid'); + if (!bscript.isCanonicalScriptSignature(a.witness[0])) + throw new TypeError('Witness has invalid signature'); + if (!(0, types_1.isPoint)(a.witness[1]) || a.witness[1].length !== 33) + throw new TypeError('Witness has invalid pubkey'); + if (a.signature && !a.signature.equals(a.witness[0])) + throw new TypeError('Signature mismatch'); + if (a.pubkey && !a.pubkey.equals(a.witness[1])) + throw new TypeError('Pubkey mismatch'); + const pkh = bcrypto.hash160(a.witness[1]); + if (hash.length > 0 && !hash.equals(pkh)) + throw new TypeError('Hash mismatch'); + } } + return Object.assign(o, a); } +exports.p2wpkh = p2wpkh; - -function stylizeNoColor(str, styleType) { - return str; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":51,"../networks":55,"../script":72,"../types":76,"./lazy":60,"bech32":120,"buffer":249}],67:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.p2wsh = void 0; +const bcrypto = require('../crypto'); +const networks_1 = require('../networks'); +const bscript = require('../script'); +const types_1 = require('../types'); +const lazy = require('./lazy'); +const bech32_1 = require('bech32'); +const OPS = bscript.OPS; +const EMPTY_BUFFER = Buffer.alloc(0); +function chunkHasUncompressedPubkey(chunk) { + if ( + Buffer.isBuffer(chunk) && + chunk.length === 65 && + chunk[0] === 0x04 && + (0, types_1.isPoint)(chunk) + ) { + return true; + } else { + return false; + } } - - -function arrayToHash(array) { - var hash = {}; - - array.forEach(function(val, idx) { - hash[val] = true; +// input: <> +// witness: [redeemScriptSig ...] {redeemScript} +// output: OP_0 {sha256(redeemScript)} +/** + * Creates a Pay-to-Witness-Script-Hash (P2WSH) payment object. + * + * @param a - The payment object containing the necessary data. + * @param opts - Optional payment options. + * @returns The P2WSH payment object. + * @throws {TypeError} If the required data is missing or invalid. + */ +function p2wsh(a, opts) { + if (!a.address && !a.hash && !a.output && !a.redeem && !a.witness) + throw new TypeError('Not enough data'); + opts = Object.assign({ validate: true }, opts || {}); + (0, types_1.typeforce)( + { + network: types_1.typeforce.maybe(types_1.typeforce.Object), + address: types_1.typeforce.maybe(types_1.typeforce.String), + hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)), + output: types_1.typeforce.maybe(types_1.typeforce.BufferN(34)), + redeem: types_1.typeforce.maybe({ + input: types_1.typeforce.maybe(types_1.typeforce.Buffer), + network: types_1.typeforce.maybe(types_1.typeforce.Object), + output: types_1.typeforce.maybe(types_1.typeforce.Buffer), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }), + input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)), + witness: types_1.typeforce.maybe( + types_1.typeforce.arrayOf(types_1.typeforce.Buffer), + ), + }, + a, + ); + const _address = lazy.value(() => { + const result = bech32_1.bech32.decode(a.address); + const version = result.words.shift(); + const data = bech32_1.bech32.fromWords(result.words); + return { + version, + prefix: result.prefix, + data: Buffer.from(data), + }; }); - - return hash; -} - - -function formatValue(ctx, value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (ctx.customInspect && - value && - isFunction(value.inspect) && - // Filter out the util module, it's inspect function is special - value.inspect !== exports.inspect && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); + const _rchunks = lazy.value(() => { + return bscript.decompile(a.redeem.input); + }); + let network = a.network; + if (!network) { + network = (a.redeem && a.redeem.network) || networks_1.bitcoin; + } + const o = { network }; + lazy.prop(o, 'address', () => { + if (!o.hash) return; + const words = bech32_1.bech32.toWords(o.hash); + words.unshift(0x00); + return bech32_1.bech32.encode(network.bech32, words); + }); + lazy.prop(o, 'hash', () => { + if (a.output) return a.output.slice(2); + if (a.address) return _address().data; + if (o.redeem && o.redeem.output) return bcrypto.sha256(o.redeem.output); + }); + lazy.prop(o, 'output', () => { + if (!o.hash) return; + return bscript.compile([OPS.OP_0, o.hash]); + }); + lazy.prop(o, 'redeem', () => { + if (!a.witness) return; + return { + output: a.witness[a.witness.length - 1], + input: EMPTY_BUFFER, + witness: a.witness.slice(0, -1), + }; + }); + lazy.prop(o, 'input', () => { + if (!o.witness) return; + return EMPTY_BUFFER; + }); + lazy.prop(o, 'witness', () => { + // transform redeem input to witness stack? + if ( + a.redeem && + a.redeem.input && + a.redeem.input.length > 0 && + a.redeem.output && + a.redeem.output.length > 0 + ) { + const stack = bscript.toStack(_rchunks()); + // assign, and blank the existing input + o.redeem = Object.assign({ witness: stack }, a.redeem); + o.redeem.input = EMPTY_BUFFER; + return [].concat(stack, a.redeem.output); + } + if (!a.redeem) return; + if (!a.redeem.output) return; + if (!a.redeem.witness) return; + return [].concat(a.redeem.witness, a.redeem.output); + }); + lazy.prop(o, 'name', () => { + const nameParts = ['p2wsh']; + if (o.redeem !== undefined && o.redeem.name !== undefined) + nameParts.push(o.redeem.name); + return nameParts.join('-'); + }); + // extended validation + if (opts.validate) { + let hash = Buffer.from([]); + if (a.address) { + if (_address().prefix !== network.bech32) + throw new TypeError('Invalid prefix or Network mismatch'); + if (_address().version !== 0x00) + throw new TypeError('Invalid address version'); + if (_address().data.length !== 32) + throw new TypeError('Invalid address data'); + hash = _address().data; + } + if (a.hash) { + if (hash.length > 0 && !hash.equals(a.hash)) + throw new TypeError('Hash mismatch'); + else hash = a.hash; + } + if (a.output) { + if ( + a.output.length !== 34 || + a.output[0] !== OPS.OP_0 || + a.output[1] !== 0x20 + ) + throw new TypeError('Output is invalid'); + const hash2 = a.output.slice(2); + if (hash.length > 0 && !hash.equals(hash2)) + throw new TypeError('Hash mismatch'); + else hash = hash2; + } + if (a.redeem) { + if (a.redeem.network && a.redeem.network !== network) + throw new TypeError('Network mismatch'); + // is there two redeem sources? + if ( + a.redeem.input && + a.redeem.input.length > 0 && + a.redeem.witness && + a.redeem.witness.length > 0 + ) + throw new TypeError('Ambiguous witness source'); + // is the redeem output non-empty/valid? + if (a.redeem.output) { + const decompile = bscript.decompile(a.redeem.output); + if (!decompile || decompile.length < 1) + throw new TypeError('Redeem.output is invalid'); + if (a.redeem.output.byteLength > 3600) + throw new TypeError( + 'Redeem.output unspendable if larger than 3600 bytes', + ); + if (bscript.countNonPushOnlyOPs(decompile) > 201) + throw new TypeError( + 'Redeem.output unspendable with more than 201 non-push ops', + ); + // match hash against other sources + const hash2 = bcrypto.sha256(a.redeem.output); + if (hash.length > 0 && !hash.equals(hash2)) + throw new TypeError('Hash mismatch'); + else hash = hash2; + } + if (a.redeem.input && !bscript.isPushOnly(_rchunks())) + throw new TypeError('Non push-only scriptSig'); + if ( + a.witness && + a.redeem.witness && + !(0, types_1.stacksEqual)(a.witness, a.redeem.witness) + ) + throw new TypeError('Witness and redeem.witness mismatch'); + if ( + (a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) || + (a.redeem.output && + (bscript.decompile(a.redeem.output) || []).some( + chunkHasUncompressedPubkey, + )) + ) { + throw new TypeError( + 'redeem.input or redeem.output contains uncompressed pubkey', + ); + } + } + if (a.witness && a.witness.length > 0) { + const wScript = a.witness[a.witness.length - 1]; + if (a.redeem && a.redeem.output && !a.redeem.output.equals(wScript)) + throw new TypeError('Witness and redeem.output mismatch'); + if ( + a.witness.some(chunkHasUncompressedPubkey) || + (bscript.decompile(wScript) || []).some(chunkHasUncompressedPubkey) + ) + throw new TypeError('Witness contains uncompressed pubkey'); } - return ret; } + return Object.assign(o, a); +} +exports.p2wsh = p2wsh; - // Primitive types cannot have properties - var primitive = formatPrimitive(ctx, value); - if (primitive) { - return primitive; +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":51,"../networks":55,"../script":72,"../types":76,"./lazy":60,"bech32":120,"buffer":249}],68:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.Psbt = void 0; +const bip174_1 = require('bip174'); +const varuint = require('bip174/src/lib/converter/varint'); +const utils_1 = require('bip174/src/lib/utils'); +const address_1 = require('./address'); +const bufferutils_1 = require('./bufferutils'); +const networks_1 = require('./networks'); +const payments = require('./payments'); +const bip341_1 = require('./payments/bip341'); +const bscript = require('./script'); +const transaction_1 = require('./transaction'); +const bip371_1 = require('./psbt/bip371'); +const psbtutils_1 = require('./psbt/psbtutils'); +/** + * These are the default arguments for a Psbt instance. + */ +const DEFAULT_OPTS = { + /** + * A bitcoinjs Network object. This is only used if you pass an `address` + * parameter to addOutput. Otherwise it is not needed and can be left default. + */ + network: networks_1.bitcoin, + /** + * When extractTransaction is called, the fee rate is checked. + * THIS IS NOT TO BE RELIED ON. + * It is only here as a last ditch effort to prevent sending a 500 BTC fee etc. + */ + maximumFeeRate: 5000, // satoshi per byte +}; +/** + * Psbt class can parse and generate a PSBT binary based off of the BIP174. + * There are 6 roles that this class fulfills. (Explained in BIP174) + * + * Creator: This can be done with `new Psbt()` + * + * Updater: This can be done with `psbt.addInput(input)`, `psbt.addInputs(inputs)`, + * `psbt.addOutput(output)`, `psbt.addOutputs(outputs)` when you are looking to + * add new inputs and outputs to the PSBT, and `psbt.updateGlobal(itemObject)`, + * `psbt.updateInput(itemObject)`, `psbt.updateOutput(itemObject)` + * addInput requires hash: Buffer | string; and index: number; as attributes + * and can also include any attributes that are used in updateInput method. + * addOutput requires script: Buffer; and value: number; and likewise can include + * data for updateOutput. + * For a list of what attributes should be what types. Check the bip174 library. + * Also, check the integration tests for some examples of usage. + * + * Signer: There are a few methods. signAllInputs and signAllInputsAsync, which will search all input + * information for your pubkey or pubkeyhash, and only sign inputs where it finds + * your info. Or you can explicitly sign a specific input with signInput and + * signInputAsync. For the async methods you can create a SignerAsync object + * and use something like a hardware wallet to sign with. (You must implement this) + * + * Combiner: psbts can be combined easily with `psbt.combine(psbt2, psbt3, psbt4 ...)` + * the psbt calling combine will always have precedence when a conflict occurs. + * Combine checks if the internal bitcoin transaction is the same, so be sure that + * all sequences, version, locktime, etc. are the same before combining. + * + * Input Finalizer: This role is fairly important. Not only does it need to construct + * the input scriptSigs and witnesses, but it SHOULD verify the signatures etc. + * Before running `psbt.finalizeAllInputs()` please run `psbt.validateSignaturesOfAllInputs()` + * Running any finalize method will delete any data in the input(s) that are no longer + * needed due to the finalized scripts containing the information. + * + * Transaction Extractor: This role will perform some checks before returning a + * Transaction object. Such as fee rate not being larger than maximumFeeRate etc. + */ +class Psbt { + static fromBase64(data, opts = {}) { + const buffer = Buffer.from(data, 'base64'); + return this.fromBuffer(buffer, opts); + } + static fromHex(data, opts = {}) { + const buffer = Buffer.from(data, 'hex'); + return this.fromBuffer(buffer, opts); + } + static fromBuffer(buffer, opts = {}) { + const psbtBase = bip174_1.Psbt.fromBuffer(buffer, transactionFromBuffer); + const psbt = new Psbt(opts, psbtBase); + checkTxForDupeIns(psbt.__CACHE.__TX, psbt.__CACHE); + return psbt; + } + constructor(opts = {}, data = new bip174_1.Psbt(new PsbtTransaction())) { + this.data = data; + // set defaults + this.opts = Object.assign({}, DEFAULT_OPTS, opts); + this.__CACHE = { + __NON_WITNESS_UTXO_TX_CACHE: [], + __NON_WITNESS_UTXO_BUF_CACHE: [], + __TX_IN_CACHE: {}, + __TX: this.data.globalMap.unsignedTx.tx, + // Psbt's predecessor (TransactionBuilder - now removed) behavior + // was to not confirm input values before signing. + // Even though we highly encourage people to get + // the full parent transaction to verify values, the ability to + // sign non-segwit inputs without the full transaction was often + // requested. So the only way to activate is to use @ts-ignore. + // We will disable exporting the Psbt when unsafe sign is active. + // because it is not BIP174 compliant. + __UNSAFE_SIGN_NONSEGWIT: false, + }; + if (this.data.inputs.length === 0) this.setVersion(2); + // Make data hidden when enumerating + const dpew = (obj, attr, enumerable, writable) => + Object.defineProperty(obj, attr, { + enumerable, + writable, + }); + dpew(this, '__CACHE', false, true); + dpew(this, 'opts', false, true); } - - // Look up the keys of the object. - var keys = Object.keys(value); - var visibleKeys = arrayToHash(keys); - - if (ctx.showHidden) { - keys = Object.getOwnPropertyNames(value); + get inputCount() { + return this.data.inputs.length; } - - // IE doesn't make error fields non-enumerable - // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx - if (isError(value) - && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { - return formatError(value); + get version() { + return this.__CACHE.__TX.version; } - - // Some type of object without properties can be shortcutted. - if (keys.length === 0) { - if (isFunction(value)) { - var name = value.name ? ': ' + value.name : ''; - return ctx.stylize('[Function' + name + ']', 'special'); + set version(version) { + this.setVersion(version); + } + get locktime() { + return this.__CACHE.__TX.locktime; + } + set locktime(locktime) { + this.setLocktime(locktime); + } + get txInputs() { + return this.__CACHE.__TX.ins.map(input => ({ + hash: (0, bufferutils_1.cloneBuffer)(input.hash), + index: input.index, + sequence: input.sequence, + })); + } + get txOutputs() { + return this.__CACHE.__TX.outs.map(output => { + let address; + try { + address = (0, address_1.fromOutputScript)( + output.script, + this.opts.network, + ); + } catch (_) {} + return { + script: (0, bufferutils_1.cloneBuffer)(output.script), + value: output.value, + address, + }; + }); + } + combine(...those) { + this.data.combine(...those.map(o => o.data)); + return this; + } + clone() { + // TODO: more efficient cloning + const res = Psbt.fromBuffer(this.data.toBuffer()); + res.opts = JSON.parse(JSON.stringify(this.opts)); + return res; + } + setMaximumFeeRate(satoshiPerByte) { + check32Bit(satoshiPerByte); // 42.9 BTC per byte IS excessive... so throw + this.opts.maximumFeeRate = satoshiPerByte; + } + setVersion(version) { + check32Bit(version); + checkInputsForPartialSig(this.data.inputs, 'setVersion'); + const c = this.__CACHE; + c.__TX.version = version; + c.__EXTRACTED_TX = undefined; + return this; + } + setLocktime(locktime) { + check32Bit(locktime); + checkInputsForPartialSig(this.data.inputs, 'setLocktime'); + const c = this.__CACHE; + c.__TX.locktime = locktime; + c.__EXTRACTED_TX = undefined; + return this; + } + setInputSequence(inputIndex, sequence) { + check32Bit(sequence); + checkInputsForPartialSig(this.data.inputs, 'setInputSequence'); + const c = this.__CACHE; + if (c.__TX.ins.length <= inputIndex) { + throw new Error('Input index too high'); } - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + c.__TX.ins[inputIndex].sequence = sequence; + c.__EXTRACTED_TX = undefined; + return this; + } + addInputs(inputDatas) { + inputDatas.forEach(inputData => this.addInput(inputData)); + return this; + } + addInput(inputData) { + if ( + arguments.length > 1 || + !inputData || + inputData.hash === undefined || + inputData.index === undefined + ) { + throw new Error( + `Invalid arguments for Psbt.addInput. ` + + `Requires single object with at least [hash] and [index]`, + ); } - if (isDate(value)) { - return ctx.stylize(Date.prototype.toString.call(value), 'date'); + (0, bip371_1.checkTaprootInputFields)(inputData, inputData, 'addInput'); + checkInputsForPartialSig(this.data.inputs, 'addInput'); + if (inputData.witnessScript) checkInvalidP2WSH(inputData.witnessScript); + const c = this.__CACHE; + this.data.addInput(inputData); + const txIn = c.__TX.ins[c.__TX.ins.length - 1]; + checkTxInputCache(c, txIn); + const inputIndex = this.data.inputs.length - 1; + const input = this.data.inputs[inputIndex]; + if (input.nonWitnessUtxo) { + addNonWitnessTxCache(this.__CACHE, input, inputIndex); + } + c.__FEE = undefined; + c.__FEE_RATE = undefined; + c.__EXTRACTED_TX = undefined; + return this; + } + addOutputs(outputDatas) { + outputDatas.forEach(outputData => this.addOutput(outputData)); + return this; + } + addOutput(outputData) { + if ( + arguments.length > 1 || + !outputData || + outputData.value === undefined || + (outputData.address === undefined && outputData.script === undefined) + ) { + throw new Error( + `Invalid arguments for Psbt.addOutput. ` + + `Requires single object with at least [script or address] and [value]`, + ); } - if (isError(value)) { - return formatError(value); + checkInputsForPartialSig(this.data.inputs, 'addOutput'); + const { address } = outputData; + if (typeof address === 'string') { + const { network } = this.opts; + const script = (0, address_1.toOutputScript)(address, network); + outputData = Object.assign({}, outputData, { script }); + } + (0, bip371_1.checkTaprootOutputFields)(outputData, outputData, 'addOutput'); + const c = this.__CACHE; + this.data.addOutput(outputData); + c.__FEE = undefined; + c.__FEE_RATE = undefined; + c.__EXTRACTED_TX = undefined; + return this; + } + extractTransaction(disableFeeCheck) { + if (!this.data.inputs.every(isFinalized)) throw new Error('Not finalized'); + const c = this.__CACHE; + if (!disableFeeCheck) { + checkFees(this, c, this.opts); } + if (c.__EXTRACTED_TX) return c.__EXTRACTED_TX; + const tx = c.__TX.clone(); + inputFinalizeGetAmts(this.data.inputs, tx, c, true); + return tx; } - - var base = '', array = false, braces = ['{', '}']; - - // Make Array say that they are Array - if (isArray(value)) { - array = true; - braces = ['[', ']']; + getFeeRate() { + return getTxCacheValue( + '__FEE_RATE', + 'fee rate', + this.data.inputs, + this.__CACHE, + ); } - - // Make functions say that they are functions - if (isFunction(value)) { - var n = value.name ? ': ' + value.name : ''; - base = ' [Function' + n + ']'; + getFee() { + return getTxCacheValue('__FEE', 'fee', this.data.inputs, this.__CACHE); } - - // Make RegExps say that they are RegExps - if (isRegExp(value)) { - base = ' ' + RegExp.prototype.toString.call(value); + finalizeAllInputs() { + (0, utils_1.checkForInput)(this.data.inputs, 0); // making sure we have at least one + range(this.data.inputs.length).forEach(idx => this.finalizeInput(idx)); + return this; } - - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + Date.prototype.toUTCString.call(value); + finalizeInput(inputIndex, finalScriptsFunc) { + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) + return this._finalizeTaprootInput( + inputIndex, + input, + undefined, + finalScriptsFunc, + ); + return this._finalizeInput(inputIndex, input, finalScriptsFunc); } - - // Make error with message first say the error - if (isError(value)) { - base = ' ' + formatError(value); + finalizeTaprootInput( + inputIndex, + tapLeafHashToFinalize, + finalScriptsFunc = bip371_1.tapScriptFinalizer, + ) { + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) + return this._finalizeTaprootInput( + inputIndex, + input, + tapLeafHashToFinalize, + finalScriptsFunc, + ); + throw new Error(`Cannot finalize input #${inputIndex}. Not Taproot.`); } - - if (keys.length === 0 && (!array || value.length == 0)) { - return braces[0] + base + braces[1]; + _finalizeInput(inputIndex, input, finalScriptsFunc = getFinalScripts) { + const { script, isP2SH, isP2WSH, isSegwit } = getScriptFromInput( + inputIndex, + input, + this.__CACHE, + ); + if (!script) throw new Error(`No script found for input #${inputIndex}`); + checkPartialSigSighashes(input); + const { finalScriptSig, finalScriptWitness } = finalScriptsFunc( + inputIndex, + input, + script, + isSegwit, + isP2SH, + isP2WSH, + ); + if (finalScriptSig) this.data.updateInput(inputIndex, { finalScriptSig }); + if (finalScriptWitness) + this.data.updateInput(inputIndex, { finalScriptWitness }); + if (!finalScriptSig && !finalScriptWitness) + throw new Error(`Unknown error finalizing input #${inputIndex}`); + this.data.clearFinalizedInput(inputIndex); + return this; } - - if (recurseTimes < 0) { - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + _finalizeTaprootInput( + inputIndex, + input, + tapLeafHashToFinalize, + finalScriptsFunc = bip371_1.tapScriptFinalizer, + ) { + if (!input.witnessUtxo) + throw new Error( + `Cannot finalize input #${inputIndex}. Missing withness utxo.`, + ); + // Check key spend first. Increased privacy and reduced block space. + if (input.tapKeySig) { + const payment = payments.p2tr({ + output: input.witnessUtxo.script, + signature: input.tapKeySig, + }); + const finalScriptWitness = (0, psbtutils_1.witnessStackToScriptWitness)( + payment.witness, + ); + this.data.updateInput(inputIndex, { finalScriptWitness }); } else { - return ctx.stylize('[Object]', 'special'); + const { finalScriptWitness } = finalScriptsFunc( + inputIndex, + input, + tapLeafHashToFinalize, + ); + this.data.updateInput(inputIndex, { finalScriptWitness }); } + this.data.clearFinalizedInput(inputIndex); + return this; } - - ctx.seen.push(value); - - var output; - if (array) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); - }); + getInputType(inputIndex) { + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + const script = getScriptFromUtxo(inputIndex, input, this.__CACHE); + const result = getMeaningfulScript( + script, + inputIndex, + 'input', + input.redeemScript || redeemFromFinalScriptSig(input.finalScriptSig), + input.witnessScript || + redeemFromFinalWitnessScript(input.finalScriptWitness), + ); + const type = result.type === 'raw' ? '' : result.type + '-'; + const mainType = classifyScript(result.meaningfulScript); + return type + mainType; } - - ctx.seen.pop(); - - return reduceToSingleString(output, base, braces); -} - - -function formatPrimitive(ctx, value) { - if (isUndefined(value)) - return ctx.stylize('undefined', 'undefined'); - if (isString(value)) { - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') - .replace(/'/g, "\\'") - .replace(/\\"/g, '"') + '\''; - return ctx.stylize(simple, 'string'); + inputHasPubkey(inputIndex, pubkey) { + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + return pubkeyInInput(pubkey, input, inputIndex, this.__CACHE); } - if (isNumber(value)) - return ctx.stylize('' + value, 'number'); - if (isBoolean(value)) - return ctx.stylize('' + value, 'boolean'); - // For some reason typeof null is "object", so special case here. - if (isNull(value)) - return ctx.stylize('null', 'null'); -} - - -function formatError(value) { - return '[' + Error.prototype.toString.call(value) + ']'; -} - - -function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { - var output = []; - for (var i = 0, l = value.length; i < l; ++i) { - if (hasOwnProperty(value, String(i))) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); - } else { - output.push(''); + inputHasHDKey(inputIndex, root) { + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + const derivationIsMine = bip32DerivationIsMine(root); + return ( + !!input.bip32Derivation && input.bip32Derivation.some(derivationIsMine) + ); + } + outputHasPubkey(outputIndex, pubkey) { + const output = (0, utils_1.checkForOutput)(this.data.outputs, outputIndex); + return pubkeyInOutput(pubkey, output, outputIndex, this.__CACHE); + } + outputHasHDKey(outputIndex, root) { + const output = (0, utils_1.checkForOutput)(this.data.outputs, outputIndex); + const derivationIsMine = bip32DerivationIsMine(root); + return ( + !!output.bip32Derivation && output.bip32Derivation.some(derivationIsMine) + ); + } + validateSignaturesOfAllInputs(validator) { + (0, utils_1.checkForInput)(this.data.inputs, 0); // making sure we have at least one + const results = range(this.data.inputs.length).map(idx => + this.validateSignaturesOfInput(idx, validator), + ); + return results.reduce((final, res) => res === true && final, true); + } + validateSignaturesOfInput(inputIndex, validator, pubkey) { + const input = this.data.inputs[inputIndex]; + if ((0, bip371_1.isTaprootInput)(input)) + return this.validateSignaturesOfTaprootInput( + inputIndex, + validator, + pubkey, + ); + return this._validateSignaturesOfInput(inputIndex, validator, pubkey); + } + _validateSignaturesOfInput(inputIndex, validator, pubkey) { + const input = this.data.inputs[inputIndex]; + const partialSig = (input || {}).partialSig; + if (!input || !partialSig || partialSig.length < 1) + throw new Error('No signatures to validate'); + if (typeof validator !== 'function') + throw new Error('Need validator function to validate signatures'); + const mySigs = pubkey + ? partialSig.filter(sig => sig.pubkey.equals(pubkey)) + : partialSig; + if (mySigs.length < 1) throw new Error('No signatures for this pubkey'); + const results = []; + let hashCache; + let scriptCache; + let sighashCache; + for (const pSig of mySigs) { + const sig = bscript.signature.decode(pSig.signature); + const { hash, script } = + sighashCache !== sig.hashType + ? getHashForSig( + inputIndex, + Object.assign({}, input, { sighashType: sig.hashType }), + this.__CACHE, + true, + ) + : { hash: hashCache, script: scriptCache }; + sighashCache = sig.hashType; + hashCache = hash; + scriptCache = script; + checkScriptForPubkey(pSig.pubkey, script, 'verify'); + results.push(validator(pSig.pubkey, hash, sig.signature)); + } + return results.every(res => res === true); + } + validateSignaturesOfTaprootInput(inputIndex, validator, pubkey) { + const input = this.data.inputs[inputIndex]; + const tapKeySig = (input || {}).tapKeySig; + const tapScriptSig = (input || {}).tapScriptSig; + if (!input && !tapKeySig && !(tapScriptSig && !tapScriptSig.length)) + throw new Error('No signatures to validate'); + if (typeof validator !== 'function') + throw new Error('Need validator function to validate signatures'); + pubkey = pubkey && (0, bip371_1.toXOnly)(pubkey); + const allHashses = pubkey + ? getTaprootHashesForSig( + inputIndex, + input, + this.data.inputs, + pubkey, + this.__CACHE, + ) + : getAllTaprootHashesForSig( + inputIndex, + input, + this.data.inputs, + this.__CACHE, + ); + if (!allHashses.length) throw new Error('No signatures for this pubkey'); + const tapKeyHash = allHashses.find(h => !h.leafHash); + let validationResultCount = 0; + if (tapKeySig && tapKeyHash) { + const isValidTapkeySig = validator( + tapKeyHash.pubkey, + tapKeyHash.hash, + trimTaprootSig(tapKeySig), + ); + if (!isValidTapkeySig) return false; + validationResultCount++; + } + if (tapScriptSig) { + for (const tapSig of tapScriptSig) { + const tapSigHash = allHashses.find(h => tapSig.pubkey.equals(h.pubkey)); + if (tapSigHash) { + const isValidTapScriptSig = validator( + tapSig.pubkey, + tapSigHash.hash, + trimTaprootSig(tapSig.signature), + ); + if (!isValidTapScriptSig) return false; + validationResultCount++; + } + } } + return validationResultCount > 0; } - keys.forEach(function(key) { - if (!key.match(/^\d+$/)) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); + signAllInputsHD( + hdKeyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + if (!hdKeyPair || !hdKeyPair.publicKey || !hdKeyPair.fingerprint) { + throw new Error('Need HDSigner to sign input'); } - }); - return output; -} - - -function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str, desc; - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; - if (desc.get) { - if (desc.set) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); + const results = []; + for (const i of range(this.data.inputs.length)) { + try { + this.signInputHD(i, hdKeyPair, sighashTypes); + results.push(true); + } catch (err) { + results.push(false); + } } - } else { - if (desc.set) { - str = ctx.stylize('[Setter]', 'special'); + if (results.every(v => v === false)) { + throw new Error('No inputs were signed'); } + return this; } - if (!hasOwnProperty(visibleKeys, key)) { - name = '[' + key + ']'; - } - if (!str) { - if (ctx.seen.indexOf(desc.value) < 0) { - if (isNull(recurseTimes)) { - str = formatValue(ctx, desc.value, null); - } else { - str = formatValue(ctx, desc.value, recurseTimes - 1); + signAllInputsHDAsync( + hdKeyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + return new Promise((resolve, reject) => { + if (!hdKeyPair || !hdKeyPair.publicKey || !hdKeyPair.fingerprint) { + return reject(new Error('Need HDSigner to sign input')); } - if (str.indexOf('\n') > -1) { - if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); - } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); + const results = []; + const promises = []; + for (const i of range(this.data.inputs.length)) { + promises.push( + this.signInputHDAsync(i, hdKeyPair, sighashTypes).then( + () => { + results.push(true); + }, + () => { + results.push(false); + }, + ), + ); + } + return Promise.all(promises).then(() => { + if (results.every(v => v === false)) { + return reject(new Error('No inputs were signed')); } + resolve(); + }); + }); + } + signInputHD( + inputIndex, + hdKeyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + if (!hdKeyPair || !hdKeyPair.publicKey || !hdKeyPair.fingerprint) { + throw new Error('Need HDSigner to sign input'); + } + const signers = getSignersFromHD(inputIndex, this.data.inputs, hdKeyPair); + signers.forEach(signer => this.signInput(inputIndex, signer, sighashTypes)); + return this; + } + signInputHDAsync( + inputIndex, + hdKeyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + return new Promise((resolve, reject) => { + if (!hdKeyPair || !hdKeyPair.publicKey || !hdKeyPair.fingerprint) { + return reject(new Error('Need HDSigner to sign input')); + } + const signers = getSignersFromHD(inputIndex, this.data.inputs, hdKeyPair); + const promises = signers.map(signer => + this.signInputAsync(inputIndex, signer, sighashTypes), + ); + return Promise.all(promises) + .then(() => { + resolve(); + }) + .catch(reject); + }); + } + signAllInputs(keyPair, sighashTypes) { + if (!keyPair || !keyPair.publicKey) + throw new Error('Need Signer to sign input'); + // TODO: Add a pubkey/pubkeyhash cache to each input + // as input information is added, then eventually + // optimize this method. + const results = []; + for (const i of range(this.data.inputs.length)) { + try { + this.signInput(i, keyPair, sighashTypes); + results.push(true); + } catch (err) { + results.push(false); } - } else { - str = ctx.stylize('[Circular]', 'special'); } + if (results.every(v => v === false)) { + throw new Error('No inputs were signed'); + } + return this; } - if (isUndefined(name)) { - if (array && key.match(/^\d+$/)) { - return str; + signAllInputsAsync(keyPair, sighashTypes) { + return new Promise((resolve, reject) => { + if (!keyPair || !keyPair.publicKey) + return reject(new Error('Need Signer to sign input')); + // TODO: Add a pubkey/pubkeyhash cache to each input + // as input information is added, then eventually + // optimize this method. + const results = []; + const promises = []; + for (const [i] of this.data.inputs.entries()) { + promises.push( + this.signInputAsync(i, keyPair, sighashTypes).then( + () => { + results.push(true); + }, + () => { + results.push(false); + }, + ), + ); + } + return Promise.all(promises).then(() => { + if (results.every(v => v === false)) { + return reject(new Error('No inputs were signed')); + } + resolve(); + }); + }); + } + signInput(inputIndex, keyPair, sighashTypes) { + if (!keyPair || !keyPair.publicKey) + throw new Error('Need Signer to sign input'); + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) { + return this._signTaprootInput( + inputIndex, + input, + keyPair, + undefined, + sighashTypes, + ); } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length - 2); - name = ctx.stylize(name, 'name'); - } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = ctx.stylize(name, 'string'); + return this._signInput(inputIndex, keyPair, sighashTypes); + } + signTaprootInput(inputIndex, keyPair, tapLeafHashToSign, sighashTypes) { + if (!keyPair || !keyPair.publicKey) + throw new Error('Need Signer to sign input'); + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) + return this._signTaprootInput( + inputIndex, + input, + keyPair, + tapLeafHashToSign, + sighashTypes, + ); + throw new Error(`Input #${inputIndex} is not of type Taproot.`); + } + _signInput( + inputIndex, + keyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + const { hash, sighashType } = getHashAndSighashType( + this.data.inputs, + inputIndex, + keyPair.publicKey, + this.__CACHE, + sighashTypes, + ); + const partialSig = [ + { + pubkey: keyPair.publicKey, + signature: bscript.signature.encode(keyPair.sign(hash), sighashType), + }, + ]; + this.data.updateInput(inputIndex, { partialSig }); + return this; + } + _signTaprootInput( + inputIndex, + input, + keyPair, + tapLeafHashToSign, + allowedSighashTypes = [transaction_1.Transaction.SIGHASH_DEFAULT], + ) { + const hashesForSig = this.checkTaprootHashesForSig( + inputIndex, + input, + keyPair, + tapLeafHashToSign, + allowedSighashTypes, + ); + const tapKeySig = hashesForSig + .filter(h => !h.leafHash) + .map(h => + (0, bip371_1.serializeTaprootSignature)( + keyPair.signSchnorr(h.hash), + input.sighashType, + ), + )[0]; + const tapScriptSig = hashesForSig + .filter(h => !!h.leafHash) + .map(h => ({ + pubkey: (0, bip371_1.toXOnly)(keyPair.publicKey), + signature: (0, bip371_1.serializeTaprootSignature)( + keyPair.signSchnorr(h.hash), + input.sighashType, + ), + leafHash: h.leafHash, + })); + if (tapKeySig) { + this.data.updateInput(inputIndex, { tapKeySig }); + } + if (tapScriptSig.length) { + this.data.updateInput(inputIndex, { tapScriptSig }); } + return this; + } + signInputAsync(inputIndex, keyPair, sighashTypes) { + return Promise.resolve().then(() => { + if (!keyPair || !keyPair.publicKey) + throw new Error('Need Signer to sign input'); + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) + return this._signTaprootInputAsync( + inputIndex, + input, + keyPair, + undefined, + sighashTypes, + ); + return this._signInputAsync(inputIndex, keyPair, sighashTypes); + }); + } + signTaprootInputAsync(inputIndex, keyPair, tapLeafHash, sighashTypes) { + return Promise.resolve().then(() => { + if (!keyPair || !keyPair.publicKey) + throw new Error('Need Signer to sign input'); + const input = (0, utils_1.checkForInput)(this.data.inputs, inputIndex); + if ((0, bip371_1.isTaprootInput)(input)) + return this._signTaprootInputAsync( + inputIndex, + input, + keyPair, + tapLeafHash, + sighashTypes, + ); + throw new Error(`Input #${inputIndex} is not of type Taproot.`); + }); + } + _signInputAsync( + inputIndex, + keyPair, + sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], + ) { + const { hash, sighashType } = getHashAndSighashType( + this.data.inputs, + inputIndex, + keyPair.publicKey, + this.__CACHE, + sighashTypes, + ); + return Promise.resolve(keyPair.sign(hash)).then(signature => { + const partialSig = [ + { + pubkey: keyPair.publicKey, + signature: bscript.signature.encode(signature, sighashType), + }, + ]; + this.data.updateInput(inputIndex, { partialSig }); + }); + } + async _signTaprootInputAsync( + inputIndex, + input, + keyPair, + tapLeafHash, + sighashTypes = [transaction_1.Transaction.SIGHASH_DEFAULT], + ) { + const hashesForSig = this.checkTaprootHashesForSig( + inputIndex, + input, + keyPair, + tapLeafHash, + sighashTypes, + ); + const signaturePromises = []; + const tapKeyHash = hashesForSig.filter(h => !h.leafHash)[0]; + if (tapKeyHash) { + const tapKeySigPromise = Promise.resolve( + keyPair.signSchnorr(tapKeyHash.hash), + ).then(sig => { + return { + tapKeySig: (0, bip371_1.serializeTaprootSignature)( + sig, + input.sighashType, + ), + }; + }); + signaturePromises.push(tapKeySigPromise); + } + const tapScriptHashes = hashesForSig.filter(h => !!h.leafHash); + if (tapScriptHashes.length) { + const tapScriptSigPromises = tapScriptHashes.map(tsh => { + return Promise.resolve(keyPair.signSchnorr(tsh.hash)).then( + signature => { + const tapScriptSig = [ + { + pubkey: (0, bip371_1.toXOnly)(keyPair.publicKey), + signature: (0, bip371_1.serializeTaprootSignature)( + signature, + input.sighashType, + ), + leafHash: tsh.leafHash, + }, + ]; + return { tapScriptSig }; + }, + ); + }); + signaturePromises.push(...tapScriptSigPromises); + } + return Promise.all(signaturePromises).then(results => { + results.forEach(v => this.data.updateInput(inputIndex, v)); + }); + } + checkTaprootHashesForSig( + inputIndex, + input, + keyPair, + tapLeafHashToSign, + allowedSighashTypes, + ) { + if (typeof keyPair.signSchnorr !== 'function') + throw new Error( + `Need Schnorr Signer to sign taproot input #${inputIndex}.`, + ); + const hashesForSig = getTaprootHashesForSig( + inputIndex, + input, + this.data.inputs, + keyPair.publicKey, + this.__CACHE, + tapLeafHashToSign, + allowedSighashTypes, + ); + if (!hashesForSig || !hashesForSig.length) + throw new Error( + `Can not sign for input #${inputIndex} with the key ${keyPair.publicKey.toString( + 'hex', + )}`, + ); + return hashesForSig; + } + toBuffer() { + checkCache(this.__CACHE); + return this.data.toBuffer(); + } + toHex() { + checkCache(this.__CACHE); + return this.data.toHex(); + } + toBase64() { + checkCache(this.__CACHE); + return this.data.toBase64(); + } + updateGlobal(updateData) { + this.data.updateGlobal(updateData); + return this; + } + updateInput(inputIndex, updateData) { + if (updateData.witnessScript) checkInvalidP2WSH(updateData.witnessScript); + (0, bip371_1.checkTaprootInputFields)( + this.data.inputs[inputIndex], + updateData, + 'updateInput', + ); + this.data.updateInput(inputIndex, updateData); + if (updateData.nonWitnessUtxo) { + addNonWitnessTxCache( + this.__CACHE, + this.data.inputs[inputIndex], + inputIndex, + ); + } + return this; + } + updateOutput(outputIndex, updateData) { + const outputData = this.data.outputs[outputIndex]; + (0, bip371_1.checkTaprootOutputFields)( + outputData, + updateData, + 'updateOutput', + ); + this.data.updateOutput(outputIndex, updateData); + return this; + } + addUnknownKeyValToGlobal(keyVal) { + this.data.addUnknownKeyValToGlobal(keyVal); + return this; + } + addUnknownKeyValToInput(inputIndex, keyVal) { + this.data.addUnknownKeyValToInput(inputIndex, keyVal); + return this; + } + addUnknownKeyValToOutput(outputIndex, keyVal) { + this.data.addUnknownKeyValToOutput(outputIndex, keyVal); + return this; + } + clearFinalizedInput(inputIndex) { + this.data.clearFinalizedInput(inputIndex); + return this; } - - return name + ': ' + str; } - - -function reduceToSingleString(output, base, braces) { - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if (cur.indexOf('\n') >= 0) numLinesEst++; - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; - }, 0); - - if (length > 60) { - return braces[0] + - (base === '' ? '' : base + '\n ') + - ' ' + - output.join(',\n ') + - ' ' + - braces[1]; +exports.Psbt = Psbt; +/** + * This function is needed to pass to the bip174 base class's fromBuffer. + * It takes the "transaction buffer" portion of the psbt buffer and returns a + * Transaction (From the bip174 library) interface. + */ +const transactionFromBuffer = buffer => new PsbtTransaction(buffer); +/** + * This class implements the Transaction interface from bip174 library. + * It contains a bitcoinjs-lib Transaction object. + */ +class PsbtTransaction { + constructor(buffer = Buffer.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) { + this.tx = transaction_1.Transaction.fromBuffer(buffer); + checkTxEmpty(this.tx); + Object.defineProperty(this, 'tx', { + enumerable: false, + writable: true, + }); + } + getInputOutputCounts() { + return { + inputCount: this.tx.ins.length, + outputCount: this.tx.outs.length, + }; + } + addInput(input) { + if ( + input.hash === undefined || + input.index === undefined || + (!Buffer.isBuffer(input.hash) && typeof input.hash !== 'string') || + typeof input.index !== 'number' + ) { + throw new Error('Error adding input.'); + } + const hash = + typeof input.hash === 'string' + ? (0, bufferutils_1.reverseBuffer)(Buffer.from(input.hash, 'hex')) + : input.hash; + this.tx.addInput(hash, input.index, input.sequence); + } + addOutput(output) { + if ( + output.script === undefined || + output.value === undefined || + !Buffer.isBuffer(output.script) || + typeof output.value !== 'number' + ) { + throw new Error('Error adding output.'); + } + this.tx.addOutput(output.script, output.value); + } + toBuffer() { + return this.tx.toBuffer(); } - - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } - - -// NOTE: These type checking functions intentionally don't use `instanceof` -// because it is fragile and can be easily faked with `Object.create()`. -function isArray(ar) { - return Array.isArray(ar); +function canFinalize(input, script, scriptType) { + switch (scriptType) { + case 'pubkey': + case 'pubkeyhash': + case 'witnesspubkeyhash': + return hasSigs(1, input.partialSig); + case 'multisig': + const p2ms = payments.p2ms({ output: script }); + return hasSigs(p2ms.m, input.partialSig, p2ms.pubkeys); + default: + return false; + } } -exports.isArray = isArray; - -function isBoolean(arg) { - return typeof arg === 'boolean'; +function checkCache(cache) { + if (cache.__UNSAFE_SIGN_NONSEGWIT !== false) { + throw new Error('Not BIP174 compliant, can not export'); + } } -exports.isBoolean = isBoolean; - -function isNull(arg) { - return arg === null; +function hasSigs(neededSigs, partialSig, pubkeys) { + if (!partialSig) return false; + let sigs; + if (pubkeys) { + sigs = pubkeys + .map(pkey => { + const pubkey = compressPubkey(pkey); + return partialSig.find(pSig => pSig.pubkey.equals(pubkey)); + }) + .filter(v => !!v); + } else { + sigs = partialSig; + } + if (sigs.length > neededSigs) throw new Error('Too many signatures'); + return sigs.length === neededSigs; } -exports.isNull = isNull; - -function isNullOrUndefined(arg) { - return arg == null; +function isFinalized(input) { + return !!input.finalScriptSig || !!input.finalScriptWitness; } -exports.isNullOrUndefined = isNullOrUndefined; - -function isNumber(arg) { - return typeof arg === 'number'; +function bip32DerivationIsMine(root) { + return d => { + if (!d.masterFingerprint.equals(root.fingerprint)) return false; + if (!root.derivePath(d.path).publicKey.equals(d.pubkey)) return false; + return true; + }; } -exports.isNumber = isNumber; - -function isString(arg) { - return typeof arg === 'string'; +function check32Bit(num) { + if ( + typeof num !== 'number' || + num !== Math.floor(num) || + num > 0xffffffff || + num < 0 + ) { + throw new Error('Invalid 32 bit integer'); + } } -exports.isString = isString; - -function isSymbol(arg) { - return typeof arg === 'symbol'; +function checkFees(psbt, cache, opts) { + const feeRate = cache.__FEE_RATE || psbt.getFeeRate(); + const vsize = cache.__EXTRACTED_TX.virtualSize(); + const satoshis = feeRate * vsize; + if (feeRate >= opts.maximumFeeRate) { + throw new Error( + `Warning: You are paying around ${(satoshis / 1e8).toFixed(8)} in ` + + `fees, which is ${feeRate} satoshi per byte for a transaction ` + + `with a VSize of ${vsize} bytes (segwit counted as 0.25 byte per ` + + `byte). Use setMaximumFeeRate method to raise your threshold, or ` + + `pass true to the first arg of extractTransaction.`, + ); + } } -exports.isSymbol = isSymbol; - -function isUndefined(arg) { - return arg === void 0; +function checkInputsForPartialSig(inputs, action) { + inputs.forEach(input => { + const throws = (0, bip371_1.isTaprootInput)(input) + ? (0, bip371_1.checkTaprootInputForSigs)(input, action) + : (0, psbtutils_1.checkInputForSig)(input, action); + if (throws) + throw new Error('Can not modify transaction, signatures exist.'); + }); } -exports.isUndefined = isUndefined; - -function isRegExp(re) { - return isObject(re) && objectToString(re) === '[object RegExp]'; +function checkPartialSigSighashes(input) { + if (!input.sighashType || !input.partialSig) return; + const { partialSig, sighashType } = input; + partialSig.forEach(pSig => { + const { hashType } = bscript.signature.decode(pSig.signature); + if (sighashType !== hashType) { + throw new Error('Signature sighash does not match input sighash type'); + } + }); } -exports.isRegExp = isRegExp; - -function isObject(arg) { - return typeof arg === 'object' && arg !== null; +function checkScriptForPubkey(pubkey, script, action) { + if (!(0, psbtutils_1.pubkeyInScript)(pubkey, script)) { + throw new Error( + `Can not ${action} for this input with the key ${pubkey.toString('hex')}`, + ); + } } -exports.isObject = isObject; - -function isDate(d) { - return isObject(d) && objectToString(d) === '[object Date]'; +function checkTxEmpty(tx) { + const isEmpty = tx.ins.every( + input => + input.script && + input.script.length === 0 && + input.witness && + input.witness.length === 0, + ); + if (!isEmpty) { + throw new Error('Format Error: Transaction ScriptSigs are not empty'); + } } -exports.isDate = isDate; - -function isError(e) { - return isObject(e) && - (objectToString(e) === '[object Error]' || e instanceof Error); +function checkTxForDupeIns(tx, cache) { + tx.ins.forEach(input => { + checkTxInputCache(cache, input); + }); } -exports.isError = isError; - -function isFunction(arg) { - return typeof arg === 'function'; +function checkTxInputCache(cache, input) { + const key = + (0, bufferutils_1.reverseBuffer)(Buffer.from(input.hash)).toString('hex') + + ':' + + input.index; + if (cache.__TX_IN_CACHE[key]) throw new Error('Duplicate input detected.'); + cache.__TX_IN_CACHE[key] = 1; +} +function scriptCheckerFactory(payment, paymentScriptName) { + return (inputIndex, scriptPubKey, redeemScript, ioType) => { + const redeemScriptOutput = payment({ + redeem: { output: redeemScript }, + }).output; + if (!scriptPubKey.equals(redeemScriptOutput)) { + throw new Error( + `${paymentScriptName} for ${ioType} #${inputIndex} doesn't match the scriptPubKey in the prevout`, + ); + } + }; } -exports.isFunction = isFunction; - -function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; +const checkRedeemScript = scriptCheckerFactory(payments.p2sh, 'Redeem script'); +const checkWitnessScript = scriptCheckerFactory( + payments.p2wsh, + 'Witness script', +); +function getTxCacheValue(key, name, inputs, c) { + if (!inputs.every(isFinalized)) + throw new Error(`PSBT must be finalized to calculate ${name}`); + if (key === '__FEE_RATE' && c.__FEE_RATE) return c.__FEE_RATE; + if (key === '__FEE' && c.__FEE) return c.__FEE; + let tx; + let mustFinalize = true; + if (c.__EXTRACTED_TX) { + tx = c.__EXTRACTED_TX; + mustFinalize = false; + } else { + tx = c.__TX.clone(); + } + inputFinalizeGetAmts(inputs, tx, c, mustFinalize); + if (key === '__FEE_RATE') return c.__FEE_RATE; + else if (key === '__FEE') return c.__FEE; +} +function getFinalScripts(inputIndex, input, script, isSegwit, isP2SH, isP2WSH) { + const scriptType = classifyScript(script); + if (!canFinalize(input, script, scriptType)) + throw new Error(`Can not finalize input #${inputIndex}`); + return prepareFinalScripts( + script, + scriptType, + input.partialSig, + isSegwit, + isP2SH, + isP2WSH, + ); } -exports.isPrimitive = isPrimitive; - -exports.isBuffer = require('./support/isBuffer'); - -function objectToString(o) { - return Object.prototype.toString.call(o); +function prepareFinalScripts( + script, + scriptType, + partialSig, + isSegwit, + isP2SH, + isP2WSH, +) { + let finalScriptSig; + let finalScriptWitness; + // Wow, the payments API is very handy + const payment = getPayment(script, scriptType, partialSig); + const p2wsh = !isP2WSH ? null : payments.p2wsh({ redeem: payment }); + const p2sh = !isP2SH ? null : payments.p2sh({ redeem: p2wsh || payment }); + if (isSegwit) { + if (p2wsh) { + finalScriptWitness = (0, psbtutils_1.witnessStackToScriptWitness)( + p2wsh.witness, + ); + } else { + finalScriptWitness = (0, psbtutils_1.witnessStackToScriptWitness)( + payment.witness, + ); + } + if (p2sh) { + finalScriptSig = p2sh.input; + } + } else { + if (p2sh) { + finalScriptSig = p2sh.input; + } else { + finalScriptSig = payment.input; + } + } + return { + finalScriptSig, + finalScriptWitness, + }; } - - -function pad(n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); +function getHashAndSighashType( + inputs, + inputIndex, + pubkey, + cache, + sighashTypes, +) { + const input = (0, utils_1.checkForInput)(inputs, inputIndex); + const { hash, sighashType, script } = getHashForSig( + inputIndex, + input, + cache, + false, + sighashTypes, + ); + checkScriptForPubkey(pubkey, script, 'sign'); + return { + hash, + sighashType, + }; +} +function getHashForSig(inputIndex, input, cache, forValidate, sighashTypes) { + const unsignedTx = cache.__TX; + const sighashType = + input.sighashType || transaction_1.Transaction.SIGHASH_ALL; + checkSighashTypeAllowed(sighashType, sighashTypes); + let hash; + let prevout; + if (input.nonWitnessUtxo) { + const nonWitnessUtxoTx = nonWitnessUtxoTxFromCache( + cache, + input, + inputIndex, + ); + const prevoutHash = unsignedTx.ins[inputIndex].hash; + const utxoHash = nonWitnessUtxoTx.getHash(); + // If a non-witness UTXO is provided, its hash must match the hash specified in the prevout + if (!prevoutHash.equals(utxoHash)) { + throw new Error( + `Non-witness UTXO hash for input #${inputIndex} doesn't match the hash specified in the prevout`, + ); + } + const prevoutIndex = unsignedTx.ins[inputIndex].index; + prevout = nonWitnessUtxoTx.outs[prevoutIndex]; + } else if (input.witnessUtxo) { + prevout = input.witnessUtxo; + } else { + throw new Error('Need a Utxo input item for signing'); + } + const { meaningfulScript, type } = getMeaningfulScript( + prevout.script, + inputIndex, + 'input', + input.redeemScript, + input.witnessScript, + ); + if (['p2sh-p2wsh', 'p2wsh'].indexOf(type) >= 0) { + hash = unsignedTx.hashForWitnessV0( + inputIndex, + meaningfulScript, + prevout.value, + sighashType, + ); + } else if ((0, psbtutils_1.isP2WPKH)(meaningfulScript)) { + // P2WPKH uses the P2PKH template for prevoutScript when signing + const signingScript = payments.p2pkh({ + hash: meaningfulScript.slice(2), + }).output; + hash = unsignedTx.hashForWitnessV0( + inputIndex, + signingScript, + prevout.value, + sighashType, + ); + } else { + // non-segwit + if ( + input.nonWitnessUtxo === undefined && + cache.__UNSAFE_SIGN_NONSEGWIT === false + ) + throw new Error( + `Input #${inputIndex} has witnessUtxo but non-segwit script: ` + + `${meaningfulScript.toString('hex')}`, + ); + if (!forValidate && cache.__UNSAFE_SIGN_NONSEGWIT !== false) + console.warn( + 'Warning: Signing non-segwit inputs without the full parent transaction ' + + 'means there is a chance that a miner could feed you incorrect information ' + + "to trick you into paying large fees. This behavior is the same as Psbt's predecessor " + + '(TransactionBuilder - now removed) when signing non-segwit scripts. You are not ' + + 'able to export this Psbt with toBuffer|toBase64|toHex since it is not ' + + 'BIP174 compliant.\n*********************\nPROCEED WITH CAUTION!\n' + + '*********************', + ); + hash = unsignedTx.hashForSignature( + inputIndex, + meaningfulScript, + sighashType, + ); + } + return { + script: meaningfulScript, + sighashType, + hash, + }; } - - -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; - -// 26 Feb 16:19:34 -function timestamp() { - var d = new Date(); - var time = [pad(d.getHours()), - pad(d.getMinutes()), - pad(d.getSeconds())].join(':'); - return [d.getDate(), months[d.getMonth()], time].join(' '); +function getAllTaprootHashesForSig(inputIndex, input, inputs, cache) { + const allPublicKeys = []; + if (input.tapInternalKey) { + const key = getPrevoutTaprootKey(inputIndex, input, cache); + if (key) { + allPublicKeys.push(key); + } + } + if (input.tapScriptSig) { + const tapScriptPubkeys = input.tapScriptSig.map(tss => tss.pubkey); + allPublicKeys.push(...tapScriptPubkeys); + } + const allHashes = allPublicKeys.map(pubicKey => + getTaprootHashesForSig(inputIndex, input, inputs, pubicKey, cache), + ); + return allHashes.flat(); } - - -// log is just a thin wrapper to console.log that prepends a timestamp -exports.log = function() { - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); -}; - - -/** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be rewritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). - * - * @param {function} ctor Constructor function which needs to inherit the - * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. - */ -exports.inherits = require('inherits'); - -exports._extend = function(origin, add) { - // Don't do anything if add isn't an object - if (!add || !isObject(add)) return origin; - - var keys = Object.keys(add); - var i = keys.length; - while (i--) { - origin[keys[i]] = add[keys[i]]; +function getPrevoutTaprootKey(inputIndex, input, cache) { + const { script } = getScriptAndAmountFromUtxo(inputIndex, input, cache); + return (0, psbtutils_1.isP2TR)(script) ? script.subarray(2, 34) : null; +} +function trimTaprootSig(signature) { + return signature.length === 64 ? signature : signature.subarray(0, 64); +} +function getTaprootHashesForSig( + inputIndex, + input, + inputs, + pubkey, + cache, + tapLeafHashToSign, + allowedSighashTypes, +) { + const unsignedTx = cache.__TX; + const sighashType = + input.sighashType || transaction_1.Transaction.SIGHASH_DEFAULT; + checkSighashTypeAllowed(sighashType, allowedSighashTypes); + const prevOuts = inputs.map((i, index) => + getScriptAndAmountFromUtxo(index, i, cache), + ); + const signingScripts = prevOuts.map(o => o.script); + const values = prevOuts.map(o => o.value); + const hashes = []; + if (input.tapInternalKey && !tapLeafHashToSign) { + const outputKey = + getPrevoutTaprootKey(inputIndex, input, cache) || Buffer.from([]); + if ((0, bip371_1.toXOnly)(pubkey).equals(outputKey)) { + const tapKeyHash = unsignedTx.hashForWitnessV1( + inputIndex, + signingScripts, + values, + sighashType, + ); + hashes.push({ pubkey, hash: tapKeyHash }); + } } - return origin; -}; - -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); + const tapLeafHashes = (input.tapLeafScript || []) + .filter(tapLeaf => (0, psbtutils_1.pubkeyInScript)(pubkey, tapLeaf.script)) + .map(tapLeaf => { + const hash = (0, bip341_1.tapleafHash)({ + output: tapLeaf.script, + version: tapLeaf.leafVersion, + }); + return Object.assign({ hash }, tapLeaf); + }) + .filter( + tapLeaf => !tapLeafHashToSign || tapLeafHashToSign.equals(tapLeaf.hash), + ) + .map(tapLeaf => { + const tapScriptHash = unsignedTx.hashForWitnessV1( + inputIndex, + signingScripts, + values, + sighashType, + tapLeaf.hash, + ); + return { + pubkey, + hash: tapScriptHash, + leafHash: tapLeaf.hash, + }; + }); + return hashes.concat(tapLeafHashes); } - -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":23,"_process":253,"inherits":22}],25:[function(require,module,exports){ -'use strict' -// base-x encoding / decoding -// Copyright (c) 2018 base-x contributors -// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp) -// Distributed under the MIT software license, see the accompanying -// file LICENSE or http://www.opensource.org/licenses/mit-license.php. -// @ts-ignore -var _Buffer = require('safe-buffer').Buffer -function base (ALPHABET) { - if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') } - var BASE_MAP = new Uint8Array(256) - for (var j = 0; j < BASE_MAP.length; j++) { - BASE_MAP[j] = 255 +function checkSighashTypeAllowed(sighashType, sighashTypes) { + if (sighashTypes && sighashTypes.indexOf(sighashType) < 0) { + const str = sighashTypeToString(sighashType); + throw new Error( + `Sighash type is not allowed. Retry the sign method passing the ` + + `sighashTypes array of whitelisted types. Sighash type: ${str}`, + ); } - for (var i = 0; i < ALPHABET.length; i++) { - var x = ALPHABET.charAt(i) - var xc = x.charCodeAt(0) - if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') } - BASE_MAP[xc] = i +} +function getPayment(script, scriptType, partialSig) { + let payment; + switch (scriptType) { + case 'multisig': + const sigs = getSortedSigs(script, partialSig); + payment = payments.p2ms({ + output: script, + signatures: sigs, + }); + break; + case 'pubkey': + payment = payments.p2pk({ + output: script, + signature: partialSig[0].signature, + }); + break; + case 'pubkeyhash': + payment = payments.p2pkh({ + output: script, + pubkey: partialSig[0].pubkey, + signature: partialSig[0].signature, + }); + break; + case 'witnesspubkeyhash': + payment = payments.p2wpkh({ + output: script, + pubkey: partialSig[0].pubkey, + signature: partialSig[0].signature, + }); + break; } - var BASE = ALPHABET.length - var LEADER = ALPHABET.charAt(0) - var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up - var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up - function encode (source) { - if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source) } - if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') } - if (source.length === 0) { return '' } - // Skip & count leading zeroes. - var zeroes = 0 - var length = 0 - var pbegin = 0 - var pend = source.length - while (pbegin !== pend && source[pbegin] === 0) { - pbegin++ - zeroes++ - } - // Allocate enough space in big-endian base58 representation. - var size = ((pend - pbegin) * iFACTOR + 1) >>> 0 - var b58 = new Uint8Array(size) - // Process the bytes. - while (pbegin !== pend) { - var carry = source[pbegin] - // Apply "b58 = b58 * 256 + ch". - var i = 0 - for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) { - carry += (256 * b58[it1]) >>> 0 - b58[it1] = (carry % BASE) >>> 0 - carry = (carry / BASE) >>> 0 - } - if (carry !== 0) { throw new Error('Non-zero carry') } - length = i - pbegin++ + return payment; +} +function getScriptFromInput(inputIndex, input, cache) { + const unsignedTx = cache.__TX; + const res = { + script: null, + isSegwit: false, + isP2SH: false, + isP2WSH: false, + }; + res.isP2SH = !!input.redeemScript; + res.isP2WSH = !!input.witnessScript; + if (input.witnessScript) { + res.script = input.witnessScript; + } else if (input.redeemScript) { + res.script = input.redeemScript; + } else { + if (input.nonWitnessUtxo) { + const nonWitnessUtxoTx = nonWitnessUtxoTxFromCache( + cache, + input, + inputIndex, + ); + const prevoutIndex = unsignedTx.ins[inputIndex].index; + res.script = nonWitnessUtxoTx.outs[prevoutIndex].script; + } else if (input.witnessUtxo) { + res.script = input.witnessUtxo.script; } - // Skip leading zeroes in base58 result. - var it2 = size - length - while (it2 !== size && b58[it2] === 0) { - it2++ - } - // Translate the result into a string. - var str = LEADER.repeat(zeroes) - for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) } - return str } - function decodeUnsafe (source) { - if (typeof source !== 'string') { throw new TypeError('Expected String') } - if (source.length === 0) { return _Buffer.alloc(0) } - var psz = 0 - // Skip leading spaces. - if (source[psz] === ' ') { return } - // Skip and count leading '1's. - var zeroes = 0 - var length = 0 - while (source[psz] === LEADER) { - zeroes++ - psz++ - } - // Allocate enough space in big-endian base256 representation. - var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up. - var b256 = new Uint8Array(size) - // Process the characters. - while (source[psz]) { - // Decode character - var carry = BASE_MAP[source.charCodeAt(psz)] - // Invalid character - if (carry === 255) { return } - var i = 0 - for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) { - carry += (BASE * b256[it3]) >>> 0 - b256[it3] = (carry % 256) >>> 0 - carry = (carry / 256) >>> 0 + if (input.witnessScript || (0, psbtutils_1.isP2WPKH)(res.script)) { + res.isSegwit = true; + } + return res; +} +function getSignersFromHD(inputIndex, inputs, hdKeyPair) { + const input = (0, utils_1.checkForInput)(inputs, inputIndex); + if (!input.bip32Derivation || input.bip32Derivation.length === 0) { + throw new Error('Need bip32Derivation to sign with HD'); + } + const myDerivations = input.bip32Derivation + .map(bipDv => { + if (bipDv.masterFingerprint.equals(hdKeyPair.fingerprint)) { + return bipDv; + } else { + return; } - if (carry !== 0) { throw new Error('Non-zero carry') } - length = i - psz++ - } - // Skip trailing spaces. - if (source[psz] === ' ') { return } - // Skip leading zeroes in b256. - var it4 = size - length - while (it4 !== size && b256[it4] === 0) { - it4++ - } - var vch = _Buffer.allocUnsafe(zeroes + (size - it4)) - vch.fill(0x00, 0, zeroes) - var j = zeroes - while (it4 !== size) { - vch[j++] = b256[it4++] + }) + .filter(v => !!v); + if (myDerivations.length === 0) { + throw new Error( + 'Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint', + ); + } + const signers = myDerivations.map(bipDv => { + const node = hdKeyPair.derivePath(bipDv.path); + if (!bipDv.pubkey.equals(node.publicKey)) { + throw new Error('pubkey did not match bip32Derivation'); } - return vch + return node; + }); + return signers; +} +function getSortedSigs(script, partialSig) { + const p2ms = payments.p2ms({ output: script }); + // for each pubkey in order of p2ms script + return p2ms.pubkeys + .map(pk => { + // filter partialSig array by pubkey being equal + return ( + partialSig.filter(ps => { + return ps.pubkey.equals(pk); + })[0] || {} + ).signature; + // Any pubkey without a match will return undefined + // this last filter removes all the undefined items in the array. + }) + .filter(v => !!v); +} +function scriptWitnessToWitnessStack(buffer) { + let offset = 0; + function readSlice(n) { + offset += n; + return buffer.slice(offset - n, offset); } - function decode (string) { - var buffer = decodeUnsafe(string) - if (buffer) { return buffer } - throw new Error('Non-base' + BASE + ' character') + function readVarInt() { + const vi = varuint.decode(buffer, offset); + offset += varuint.decode.bytes; + return vi; } - return { - encode: encode, - decodeUnsafe: decodeUnsafe, - decode: decode + function readVarSlice() { + return readSlice(readVarInt()); + } + function readVector() { + const count = readVarInt(); + const vector = []; + for (let i = 0; i < count; i++) vector.push(readVarSlice()); + return vector; + } + return readVector(); +} +function sighashTypeToString(sighashType) { + let text = + sighashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY + ? 'SIGHASH_ANYONECANPAY | ' + : ''; + const sigMod = sighashType & 0x1f; + switch (sigMod) { + case transaction_1.Transaction.SIGHASH_ALL: + text += 'SIGHASH_ALL'; + break; + case transaction_1.Transaction.SIGHASH_SINGLE: + text += 'SIGHASH_SINGLE'; + break; + case transaction_1.Transaction.SIGHASH_NONE: + text += 'SIGHASH_NONE'; + break; } + return text; } -module.exports = base - -},{"safe-buffer":280}],26:[function(require,module,exports){ -'use strict' - -exports.byteLength = byteLength -exports.toByteArray = toByteArray -exports.fromByteArray = fromByteArray - -var lookup = [] -var revLookup = [] -var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array - -var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i] - revLookup[code.charCodeAt(i)] = i +function addNonWitnessTxCache(cache, input, inputIndex) { + cache.__NON_WITNESS_UTXO_BUF_CACHE[inputIndex] = input.nonWitnessUtxo; + const tx = transaction_1.Transaction.fromBuffer(input.nonWitnessUtxo); + cache.__NON_WITNESS_UTXO_TX_CACHE[inputIndex] = tx; + const self = cache; + const selfIndex = inputIndex; + delete input.nonWitnessUtxo; + Object.defineProperty(input, 'nonWitnessUtxo', { + enumerable: true, + get() { + const buf = self.__NON_WITNESS_UTXO_BUF_CACHE[selfIndex]; + const txCache = self.__NON_WITNESS_UTXO_TX_CACHE[selfIndex]; + if (buf !== undefined) { + return buf; + } else { + const newBuf = txCache.toBuffer(); + self.__NON_WITNESS_UTXO_BUF_CACHE[selfIndex] = newBuf; + return newBuf; + } + }, + set(data) { + self.__NON_WITNESS_UTXO_BUF_CACHE[selfIndex] = data; + }, + }); } - -// Support decoding URL-safe base64 strings, as Node.js does. -// See: https://en.wikipedia.org/wiki/Base64#URL_applications -revLookup['-'.charCodeAt(0)] = 62 -revLookup['_'.charCodeAt(0)] = 63 - -function getLens (b64) { - var len = b64.length - - if (len % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') +function inputFinalizeGetAmts(inputs, tx, cache, mustFinalize) { + let inputAmount = 0; + inputs.forEach((input, idx) => { + if (mustFinalize && input.finalScriptSig) + tx.ins[idx].script = input.finalScriptSig; + if (mustFinalize && input.finalScriptWitness) { + tx.ins[idx].witness = scriptWitnessToWitnessStack( + input.finalScriptWitness, + ); + } + if (input.witnessUtxo) { + inputAmount += input.witnessUtxo.value; + } else if (input.nonWitnessUtxo) { + const nwTx = nonWitnessUtxoTxFromCache(cache, input, idx); + const vout = tx.ins[idx].index; + const out = nwTx.outs[vout]; + inputAmount += out.value; + } + }); + const outputAmount = tx.outs.reduce((total, o) => total + o.value, 0); + const fee = inputAmount - outputAmount; + if (fee < 0) { + throw new Error('Outputs are spending more than Inputs'); } - - // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - var validLen = b64.indexOf('=') - if (validLen === -1) validLen = len - - var placeHoldersLen = validLen === len - ? 0 - : 4 - (validLen % 4) - - return [validLen, placeHoldersLen] + const bytes = tx.virtualSize(); + cache.__FEE = fee; + cache.__EXTRACTED_TX = tx; + cache.__FEE_RATE = Math.floor(fee / bytes); } - -// base64 is 4/3 + up to two characters of the original data -function byteLength (b64) { - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +function nonWitnessUtxoTxFromCache(cache, input, inputIndex) { + const c = cache.__NON_WITNESS_UTXO_TX_CACHE; + if (!c[inputIndex]) { + addNonWitnessTxCache(cache, input, inputIndex); + } + return c[inputIndex]; } - -function _byteLength (b64, validLen, placeHoldersLen) { - return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +function getScriptFromUtxo(inputIndex, input, cache) { + const { script } = getScriptAndAmountFromUtxo(inputIndex, input, cache); + return script; } - -function toByteArray (b64) { - var tmp - var lens = getLens(b64) - var validLen = lens[0] - var placeHoldersLen = lens[1] - - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) - - var curByte = 0 - - // if there are placeholders, only get up to the last complete 4 chars - var len = placeHoldersLen > 0 - ? validLen - 4 - : validLen - - var i - for (i = 0; i < len; i += 4) { - tmp = - (revLookup[b64.charCodeAt(i)] << 18) | - (revLookup[b64.charCodeAt(i + 1)] << 12) | - (revLookup[b64.charCodeAt(i + 2)] << 6) | - revLookup[b64.charCodeAt(i + 3)] - arr[curByte++] = (tmp >> 16) & 0xFF - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF - } - - if (placeHoldersLen === 2) { - tmp = - (revLookup[b64.charCodeAt(i)] << 2) | - (revLookup[b64.charCodeAt(i + 1)] >> 4) - arr[curByte++] = tmp & 0xFF - } - - if (placeHoldersLen === 1) { - tmp = - (revLookup[b64.charCodeAt(i)] << 10) | - (revLookup[b64.charCodeAt(i + 1)] << 4) | - (revLookup[b64.charCodeAt(i + 2)] >> 2) - arr[curByte++] = (tmp >> 8) & 0xFF - arr[curByte++] = tmp & 0xFF +function getScriptAndAmountFromUtxo(inputIndex, input, cache) { + if (input.witnessUtxo !== undefined) { + return { + script: input.witnessUtxo.script, + value: input.witnessUtxo.value, + }; + } else if (input.nonWitnessUtxo !== undefined) { + const nonWitnessUtxoTx = nonWitnessUtxoTxFromCache( + cache, + input, + inputIndex, + ); + const o = nonWitnessUtxoTx.outs[cache.__TX.ins[inputIndex].index]; + return { script: o.script, value: o.value }; + } else { + throw new Error("Can't find pubkey in input without Utxo data"); } - - return arr } - -function tripletToBase64 (num) { - return lookup[num >> 18 & 0x3F] + - lookup[num >> 12 & 0x3F] + - lookup[num >> 6 & 0x3F] + - lookup[num & 0x3F] +function pubkeyInInput(pubkey, input, inputIndex, cache) { + const script = getScriptFromUtxo(inputIndex, input, cache); + const { meaningfulScript } = getMeaningfulScript( + script, + inputIndex, + 'input', + input.redeemScript, + input.witnessScript, + ); + return (0, psbtutils_1.pubkeyInScript)(pubkey, meaningfulScript); +} +function pubkeyInOutput(pubkey, output, outputIndex, cache) { + const script = cache.__TX.outs[outputIndex].script; + const { meaningfulScript } = getMeaningfulScript( + script, + outputIndex, + 'output', + output.redeemScript, + output.witnessScript, + ); + return (0, psbtutils_1.pubkeyInScript)(pubkey, meaningfulScript); } - -function encodeChunk (uint8, start, end) { - var tmp - var output = [] - for (var i = start; i < end; i += 3) { - tmp = - ((uint8[i] << 16) & 0xFF0000) + - ((uint8[i + 1] << 8) & 0xFF00) + - (uint8[i + 2] & 0xFF) - output.push(tripletToBase64(tmp)) +function redeemFromFinalScriptSig(finalScript) { + if (!finalScript) return; + const decomp = bscript.decompile(finalScript); + if (!decomp) return; + const lastItem = decomp[decomp.length - 1]; + if ( + !Buffer.isBuffer(lastItem) || + isPubkeyLike(lastItem) || + isSigLike(lastItem) + ) + return; + const sDecomp = bscript.decompile(lastItem); + if (!sDecomp) return; + return lastItem; +} +function redeemFromFinalWitnessScript(finalScript) { + if (!finalScript) return; + const decomp = scriptWitnessToWitnessStack(finalScript); + const lastItem = decomp[decomp.length - 1]; + if (isPubkeyLike(lastItem)) return; + const sDecomp = bscript.decompile(lastItem); + if (!sDecomp) return; + return lastItem; +} +function compressPubkey(pubkey) { + if (pubkey.length === 65) { + const parity = pubkey[64] & 1; + const newKey = pubkey.slice(0, 33); + newKey[0] = 2 | parity; + return newKey; + } + return pubkey.slice(); +} +function isPubkeyLike(buf) { + return buf.length === 33 && bscript.isCanonicalPubKey(buf); +} +function isSigLike(buf) { + return bscript.isCanonicalScriptSignature(buf); +} +function getMeaningfulScript( + script, + index, + ioType, + redeemScript, + witnessScript, +) { + const isP2SH = (0, psbtutils_1.isP2SHScript)(script); + const isP2SHP2WSH = + isP2SH && redeemScript && (0, psbtutils_1.isP2WSHScript)(redeemScript); + const isP2WSH = (0, psbtutils_1.isP2WSHScript)(script); + if (isP2SH && redeemScript === undefined) + throw new Error('scriptPubkey is P2SH but redeemScript missing'); + if ((isP2WSH || isP2SHP2WSH) && witnessScript === undefined) + throw new Error( + 'scriptPubkey or redeemScript is P2WSH but witnessScript missing', + ); + let meaningfulScript; + if (isP2SHP2WSH) { + meaningfulScript = witnessScript; + checkRedeemScript(index, script, redeemScript, ioType); + checkWitnessScript(index, redeemScript, witnessScript, ioType); + checkInvalidP2WSH(meaningfulScript); + } else if (isP2WSH) { + meaningfulScript = witnessScript; + checkWitnessScript(index, script, witnessScript, ioType); + checkInvalidP2WSH(meaningfulScript); + } else if (isP2SH) { + meaningfulScript = redeemScript; + checkRedeemScript(index, script, redeemScript, ioType); + } else { + meaningfulScript = script; } - return output.join('') + return { + meaningfulScript, + type: isP2SHP2WSH + ? 'p2sh-p2wsh' + : isP2SH + ? 'p2sh' + : isP2WSH + ? 'p2wsh' + : 'raw', + }; } - -function fromByteArray (uint8) { - var tmp - var len = uint8.length - var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes - var parts = [] - var maxChunkLength = 16383 // must be multiple of 3 - - // go through the array every three bytes, we'll deal with trailing stuff later - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk( - uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) - )) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - if (extraBytes === 1) { - tmp = uint8[len - 1] - parts.push( - lookup[tmp >> 2] + - lookup[(tmp << 4) & 0x3F] + - '==' - ) - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1] - parts.push( - lookup[tmp >> 10] + - lookup[(tmp >> 4) & 0x3F] + - lookup[(tmp << 2) & 0x3F] + - '=' - ) +function checkInvalidP2WSH(script) { + if ( + (0, psbtutils_1.isP2WPKH)(script) || + (0, psbtutils_1.isP2SHScript)(script) + ) { + throw new Error('P2WPKH or P2SH can not be contained within P2WSH'); } - - return parts.join('') +} +function classifyScript(script) { + if ((0, psbtutils_1.isP2WPKH)(script)) return 'witnesspubkeyhash'; + if ((0, psbtutils_1.isP2PKH)(script)) return 'pubkeyhash'; + if ((0, psbtutils_1.isP2MS)(script)) return 'multisig'; + if ((0, psbtutils_1.isP2PK)(script)) return 'pubkey'; + return 'nonstandard'; +} +function range(n) { + return [...Array(n).keys()]; } -},{}],27:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./address":47,"./bufferutils":50,"./networks":55,"./payments":59,"./payments/bip341":57,"./psbt/bip371":69,"./psbt/psbtutils":70,"./script":72,"./transaction":75,"bip174":40,"bip174/src/lib/converter/varint":36,"bip174/src/lib/utils":42,"buffer":249}],69:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.bech32m = exports.bech32 = void 0; -const ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'; -const ALPHABET_MAP = {}; -for (let z = 0; z < ALPHABET.length; z++) { - const x = ALPHABET.charAt(z); - ALPHABET_MAP[x] = z; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.checkTaprootInputForSigs = + exports.tapTreeFromList = + exports.tapTreeToList = + exports.tweakInternalPubKey = + exports.checkTaprootOutputFields = + exports.checkTaprootInputFields = + exports.isTaprootOutput = + exports.isTaprootInput = + exports.serializeTaprootSignature = + exports.tapScriptFinalizer = + exports.toXOnly = + void 0; +const types_1 = require('../types'); +const transaction_1 = require('../transaction'); +const psbtutils_1 = require('./psbtutils'); +const bip341_1 = require('../payments/bip341'); +const payments_1 = require('../payments'); +const psbtutils_2 = require('./psbtutils'); +const toXOnly = pubKey => (pubKey.length === 32 ? pubKey : pubKey.slice(1, 33)); +exports.toXOnly = toXOnly; +/** + * Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided. + * Otherwise it will search for the tapleaf that has at least one signature and has the shortest path. + * @param inputIndex the position of the PSBT input. + * @param input the PSBT input. + * @param tapLeafHashToFinalize optional, if provided the finalizer will search for a tapleaf that has this hash + * and will try to build the finalScriptWitness. + * @returns the finalScriptWitness or throws an exception if no tapleaf found. + */ +function tapScriptFinalizer(inputIndex, input, tapLeafHashToFinalize) { + const tapLeaf = findTapLeafToFinalize( + input, + inputIndex, + tapLeafHashToFinalize, + ); + try { + const sigs = sortSignatures(input, tapLeaf); + const witness = sigs.concat(tapLeaf.script).concat(tapLeaf.controlBlock); + return { + finalScriptWitness: (0, psbtutils_1.witnessStackToScriptWitness)(witness), + }; + } catch (err) { + throw new Error(`Can not finalize taproot input #${inputIndex}: ${err}`); + } } -function polymodStep(pre) { - const b = pre >> 25; - return (((pre & 0x1ffffff) << 5) ^ - (-((b >> 0) & 1) & 0x3b6a57b2) ^ - (-((b >> 1) & 1) & 0x26508e6d) ^ - (-((b >> 2) & 1) & 0x1ea119fa) ^ - (-((b >> 3) & 1) & 0x3d4233dd) ^ - (-((b >> 4) & 1) & 0x2a1462b3)); +exports.tapScriptFinalizer = tapScriptFinalizer; +function serializeTaprootSignature(sig, sighashType) { + const sighashTypeByte = sighashType + ? Buffer.from([sighashType]) + : Buffer.from([]); + return Buffer.concat([sig, sighashTypeByte]); } -function prefixChk(prefix) { - let chk = 1; - for (let i = 0; i < prefix.length; ++i) { - const c = prefix.charCodeAt(i); - if (c < 33 || c > 126) - return 'Invalid prefix (' + prefix + ')'; - chk = polymodStep(chk) ^ (c >> 5); - } - chk = polymodStep(chk); - for (let i = 0; i < prefix.length; ++i) { - const v = prefix.charCodeAt(i); - chk = polymodStep(chk) ^ (v & 0x1f); - } - return chk; +exports.serializeTaprootSignature = serializeTaprootSignature; +function isTaprootInput(input) { + return ( + input && + !!( + input.tapInternalKey || + input.tapMerkleRoot || + (input.tapLeafScript && input.tapLeafScript.length) || + (input.tapBip32Derivation && input.tapBip32Derivation.length) || + (input.witnessUtxo && (0, psbtutils_1.isP2TR)(input.witnessUtxo.script)) + ) + ); } -function convert(data, inBits, outBits, pad) { - let value = 0; - let bits = 0; - const maxV = (1 << outBits) - 1; - const result = []; - for (let i = 0; i < data.length; ++i) { - value = (value << inBits) | data[i]; - bits += inBits; - while (bits >= outBits) { - bits -= outBits; - result.push((value >> bits) & maxV); - } - } - if (pad) { - if (bits > 0) { - result.push((value << (outBits - bits)) & maxV); - } - } - else { - if (bits >= inBits) - return 'Excess padding'; - if ((value << (outBits - bits)) & maxV) - return 'Non-zero padding'; - } - return result; +exports.isTaprootInput = isTaprootInput; +function isTaprootOutput(output, script) { + return ( + output && + !!( + output.tapInternalKey || + output.tapTree || + (output.tapBip32Derivation && output.tapBip32Derivation.length) || + (script && (0, psbtutils_1.isP2TR)(script)) + ) + ); } -function toWords(bytes) { - return convert(bytes, 8, 5, true); +exports.isTaprootOutput = isTaprootOutput; +function checkTaprootInputFields(inputData, newInputData, action) { + checkMixedTaprootAndNonTaprootInputFields(inputData, newInputData, action); + checkIfTapLeafInTree(inputData, newInputData, action); +} +exports.checkTaprootInputFields = checkTaprootInputFields; +function checkTaprootOutputFields(outputData, newOutputData, action) { + checkMixedTaprootAndNonTaprootOutputFields(outputData, newOutputData, action); + checkTaprootScriptPubkey(outputData, newOutputData); +} +exports.checkTaprootOutputFields = checkTaprootOutputFields; +function checkTaprootScriptPubkey(outputData, newOutputData) { + if (!newOutputData.tapTree && !newOutputData.tapInternalKey) return; + const tapInternalKey = + newOutputData.tapInternalKey || outputData.tapInternalKey; + const tapTree = newOutputData.tapTree || outputData.tapTree; + if (tapInternalKey) { + const { script: scriptPubkey } = outputData; + const script = getTaprootScripPubkey(tapInternalKey, tapTree); + if (scriptPubkey && !scriptPubkey.equals(script)) + throw new Error('Error adding output. Script or address missmatch.'); + } +} +function getTaprootScripPubkey(tapInternalKey, tapTree) { + const scriptTree = tapTree && tapTreeFromList(tapTree.leaves); + const { output } = (0, payments_1.p2tr)({ + internalPubkey: tapInternalKey, + scriptTree, + }); + return output; } -function fromWordsUnsafe(words) { - const res = convert(words, 5, 8, false); - if (Array.isArray(res)) - return res; +function tweakInternalPubKey(inputIndex, input) { + const tapInternalKey = input.tapInternalKey; + const outputKey = + tapInternalKey && + (0, bip341_1.tweakKey)(tapInternalKey, input.tapMerkleRoot); + if (!outputKey) + throw new Error( + `Cannot tweak tap internal key for input #${inputIndex}. Public key: ${ + tapInternalKey && tapInternalKey.toString('hex') + }`, + ); + return outputKey.x; } -function fromWords(words) { - const res = convert(words, 5, 8, false); - if (Array.isArray(res)) - return res; - throw new Error(res); +exports.tweakInternalPubKey = tweakInternalPubKey; +/** + * Convert a binary tree to a BIP371 type list. Each element of the list is (according to BIP371): + * One or more tuples representing the depth, leaf version, and script for a leaf in the Taproot tree, + * allowing the entire tree to be reconstructed. The tuples must be in depth first search order so that + * the tree is correctly reconstructed. + * @param tree the binary tap tree + * @returns a list of BIP 371 tapleaves + */ +function tapTreeToList(tree) { + if (!(0, types_1.isTaptree)(tree)) + throw new Error( + 'Cannot convert taptree to tapleaf list. Expecting a tapree structure.', + ); + return _tapTreeToList(tree); } -function getLibraryFromEncoding(encoding) { - let ENCODING_CONST; - if (encoding === 'bech32') { - ENCODING_CONST = 1; - } - else { - ENCODING_CONST = 0x2bc830a3; - } - function encode(prefix, words, LIMIT) { - LIMIT = LIMIT || 90; - if (prefix.length + 7 + words.length > LIMIT) - throw new TypeError('Exceeds length limit'); - prefix = prefix.toLowerCase(); - // determine chk mod - let chk = prefixChk(prefix); - if (typeof chk === 'string') - throw new Error(chk); - let result = prefix + '1'; - for (let i = 0; i < words.length; ++i) { - const x = words[i]; - if (x >> 5 !== 0) - throw new Error('Non 5-bit word'); - chk = polymodStep(chk) ^ x; - result += ALPHABET.charAt(x); - } - for (let i = 0; i < 6; ++i) { - chk = polymodStep(chk); - } - chk ^= ENCODING_CONST; - for (let i = 0; i < 6; ++i) { - const v = (chk >> ((5 - i) * 5)) & 0x1f; - result += ALPHABET.charAt(v); - } - return result; - } - function __decode(str, LIMIT) { - LIMIT = LIMIT || 90; - if (str.length < 8) - return str + ' too short'; - if (str.length > LIMIT) - return 'Exceeds length limit'; - // don't allow mixed case - const lowered = str.toLowerCase(); - const uppered = str.toUpperCase(); - if (str !== lowered && str !== uppered) - return 'Mixed-case string ' + str; - str = lowered; - const split = str.lastIndexOf('1'); - if (split === -1) - return 'No separator character for ' + str; - if (split === 0) - return 'Missing prefix for ' + str; - const prefix = str.slice(0, split); - const wordChars = str.slice(split + 1); - if (wordChars.length < 6) - return 'Data too short'; - let chk = prefixChk(prefix); - if (typeof chk === 'string') - return chk; - const words = []; - for (let i = 0; i < wordChars.length; ++i) { - const c = wordChars.charAt(i); - const v = ALPHABET_MAP[c]; - if (v === undefined) - return 'Unknown character ' + c; - chk = polymodStep(chk) ^ v; - // not in the checksum? - if (i + 6 >= wordChars.length) - continue; - words.push(v); - } - if (chk !== ENCODING_CONST) - return 'Invalid checksum for ' + str; - return { prefix, words }; - } - function decodeUnsafe(str, LIMIT) { - const res = __decode(str, LIMIT); - if (typeof res === 'object') - return res; - } - function decode(str, LIMIT) { - const res = __decode(str, LIMIT); - if (typeof res === 'object') - return res; - throw new Error(res); - } +exports.tapTreeToList = tapTreeToList; +/** + * Convert a BIP371 TapLeaf list to a TapTree (binary). + * @param leaves a list of tapleaves where each element of the list is (according to BIP371): + * One or more tuples representing the depth, leaf version, and script for a leaf in the Taproot tree, + * allowing the entire tree to be reconstructed. The tuples must be in depth first search order so that + * the tree is correctly reconstructed. + * @returns the corresponding taptree, or throws an exception if the tree cannot be reconstructed + */ +function tapTreeFromList(leaves = []) { + if (leaves.length === 1 && leaves[0].depth === 0) return { - decodeUnsafe, - decode, - encode, - toWords, - fromWordsUnsafe, - fromWords, + output: leaves[0].script, + version: leaves[0].leafVersion, }; + return instertLeavesInTree(leaves); } -exports.bech32 = getLibraryFromEncoding('bech32'); -exports.bech32m = getLibraryFromEncoding('bech32m'); - -},{}],28:[function(require,module,exports){ -// (public) Constructor -function BigInteger(a, b, c) { - if (!(this instanceof BigInteger)) - return new BigInteger(a, b, c) - - if (a != null) { - if ("number" == typeof a) this.fromNumber(a, b, c) - else if (b == null && "string" != typeof a) this.fromString(a, 256) - else this.fromString(a, b) - } -} - -var proto = BigInteger.prototype - -// duck-typed isBigInteger -proto.__bigi = require('../package.json').version -BigInteger.isBigInteger = function (obj, check_ver) { - return obj && obj.__bigi && (!check_ver || obj.__bigi === proto.__bigi) +exports.tapTreeFromList = tapTreeFromList; +function checkTaprootInputForSigs(input, action) { + const sigs = extractTaprootSigs(input); + return sigs.some(sig => + (0, psbtutils_2.signatureBlocksAction)(sig, decodeSchnorrSignature, action), + ); } - -// Bits per digit -var dbits - -// am: Compute w_j += (x*this_i), propagate carries, -// c is initial carry, returns final carry. -// c < 3*dvalue, x < 2*dvalue, this_i < dvalue -// We need to select the fastest one that works in this environment. - -// am1: use a single mult and divide to get the high bits, -// max digit bits should be 26 because -// max internal value = 2*dvalue^2-2*dvalue (< 2^53) -function am1(i, x, w, j, c, n) { - while (--n >= 0) { - var v = x * this[i++] + w[j] + c - c = Math.floor(v / 0x4000000) - w[j++] = v & 0x3ffffff +exports.checkTaprootInputForSigs = checkTaprootInputForSigs; +function decodeSchnorrSignature(signature) { + return { + signature: signature.slice(0, 64), + hashType: + signature.slice(64)[0] || transaction_1.Transaction.SIGHASH_DEFAULT, + }; +} +function extractTaprootSigs(input) { + const sigs = []; + if (input.tapKeySig) sigs.push(input.tapKeySig); + if (input.tapScriptSig) + sigs.push(...input.tapScriptSig.map(s => s.signature)); + if (!sigs.length) { + const finalTapKeySig = getTapKeySigFromWithness(input.finalScriptWitness); + if (finalTapKeySig) sigs.push(finalTapKeySig); + } + return sigs; +} +function getTapKeySigFromWithness(finalScriptWitness) { + if (!finalScriptWitness) return; + const witness = finalScriptWitness.slice(2); + // todo: add schnorr signature validation + if (witness.length === 64 || witness.length === 65) return witness; +} +function _tapTreeToList(tree, leaves = [], depth = 0) { + if (depth > bip341_1.MAX_TAPTREE_DEPTH) + throw new Error('Max taptree depth exceeded.'); + if (!tree) return []; + if ((0, types_1.isTapleaf)(tree)) { + leaves.push({ + depth, + leafVersion: tree.version || bip341_1.LEAF_VERSION_TAPSCRIPT, + script: tree.output, + }); + return leaves; } - return c + if (tree[0]) _tapTreeToList(tree[0], leaves, depth + 1); + if (tree[1]) _tapTreeToList(tree[1], leaves, depth + 1); + return leaves; } -// am2 avoids a big mult-and-extract completely. -// Max digit bits should be <= 30 because we do bitwise ops -// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) -function am2(i, x, w, j, c, n) { - var xl = x & 0x7fff, - xh = x >> 15 - while (--n >= 0) { - var l = this[i] & 0x7fff - var h = this[i++] >> 15 - var m = xh * l + h * xl - l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff) - c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30) - w[j++] = l & 0x3fffffff +function instertLeavesInTree(leaves) { + let tree; + for (const leaf of leaves) { + tree = instertLeafInTree(leaf, tree); + if (!tree) throw new Error(`No room left to insert tapleaf in tree`); } - return c + return tree; } -// Alternately, set max digit bits to 28 since some -// browsers slow down when dealing with 32-bit numbers. -function am3(i, x, w, j, c, n) { - var xl = x & 0x3fff, - xh = x >> 14 - while (--n >= 0) { - var l = this[i] & 0x3fff - var h = this[i++] >> 14 - var m = xh * l + h * xl - l = xl * l + ((m & 0x3fff) << 14) + w[j] + c - c = (l >> 28) + (m >> 14) + xh * h - w[j++] = l & 0xfffffff +function instertLeafInTree(leaf, tree, depth = 0) { + if (depth > bip341_1.MAX_TAPTREE_DEPTH) + throw new Error('Max taptree depth exceeded.'); + if (leaf.depth === depth) { + if (!tree) + return { + output: leaf.script, + version: leaf.leafVersion, + }; + return; } - return c + if ((0, types_1.isTapleaf)(tree)) return; + const leftSide = instertLeafInTree(leaf, tree && tree[0], depth + 1); + if (leftSide) return [leftSide, tree && tree[1]]; + const rightSide = instertLeafInTree(leaf, tree && tree[1], depth + 1); + if (rightSide) return [tree && tree[0], rightSide]; } - -// wtf? -BigInteger.prototype.am = am1 -dbits = 26 - -BigInteger.prototype.DB = dbits -BigInteger.prototype.DM = ((1 << dbits) - 1) -var DV = BigInteger.prototype.DV = (1 << dbits) - -var BI_FP = 52 -BigInteger.prototype.FV = Math.pow(2, BI_FP) -BigInteger.prototype.F1 = BI_FP - dbits -BigInteger.prototype.F2 = 2 * dbits - BI_FP - -// Digit conversions -var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz" -var BI_RC = new Array() -var rr, vv -rr = "0".charCodeAt(0) -for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv -rr = "a".charCodeAt(0) -for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv -rr = "A".charCodeAt(0) -for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv - -function int2char(n) { - return BI_RM.charAt(n) -} - -function intAt(s, i) { - var c = BI_RC[s.charCodeAt(i)] - return (c == null) ? -1 : c -} - -// (protected) copy this to r -function bnpCopyTo(r) { - for (var i = this.t - 1; i >= 0; --i) r[i] = this[i] - r.t = this.t - r.s = this.s -} - -// (protected) set from integer value x, -DV <= x < DV -function bnpFromInt(x) { - this.t = 1 - this.s = (x < 0) ? -1 : 0 - if (x > 0) this[0] = x - else if (x < -1) this[0] = x + DV - else this.t = 0 +function checkMixedTaprootAndNonTaprootInputFields( + inputData, + newInputData, + action, +) { + const isBadTaprootUpdate = + isTaprootInput(inputData) && hasNonTaprootFields(newInputData); + const isBadNonTaprootUpdate = + hasNonTaprootFields(inputData) && isTaprootInput(newInputData); + const hasMixedFields = + inputData === newInputData && + isTaprootInput(newInputData) && + hasNonTaprootFields(newInputData); // todo: bad? use !=== + if (isBadTaprootUpdate || isBadNonTaprootUpdate || hasMixedFields) + throw new Error( + `Invalid arguments for Psbt.${action}. ` + + `Cannot use both taproot and non-taproot fields.`, + ); } - -// return bigint initialized to value -function nbv(i) { - var r = new BigInteger() - r.fromInt(i) - return r +function checkMixedTaprootAndNonTaprootOutputFields( + inputData, + newInputData, + action, +) { + const isBadTaprootUpdate = + isTaprootOutput(inputData) && hasNonTaprootFields(newInputData); + const isBadNonTaprootUpdate = + hasNonTaprootFields(inputData) && isTaprootOutput(newInputData); + const hasMixedFields = + inputData === newInputData && + isTaprootOutput(newInputData) && + hasNonTaprootFields(newInputData); + if (isBadTaprootUpdate || isBadNonTaprootUpdate || hasMixedFields) + throw new Error( + `Invalid arguments for Psbt.${action}. ` + + `Cannot use both taproot and non-taproot fields.`, + ); } - -// (protected) set from string and radix -function bnpFromString(s, b) { - var self = this - - var k - if (b == 16) k = 4 - else if (b == 8) k = 3 - else if (b == 256) k = 8; // byte array - else if (b == 2) k = 1 - else if (b == 32) k = 5 - else if (b == 4) k = 2 - else { - self.fromRadix(s, b) - return - } - self.t = 0 - self.s = 0 - var i = s.length, - mi = false, - sh = 0 - while (--i >= 0) { - var x = (k == 8) ? s[i] & 0xff : intAt(s, i) - if (x < 0) { - if (s.charAt(i) == "-") mi = true - continue - } - mi = false - if (sh == 0) - self[self.t++] = x - else if (sh + k > self.DB) { - self[self.t - 1] |= (x & ((1 << (self.DB - sh)) - 1)) << sh - self[self.t++] = (x >> (self.DB - sh)) - } else - self[self.t - 1] |= x << sh - sh += k - if (sh >= self.DB) sh -= self.DB - } - if (k == 8 && (s[0] & 0x80) != 0) { - self.s = -1 - if (sh > 0) self[self.t - 1] |= ((1 << (self.DB - sh)) - 1) << sh +/** + * Checks if the tap leaf is part of the tap tree for the given input data. + * Throws an error if the tap leaf is not part of the tap tree. + * @param inputData - The original PsbtInput data. + * @param newInputData - The new PsbtInput data. + * @param action - The action being performed. + * @throws {Error} - If the tap leaf is not part of the tap tree. + */ +function checkIfTapLeafInTree(inputData, newInputData, action) { + if (newInputData.tapMerkleRoot) { + const newLeafsInTree = (newInputData.tapLeafScript || []).every(l => + isTapLeafInTree(l, newInputData.tapMerkleRoot), + ); + const oldLeafsInTree = (inputData.tapLeafScript || []).every(l => + isTapLeafInTree(l, newInputData.tapMerkleRoot), + ); + if (!newLeafsInTree || !oldLeafsInTree) + throw new Error( + `Invalid arguments for Psbt.${action}. Tapleaf not part of taptree.`, + ); + } else if (inputData.tapMerkleRoot) { + const newLeafsInTree = (newInputData.tapLeafScript || []).every(l => + isTapLeafInTree(l, inputData.tapMerkleRoot), + ); + if (!newLeafsInTree) + throw new Error( + `Invalid arguments for Psbt.${action}. Tapleaf not part of taptree.`, + ); } - self.clamp() - if (mi) BigInteger.ZERO.subTo(self, self) } - -// (protected) clamp off excess high words -function bnpClamp() { - var c = this.s & this.DM - while (this.t > 0 && this[this.t - 1] == c)--this.t +/** + * Checks if a TapLeafScript is present in a Merkle tree. + * @param tapLeaf The TapLeafScript to check. + * @param merkleRoot The Merkle root of the tree. If not provided, the function assumes the TapLeafScript is present. + * @returns A boolean indicating whether the TapLeafScript is present in the tree. + */ +function isTapLeafInTree(tapLeaf, merkleRoot) { + if (!merkleRoot) return true; + const leafHash = (0, bip341_1.tapleafHash)({ + output: tapLeaf.script, + version: tapLeaf.leafVersion, + }); + const rootHash = (0, bip341_1.rootHashFromPath)( + tapLeaf.controlBlock, + leafHash, + ); + return rootHash.equals(merkleRoot); } - -// (public) return string representation in given radix -function bnToString(b) { - var self = this - if (self.s < 0) return "-" + self.negate() - .toString(b) - var k - if (b == 16) k = 4 - else if (b == 8) k = 3 - else if (b == 2) k = 1 - else if (b == 32) k = 5 - else if (b == 4) k = 2 - else return self.toRadix(b) - var km = (1 << k) - 1, - d, m = false, - r = "", - i = self.t - var p = self.DB - (i * self.DB) % k - if (i-- > 0) { - if (p < self.DB && (d = self[i] >> p) > 0) { - m = true - r = int2char(d) - } - while (i >= 0) { - if (p < k) { - d = (self[i] & ((1 << p) - 1)) << (k - p) - d |= self[--i] >> (p += self.DB - k) - } else { - d = (self[i] >> (p -= k)) & km - if (p <= 0) { - p += self.DB - --i - } - } - if (d > 0) m = true - if (m) r += int2char(d) - } - } - return m ? r : "0" +/** + * Sorts the signatures in the input's tapScriptSig array based on their position in the tapLeaf script. + * + * @param input - The PsbtInput object. + * @param tapLeaf - The TapLeafScript object. + * @returns An array of sorted signatures as Buffers. + */ +function sortSignatures(input, tapLeaf) { + const leafHash = (0, bip341_1.tapleafHash)({ + output: tapLeaf.script, + version: tapLeaf.leafVersion, + }); + return (input.tapScriptSig || []) + .filter(tss => tss.leafHash.equals(leafHash)) + .map(tss => addPubkeyPositionInScript(tapLeaf.script, tss)) + .sort((t1, t2) => t2.positionInScript - t1.positionInScript) + .map(t => t.signature); } - -// (public) -this -function bnNegate() { - var r = new BigInteger() - BigInteger.ZERO.subTo(this, r) - return r +/** + * Adds the position of a public key in a script to a TapScriptSig object. + * @param script The script in which to find the position of the public key. + * @param tss The TapScriptSig object to add the position to. + * @returns A TapScriptSigWitPosition object with the added position. + */ +function addPubkeyPositionInScript(script, tss) { + return Object.assign( + { + positionInScript: (0, psbtutils_1.pubkeyPositionInScript)( + tss.pubkey, + script, + ), + }, + tss, + ); } - -// (public) |this| -function bnAbs() { - return (this.s < 0) ? this.negate() : this +/** + * Find tapleaf by hash, or get the signed tapleaf with the shortest path. + */ +function findTapLeafToFinalize(input, inputIndex, leafHashToFinalize) { + if (!input.tapScriptSig || !input.tapScriptSig.length) + throw new Error( + `Can not finalize taproot input #${inputIndex}. No tapleaf script signature provided.`, + ); + const tapLeaf = (input.tapLeafScript || []) + .sort((a, b) => a.controlBlock.length - b.controlBlock.length) + .find(leaf => + canFinalizeLeaf(leaf, input.tapScriptSig, leafHashToFinalize), + ); + if (!tapLeaf) + throw new Error( + `Can not finalize taproot input #${inputIndex}. Signature for tapleaf script not found.`, + ); + return tapLeaf; } - -// (public) return + if this > a, - if this < a, 0 if equal -function bnCompareTo(a) { - var r = this.s - a.s - if (r != 0) return r - var i = this.t - r = i - a.t - if (r != 0) return (this.s < 0) ? -r : r - while (--i >= 0) - if ((r = this[i] - a[i]) != 0) return r - return 0 +/** + * Determines whether a TapLeafScript can be finalized. + * + * @param leaf - The TapLeafScript to check. + * @param tapScriptSig - The array of TapScriptSig objects. + * @param hash - The optional hash to compare with the leaf hash. + * @returns A boolean indicating whether the TapLeafScript can be finalized. + */ +function canFinalizeLeaf(leaf, tapScriptSig, hash) { + const leafHash = (0, bip341_1.tapleafHash)({ + output: leaf.script, + version: leaf.leafVersion, + }); + const whiteListedHash = !hash || hash.equals(leafHash); + return ( + whiteListedHash && + tapScriptSig.find(tss => tss.leafHash.equals(leafHash)) !== undefined + ); } - -// returns bit length of the integer x -function nbits(x) { - var r = 1, - t - if ((t = x >>> 16) != 0) { - x = t - r += 16 - } - if ((t = x >> 8) != 0) { - x = t - r += 8 - } - if ((t = x >> 4) != 0) { - x = t - r += 4 - } - if ((t = x >> 2) != 0) { - x = t - r += 2 - } - if ((t = x >> 1) != 0) { - x = t - r += 1 - } - return r +/** + * Checks if the given PsbtInput or PsbtOutput has non-taproot fields. + * Non-taproot fields include redeemScript, witnessScript, and bip32Derivation. + * @param io The PsbtInput or PsbtOutput to check. + * @returns A boolean indicating whether the given input or output has non-taproot fields. + */ +function hasNonTaprootFields(io) { + return ( + io && + !!( + io.redeemScript || + io.witnessScript || + (io.bip32Derivation && io.bip32Derivation.length) + ) + ); } -// (public) return the number of bits in "this" -function bnBitLength() { - if (this.t <= 0) return 0 - return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM)) +}).call(this)}).call(this,require("buffer").Buffer) +},{"../payments":59,"../payments/bip341":57,"../transaction":75,"../types":76,"./psbtutils":70,"buffer":249}],70:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.signatureBlocksAction = + exports.checkInputForSig = + exports.pubkeyInScript = + exports.pubkeyPositionInScript = + exports.witnessStackToScriptWitness = + exports.isP2TR = + exports.isP2SHScript = + exports.isP2WSHScript = + exports.isP2WPKH = + exports.isP2PKH = + exports.isP2PK = + exports.isP2MS = + void 0; +const varuint = require('bip174/src/lib/converter/varint'); +const bscript = require('../script'); +const transaction_1 = require('../transaction'); +const crypto_1 = require('../crypto'); +const payments = require('../payments'); +function isPaymentFactory(payment) { + return script => { + try { + payment({ output: script }); + return true; + } catch (err) { + return false; + } + }; } - -// (public) return the number of bytes in "this" -function bnByteLength() { - return this.bitLength() >> 3 +exports.isP2MS = isPaymentFactory(payments.p2ms); +exports.isP2PK = isPaymentFactory(payments.p2pk); +exports.isP2PKH = isPaymentFactory(payments.p2pkh); +exports.isP2WPKH = isPaymentFactory(payments.p2wpkh); +exports.isP2WSHScript = isPaymentFactory(payments.p2wsh); +exports.isP2SHScript = isPaymentFactory(payments.p2sh); +exports.isP2TR = isPaymentFactory(payments.p2tr); +/** + * Converts a witness stack to a script witness. + * @param witness The witness stack to convert. + * @returns The script witness as a Buffer. + */ +/** + * Converts a witness stack to a script witness. + * @param witness The witness stack to convert. + * @returns The converted script witness. + */ +function witnessStackToScriptWitness(witness) { + let buffer = Buffer.allocUnsafe(0); + function writeSlice(slice) { + buffer = Buffer.concat([buffer, Buffer.from(slice)]); + } + function writeVarInt(i) { + const currentLen = buffer.length; + const varintLen = varuint.encodingLength(i); + buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]); + varuint.encode(i, buffer, currentLen); + } + function writeVarSlice(slice) { + writeVarInt(slice.length); + writeSlice(slice); + } + function writeVector(vector) { + writeVarInt(vector.length); + vector.forEach(writeVarSlice); + } + writeVector(witness); + return buffer; } - -// (protected) r = this << n*DB -function bnpDLShiftTo(n, r) { - var i - for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i] - for (i = n - 1; i >= 0; --i) r[i] = 0 - r.t = this.t + n - r.s = this.s +exports.witnessStackToScriptWitness = witnessStackToScriptWitness; +/** + * Finds the position of a public key in a script. + * @param pubkey The public key to search for. + * @param script The script to search in. + * @returns The index of the public key in the script, or -1 if not found. + * @throws {Error} If there is an unknown script error. + */ +function pubkeyPositionInScript(pubkey, script) { + const pubkeyHash = (0, crypto_1.hash160)(pubkey); + const pubkeyXOnly = pubkey.slice(1, 33); // slice before calling? + const decompiled = bscript.decompile(script); + if (decompiled === null) throw new Error('Unknown script error'); + return decompiled.findIndex(element => { + if (typeof element === 'number') return false; + return ( + element.equals(pubkey) || + element.equals(pubkeyHash) || + element.equals(pubkeyXOnly) + ); + }); } - -// (protected) r = this >> n*DB -function bnpDRShiftTo(n, r) { - for (var i = n; i < this.t; ++i) r[i - n] = this[i] - r.t = Math.max(this.t - n, 0) - r.s = this.s +exports.pubkeyPositionInScript = pubkeyPositionInScript; +/** + * Checks if a public key is present in a script. + * @param pubkey The public key to check. + * @param script The script to search in. + * @returns A boolean indicating whether the public key is present in the script. + */ +function pubkeyInScript(pubkey, script) { + return pubkeyPositionInScript(pubkey, script) !== -1; } - -// (protected) r = this << n -function bnpLShiftTo(n, r) { - var self = this - var bs = n % self.DB - var cbs = self.DB - bs - var bm = (1 << cbs) - 1 - var ds = Math.floor(n / self.DB), - c = (self.s << bs) & self.DM, - i - for (i = self.t - 1; i >= 0; --i) { - r[i + ds + 1] = (self[i] >> cbs) | c - c = (self[i] & bm) << bs - } - for (i = ds - 1; i >= 0; --i) r[i] = 0 - r[ds] = c - r.t = self.t + ds + 1 - r.s = self.s - r.clamp() +exports.pubkeyInScript = pubkeyInScript; +/** + * Checks if an input contains a signature for a specific action. + * @param input - The input to check. + * @param action - The action to check for. + * @returns A boolean indicating whether the input contains a signature for the specified action. + */ +function checkInputForSig(input, action) { + const pSigs = extractPartialSigs(input); + return pSigs.some(pSig => + signatureBlocksAction(pSig, bscript.signature.decode, action), + ); } - -// (protected) r = this >> n -function bnpRShiftTo(n, r) { - var self = this - r.s = self.s - var ds = Math.floor(n / self.DB) - if (ds >= self.t) { - r.t = 0 - return +exports.checkInputForSig = checkInputForSig; +/** + * Determines if a given action is allowed for a signature block. + * @param signature - The signature block. + * @param signatureDecodeFn - The function used to decode the signature. + * @param action - The action to be checked. + * @returns True if the action is allowed, false otherwise. + */ +function signatureBlocksAction(signature, signatureDecodeFn, action) { + const { hashType } = signatureDecodeFn(signature); + const whitelist = []; + const isAnyoneCanPay = + hashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY; + if (isAnyoneCanPay) whitelist.push('addInput'); + const hashMod = hashType & 0x1f; + switch (hashMod) { + case transaction_1.Transaction.SIGHASH_ALL: + break; + case transaction_1.Transaction.SIGHASH_SINGLE: + case transaction_1.Transaction.SIGHASH_NONE: + whitelist.push('addOutput'); + whitelist.push('setInputSequence'); + break; } - var bs = n % self.DB - var cbs = self.DB - bs - var bm = (1 << bs) - 1 - r[0] = self[ds] >> bs - for (var i = ds + 1; i < self.t; ++i) { - r[i - ds - 1] |= (self[i] & bm) << cbs - r[i - ds] = self[i] >> bs + if (whitelist.indexOf(action) === -1) { + return true; } - if (bs > 0) r[self.t - ds - 1] |= (self.s & bm) << cbs - r.t = self.t - ds - r.clamp() + return false; } - -// (protected) r = this - a -function bnpSubTo(a, r) { - var self = this - var i = 0, - c = 0, - m = Math.min(a.t, self.t) - while (i < m) { - c += self[i] - a[i] - r[i++] = c & self.DM - c >>= self.DB - } - if (a.t < self.t) { - c -= a.s - while (i < self.t) { - c += self[i] - r[i++] = c & self.DM - c >>= self.DB - } - c += self.s +exports.signatureBlocksAction = signatureBlocksAction; +/** + * Extracts the signatures from a PsbtInput object. + * If the input has partial signatures, it returns an array of the signatures. + * If the input does not have partial signatures, it checks if it has a finalScriptSig or finalScriptWitness. + * If it does, it extracts the signatures from the final scripts and returns them. + * If none of the above conditions are met, it returns an empty array. + * + * @param input - The PsbtInput object from which to extract the signatures. + * @returns An array of signatures extracted from the PsbtInput object. + */ +function extractPartialSigs(input) { + let pSigs = []; + if ((input.partialSig || []).length === 0) { + if (!input.finalScriptSig && !input.finalScriptWitness) return []; + pSigs = getPsigsFromInputFinalScripts(input); } else { - c += self.s - while (i < a.t) { - c -= a[i] - r[i++] = c & self.DM - c >>= self.DB - } - c -= a.s + pSigs = input.partialSig; } - r.s = (c < 0) ? -1 : 0 - if (c < -1) r[i++] = self.DV + c - else if (c > 0) r[i++] = c - r.t = i - r.clamp() + return pSigs.map(p => p.signature); } - -// (protected) r = this * a, r != this,a (HAC 14.12) -// "this" should be the larger one if appropriate. -function bnpMultiplyTo(a, r) { - var x = this.abs(), - y = a.abs() - var i = x.t - r.t = i + y.t - while (--i >= 0) r[i] = 0 - for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t) - r.s = 0 - r.clamp() - if (this.s != a.s) BigInteger.ZERO.subTo(r, r) +/** + * Retrieves the partial signatures (Psigs) from the input's final scripts. + * Psigs are extracted from both the final scriptSig and final scriptWitness of the input. + * Only canonical script signatures are considered. + * + * @param input - The PsbtInput object representing the input. + * @returns An array of PartialSig objects containing the extracted Psigs. + */ +function getPsigsFromInputFinalScripts(input) { + const scriptItems = !input.finalScriptSig + ? [] + : bscript.decompile(input.finalScriptSig) || []; + const witnessItems = !input.finalScriptWitness + ? [] + : bscript.decompile(input.finalScriptWitness) || []; + return scriptItems + .concat(witnessItems) + .filter(item => { + return Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item); + }) + .map(sig => ({ signature: sig })); } -// (protected) r = this^2, r != this (HAC 14.16) -function bnpSquareTo(r) { - var x = this.abs() - var i = r.t = 2 * x.t - while (--i >= 0) r[i] = 0 - for (i = 0; i < x.t - 1; ++i) { - var c = x.am(i, x[i], r, 2 * i, 0, 1) - if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { - r[i + x.t] -= x.DV - r[i + x.t + 1] = 1 - } - } - if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1) - r.s = 0 - r.clamp() +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":51,"../payments":59,"../script":72,"../transaction":75,"bip174/src/lib/converter/varint":36,"buffer":249}],71:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.decode = exports.encode = exports.encodingLength = void 0; +const ops_1 = require('./ops'); +/** + * Calculates the encoding length of a number used for push data in Bitcoin transactions. + * @param i The number to calculate the encoding length for. + * @returns The encoding length of the number. + */ +function encodingLength(i) { + return i < ops_1.OPS.OP_PUSHDATA1 ? 1 : i <= 0xff ? 2 : i <= 0xffff ? 3 : 5; } - -// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) -// r != q, this != m. q or r may be null. -function bnpDivRemTo(m, q, r) { - var self = this - var pm = m.abs() - if (pm.t <= 0) return - var pt = self.abs() - if (pt.t < pm.t) { - if (q != null) q.fromInt(0) - if (r != null) self.copyTo(r) - return - } - if (r == null) r = new BigInteger() - var y = new BigInteger(), - ts = self.s, - ms = m.s - var nsh = self.DB - nbits(pm[pm.t - 1]); // normalize modulus - if (nsh > 0) { - pm.lShiftTo(nsh, y) - pt.lShiftTo(nsh, r) +exports.encodingLength = encodingLength; +/** + * Encodes a number into a buffer using a variable-length encoding scheme. + * The encoded buffer is written starting at the specified offset. + * Returns the size of the encoded buffer. + * + * @param buffer - The buffer to write the encoded data into. + * @param num - The number to encode. + * @param offset - The offset at which to start writing the encoded buffer. + * @returns The size of the encoded buffer. + */ +function encode(buffer, num, offset) { + const size = encodingLength(num); + // ~6 bit + if (size === 1) { + buffer.writeUInt8(num, offset); + // 8 bit + } else if (size === 2) { + buffer.writeUInt8(ops_1.OPS.OP_PUSHDATA1, offset); + buffer.writeUInt8(num, offset + 1); + // 16 bit + } else if (size === 3) { + buffer.writeUInt8(ops_1.OPS.OP_PUSHDATA2, offset); + buffer.writeUInt16LE(num, offset + 1); + // 32 bit } else { - pm.copyTo(y) - pt.copyTo(r) - } - var ys = y.t - var y0 = y[ys - 1] - if (y0 == 0) return - var yt = y0 * (1 << self.F1) + ((ys > 1) ? y[ys - 2] >> self.F2 : 0) - var d1 = self.FV / yt, - d2 = (1 << self.F1) / yt, - e = 1 << self.F2 - var i = r.t, - j = i - ys, - t = (q == null) ? new BigInteger() : q - y.dlShiftTo(j, t) - if (r.compareTo(t) >= 0) { - r[r.t++] = 1 - r.subTo(t, r) - } - BigInteger.ONE.dlShiftTo(ys, t) - t.subTo(y, y); // "negative" y so we can replace sub with am later - while (y.t < ys) y[y.t++] = 0 - while (--j >= 0) { - // Estimate quotient digit - var qd = (r[--i] == y0) ? self.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2) - if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out - y.dlShiftTo(j, t) - r.subTo(t, r) - while (r[i] < --qd) r.subTo(t, r) - } + buffer.writeUInt8(ops_1.OPS.OP_PUSHDATA4, offset); + buffer.writeUInt32LE(num, offset + 1); } - if (q != null) { - r.drShiftTo(ys, q) - if (ts != ms) BigInteger.ZERO.subTo(q, q) + return size; +} +exports.encode = encode; +/** + * Decodes a buffer and returns information about the opcode, number, and size. + * @param buffer - The buffer to decode. + * @param offset - The offset within the buffer to start decoding. + * @returns An object containing the opcode, number, and size, or null if decoding fails. + */ +function decode(buffer, offset) { + const opcode = buffer.readUInt8(offset); + let num; + let size; + // ~6 bit + if (opcode < ops_1.OPS.OP_PUSHDATA1) { + num = opcode; + size = 1; + // 8 bit + } else if (opcode === ops_1.OPS.OP_PUSHDATA1) { + if (offset + 2 > buffer.length) return null; + num = buffer.readUInt8(offset + 1); + size = 2; + // 16 bit + } else if (opcode === ops_1.OPS.OP_PUSHDATA2) { + if (offset + 3 > buffer.length) return null; + num = buffer.readUInt16LE(offset + 1); + size = 3; + // 32 bit + } else { + if (offset + 5 > buffer.length) return null; + if (opcode !== ops_1.OPS.OP_PUSHDATA4) throw new Error('Unexpected opcode'); + num = buffer.readUInt32LE(offset + 1); + size = 5; } - r.t = ys - r.clamp() - if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder - if (ts < 0) BigInteger.ZERO.subTo(r, r) + return { + opcode, + number: num, + size, + }; } +exports.decode = decode; -// (public) this mod a -function bnMod(a) { - var r = new BigInteger() - this.abs() - .divRemTo(a, null, r) - if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r) - return r +},{"./ops":56}],72:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.signature = + exports.number = + exports.isCanonicalScriptSignature = + exports.isDefinedHashType = + exports.isCanonicalPubKey = + exports.toStack = + exports.fromASM = + exports.toASM = + exports.decompile = + exports.compile = + exports.countNonPushOnlyOPs = + exports.isPushOnly = + exports.OPS = + void 0; +/** + * Script tools, including decompile, compile, toASM, fromASM, toStack, isCanonicalPubKey, isCanonicalScriptSignature + * @packageDocumentation + */ +const bip66 = require('./bip66'); +const ops_1 = require('./ops'); +Object.defineProperty(exports, 'OPS', { + enumerable: true, + get: function () { + return ops_1.OPS; + }, +}); +const pushdata = require('./push_data'); +const scriptNumber = require('./script_number'); +const scriptSignature = require('./script_signature'); +const types = require('./types'); +const { typeforce } = types; +const OP_INT_BASE = ops_1.OPS.OP_RESERVED; // OP_1 - 1 +function isOPInt(value) { + return ( + types.Number(value) && + (value === ops_1.OPS.OP_0 || + (value >= ops_1.OPS.OP_1 && value <= ops_1.OPS.OP_16) || + value === ops_1.OPS.OP_1NEGATE) + ); } - -// Modular reduction using "classic" algorithm -function Classic(m) { - this.m = m +function isPushOnlyChunk(value) { + return types.Buffer(value) || isOPInt(value); } - -function cConvert(x) { - if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m) - else return x +function isPushOnly(value) { + return types.Array(value) && value.every(isPushOnlyChunk); } - -function cRevert(x) { - return x +exports.isPushOnly = isPushOnly; +function countNonPushOnlyOPs(value) { + return value.length - value.filter(isPushOnlyChunk).length; } - -function cReduce(x) { - x.divRemTo(this.m, null, x) +exports.countNonPushOnlyOPs = countNonPushOnlyOPs; +function asMinimalOP(buffer) { + if (buffer.length === 0) return ops_1.OPS.OP_0; + if (buffer.length !== 1) return; + if (buffer[0] >= 1 && buffer[0] <= 16) return OP_INT_BASE + buffer[0]; + if (buffer[0] === 0x81) return ops_1.OPS.OP_1NEGATE; } - -function cMulTo(x, y, r) { - x.multiplyTo(y, r) - this.reduce(r) -} - -function cSqrTo(x, r) { - x.squareTo(r) - this.reduce(r) -} - -Classic.prototype.convert = cConvert -Classic.prototype.revert = cRevert -Classic.prototype.reduce = cReduce -Classic.prototype.mulTo = cMulTo -Classic.prototype.sqrTo = cSqrTo - -// (protected) return "-1/this % 2^DB"; useful for Mont. reduction -// justification: -// xy == 1 (mod m) -// xy = 1+km -// xy(2-xy) = (1+km)(1-km) -// x[y(2-xy)] = 1-k^2m^2 -// x[y(2-xy)] == 1 (mod m^2) -// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 -// should reduce x and y(2-xy) by m^2 at each step to keep size bounded. -// JS multiply "overflows" differently from C/C++, so care is needed here. -function bnpInvDigit() { - if (this.t < 1) return 0 - var x = this[0] - if ((x & 1) == 0) return 0 - var y = x & 3; // y == 1/x mod 2^2 - y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 - y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 - y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16 - // last step - calculate inverse mod DV directly - // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits - // we really want the negative inverse, and -DV < y < DV - return (y > 0) ? this.DV - y : -y +function chunksIsBuffer(buf) { + return Buffer.isBuffer(buf); } - -// Montgomery reduction -function Montgomery(m) { - this.m = m - this.mp = m.invDigit() - this.mpl = this.mp & 0x7fff - this.mph = this.mp >> 15 - this.um = (1 << (m.DB - 15)) - 1 - this.mt2 = 2 * m.t +function chunksIsArray(buf) { + return types.Array(buf); } - -// xR mod m -function montConvert(x) { - var r = new BigInteger() - x.abs() - .dlShiftTo(this.m.t, r) - r.divRemTo(this.m, null, r) - if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r) - return r +function singleChunkIsBuffer(buf) { + return Buffer.isBuffer(buf); } - -// x/R mod m -function montRevert(x) { - var r = new BigInteger() - x.copyTo(r) - this.reduce(r) - return r +/** + * Compiles an array of chunks into a Buffer. + * + * @param chunks - The array of chunks to compile. + * @returns The compiled Buffer. + * @throws Error if the compilation fails. + */ +function compile(chunks) { + // TODO: remove me + if (chunksIsBuffer(chunks)) return chunks; + typeforce(types.Array, chunks); + const bufferSize = chunks.reduce((accum, chunk) => { + // data chunk + if (singleChunkIsBuffer(chunk)) { + // adhere to BIP62.3, minimal push policy + if (chunk.length === 1 && asMinimalOP(chunk) !== undefined) { + return accum + 1; + } + return accum + pushdata.encodingLength(chunk.length) + chunk.length; + } + // opcode + return accum + 1; + }, 0.0); + const buffer = Buffer.allocUnsafe(bufferSize); + let offset = 0; + chunks.forEach(chunk => { + // data chunk + if (singleChunkIsBuffer(chunk)) { + // adhere to BIP62.3, minimal push policy + const opcode = asMinimalOP(chunk); + if (opcode !== undefined) { + buffer.writeUInt8(opcode, offset); + offset += 1; + return; + } + offset += pushdata.encode(buffer, chunk.length, offset); + chunk.copy(buffer, offset); + offset += chunk.length; + // opcode + } else { + buffer.writeUInt8(chunk, offset); + offset += 1; + } + }); + if (offset !== buffer.length) throw new Error('Could not decode chunks'); + return buffer; } - -// x = x/R mod m (HAC 14.32) -function montReduce(x) { - while (x.t <= this.mt2) // pad x so am has enough room later - x[x.t++] = 0 - for (var i = 0; i < this.m.t; ++i) { - // faster way of calculating u0 = x[i]*mp mod DV - var j = x[i] & 0x7fff - var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM - // use am to combine the multiply-shift-add into one call - j = i + this.m.t - x[j] += this.m.am(0, u0, x, i, 0, this.m.t) - // propagate carry - while (x[j] >= x.DV) { - x[j] -= x.DV - x[++j]++ +exports.compile = compile; +function decompile(buffer) { + // TODO: remove me + if (chunksIsArray(buffer)) return buffer; + typeforce(types.Buffer, buffer); + const chunks = []; + let i = 0; + while (i < buffer.length) { + const opcode = buffer[i]; + // data chunk + if (opcode > ops_1.OPS.OP_0 && opcode <= ops_1.OPS.OP_PUSHDATA4) { + const d = pushdata.decode(buffer, i); + // did reading a pushDataInt fail? + if (d === null) return null; + i += d.size; + // attempt to read too much data? + if (i + d.number > buffer.length) return null; + const data = buffer.slice(i, i + d.number); + i += d.number; + // decompile minimally + const op = asMinimalOP(data); + if (op !== undefined) { + chunks.push(op); + } else { + chunks.push(data); + } + // opcode + } else { + chunks.push(opcode); + i += 1; } } - x.clamp() - x.drShiftTo(this.m.t, x) - if (x.compareTo(this.m) >= 0) x.subTo(this.m, x) + return chunks; } - -// r = "x^2/R mod m"; x != r -function montSqrTo(x, r) { - x.squareTo(r) - this.reduce(r) +exports.decompile = decompile; +/** + * Converts the given chunks into an ASM (Assembly) string representation. + * If the chunks parameter is a Buffer, it will be decompiled into a Stack before conversion. + * @param chunks - The chunks to convert into ASM. + * @returns The ASM string representation of the chunks. + */ +function toASM(chunks) { + if (chunksIsBuffer(chunks)) { + chunks = decompile(chunks); + } + if (!chunks) { + throw new Error('Could not convert invalid chunks to ASM'); + } + return chunks + .map(chunk => { + // data? + if (singleChunkIsBuffer(chunk)) { + const op = asMinimalOP(chunk); + if (op === undefined) return chunk.toString('hex'); + chunk = op; + } + // opcode! + return ops_1.REVERSE_OPS[chunk]; + }) + .join(' '); } - -// r = "xy/R mod m"; x,y != r -function montMulTo(x, y, r) { - x.multiplyTo(y, r) - this.reduce(r) +exports.toASM = toASM; +/** + * Converts an ASM string to a Buffer. + * @param asm The ASM string to convert. + * @returns The converted Buffer. + */ +function fromASM(asm) { + typeforce(types.String, asm); + return compile( + asm.split(' ').map(chunkStr => { + // opcode? + if (ops_1.OPS[chunkStr] !== undefined) return ops_1.OPS[chunkStr]; + typeforce(types.Hex, chunkStr); + // data! + return Buffer.from(chunkStr, 'hex'); + }), + ); } - -Montgomery.prototype.convert = montConvert -Montgomery.prototype.revert = montRevert -Montgomery.prototype.reduce = montReduce -Montgomery.prototype.mulTo = montMulTo -Montgomery.prototype.sqrTo = montSqrTo - -// (protected) true iff this is even -function bnpIsEven() { - return ((this.t > 0) ? (this[0] & 1) : this.s) == 0 +exports.fromASM = fromASM; +/** + * Converts the given chunks into a stack of buffers. + * + * @param chunks - The chunks to convert. + * @returns The stack of buffers. + */ +function toStack(chunks) { + chunks = decompile(chunks); + typeforce(isPushOnly, chunks); + return chunks.map(op => { + if (singleChunkIsBuffer(op)) return op; + if (op === ops_1.OPS.OP_0) return Buffer.allocUnsafe(0); + return scriptNumber.encode(op - OP_INT_BASE); + }); } - -// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) -function bnpExp(e, z) { - if (e > 0xffffffff || e < 1) return BigInteger.ONE - var r = new BigInteger(), - r2 = new BigInteger(), - g = z.convert(this), - i = nbits(e) - 1 - g.copyTo(r) - while (--i >= 0) { - z.sqrTo(r, r2) - if ((e & (1 << i)) > 0) z.mulTo(r2, g, r) - else { - var t = r - r = r2 - r2 = t - } - } - return z.revert(r) +exports.toStack = toStack; +function isCanonicalPubKey(buffer) { + return types.isPoint(buffer); } - -// (public) this^e % m, 0 <= e < 2^32 -function bnModPowInt(e, m) { - var z - if (e < 256 || m.isEven()) z = new Classic(m) - else z = new Montgomery(m) - return this.exp(e, z) +exports.isCanonicalPubKey = isCanonicalPubKey; +function isDefinedHashType(hashType) { + const hashTypeMod = hashType & ~0x80; + // return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE + return hashTypeMod > 0x00 && hashTypeMod < 0x04; } - -// protected -proto.copyTo = bnpCopyTo -proto.fromInt = bnpFromInt -proto.fromString = bnpFromString -proto.clamp = bnpClamp -proto.dlShiftTo = bnpDLShiftTo -proto.drShiftTo = bnpDRShiftTo -proto.lShiftTo = bnpLShiftTo -proto.rShiftTo = bnpRShiftTo -proto.subTo = bnpSubTo -proto.multiplyTo = bnpMultiplyTo -proto.squareTo = bnpSquareTo -proto.divRemTo = bnpDivRemTo -proto.invDigit = bnpInvDigit -proto.isEven = bnpIsEven -proto.exp = bnpExp - -// public -proto.toString = bnToString -proto.negate = bnNegate -proto.abs = bnAbs -proto.compareTo = bnCompareTo -proto.bitLength = bnBitLength -proto.byteLength = bnByteLength -proto.mod = bnMod -proto.modPowInt = bnModPowInt - -// (public) -function bnClone() { - var r = new BigInteger() - this.copyTo(r) - return r +exports.isDefinedHashType = isDefinedHashType; +function isCanonicalScriptSignature(buffer) { + if (!Buffer.isBuffer(buffer)) return false; + if (!isDefinedHashType(buffer[buffer.length - 1])) return false; + return bip66.check(buffer.slice(0, -1)); } +exports.isCanonicalScriptSignature = isCanonicalScriptSignature; +exports.number = scriptNumber; +exports.signature = scriptSignature; -// (public) return value as integer -function bnIntValue() { - if (this.s < 0) { - if (this.t == 1) return this[0] - this.DV - else if (this.t == 0) return -1 - } else if (this.t == 1) return this[0] - else if (this.t == 0) return 0 - // assumes 16 < DB < 32 - return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0] +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bip66":48,"./ops":56,"./push_data":71,"./script_number":73,"./script_signature":74,"./types":76,"buffer":249}],73:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.encode = exports.decode = void 0; +/** + * Decodes a script number from a buffer. + * + * @param buffer - The buffer containing the script number. + * @param maxLength - The maximum length of the script number. Defaults to 4. + * @param minimal - Whether the script number should be minimal. Defaults to true. + * @returns The decoded script number. + * @throws {TypeError} If the script number overflows the maximum length. + * @throws {Error} If the script number is not minimally encoded when minimal is true. + */ +function decode(buffer, maxLength, minimal) { + maxLength = maxLength || 4; + minimal = minimal === undefined ? true : minimal; + const length = buffer.length; + if (length === 0) return 0; + if (length > maxLength) throw new TypeError('Script number overflow'); + if (minimal) { + if ((buffer[length - 1] & 0x7f) === 0) { + if (length <= 1 || (buffer[length - 2] & 0x80) === 0) + throw new Error('Non-minimally encoded script number'); + } + } + // 40-bit + if (length === 5) { + const a = buffer.readUInt32LE(0); + const b = buffer.readUInt8(4); + if (b & 0x80) return -((b & ~0x80) * 0x100000000 + a); + return b * 0x100000000 + a; + } + // 32-bit / 24-bit / 16-bit / 8-bit + let result = 0; + for (let i = 0; i < length; ++i) { + result |= buffer[i] << (8 * i); + } + if (buffer[length - 1] & 0x80) + return -(result & ~(0x80 << (8 * (length - 1)))); + return result; } - -// (public) return value as byte -function bnByteValue() { - return (this.t == 0) ? this.s : (this[0] << 24) >> 24 +exports.decode = decode; +function scriptNumSize(i) { + return i > 0x7fffffff + ? 5 + : i > 0x7fffff + ? 4 + : i > 0x7fff + ? 3 + : i > 0x7f + ? 2 + : i > 0x00 + ? 1 + : 0; } - -// (public) return value as short (assumes DB>=16) -function bnShortValue() { - return (this.t == 0) ? this.s : (this[0] << 16) >> 16 +/** + * Encodes a number into a Buffer using a specific format. + * + * @param _number - The number to encode. + * @returns The encoded number as a Buffer. + */ +function encode(_number) { + let value = Math.abs(_number); + const size = scriptNumSize(value); + const buffer = Buffer.allocUnsafe(size); + const negative = _number < 0; + for (let i = 0; i < size; ++i) { + buffer.writeUInt8(value & 0xff, i); + value >>= 8; + } + if (buffer[size - 1] & 0x80) { + buffer.writeUInt8(negative ? 0x80 : 0x00, size - 1); + } else if (negative) { + buffer[size - 1] |= 0x80; + } + return buffer; } +exports.encode = encode; -// (protected) return x s.t. r^x < DV -function bnpChunkSize(r) { - return Math.floor(Math.LN2 * this.DB / Math.log(r)) +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],74:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.encode = exports.decode = void 0; +const bip66 = require('./bip66'); +const script_1 = require('./script'); +const types = require('./types'); +const { typeforce } = types; +const ZERO = Buffer.alloc(1, 0); +/** + * Converts a buffer to a DER-encoded buffer. + * @param x - The buffer to be converted. + * @returns The DER-encoded buffer. + */ +function toDER(x) { + let i = 0; + while (x[i] === 0) ++i; + if (i === x.length) return ZERO; + x = x.slice(i); + if (x[0] & 0x80) return Buffer.concat([ZERO, x], 1 + x.length); + return x; } - -// (public) 0 if this == 0, 1 if this > 0 -function bnSigNum() { - if (this.s < 0) return -1 - else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0 - else return 1 +/** + * Converts a DER-encoded signature to a buffer. + * If the first byte of the input buffer is 0x00, it is skipped. + * The resulting buffer is 32 bytes long, filled with zeros if necessary. + * @param x - The DER-encoded signature. + * @returns The converted buffer. + */ +function fromDER(x) { + if (x[0] === 0x00) x = x.slice(1); + const buffer = Buffer.alloc(32, 0); + const bstart = Math.max(0, 32 - x.length); + x.copy(buffer, bstart); + return buffer; } - -// (protected) convert to radix string -function bnpToRadix(b) { - if (b == null) b = 10 - if (this.signum() == 0 || b < 2 || b > 36) return "0" - var cs = this.chunkSize(b) - var a = Math.pow(b, cs) - var d = nbv(a), - y = new BigInteger(), - z = new BigInteger(), - r = "" - this.divRemTo(d, y, z) - while (y.signum() > 0) { - r = (a + z.intValue()) - .toString(b) - .substr(1) + r - y.divRemTo(d, y, z) +// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed) +/** + * Decodes a buffer into a ScriptSignature object. + * @param buffer - The buffer to decode. + * @returns The decoded ScriptSignature object. + * @throws Error if the hashType is invalid. + */ +function decode(buffer) { + const hashType = buffer.readUInt8(buffer.length - 1); + if (!(0, script_1.isDefinedHashType)(hashType)) { + throw new Error('Invalid hashType ' + hashType); } - return z.intValue() - .toString(b) + r + const decoded = bip66.decode(buffer.slice(0, -1)); + const r = fromDER(decoded.r); + const s = fromDER(decoded.s); + const signature = Buffer.concat([r, s], 64); + return { signature, hashType }; } - -// (protected) convert from radix string -function bnpFromRadix(s, b) { - var self = this - self.fromInt(0) - if (b == null) b = 10 - var cs = self.chunkSize(b) - var d = Math.pow(b, cs), - mi = false, - j = 0, - w = 0 - for (var i = 0; i < s.length; ++i) { - var x = intAt(s, i) - if (x < 0) { - if (s.charAt(i) == "-" && self.signum() == 0) mi = true - continue - } - w = b * w + x - if (++j >= cs) { - self.dMultiply(d) - self.dAddOffset(w, 0) - j = 0 - w = 0 - } - } - if (j > 0) { - self.dMultiply(Math.pow(b, j)) - self.dAddOffset(w, 0) +exports.decode = decode; +/** + * Encodes a signature and hash type into a buffer. + * @param signature - The signature to encode. + * @param hashType - The hash type to encode. + * @returns The encoded buffer. + * @throws Error if the hashType is invalid. + */ +function encode(signature, hashType) { + typeforce( + { + signature: types.BufferN(64), + hashType: types.UInt8, + }, + { signature, hashType }, + ); + if (!(0, script_1.isDefinedHashType)(hashType)) { + throw new Error('Invalid hashType ' + hashType); } - if (mi) BigInteger.ZERO.subTo(self, self) + const hashTypeBuffer = Buffer.allocUnsafe(1); + hashTypeBuffer.writeUInt8(hashType, 0); + const r = toDER(signature.slice(0, 32)); + const s = toDER(signature.slice(32, 64)); + return Buffer.concat([bip66.encode(r, s), hashTypeBuffer]); } +exports.encode = encode; -// (protected) alternate constructor -function bnpFromNumber(a, b, c) { - var self = this - if ("number" == typeof b) { - // new BigInteger(int,int,RNG) - if (a < 2) self.fromInt(1) - else { - self.fromNumber(a, c) - if (!self.testBit(a - 1)) // force MSB set - self.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, self) - if (self.isEven()) self.dAddOffset(1, 0); // force odd - while (!self.isProbablePrime(b)) { - self.dAddOffset(2, 0) - if (self.bitLength() > a) self.subTo(BigInteger.ONE.shiftLeft(a - 1), self) - } - } - } else { - // new BigInteger(int,RNG) - var x = new Array(), - t = a & 7 - x.length = (a >> 3) + 1 - b.nextBytes(x) - if (t > 0) x[0] &= ((1 << t) - 1) - else x[0] = 0 - self.fromString(x, 256) - } +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bip66":48,"./script":72,"./types":76,"buffer":249}],75:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.Transaction = void 0; +const bufferutils_1 = require('./bufferutils'); +const bcrypto = require('./crypto'); +const bscript = require('./script'); +const script_1 = require('./script'); +const types = require('./types'); +const { typeforce } = types; +function varSliceSize(someScript) { + const length = someScript.length; + return bufferutils_1.varuint.encodingLength(length) + length; } - -// (public) convert to bigendian byte array -function bnToByteArray() { - var self = this - var i = self.t, - r = new Array() - r[0] = self.s - var p = self.DB - (i * self.DB) % 8, - d, k = 0 - if (i-- > 0) { - if (p < self.DB && (d = self[i] >> p) != (self.s & self.DM) >> p) - r[k++] = d | (self.s << (self.DB - p)) - while (i >= 0) { - if (p < 8) { - d = (self[i] & ((1 << p) - 1)) << (8 - p) - d |= self[--i] >> (p += self.DB - 8) +function vectorSize(someVector) { + const length = someVector.length; + return ( + bufferutils_1.varuint.encodingLength(length) + + someVector.reduce((sum, witness) => { + return sum + varSliceSize(witness); + }, 0) + ); +} +const EMPTY_BUFFER = Buffer.allocUnsafe(0); +const EMPTY_WITNESS = []; +const ZERO = Buffer.from( + '0000000000000000000000000000000000000000000000000000000000000000', + 'hex', +); +const ONE = Buffer.from( + '0000000000000000000000000000000000000000000000000000000000000001', + 'hex', +); +const VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex'); +const BLANK_OUTPUT = { + script: EMPTY_BUFFER, + valueBuffer: VALUE_UINT64_MAX, +}; +function isOutput(out) { + return out.value !== undefined; +} +/** + * Represents a Bitcoin transaction. + */ +class Transaction { + constructor() { + this.version = 1; + this.locktime = 0; + this.ins = []; + this.outs = []; + } + static fromBuffer(buffer, _NO_STRICT) { + const bufferReader = new bufferutils_1.BufferReader(buffer); + const tx = new Transaction(); + tx.version = bufferReader.readInt32(); + const marker = bufferReader.readUInt8(); + const flag = bufferReader.readUInt8(); + let hasWitnesses = false; + if ( + marker === Transaction.ADVANCED_TRANSACTION_MARKER && + flag === Transaction.ADVANCED_TRANSACTION_FLAG + ) { + hasWitnesses = true; + } else { + bufferReader.offset -= 2; + } + const vinLen = bufferReader.readVarInt(); + for (let i = 0; i < vinLen; ++i) { + tx.ins.push({ + hash: bufferReader.readSlice(32), + index: bufferReader.readUInt32(), + script: bufferReader.readVarSlice(), + sequence: bufferReader.readUInt32(), + witness: EMPTY_WITNESS, + }); + } + const voutLen = bufferReader.readVarInt(); + for (let i = 0; i < voutLen; ++i) { + tx.outs.push({ + value: bufferReader.readUInt64(), + script: bufferReader.readVarSlice(), + }); + } + if (hasWitnesses) { + for (let i = 0; i < vinLen; ++i) { + tx.ins[i].witness = bufferReader.readVector(); + } + // was this pointless? + if (!tx.hasWitnesses()) + throw new Error('Transaction has superfluous witness data'); + } + tx.locktime = bufferReader.readUInt32(); + if (_NO_STRICT) return tx; + if (bufferReader.offset !== buffer.length) + throw new Error('Transaction has unexpected data'); + return tx; + } + static fromHex(hex) { + return Transaction.fromBuffer(Buffer.from(hex, 'hex'), false); + } + static isCoinbaseHash(buffer) { + typeforce(types.Hash256bit, buffer); + for (let i = 0; i < 32; ++i) { + if (buffer[i] !== 0) return false; + } + return true; + } + isCoinbase() { + return ( + this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash) + ); + } + addInput(hash, index, sequence, scriptSig) { + typeforce( + types.tuple( + types.Hash256bit, + types.UInt32, + types.maybe(types.UInt32), + types.maybe(types.Buffer), + ), + arguments, + ); + if (types.Null(sequence)) { + sequence = Transaction.DEFAULT_SEQUENCE; + } + // Add the input and return the input's index + return ( + this.ins.push({ + hash, + index, + script: scriptSig || EMPTY_BUFFER, + sequence: sequence, + witness: EMPTY_WITNESS, + }) - 1 + ); + } + addOutput(scriptPubKey, value) { + typeforce(types.tuple(types.Buffer, types.Satoshi), arguments); + // Add the output and return the output's index + return ( + this.outs.push({ + script: scriptPubKey, + value, + }) - 1 + ); + } + hasWitnesses() { + return this.ins.some(x => { + return x.witness.length !== 0; + }); + } + weight() { + const base = this.byteLength(false); + const total = this.byteLength(true); + return base * 3 + total; + } + virtualSize() { + return Math.ceil(this.weight() / 4); + } + byteLength(_ALLOW_WITNESS = true) { + const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses(); + return ( + (hasWitnesses ? 10 : 8) + + bufferutils_1.varuint.encodingLength(this.ins.length) + + bufferutils_1.varuint.encodingLength(this.outs.length) + + this.ins.reduce((sum, input) => { + return sum + 40 + varSliceSize(input.script); + }, 0) + + this.outs.reduce((sum, output) => { + return sum + 8 + varSliceSize(output.script); + }, 0) + + (hasWitnesses + ? this.ins.reduce((sum, input) => { + return sum + vectorSize(input.witness); + }, 0) + : 0) + ); + } + clone() { + const newTx = new Transaction(); + newTx.version = this.version; + newTx.locktime = this.locktime; + newTx.ins = this.ins.map(txIn => { + return { + hash: txIn.hash, + index: txIn.index, + script: txIn.script, + sequence: txIn.sequence, + witness: txIn.witness, + }; + }); + newTx.outs = this.outs.map(txOut => { + return { + script: txOut.script, + value: txOut.value, + }; + }); + return newTx; + } + /** + * Hash transaction for signing a specific input. + * + * Bitcoin uses a different hash for each signed transaction input. + * This method copies the transaction, makes the necessary changes based on the + * hashType, and then hashes the result. + * This hash can then be used to sign the provided transaction input. + */ + hashForSignature(inIndex, prevOutScript, hashType) { + typeforce( + types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number), + arguments, + ); + // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29 + if (inIndex >= this.ins.length) return ONE; + // ignore OP_CODESEPARATOR + const ourScript = bscript.compile( + bscript.decompile(prevOutScript).filter(x => { + return x !== script_1.OPS.OP_CODESEPARATOR; + }), + ); + const txTmp = this.clone(); + // SIGHASH_NONE: ignore all outputs? (wildcard payee) + if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) { + txTmp.outs = []; + // ignore sequence numbers (except at inIndex) + txTmp.ins.forEach((input, i) => { + if (i === inIndex) return; + input.sequence = 0; + }); + // SIGHASH_SINGLE: ignore all outputs, except at the same index? + } else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE) { + // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60 + if (inIndex >= this.outs.length) return ONE; + // truncate outputs after + txTmp.outs.length = inIndex + 1; + // "blank" outputs before + for (let i = 0; i < inIndex; i++) { + txTmp.outs[i] = BLANK_OUTPUT; + } + // ignore sequence numbers (except at inIndex) + txTmp.ins.forEach((input, y) => { + if (y === inIndex) return; + input.sequence = 0; + }); + } + // SIGHASH_ANYONECANPAY: ignore inputs entirely? + if (hashType & Transaction.SIGHASH_ANYONECANPAY) { + txTmp.ins = [txTmp.ins[inIndex]]; + txTmp.ins[0].script = ourScript; + // SIGHASH_ALL: only ignore input scripts + } else { + // "blank" others input scripts + txTmp.ins.forEach(input => { + input.script = EMPTY_BUFFER; + }); + txTmp.ins[inIndex].script = ourScript; + } + // serialize and hash + const buffer = Buffer.allocUnsafe(txTmp.byteLength(false) + 4); + buffer.writeInt32LE(hashType, buffer.length - 4); + txTmp.__toBuffer(buffer, 0, false); + return bcrypto.hash256(buffer); + } + hashForWitnessV1(inIndex, prevOutScripts, values, hashType, leafHash, annex) { + // https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#common-signature-message + typeforce( + types.tuple( + types.UInt32, + typeforce.arrayOf(types.Buffer), + typeforce.arrayOf(types.Satoshi), + types.UInt32, + ), + arguments, + ); + if ( + values.length !== this.ins.length || + prevOutScripts.length !== this.ins.length + ) { + throw new Error('Must supply prevout script and value for all inputs'); + } + const outputType = + hashType === Transaction.SIGHASH_DEFAULT + ? Transaction.SIGHASH_ALL + : hashType & Transaction.SIGHASH_OUTPUT_MASK; + const inputType = hashType & Transaction.SIGHASH_INPUT_MASK; + const isAnyoneCanPay = inputType === Transaction.SIGHASH_ANYONECANPAY; + const isNone = outputType === Transaction.SIGHASH_NONE; + const isSingle = outputType === Transaction.SIGHASH_SINGLE; + let hashPrevouts = EMPTY_BUFFER; + let hashAmounts = EMPTY_BUFFER; + let hashScriptPubKeys = EMPTY_BUFFER; + let hashSequences = EMPTY_BUFFER; + let hashOutputs = EMPTY_BUFFER; + if (!isAnyoneCanPay) { + let bufferWriter = bufferutils_1.BufferWriter.withCapacity( + 36 * this.ins.length, + ); + this.ins.forEach(txIn => { + bufferWriter.writeSlice(txIn.hash); + bufferWriter.writeUInt32(txIn.index); + }); + hashPrevouts = bcrypto.sha256(bufferWriter.end()); + bufferWriter = bufferutils_1.BufferWriter.withCapacity( + 8 * this.ins.length, + ); + values.forEach(value => bufferWriter.writeUInt64(value)); + hashAmounts = bcrypto.sha256(bufferWriter.end()); + bufferWriter = bufferutils_1.BufferWriter.withCapacity( + prevOutScripts.map(varSliceSize).reduce((a, b) => a + b), + ); + prevOutScripts.forEach(prevOutScript => + bufferWriter.writeVarSlice(prevOutScript), + ); + hashScriptPubKeys = bcrypto.sha256(bufferWriter.end()); + bufferWriter = bufferutils_1.BufferWriter.withCapacity( + 4 * this.ins.length, + ); + this.ins.forEach(txIn => bufferWriter.writeUInt32(txIn.sequence)); + hashSequences = bcrypto.sha256(bufferWriter.end()); + } + if (!(isNone || isSingle)) { + const txOutsSize = this.outs + .map(output => 8 + varSliceSize(output.script)) + .reduce((a, b) => a + b); + const bufferWriter = bufferutils_1.BufferWriter.withCapacity(txOutsSize); + this.outs.forEach(out => { + bufferWriter.writeUInt64(out.value); + bufferWriter.writeVarSlice(out.script); + }); + hashOutputs = bcrypto.sha256(bufferWriter.end()); + } else if (isSingle && inIndex < this.outs.length) { + const output = this.outs[inIndex]; + const bufferWriter = bufferutils_1.BufferWriter.withCapacity( + 8 + varSliceSize(output.script), + ); + bufferWriter.writeUInt64(output.value); + bufferWriter.writeVarSlice(output.script); + hashOutputs = bcrypto.sha256(bufferWriter.end()); + } + const spendType = (leafHash ? 2 : 0) + (annex ? 1 : 0); + // Length calculation from: + // https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-14 + // With extension from: + // https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#signature-validation + const sigMsgSize = + 174 - + (isAnyoneCanPay ? 49 : 0) - + (isNone ? 32 : 0) + + (annex ? 32 : 0) + + (leafHash ? 37 : 0); + const sigMsgWriter = bufferutils_1.BufferWriter.withCapacity(sigMsgSize); + sigMsgWriter.writeUInt8(hashType); + // Transaction + sigMsgWriter.writeInt32(this.version); + sigMsgWriter.writeUInt32(this.locktime); + sigMsgWriter.writeSlice(hashPrevouts); + sigMsgWriter.writeSlice(hashAmounts); + sigMsgWriter.writeSlice(hashScriptPubKeys); + sigMsgWriter.writeSlice(hashSequences); + if (!(isNone || isSingle)) { + sigMsgWriter.writeSlice(hashOutputs); + } + // Input + sigMsgWriter.writeUInt8(spendType); + if (isAnyoneCanPay) { + const input = this.ins[inIndex]; + sigMsgWriter.writeSlice(input.hash); + sigMsgWriter.writeUInt32(input.index); + sigMsgWriter.writeUInt64(values[inIndex]); + sigMsgWriter.writeVarSlice(prevOutScripts[inIndex]); + sigMsgWriter.writeUInt32(input.sequence); + } else { + sigMsgWriter.writeUInt32(inIndex); + } + if (annex) { + const bufferWriter = bufferutils_1.BufferWriter.withCapacity( + varSliceSize(annex), + ); + bufferWriter.writeVarSlice(annex); + sigMsgWriter.writeSlice(bcrypto.sha256(bufferWriter.end())); + } + // Output + if (isSingle) { + sigMsgWriter.writeSlice(hashOutputs); + } + // BIP342 extension + if (leafHash) { + sigMsgWriter.writeSlice(leafHash); + sigMsgWriter.writeUInt8(0); + sigMsgWriter.writeUInt32(0xffffffff); + } + // Extra zero byte because: + // https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-19 + return bcrypto.taggedHash( + 'TapSighash', + Buffer.concat([Buffer.from([0x00]), sigMsgWriter.end()]), + ); + } + hashForWitnessV0(inIndex, prevOutScript, value, hashType) { + typeforce( + types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), + arguments, + ); + let tbuffer = Buffer.from([]); + let bufferWriter; + let hashOutputs = ZERO; + let hashPrevouts = ZERO; + let hashSequence = ZERO; + if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) { + tbuffer = Buffer.allocUnsafe(36 * this.ins.length); + bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); + this.ins.forEach(txIn => { + bufferWriter.writeSlice(txIn.hash); + bufferWriter.writeUInt32(txIn.index); + }); + hashPrevouts = bcrypto.hash256(tbuffer); + } + if ( + !(hashType & Transaction.SIGHASH_ANYONECANPAY) && + (hashType & 0x1f) !== Transaction.SIGHASH_SINGLE && + (hashType & 0x1f) !== Transaction.SIGHASH_NONE + ) { + tbuffer = Buffer.allocUnsafe(4 * this.ins.length); + bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); + this.ins.forEach(txIn => { + bufferWriter.writeUInt32(txIn.sequence); + }); + hashSequence = bcrypto.hash256(tbuffer); + } + if ( + (hashType & 0x1f) !== Transaction.SIGHASH_SINGLE && + (hashType & 0x1f) !== Transaction.SIGHASH_NONE + ) { + const txOutsSize = this.outs.reduce((sum, output) => { + return sum + 8 + varSliceSize(output.script); + }, 0); + tbuffer = Buffer.allocUnsafe(txOutsSize); + bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); + this.outs.forEach(out => { + bufferWriter.writeUInt64(out.value); + bufferWriter.writeVarSlice(out.script); + }); + hashOutputs = bcrypto.hash256(tbuffer); + } else if ( + (hashType & 0x1f) === Transaction.SIGHASH_SINGLE && + inIndex < this.outs.length + ) { + const output = this.outs[inIndex]; + tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script)); + bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); + bufferWriter.writeUInt64(output.value); + bufferWriter.writeVarSlice(output.script); + hashOutputs = bcrypto.hash256(tbuffer); + } + tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript)); + bufferWriter = new bufferutils_1.BufferWriter(tbuffer, 0); + const input = this.ins[inIndex]; + bufferWriter.writeInt32(this.version); + bufferWriter.writeSlice(hashPrevouts); + bufferWriter.writeSlice(hashSequence); + bufferWriter.writeSlice(input.hash); + bufferWriter.writeUInt32(input.index); + bufferWriter.writeVarSlice(prevOutScript); + bufferWriter.writeUInt64(value); + bufferWriter.writeUInt32(input.sequence); + bufferWriter.writeSlice(hashOutputs); + bufferWriter.writeUInt32(this.locktime); + bufferWriter.writeUInt32(hashType); + return bcrypto.hash256(tbuffer); + } + getHash(forWitness) { + // wtxid for coinbase is always 32 bytes of 0x00 + if (forWitness && this.isCoinbase()) return Buffer.alloc(32, 0); + return bcrypto.hash256(this.__toBuffer(undefined, undefined, forWitness)); + } + getId() { + // transaction hash's are displayed in reverse order + return (0, bufferutils_1.reverseBuffer)(this.getHash(false)).toString( + 'hex', + ); + } + toBuffer(buffer, initialOffset) { + return this.__toBuffer(buffer, initialOffset, true); + } + toHex() { + return this.toBuffer(undefined, undefined).toString('hex'); + } + setInputScript(index, scriptSig) { + typeforce(types.tuple(types.Number, types.Buffer), arguments); + this.ins[index].script = scriptSig; + } + setWitness(index, witness) { + typeforce(types.tuple(types.Number, [types.Buffer]), arguments); + this.ins[index].witness = witness; + } + __toBuffer(buffer, initialOffset, _ALLOW_WITNESS = false) { + if (!buffer) buffer = Buffer.allocUnsafe(this.byteLength(_ALLOW_WITNESS)); + const bufferWriter = new bufferutils_1.BufferWriter( + buffer, + initialOffset || 0, + ); + bufferWriter.writeInt32(this.version); + const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses(); + if (hasWitnesses) { + bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER); + bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_FLAG); + } + bufferWriter.writeVarInt(this.ins.length); + this.ins.forEach(txIn => { + bufferWriter.writeSlice(txIn.hash); + bufferWriter.writeUInt32(txIn.index); + bufferWriter.writeVarSlice(txIn.script); + bufferWriter.writeUInt32(txIn.sequence); + }); + bufferWriter.writeVarInt(this.outs.length); + this.outs.forEach(txOut => { + if (isOutput(txOut)) { + bufferWriter.writeUInt64(txOut.value); } else { - d = (self[i] >> (p -= 8)) & 0xff - if (p <= 0) { - p += self.DB - --i - } + bufferWriter.writeSlice(txOut.valueBuffer); } - if ((d & 0x80) != 0) d |= -256 - if (k === 0 && (self.s & 0x80) != (d & 0x80))++k - if (k > 0 || d != self.s) r[k++] = d + bufferWriter.writeVarSlice(txOut.script); + }); + if (hasWitnesses) { + this.ins.forEach(input => { + bufferWriter.writeVector(input.witness); + }); } + bufferWriter.writeUInt32(this.locktime); + // avoid slicing unless necessary + if (initialOffset !== undefined) + return buffer.slice(initialOffset, bufferWriter.offset); + return buffer; } - return r -} - -function bnEquals(a) { - return (this.compareTo(a) == 0) -} - -function bnMin(a) { - return (this.compareTo(a) < 0) ? this : a } +exports.Transaction = Transaction; +Transaction.DEFAULT_SEQUENCE = 0xffffffff; +Transaction.SIGHASH_DEFAULT = 0x00; +Transaction.SIGHASH_ALL = 0x01; +Transaction.SIGHASH_NONE = 0x02; +Transaction.SIGHASH_SINGLE = 0x03; +Transaction.SIGHASH_ANYONECANPAY = 0x80; +Transaction.SIGHASH_OUTPUT_MASK = 0x03; +Transaction.SIGHASH_INPUT_MASK = 0x80; +Transaction.ADVANCED_TRANSACTION_MARKER = 0x00; +Transaction.ADVANCED_TRANSACTION_FLAG = 0x01; -function bnMax(a) { - return (this.compareTo(a) > 0) ? this : a +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bufferutils":50,"./crypto":51,"./script":72,"./types":76,"buffer":249}],76:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.oneOf = + exports.Null = + exports.BufferN = + exports.Function = + exports.UInt32 = + exports.UInt8 = + exports.tuple = + exports.maybe = + exports.Hex = + exports.Buffer = + exports.String = + exports.Boolean = + exports.Array = + exports.Number = + exports.Hash256bit = + exports.Hash160bit = + exports.Buffer256bit = + exports.isTaptree = + exports.isTapleaf = + exports.TAPLEAF_VERSION_MASK = + exports.Satoshi = + exports.isPoint = + exports.stacksEqual = + exports.typeforce = + void 0; +const buffer_1 = require('buffer'); +exports.typeforce = require('typeforce'); +const ZERO32 = buffer_1.Buffer.alloc(32, 0); +const EC_P = buffer_1.Buffer.from( + 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', + 'hex', +); +/** + * Checks if two arrays of Buffers are equal. + * @param a - The first array of Buffers. + * @param b - The second array of Buffers. + * @returns True if the arrays are equal, false otherwise. + */ +function stacksEqual(a, b) { + if (a.length !== b.length) return false; + return a.every((x, i) => { + return x.equals(b[i]); + }); } - -// (protected) r = this op a (bitwise) -function bnpBitwiseTo(a, op, r) { - var self = this - var i, f, m = Math.min(a.t, self.t) - for (i = 0; i < m; ++i) r[i] = op(self[i], a[i]) - if (a.t < self.t) { - f = a.s & self.DM - for (i = m; i < self.t; ++i) r[i] = op(self[i], f) - r.t = self.t - } else { - f = self.s & self.DM - for (i = m; i < a.t; ++i) r[i] = op(f, a[i]) - r.t = a.t +exports.stacksEqual = stacksEqual; +/** + * Checks if the given value is a valid elliptic curve point. + * @param p - The value to check. + * @returns True if the value is a valid elliptic curve point, false otherwise. + */ +function isPoint(p) { + if (!buffer_1.Buffer.isBuffer(p)) return false; + if (p.length < 33) return false; + const t = p[0]; + const x = p.slice(1, 33); + if (x.compare(ZERO32) === 0) return false; + if (x.compare(EC_P) >= 0) return false; + if ((t === 0x02 || t === 0x03) && p.length === 33) { + return true; } - r.s = op(self.s, a.s) - r.clamp() + const y = p.slice(33); + if (y.compare(ZERO32) === 0) return false; + if (y.compare(EC_P) >= 0) return false; + if (t === 0x04 && p.length === 65) return true; + return false; } - -// (public) this & a -function op_and(x, y) { - return x & y +exports.isPoint = isPoint; +const SATOSHI_MAX = 21 * 1e14; +function Satoshi(value) { + return exports.typeforce.UInt53(value) && value <= SATOSHI_MAX; } - -function bnAnd(a) { - var r = new BigInteger() - this.bitwiseTo(a, op_and, r) - return r +exports.Satoshi = Satoshi; +exports.TAPLEAF_VERSION_MASK = 0xfe; +function isTapleaf(o) { + if (!o || !('output' in o)) return false; + if (!buffer_1.Buffer.isBuffer(o.output)) return false; + if (o.version !== undefined) + return (o.version & exports.TAPLEAF_VERSION_MASK) === o.version; + return true; } +exports.isTapleaf = isTapleaf; +function isTaptree(scriptTree) { + if (!(0, exports.Array)(scriptTree)) return isTapleaf(scriptTree); + if (scriptTree.length !== 2) return false; + return scriptTree.every(t => isTaptree(t)); +} +exports.isTaptree = isTaptree; +exports.Buffer256bit = exports.typeforce.BufferN(32); +exports.Hash160bit = exports.typeforce.BufferN(20); +exports.Hash256bit = exports.typeforce.BufferN(32); +exports.Number = exports.typeforce.Number; +exports.Array = exports.typeforce.Array; +exports.Boolean = exports.typeforce.Boolean; +exports.String = exports.typeforce.String; +exports.Buffer = exports.typeforce.Buffer; +exports.Hex = exports.typeforce.Hex; +exports.maybe = exports.typeforce.maybe; +exports.tuple = exports.typeforce.tuple; +exports.UInt8 = exports.typeforce.UInt8; +exports.UInt32 = exports.typeforce.UInt32; +exports.Function = exports.typeforce.Function; +exports.BufferN = exports.typeforce.BufferN; +exports.Null = exports.typeforce.Null; +exports.oneOf = exports.typeforce.oneOf; + +},{"buffer":249,"typeforce":521}],77:[function(require,module,exports){ +const basex = require('base-x') +const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' -// (public) this | a -function op_or(x, y) { - return x | y -} +module.exports = basex(ALPHABET) -function bnOr(a) { - var r = new BigInteger() - this.bitwiseTo(a, op_or, r) - return r -} +},{"base-x":12}],78:[function(require,module,exports){ +'use strict' -// (public) this ^ a -function op_xor(x, y) { - return x ^ y -} +var base58 = require('bs58') -function bnXor(a) { - var r = new BigInteger() - this.bitwiseTo(a, op_xor, r) - return r -} +module.exports = function (checksumFn) { + // Encode a buffer as a base58-check encoded string + function encode (payload) { + var payloadU8 = Uint8Array.from(payload) + var checksum = checksumFn(payloadU8) + var length = payloadU8.length + 4 + var both = new Uint8Array(length) + both.set(payloadU8, 0) + both.set(checksum.subarray(0, 4), payloadU8.length) + return base58.encode(both, length) + } -// (public) this & ~a -function op_andnot(x, y) { - return x & ~y -} + function decodeRaw (buffer) { + var payload = buffer.slice(0, -4) + var checksum = buffer.slice(-4) + var newChecksum = checksumFn(payload) -function bnAndNot(a) { - var r = new BigInteger() - this.bitwiseTo(a, op_andnot, r) - return r -} + if (checksum[0] ^ newChecksum[0] | + checksum[1] ^ newChecksum[1] | + checksum[2] ^ newChecksum[2] | + checksum[3] ^ newChecksum[3]) return -// (public) ~this -function bnNot() { - var r = new BigInteger() - for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i] - r.t = this.t - r.s = ~this.s - return r -} + return payload + } -// (public) this << n -function bnShiftLeft(n) { - var r = new BigInteger() - if (n < 0) this.rShiftTo(-n, r) - else this.lShiftTo(n, r) - return r + // Decode a base58-check encoded string to a buffer, no result if checksum is wrong + function decodeUnsafe (string) { + var buffer = base58.decodeUnsafe(string) + if (!buffer) return + + return decodeRaw(buffer) + } + + function decode (string) { + var buffer = base58.decode(string) + var payload = decodeRaw(buffer, checksumFn) + if (!payload) throw new Error('Invalid checksum') + return payload + } + + return { + encode: encode, + decode: decode, + decodeUnsafe: decodeUnsafe + } } -// (public) this >> n -function bnShiftRight(n) { - var r = new BigInteger() - if (n < 0) this.lShiftTo(-n, r) - else this.rShiftTo(n, r) - return r +},{"bs58":77}],79:[function(require,module,exports){ +'use strict' + +var { sha256 } = require('@noble/hashes/sha256') +var bs58checkBase = require('./base') + +// SHA256(SHA256(buffer)) +function sha256x2 (buffer) { + return sha256(sha256(buffer)) } -// return index of lowest 1-bit in x, x < 2^31 -function lbit(x) { - if (x == 0) return -1 - var r = 0 - if ((x & 0xffff) == 0) { - x >>= 16 - r += 16 - } - if ((x & 0xff) == 0) { - x >>= 8 - r += 8 +module.exports = bs58checkBase(sha256x2) + +},{"./base":78,"@noble/hashes/sha256":89}],80:[function(require,module,exports){ +'use strict'; + +var bip68 = require('bip68'); + +// Copyright (c) 2022 Jose-Luis Landabaso - https://bitcoinerlab.com + +const ABSOLUTE = 'ABSOLUTE'; +const RELATIVE = 'RELATIVE'; + +/** + * Calculates the maximum lock time value between two lock time values (a and b) + * using the specified lock type (ABSOLUTE or RELATIVE). + * It asserts that there are no timeLock mixings. + * It asserts that a or b are correctly encoded in bip68 format if they are + * RELATIVE. + * Either both a and b are block based or time based. + * https://medium.com/blockstream/dont-mix-your-timelocks-d9939b665094 + * + * If only a or b is undefined it asserts the value and returns it. + * If none are defined it returns undefined. + * @param {string|number} [a] - The first lock time value to compare. + * @param {string|number} [b] - The second lock time value to compare. + * @param {string} lockType - The type of lock time to use. Can be either "ABSOLUTE" or "RELATIVE". + * @return {number} - The maximum lock time value between a and b. + */ + +function maxLock(a, b, lockType) { + if (typeof a === 'undefined' && typeof b === 'undefined') { + return undefined; + } + if (typeof lockType === 'undefined') + throw new Error('lockType must be specified'); + // Check that lockType is either "ABSOLUTE" or "RELATIVE" + if (lockType !== ABSOLUTE && lockType !== RELATIVE) + throw new Error('lockType must be either "ABSOLUTE" or "RELATIVE"'); + + function isInteger(number) { + const isNumeric = !isNaN(number) && !isNaN(parseFloat(number)); + if (isNumeric && Number.isInteger(Number(number))) return true; + else return false; + } + if (typeof a !== 'undefined') { + if (isInteger(a) === false) + throw new Error('nSequence/nLockTime must be an integer: ' + a); + a = Number(a); + if ( + lockType === RELATIVE && + !bip68.decode(a).hasOwnProperty('seconds') && + !bip68.decode(a).hasOwnProperty('blocks') + ) + throw new Error('Invalid bip68 encoded a value: ' + a); } - if ((x & 0xf) == 0) { - x >>= 4 - r += 4 + if (typeof b !== 'undefined') { + if (isInteger(b) === false) + throw new Error('nSequence/nLockTime must be an integer: ' + b); + b = Number(b); + if ( + lockType === RELATIVE && + !bip68.decode(b).hasOwnProperty('seconds') && + !bip68.decode(b).hasOwnProperty('blocks') + ) + throw new Error('Invalid bip68 encoded b value: ' + b); } - if ((x & 3) == 0) { - x >>= 2 - r += 2 + + if (typeof a !== 'undefined' && typeof b !== 'undefined') { + if (lockType === ABSOLUTE) { + // Both a and b must be either below 500000000 or both above or equal 500000000 + if ( + (a < 500000000 && b >= 500000000) || + (a >= 500000000 && b < 500000000) + ) { + throw new Error( + 'nLockTime values must be either below 500000000 or both above or equal 500000000' + ); + } + } else { + const decodedA = bip68.decode(a); + const decodedB = bip68.decode(b); + + if ( + decodedA.hasOwnProperty('seconds') !== + decodedB.hasOwnProperty('seconds') + ) { + throw new Error( + 'a and b must both be either represent seconds or block height' + ); + } + } + return Math.max(a, b); } - if ((x & 1) == 0)++r - return r -} -// (public) returns index of lowest 1-bit (or -1 if none) -function bnGetLowestSetBit() { - for (var i = 0; i < this.t; ++i) - if (this[i] != 0) return i * this.DB + lbit(this[i]) - if (this.s < 0) return this.t * this.DB - return -1 + if (typeof a !== 'undefined') return a; + if (typeof b !== 'undefined') return b; + return undefined; } -// return number of 1 bits in x -function cbit(x) { - var r = 0 - while (x != 0) { - x &= x - 1 - ++r +// Copyright (c) 2022 Jose-Luis Landabaso - https://bitcoinerlab.com + +/** + * Given a `solutionTemplate`, such as "0 dsat(X) sat(Y) 1 sat(Z)", and given the + * sat/dissatisfactions for X, Y, Z,... (comprised in `satisfactionsMap`) it + * computes all the possible combination of solutions returned in an array + * of {@link Solution}. + * + * Terminology: + * + * A solution of type {@link Solution} is an object + * that contains an unlocking witness for a + * miniscript fragment. + * + * When matching an unlocking witness with a locking + * script, they can produce True or False. These solutions are called sats and + * dsats, respectively. + * + * For example, take this solution: `sol = {asm:"sig key"}`. + * + * When matched with `DUP HASH160 EQUALVERIFY CHECKSIG` it + * produces `True`, that is, a valid sat solution: ` DUP HASH160 EQUALVERIFY CHECKSIG`. + * + * A solution object can also contain other associated pieces of information: `solution: {asm, nLockTime, nSequence}`: + * - nLockTime, nSequence: (number/str) interlock attached to this transaction + * + * A `solutionTemplate` describes a solution using sats and dsats of subexpressions. + * + * F.ex., this is a `solutionTemplate = "0 dsat(X) sat(Y) 1 sat(Z)"`. + * + * satisfactions is an object of type {@link Satisfactions} + * that comprises both sat and dsat solutions for a + * miniscript fragment: + * + * `satisfactions = {sats: [sol_s1, sol_s2, ...], dsats: [sol_d1, ...]}` + * + * satisfactionsMap is a group of satisfactions: + * ```javascript + * satisfactionsMap = { X: satisfactions_X, Y: satisfactions_Y, ...} = + * satisfactionsMap = { + * X: { + * sats: [sol_s1, sol_s2, ...], + * dsats:[...] + * }, + * Y: {sats: [...], dsats: [...]}, + * ...} + * ``` + * + * @param {string} solutionTemplate - a string containing sat or dsat expressions such as: "0 dsat(X) sat(Y) 1 sat(Z)" + * @param {Object} satisfactionsMap - an object mapping the arguments for the sat and dsat expressions + * in `solutionTemplate` (f.ex: `X, Y, Z`) to their {@link Satisfactions}. + * @param {Satisfactions} [satisfactionsMap.X] - The satisfactions for `X` + * @param {Satisfactions} [satisfactionsMap.Y] - The satisfactions for `Y` + * @param {Satisfactions} [satisfactionsMap.Z] - The satisfactions for `Z` + * @param {Satisfactions} [satisfactionsMap....] - The satisfactions for `...` + * + * @returns {Solution[]} an array of solutions, containing the resulting witness, nSequence and nLockTime values, and whether the solution has a HASSIG marker or should be marked as "DONTUSE". + */ + +function combine(solutionTemplate, satisfactionsMap) { + //First, break solutionTemplate into 3 parts: + // pre + curr + post, + //where curr is the first sat(...)/dsat(...) in solutionTemplate. + // + //For example, in "0 dsat(X) sat(Y) 1 sat(Z)": + // pre= "0 "; curr = "dsat(X)"; post: " sat(Y) sat(Z)" + // + //Recursively call combine(post) until there are no further + //sat()/dsat() in *post* + + //regExp that matches the first dsat(...) or sat(...): + const reCurr = /d?sat\(([^\(]*)\)/; + const currMatch = solutionTemplate.match(reCurr); + + if (currMatch && currMatch.length) { + //The array of solutions to be computed and returned. + const solutions = []; + + //curr is the first d?sat() matched in solutionTemplate: + const curr = currMatch[0]; + //pre is whatever was before the first d?sat(): + const pre = solutionTemplate.split(curr)[0]; + //post is whatever was after the first d?sat(): + const post = solutionTemplate.slice(curr.length + pre.length); + + //the argument for curr: d?sat( -> argument <- ): + //This will match the string "X" in the example above: + //currArg = "X" for solutionTemplate "0 dsat(X) sat(Y) 1 sat(Z)" + const currArg = currMatch[1]; + //currKey = "sats" or "dsats". "dsats" for the example above. + const currKey = curr[0] === 'd' ? 'dsats' : 'sats'; + + if (typeof satisfactionsMap[currArg] !== 'object') + throw new Error( + `satisfactionsMap does not provide sats/dsats solutions for argument ${currArg}, evaluating: ${solutionTemplate}` + ); + const currSolutions = satisfactionsMap[currArg][currKey] || []; + for (const currSolution of currSolutions) { + //Does *post* contain further sat() or dsat() expressions? + if (post.match(reCurr)) { + //There are more sat/dsat, do a recursive call: + const postSolutions = combine(post, satisfactionsMap); + for (const postSolution of postSolutions) { + //if ((currSolution.nLockTime && postSolution.nLockTime)) return []; + solutions.push({ + nSequence: maxLock( + currSolution.nSequence, + postSolution.nSequence, + RELATIVE + ), + nLockTime: maxLock( + currSolution.nLockTime, + postSolution.nLockTime, + ABSOLUTE + ), + asm: `${pre}${currSolution.asm}${postSolution.asm}` + }); + } + } else { + //This was the last instance of combine where there are no *post* + //sat/dsats + solutions.push({ + ...currSolution, + asm: `${pre}${currSolution.asm}${post}` + }); + } + } + //markDontUseSolutions(solutions); + + return solutions; } - return r + throw new Error('Invalid solutionTemplate: ' + solutionTemplate); } -// (public) return number of set bits -function bnBitCount() { - var r = 0, - x = this.s & this.DM - for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x) - return r -} +/** + * An object containing functions for generating Basic satisfaction and dissatisfaction sets for miniscripts. + * + * @see {@link https://bitcoin.sipa.be/miniscript/} + * @typedef {Object} SatisfactionsMaker + * + */ +const satisfactionsMaker = { + 0: () => ({ + dsats: [{ asm: `` }] + }), + 1: () => ({ + sats: [{ asm: `` }] + }), + pk_k: key => ({ + dsats: [{ asm: `0` }], + sats: [{ asm: `` }] + }), + pk_h: key => ({ + dsats: [{ asm: `0 <${key}>` }], + sats: [{ asm: ` <${key}>` }] + }), + older: n => ({ + sats: [{ asm: ``, nSequence: n }] + }), + after: n => ({ + sats: [{ asm: ``, nLockTime: n }] + }), + sha256: h => ({ + sats: [{ asm: `` }], + dsats: [{ asm: `` }] + }), + ripemd160: h => ({ + sats: [{ asm: `` }], + dsats: [{ asm: `` }] + }), + hash256: h => ({ + sats: [{ asm: `` }], + dsats: [{ asm: `` }] + }), + hash160: h => ({ + sats: [{ asm: `` }], + dsats: [{ asm: `` }] + }), + andor: (X, Y, Z) => ({ + dsats: [ + ...combine(`dsat(Z) dsat(X)`, { X, Y, Z }), + ...combine(`dsat(Y) sat(X)`, { X, Y, Z }) + ], + sats: [ + ...combine('sat(Y) sat(X)', { X, Y, Z }), + ...combine('sat(Z) dsat(X)', { X, Y, Z }) + ] + }), + and_v: (X, Y) => ({ + dsats: [...combine(`dsat(Y) sat(X)`, { X, Y })], + sats: [...combine(`sat(Y) sat(X)`, { X, Y })] + }), + and_b: (X, Y) => ({ + dsats: [ + ...combine(`dsat(Y) dsat(X)`, { X, Y }), + //https://bitcoin.sipa.be/miniscript/ + //The non-canonical options for and_b, or_b, and thresh are always + //overcomplete (reason 3), so instead use DONTUSE there + ...combine(`sat(Y) dsat(X)`, { X, Y }), + ...combine(`dsat(Y) sat(X)`, { X, Y }) + ], + sats: [...combine(`sat(Y) sat(X)`, { Y, X })] + }), + or_b: (X, Z) => ({ + dsats: [...combine(`dsat(Z) dsat(X)`, { X, Z })], + sats: [ + ...combine(`dsat(Z) sat(X)`, { X, Z }), + ...combine(`sat(Z) dsat(X)`, { X, Z }), + //https://bitcoin.sipa.be/miniscript/ + //The non-canonical options for and_b, or_b, and thresh are always + //overcomplete (reason 3), so instead use DONTUSE there + ...combine(`sat(Z) sat(X)`, { X, Z }) + ] + }), + or_c: (X, Z) => ({ + sats: [ + ...combine(`sat(X)`, { X, Z }), + ...combine(`sat(Z) dsat(X)`, { X, Z }) + ] + }), + or_d: (X, Z) => ({ + dsats: [...combine(`dsat(Z) dsat(X)`, { X, Z })], + sats: [ + ...combine(`sat(X)`, { X, Z }), + ...combine(`sat(Z) dsat(X)`, { X, Z }) + ] + }), + or_i: (X, Z) => ({ + dsats: [ + ...combine(`dsat(X) 1`, { X, Z }), + ...combine(`dsat(Z) 0`, { X, Z }) + ], + sats: [...combine(`sat(X) 1`, { X, Z }), ...combine(`sat(Z) 0`, { X, Z })] + }), + /* + * This is not entirely trivial from the docs + * (https://bitcoin.sipa.be/miniscript/), + * but solution templates for thresh must be written in reverse order. + * For example the first dsat, which is "All dsats", corresponds to: + * " ... " (note the reverse order in N) + * While this is not entirely trivial by reading the document + * it can be deduced by analyzing the script: + * thresh(k,X1,...,Xn) [X1] [X2] ADD ... [Xn] ADD ... EQUAL + */ + thresh: (k, ...satisfactionsArray) => { + if (Number.isInteger(Number(k)) && Number(k) > 0) k = Number(k); + else throw new Error(`k must be positive number: ${k}`); + + //First, convert input satisfactions (which are dynamic for thresh + //and multi) into an object. + //For example, if input was, thresh(k, X, Y, Z), then + //create an object like this: satisfactionsMap = {X, Y, Z}; + const satisfactionsMap = {}; + const N = satisfactionsArray.length; + satisfactionsArray.map((satisfactions, index) => { + satisfactionsMap[index] = satisfactions; + }); -// (public) true iff nth bit is set -function bnTestBit(n) { - var j = Math.floor(n / this.DB) - if (j >= this.t) return (this.s != 0) - return ((this[j] & (1 << (n % this.DB))) != 0) -} + const dsats = []; + const sats = []; + //Push the canonical dsat (All dsats): + //" ... " (note the reverse order) + dsats.push( + ...combine( + Object.keys(satisfactionsMap) + .map(mapKeyName => `dsat(${mapKeyName})`) + .reverse() + .join(' '), + satisfactionsMap + ) + ); -// (protected) this op (1< { + if (Number.isInteger(Number(k)) && Number(k) > 0) k = Number(k); + else throw new Error(`k must be positive number: ${k}`); + + //Example of a multi-sig locking script: + //OP_3 OP_4 OP_CHECKMULTISIG + //unlockingScript: OP_0 + //OP_0 is a dummy OP, needed because of a bug in Bitcoin + if (typeof k !== 'number') throw new Error('k must be a number:' + k); + if (k === 0) throw new Error('k cannot be 0'); + const dsats = [{ asm: '0 '.repeat(k + 1).trim() }]; + + // Create all combinations of k signatures + function keyCombinations(keys, k) { + if (k === 0) { + return [[]]; + } -// (protected) r = this + a -function bnpAddTo(a, r) { - var self = this + const combinations = []; - var i = 0, - c = 0, - m = Math.min(a.t, self.t) - while (i < m) { - c += self[i] + a[i] - r[i++] = c & self.DM - c >>= self.DB - } - if (a.t < self.t) { - c += a.s - while (i < self.t) { - c += self[i] - r[i++] = c & self.DM - c >>= self.DB + for (let i = 0; i < keys.length; i++) { + const remainingKeys = keys.slice(i + 1); + const subCombinations = keyCombinations(remainingKeys, k - 1); + subCombinations.forEach(combination => { + combinations.push([keys[i], ...combination]); + }); + } + + return combinations; } - c += self.s - } else { - c += self.s - while (i < a.t) { - c += a[i] - r[i++] = c & self.DM - c >>= self.DB + + const asms = []; + // Create asms from keyCombination + keyCombinations(keys, k).forEach(combination => { + let asm = '0'; + combination.forEach(key => { + asm += ` `; + }); + asms.push(asm); + }); + + let asm = '0'; + for (let i = 0; i < k; i++) { + asm += ` `; } - c += a.s - } - r.s = (c < 0) ? -1 : 0 - if (c > 0) r[i++] = c - else if (c < -1) r[i++] = self.DV + c - r.t = i - r.clamp() -} + const sats = asms.map(asm => ({ asm })); -// (public) this + a -function bnAdd(a) { - var r = new BigInteger() - this.addTo(a, r) - return r -} + return { sats, dsats }; + }, + a: X => ({ + dsats: [...combine(`dsat(X)`, { X })], + sats: [...combine(`sat(X)`, { X })] + }), + s: X => ({ + dsats: [...combine(`dsat(X)`, { X })], + sats: [...combine(`sat(X)`, { X })] + }), + c: X => ({ + dsats: [...combine(`dsat(X)`, { X })], + sats: [...combine(`sat(X)`, { X })] + }), + d: X => ({ + dsats: [{ asm: `0` }], + sats: [...combine(`sat(X) 1`, { X })] + }), + v: X => ({ + sats: [...combine(`sat(X)`, { X })] + }), -// (public) this - a -function bnSubtract(a) { - var r = new BigInteger() - this.subTo(a, r) - return r -} + /** + * j:X corresponds to SIZE 0NOTEQUAL IF [X] ENDIF + * + * By definition, this: "dsat(X) X" produces a zero. + * + * + * A dsat needs to make this "dsat(X) X" return zero. + + * The easiest dsat for j:X is using 0: + * 0 SIZE 0NOTEQUAL IF [X] ENDIF + * 0 0 0NOTEQUAL IF [X] ENDIF + * 0 0 IF [X] ENDIF + * 0 + + * Now let's do the case where dsat(X) finishes with a 0: "... 0" + * ... 0 SIZE 0NOTEQUAL IF [X] ENDIF + * ... 0 0 0NOTEQUAL IF [X] ENDIF + * ... 0 0 IF [X] ENDIF + * ... 0 + * DSAT(X) + * The final expression is "DSAT(X)". + * It should have either been "0" or "DSAT(X) X" + * Thus, this is not a valid dsat. + + * Now let's do the case where dsat(X) is this: "... " + * ... SIZE 0NOTEQUAL IF [X] ENDIF + * ... 0NOTEQUAL IF [X] ENDIF + * ... 1 IF [X] ENDIF + * ... [X] + * DSAT(X) [X] + + * DSAT(X) X is a good dsat + */ + j: X => { + const dsats = []; -// (public) this * a -function bnMultiply(a) { - var r = new BigInteger() - this.multiplyTo(a, r) - return r -} + dsats.push({ asm: `0` }); -// (public) this^2 -function bnSquare() { - var r = new BigInteger() - this.squareTo(r) - return r -} + //Filter the dsats of X with Non Zero Top Stack (nztp). + const dsats_nzts = X.dsats.filter( + //The top stack corresponds to the last element pushed to the stack, + //that is, the last element in the produced witness + solution => solution.asm.trim().split(' ').pop() !== '0' + ); + dsats.push(...dsats_nzts); -// (public) this / a -function bnDivide(a) { - var r = new BigInteger() - this.divRemTo(a, r, null) - return r -} + return { dsats, sats: [...combine(`sat(X)`, { X })] }; + }, + n: X => ({ + dsats: [...combine(`dsat(X)`, { X })], + sats: [...combine(`sat(X)`, { X })] + }) +}; -// (public) this % a -function bnRemainder(a) { - var r = new BigInteger() - this.divRemTo(a, null, r) - return r +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; } -// (public) [this/a,this%a] -function bnDivideAndRemainder(a) { - var q = new BigInteger(), - r = new BigInteger() - this.divRemTo(a, q, r) - return new Array(q, r) -} +var bindings = createCommonjsModule(function (module, exports) { +var Module = (() => { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + + return ( +function(moduleArg = {}) { -// (protected) this *= n, this >= 0, 1 < n < DV -function bnpDMultiply(n) { - this[this.t] = this.am(0, n - 1, this, 0, 0, this.t) - ++this.t - this.clamp() -} +var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject;});var moduleOverrides=Object.assign({},Module);var thisProgram="./this.program";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}{if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src;}if(_scriptDir){scriptDirectory=_scriptDir;}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1);}else {scriptDirectory="";}}Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];Module["noExitRuntime"]||true;var WebAssembly={Memory:function(opts){this.buffer=new ArrayBuffer(opts["initial"]*65536);},Module:function(binary){},Instance:function(module,info){this.exports=( +// EMSCRIPTEN_START_ASM +function instantiate(_a){function c(d){d.set=function(a,b){this[a]=b;};d.get=function(a){return this[a]};return d}var e;var f=new Uint8Array(123);for(var a=25;a>=0;--a){f[48+a]=52+a;f[65+a]=a;f[97+a]=26+a;}f[43]=62;f[47]=63;function l(m,n,o){var g,h,a=0,i=n,j=o.length,k=n+(j*3>>2)-(o[j-2]=="=")-(o[j-1]=="=");for(;a>4;if(i>2;if(i>2]=0;J[e+320>>2]=0;J[e+324>>2]=0;J[5996]=0;J[e+316>>2]=0;J[e+308>>2]=0;J[e+312>>2]=0;f=$(3,24)|0;d=J[5996];J[5996]=0;a:{b:{c:{if((d|0)!=1){J[f+8>>2]=-1;J[f+12>>2]=-1;J[f>>2]=0;J[f+16>>2]=-1;J[f+20>>2]=-1;c=f+24|0;J[e+328>>2]=c;J[e+320>>2]=f;m=e+296|0;d:{e:{f:{g:{h:{i:{j:{k:{l:{while(1){d=c-24|0;g=J[d+20>>2];J[m>>2]=J[d+16>>2];J[m+4>>2]=g;g=J[d+12>>2];J[e+288>>2]=J[d+8>>2];J[e+292>>2]=g;h=J[d+4>>2];g=J[d>>2];J[e+280>>2]=g;J[e+284>>2]=h;J[e+324>>2]=d;l=18;m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{switch(g|0){case 0:c=J[b+4>>2];A:{if((c|0)<2){f=-1;break A}g=J[b>>2];f=1;while(1){h=K[f+g|0];if((h|0)==58){l=0;B:{C:{D:{E:{while(1){F:{G:{switch(K[J[b>>2]+l|0]-97|0){case 0:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=3;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}H:{I:{J:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;K:{if(c>>>0>=178956971){J[5996]=0;ca(142);a=J[5996];J[5996]=0;if((a|0)==1){break K}break a}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break I}if(h>>>0<178956971){break J}J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break H}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=3;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 18:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=2;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}L:{M:{N:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;O:{if(c>>>0>=178956971){J[5996]=0;ca(142);break O}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break M}if(h>>>0<178956971){break N}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break L}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=2;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 2:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=4;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}P:{Q:{R:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;S:{if(c>>>0>=178956971){J[5996]=0;ca(142);break S}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break Q}if(h>>>0<178956971){break R}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break P}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=4;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 3:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=5;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}T:{U:{V:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;W:{if(c>>>0>=178956971){J[5996]=0;ca(142);break W}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break U}if(h>>>0<178956971){break V}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break T}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=5;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 9:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=7;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}X:{Y:{Z:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;_:{if(c>>>0>=178956971){J[5996]=0;ca(142);break _}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break Y}if(h>>>0<178956971){break Z}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break X}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=7;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 13:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=8;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}$:{aa:{ba:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;ca:{if(c>>>0>=178956971){J[5996]=0;ca(142);break ca}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break aa}if(h>>>0<178956971){break ba}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break $}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=8;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 21:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=6;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}da:{ea:{fa:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;ga:{if(c>>>0>=178956971){J[5996]=0;ca(142);break ga}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break ea}if(h>>>0<178956971){break fa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break da}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=6;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 20:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=9;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}ha:{ia:{ja:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;ka:{if(c>>>0>=178956971){J[5996]=0;ca(142);break ka}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break ia}if(h>>>0<178956971){break ja}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break ha}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=9;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 19:d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=10;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}la:{ma:{na:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;oa:{if(c>>>0>=178956971){J[5996]=0;ca(142);break oa}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break ma}if(h>>>0<178956971){break na}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break la}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=10;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);break F}b=Z()|0;break b;case 11:break G;default:break B}}J[5996]=0;d=$(3,104)|0;c=J[5996];J[5996]=0;if((c|0)==1){break E}J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;g=ba(143,d+12|0,0,0)|0;c=J[5996];J[5996]=0;if((c|0)==1){b=Z()|0;$a(d);break b}J[e+244>>2]=d;J[e+240>>2]=g;c=J[e+312>>2];pa:{if(c>>>0>2]){J[c+4>>2]=d;J[c>>2]=g;J[e+312>>2]=c+8;break pa}J[5996]=0;aa(144,e+308|0,e+240|0);d=J[5996];J[5996]=0;if((d|0)==1){break D}d=J[e+244>>2];if(!d){break pa}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break pa}Xa[J[J[d>>2]+8>>2]](d);bb(d);}d=J[e+324>>2];h=J[e+328>>2];if(d>>>0>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=18;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break F}qa:{ra:{g=J[e+320>>2];j=(d-g|0)/24|0;c=j+1|0;sa:{if(c>>>0>=178956971){J[5996]=0;ca(142);break sa}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break qa}if(h>>>0<178956971){break ra}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break C}}c=P(j,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=18;J[c+16>>2]=-1;J[c+20>>2]=-1;j=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;k=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=k;k=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=k;k=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=k;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=j;J[e+320>>2]=c;if(!d){break F}$a(d);}l=l+1|0;if((l|0)!=(f|0)){continue}break}d=J[e+324>>2];break A}b=Z()|0;break b}b=Z()|0;mb(e+240|0);break b}b=Z()|0;break b}J[a>>2]=0;J[a+4>>2]=0;break l}if((h-97&255)>>>0>25){f=-1;break A}f=f+1|0;if((c|0)>(f|0)){continue}break}f=-1;}ta:{h=J[e+328>>2];ua:{if(h>>>0>d>>>0){J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=1;J[d+16>>2]=-1;J[d+20>>2]=-1;J[e+324>>2]=d+24;break ua}va:{wa:{g=J[e+320>>2];l=(d-g|0)/24|0;c=l+1|0;xa:{if(c>>>0>=178956971){J[5996]=0;ca(142);break xa}h=(h-g|0)/24|0;i=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?i:c;if(!h){i=0;break va}if(h>>>0<178956971){break wa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(h,24)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break ta}}c=P(l,24)+i|0;J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=1;J[c+16>>2]=-1;J[c+20>>2]=-1;l=c+24|0;if((d|0)!=(g|0)){while(1){d=d-24|0;j=J[d+4>>2];c=c-24|0;J[c>>2]=J[d>>2];J[c+4>>2]=j;j=J[d+20>>2];J[c+16>>2]=J[d+16>>2];J[c+20>>2]=j;j=J[d+12>>2];J[c+8>>2]=J[d+8>>2];J[c+12>>2]=j;if((d|0)!=(g|0)){continue}break}d=g;}J[e+328>>2]=P(h,24)+i;J[e+324>>2]=l;J[e+320>>2]=c;if(!d){break ua}$a(d);}d=f+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break b;case 21:ya:{d=J[b+4>>2];if(d){c=J[b>>2];if(K[c|0]==41){break ya}}J[a>>2]=0;J[a+4>>2]=0;break l}J[b+4>>2]=d-1;J[b>>2]=c+1;break m;case 20:za:{d=J[b+4>>2];if(d){c=J[b>>2];if(K[c|0]==44){break za}}J[a>>2]=0;J[a+4>>2]=0;break l}J[b+4>>2]=d-1;J[b>>2]=c+1;break m;case 19:g=J[b+4>>2];if(!g){J[a>>2]=0;J[a+4>>2]=0;break l}Aa:{Ba:{Ca:{Da:{Ea:{Fa:{h=J[b>>2];switch(K[h|0]-41|0){case 0:break Ea;case 3:break Fa;default:break Da}}J[b+4>>2]=g-1;J[b>>2]=h+1;g=J[e+292>>2];h=J[e+288>>2]+1|0;g=h?g:g+1|0;Ga:{Ha:{i=J[e+328>>2];Ia:{if(i>>>0>d>>>0){J[d>>2]=19;J[d+8>>2]=h;J[d+12>>2]=g;f=J[e+300>>2];J[d+16>>2]=J[e+296>>2];J[d+20>>2]=f;J[e+324>>2]=c;break Ia}Ja:{Ka:{l=(d-f|0)/24|0;c=l+1|0;La:{if(c>>>0>=178956971){J[5996]=0;ca(142);break La}i=(i-f|0)/24|0;j=i<<1;c=i>>>0>=89478485?178956970:c>>>0>>0?j:c;if(!c){i=0;break Ja}if(c>>>0<178956971){break Ka}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(c,24)|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break Ha}}l=P(l,24)+i|0;J[l+8>>2]=h;J[l+12>>2]=g;J[l>>2]=19;g=J[e+300>>2];J[l+16>>2]=J[e+296>>2];J[l+20>>2]=g;i=P(c,24)+i|0;c=l+24|0;Ma:{if((d|0)==(f|0)){J[e+328>>2]=i;J[e+324>>2]=c;J[e+320>>2]=l;break Ma}while(1){d=d-24|0;h=J[d+4>>2];l=l-24|0;g=l;J[g>>2]=J[d>>2];J[g+4>>2]=h;g=J[d+20>>2];J[l+16>>2]=J[d+16>>2];J[l+20>>2]=g;g=J[d+12>>2];J[l+8>>2]=J[d+8>>2];J[l+12>>2]=g;if((d|0)!=(f|0)){continue}break}J[e+328>>2]=i;J[e+324>>2]=c;J[e+320>>2]=l;if(!f){break Ia}}$a(f);i=J[e+328>>2];c=J[e+324>>2];}if(c>>>0>>0){J[c+8>>2]=-1;J[c+12>>2]=-1;J[c>>2]=0;J[c+16>>2]=-1;J[c+20>>2]=-1;J[e+324>>2]=c+24;break m}Na:{Oa:{f=J[e+320>>2];h=(c-f|0)/24|0;d=h+1|0;Pa:{if(d>>>0>=178956971){J[5996]=0;ca(142);break Pa}g=(i-f|0)/24|0;i=g<<1;g=g>>>0>=89478485?178956970:d>>>0>>0?i:d;if(!g){i=0;break Na}if(g>>>0<178956971){break Oa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[5996]=0;i=$(3,P(g,24)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ga}}d=P(h,24)+i|0;J[d+8>>2]=-1;J[d+12>>2]=-1;J[d>>2]=0;J[d+16>>2]=-1;J[d+20>>2]=-1;h=d+24|0;if((c|0)!=(f|0)){while(1){c=c-24|0;l=J[c+4>>2];d=d-24|0;J[d>>2]=J[c>>2];J[d+4>>2]=l;l=J[c+20>>2];J[d+16>>2]=J[c+16>>2];J[d+20>>2]=l;l=J[c+12>>2];J[d+8>>2]=J[c+8>>2];J[d+12>>2]=l;if((c|0)!=(f|0)){continue}break}c=f;}J[e+328>>2]=P(g,24)+i;J[e+324>>2]=h;J[e+320>>2]=d;if(!c){break m}$a(c);break m}b=Z()|0;break b}b=Z()|0;break b}d=J[e+288>>2];c=J[e+292>>2];f=J[e+300>>2];if(d>>>0>2]&(c|0)<=(f|0)|(c|0)<(f|0)){J[a>>2]=0;J[a+4>>2]=0;break l}J[b+4>>2]=g-1;J[b>>2]=h+1;J[e+340>>2]=0;J[e+332>>2]=0;J[e+336>>2]=0;if(!d&(c|0)<=0|(c|0)<0){break Ba}f=0;c=0;d=J[e+312>>2];while(1){Qa:{g=d-8|0;h=J[e+336>>2];Ra:{if(h>>>0>2]){J[h>>2]=J[g>>2];i=d-4|0;J[h+4>>2]=J[i>>2];J[g>>2]=0;J[i>>2]=0;J[e+336>>2]=h+8;break Ra}J[5996]=0;aa(144,e+332|0,g|0);d=J[5996];J[5996]=0;if((d|0)==1){break Qa}d=J[e+312>>2];g=J[d-4>>2];if(!g){break Ra}h=J[g+4>>2];J[g+4>>2]=h-1;if(h){break Ra}Xa[J[J[g>>2]+8>>2]](g);bb(g);}d=d-8|0;J[e+312>>2]=d;f=f+1|0;c=f?c:c+1|0;g=J[e+292>>2];if(M[e+288>>2]>f>>>0&(g|0)>=(c|0)|(c|0)<(g|0)){continue}break Ca}break}b=Z()|0;break Aa}J[a>>2]=0;J[a+4>>2]=0;break l}d=J[e+332>>2];f=J[e+336>>2];if((d|0)==(f|0)){break Ba}c=f-8|0;if(c>>>0<=d>>>0){break Ba}while(1){g=J[d>>2];J[d>>2]=J[c>>2];J[c>>2]=g;g=J[d+4>>2];f=f-4|0;J[d+4>>2]=J[f>>2];J[f>>2]=g;f=c;d=d+8|0;c=c-8|0;if(d>>>0>>0){continue}break}}J[5996]=0;f=$(3,104)|0;d=J[5996];J[5996]=0;Sa:{Ta:{if((d|0)!=1){J[f>>2]=7e3;J[f+4>>2]=0;J[f+8>>2]=0;J[5996]=0;J[e+240>>2]=J[e+332>>2];d=J[e+336>>2];c=J[e+340>>2];J[e+340>>2]=0;J[e+244>>2]=d;J[e+248>>2]=c;J[e+332>>2]=0;J[e+336>>2]=0;h=ia(64,f+12|0,24,e+240|0,J[e+296>>2])|0;d=J[5996];J[5996]=0;if((d|0)==1){break Sa}c=J[e+240>>2];if(c){d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;g=J[d+4>>2];Ua:{if(!g){break Ua}i=J[g+4>>2];J[g+4>>2]=i-1;if(i){break Ua}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);}J[e+348>>2]=f;J[e+344>>2]=h;d=J[e+312>>2];Va:{if(d>>>0>2]){J[d+4>>2]=f;J[d>>2]=h;J[e+312>>2]=d+8;break Va}J[5996]=0;aa(144,e+308|0,e+344|0);d=J[5996];J[5996]=0;if((d|0)==1){break Ta}d=J[e+348>>2];if(!d){break Va}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break Va}Xa[J[J[d>>2]+8>>2]](d);bb(d);}c=J[e+332>>2];if(!c){break m}d=J[e+336>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Wa:{if(!f){break Wa}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Wa}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+332>>2];}$a(c);break m}b=Z()|0;break Aa}b=Z()|0;mb(e+344|0);break Aa}b=Z()|0;lb(e+240|0);$a(f);}lb(e+332|0);break b;case 14:c=J[e+312>>2];d=c-8|0;J[e+332>>2]=J[d>>2];J[e+336>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;d=c-16|0;J[e+344>>2]=J[d>>2];J[e+348>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[e+312>>2]=d;J[5996]=0;f=e+240|0;ga(145,f|0,c-24|0,e+344|0,e+332|0);d=J[5996];J[5996]=0;Xa:{Ya:{Za:{if((d|0)!=1){J[5996]=0;d=$(3,104)|0;c=J[5996];J[5996]=0;if((c|0)==1){break Za}J[5996]=0;c=ba(146,d|0,23,f|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){b=Z()|0;$a(d);break Ya}f=J[e+312>>2]-8|0;J[f>>2]=c+12;d=J[f+4>>2];J[f+4>>2]=c;_a:{if(!d){break _a}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break _a}Xa[J[J[d>>2]+8>>2]](d);bb(d);}f=J[e+240>>2];if(f){d=J[e+244>>2];c=f;if((d|0)!=(c|0)){while(1){d=d-8|0;c=J[d+4>>2];$a:{if(!c){break $a}g=J[c+4>>2];J[c+4>>2]=g-1;if(g){break $a}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(f|0)){continue}break}c=J[e+240>>2];}J[e+244>>2]=f;$a(c);}d=J[e+348>>2];ab:{if(!d){break ab}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break ab}Xa[J[J[d>>2]+8>>2]](d);bb(d);}d=J[e+336>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break Xa}b=Z()|0;}lb(e+240|0);}mb(e+344|0);mb(e+332|0);break b;case 18:l=22;break y;case 17:l=21;break y;case 16:l=20;break y;case 15:l=19;break y;case 1:break n;case 3:break o;case 2:break p;case 4:break q;case 5:break r;case 7:break s;case 8:break t;case 6:break u;case 9:break v;case 10:break w;case 11:break x;case 13:break y;case 12:break z;default:break m}}l=17;}f=J[e+312>>2];c=f-8|0;J[e+344>>2]=J[c>>2];J[e+348>>2]=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;J[e+312>>2]=c;J[5996]=0;J[e+340>>2]=0;J[e+332>>2]=0;J[e+336>>2]=0;d=$(3,16)|0;g=J[5996];J[5996]=0;bb:{if((g|0)==1){b=Z()|0;break bb}J[e+332>>2]=d;g=d+16|0;J[e+340>>2]=g;f=f-16|0;J[d>>2]=J[f>>2];J[d+4>>2]=J[f+4>>2];J[f>>2]=0;J[f+4>>2]=0;J[d+8>>2]=J[e+344>>2];J[d+12>>2]=J[e+348>>2];J[e+336>>2]=g;J[e+344>>2]=0;J[e+348>>2]=0;J[5996]=0;f=$(3,104)|0;h=J[5996];J[5996]=0;if((h|0)!=1){J[f>>2]=7e3;J[f+4>>2]=0;J[f+8>>2]=0;J[e+244>>2]=g;J[e+240>>2]=d;J[e+332>>2]=0;J[e+336>>2]=0;J[5996]=0;d=J[e+340>>2];J[e+340>>2]=0;J[e+248>>2]=d;g=ia(64,f+12|0,l|0,e+240|0,0)|0;d=J[5996];J[5996]=0;if((d|0)!=1){l=J[e+240>>2];if(l){d=J[e+244>>2];if((l|0)!=(d|0)){while(1){d=d-8|0;c=J[d+4>>2];cb:{if(!c){break cb}h=J[c+4>>2];J[c+4>>2]=h-1;if(h){break cb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(l|0)){continue}break}l=J[e+240>>2];c=J[e+312>>2];}$a(l);}c=c-8|0;J[c>>2]=g;d=J[c+4>>2];J[c+4>>2]=f;db:{if(!d){break db}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break db}Xa[J[J[d>>2]+8>>2]](d);bb(d);}c=J[e+332>>2];if(c){d=J[e+336>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];eb:{if(!f){break eb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break eb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+332>>2];}$a(c);}d=J[e+348>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;lb(e+240|0);$a(f);break bb}b=Z()|0;}lb(e+332|0);mb(e+344|0);break b}c=J[e+312>>2];d=c-8|0;J[e+332>>2]=J[d>>2];J[e+336>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[e+312>>2]=d;J[5996]=0;d=$(3,104)|0;f=J[5996];J[5996]=0;fb:{gb:{hb:{ib:{jb:{if((f|0)!=1){J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=ba(143,d+12|0,0,0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(d);break fb}J[e+348>>2]=d;J[e+344>>2]=f;J[5996]=0;f=e+240|0;ga(145,f|0,c-16|0,e+332|0,e+344|0);d=J[5996];J[5996]=0;if((d|0)==1){break jb}J[5996]=0;d=$(3,104)|0;c=J[5996];J[5996]=0;if((c|0)==1){break ib}J[5996]=0;c=ba(146,d|0,23,f|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){b=Z()|0;$a(d);break hb}f=J[e+312>>2]-8|0;J[f>>2]=c+12;d=J[f+4>>2];J[f+4>>2]=c;kb:{if(!d){break kb}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break kb}Xa[J[J[d>>2]+8>>2]](d);bb(d);}f=J[e+240>>2];if(f){d=J[e+244>>2];c=f;if((d|0)!=(c|0)){while(1){d=d-8|0;c=J[d+4>>2];lb:{if(!c){break lb}g=J[c+4>>2];J[c+4>>2]=g-1;if(g){break lb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(f|0)){continue}break}c=J[e+240>>2];}J[e+244>>2]=f;$a(c);}d=J[e+348>>2];mb:{if(!d){break mb}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break mb}Xa[J[J[d>>2]+8>>2]](d);bb(d);}d=J[e+336>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break fb}b=Z()|0;break gb}b=Z()|0;}lb(e+240|0);}mb(e+344|0);}mb(e+332|0);break b}J[5996]=0;c=J[e+312>>2];d=$(3,104)|0;f=J[5996];J[5996]=0;nb:{ob:{if((f|0)!=1){J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=ba(143,d+12|0,1,0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(d);break b}J[e+336>>2]=d;J[e+332>>2]=f;J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=$(3,16)|0;f=J[5996];J[5996]=0;if((f|0)==1){b=Z()|0;break nb}J[e+240>>2]=d;g=d+16|0;J[e+248>>2]=g;f=c-8|0;J[d>>2]=J[f>>2];c=c-4|0;J[d+4>>2]=J[c>>2];J[f>>2]=0;J[c>>2]=0;J[d+8>>2]=J[e+332>>2];J[d+12>>2]=J[e+336>>2];J[e+244>>2]=g;J[e+332>>2]=0;J[e+336>>2]=0;J[5996]=0;d=$(3,104)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ob}J[5996]=0;g=ba(146,d|0,17,e+240|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){b=Z()|0;$a(d);break nb}J[f>>2]=g+12;d=J[c>>2];J[c>>2]=g;pb:{if(!d){break pb}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break pb}Xa[J[J[d>>2]+8>>2]](d);bb(d);}f=J[e+240>>2];if(f){d=J[e+244>>2];c=f;if((d|0)!=(c|0)){while(1){d=d-8|0;c=J[d+4>>2];qb:{if(!c){break qb}g=J[c+4>>2];J[c+4>>2]=g-1;if(g){break qb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(f|0)){continue}break}c=J[e+240>>2];}J[e+244>>2]=f;$a(c);}d=J[e+336>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break b}b=Z()|0;}lb(e+240|0);mb(e+332|0);break b}J[5996]=0;c=J[e+312>>2];d=$(3,104)|0;f=J[5996];J[5996]=0;rb:{sb:{if((f|0)!=1){J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=ba(143,d+12|0,0,0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(d);break b}J[e+336>>2]=d;J[e+332>>2]=f;J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=$(3,16)|0;f=J[5996];J[5996]=0;if((f|0)==1){b=Z()|0;break rb}J[e+240>>2]=d;g=d+16|0;J[e+248>>2]=g;f=c-8|0;J[d>>2]=J[f>>2];c=c-4|0;J[d+4>>2]=J[c>>2];J[f>>2]=0;J[c>>2]=0;J[d+8>>2]=J[e+332>>2];J[d+12>>2]=J[e+336>>2];J[e+244>>2]=g;J[e+332>>2]=0;J[e+336>>2]=0;J[5996]=0;d=$(3,104)|0;g=J[5996];J[5996]=0;if((g|0)==1){break sb}J[5996]=0;g=ba(146,d|0,22,e+240|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){b=Z()|0;$a(d);break rb}J[f>>2]=g+12;d=J[c>>2];J[c>>2]=g;tb:{if(!d){break tb}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break tb}Xa[J[J[d>>2]+8>>2]](d);bb(d);}f=J[e+240>>2];if(f){d=J[e+244>>2];c=f;if((d|0)!=(c|0)){while(1){d=d-8|0;c=J[d+4>>2];ub:{if(!c){break ub}g=J[c+4>>2];J[c+4>>2]=g-1;if(g){break ub}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(f|0)){continue}break}c=J[e+240>>2];}J[e+244>>2]=f;$a(c);}d=J[e+336>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break b}b=Z()|0;}lb(e+240|0);mb(e+332|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;vb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,14,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break vb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;wb:{if(!c){break wb}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break wb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];xb:{if(!f){break xb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break xb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break vb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;yb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,16,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break yb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;zb:{if(!c){break zb}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break zb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Ab:{if(!f){break Ab}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Ab}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break yb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;Bb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,15,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Bb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;Cb:{if(!c){break Cb}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break Cb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Db:{if(!f){break Db}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Db}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break Bb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;Eb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,13,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Eb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;Fb:{if(!c){break Fb}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break Fb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Gb:{if(!f){break Gb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Gb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break Eb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;Hb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,12,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Hb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;Ib:{if(!c){break Ib}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break Ib}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Jb:{if(!f){break Jb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Jb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break Hb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;Kb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,11,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Kb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;Lb:{if(!c){break Lb}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break Lb}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Mb:{if(!f){break Mb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Mb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break Kb}b=Z()|0;}lb(e+240|0);break b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;d=J[e+312>>2];c=$(3,8)|0;f=J[5996];J[5996]=0;Nb:{if((f|0)!=1){J[e+240>>2]=c;f=c+8|0;J[e+248>>2]=f;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[5996]=0;J[e+244>>2]=f;c=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)!=1){J[5996]=0;f=ba(146,c|0,10,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Nb}J[d>>2]=f+12;c=J[d+4>>2];J[d+4>>2]=f;Ob:{if(!c){break Ob}d=J[c+4>>2];J[c+4>>2]=d-1;if(d){break Ob}Xa[J[J[c>>2]+8>>2]](c);bb(c);}c=J[e+240>>2];if(!c){break m}d=J[e+244>>2];if((c|0)!=(d|0)){while(1){d=d-8|0;f=J[d+4>>2];Pb:{if(!f){break Pb}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break Pb}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(d|0)){continue}break}c=J[e+240>>2];}$a(c);break m}b=Z()|0;break Nb}b=Z()|0;}lb(e+240|0);break b}I[e+240>>1]=48;H[e+251|0]=1;Qb:{Rb:{Sb:{Tb:{d=J[b+4>>2];if(!d){H[e+251|0]=3;H[e+243|0]=0;I[e+240>>1]=K[5279]|K[5280]<<8;H[e+242|0]=K[5281];break Tb}c=J[b>>2];if(K[e+240|0]==K[c|0]){J[b+4>>2]=d-1;J[b>>2]=c+1;J[5996]=0;d=$(3,104)|0;c=J[5996];J[5996]=0;Ub:{if((c|0)!=1){J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=ba(143,d+12|0,0,0)|0;c=J[5996];J[5996]=0;if((c|0)==1){b=Z()|0;$a(d);break b}J[e+244>>2]=d;J[e+240>>2]=f;c=J[e+312>>2];if(c>>>0>2]){J[c+4>>2]=d;J[c>>2]=f;J[e+312>>2]=c+8;break m}J[5996]=0;aa(144,e+308|0,e+240|0);d=J[5996];J[5996]=0;if((d|0)==1){break Ub}d=J[e+244>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break b}b=Z()|0;mb(e+240|0);break b}H[e+251|0]=1;I[e+240>>1]=49;c=J[b>>2];if(K[c|0]==49){J[b+4>>2]=d-1;J[b>>2]=c+1;J[5996]=0;d=$(3,104)|0;c=J[5996];J[5996]=0;Vb:{if((c|0)!=1){J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=ba(143,d+12|0,1,0)|0;c=J[5996];J[5996]=0;if((c|0)==1){b=Z()|0;$a(d);break b}J[e+244>>2]=d;J[e+240>>2]=f;c=J[e+312>>2];if(c>>>0>2]){J[c+4>>2]=d;J[c>>2]=f;J[e+312>>2]=c+8;break m}J[5996]=0;aa(144,e+308|0,e+240|0);d=J[5996];J[5996]=0;if((d|0)==1){break Vb}d=J[e+244>>2];if(!d){break m}c=J[d+4>>2];J[d+4>>2]=c-1;if(c){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);break m}b=Z()|0;break b}b=Z()|0;mb(e+240|0);break b}H[e+243|0]=0;I[e+240>>1]=K[5279]|K[5280]<<8;H[e+242|0]=K[5281];H[e+251|0]=3;if(d>>>0<3){break Tb}Wb:{Xb:{Yb:{Zb:{_b:{$b:{ac:{bc:{cc:{dc:{ec:{fc:{gc:{c=J[b>>2];if(!(K[e+240|0]!=K[c|0]|K[e+241|0]!=K[c+1|0]|K[e+242|0]!=K[c+2|0])){g=d-3|0;J[b+4>>2]=g;J[b>>2]=c+3;if((g|0)<=0){break Wb}f=J[b>>2];c=J[b>>2];d=0;while(1){if(K[c+d|0]!=41){d=d+1|0;if((g|0)!=(d|0)){continue}break Wb}break}if(d-18>>>0<4294967279){break Wb}hc:{if(d>>>0<=10){H[e+251|0]=d;c=e+240|0;break hc}J[5996]=0;g=(d|15)+1|0;c=$(3,g|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break gc}J[e+240>>2]=c;J[e+244>>2]=d;J[e+248>>2]=g|-2147483648;}H[fb(c,f,d)+d|0]=0;J[e+272>>2]=J[e+244>>2];c=K[e+247|0]|K[e+248|0]<<8|(K[e+249|0]<<16|K[e+250|0]<<24);H[e+275|0]=c;H[e+276|0]=c>>>8;H[e+277|0]=c>>>16;H[e+278|0]=c>>>24;J[5996]=0;f=J[e+240>>2];g=H[e+251|0];J[e+340>>2]=0;J[e+332>>2]=0;J[e+336>>2]=0;c=$(3,12)|0;h=J[5996];J[5996]=0;if((h|0)!=1){J[e+332>>2]=c;h=c+12|0;J[e+340>>2]=h;J[c>>2]=f;J[c+4>>2]=J[e+272>>2];f=K[e+275|0]|K[e+276|0]<<8|(K[e+277|0]<<16|K[e+278|0]<<24);H[c+7|0]=f;H[c+8|0]=f>>>8;H[c+9|0]=f>>>16;H[c+10|0]=f>>>24;H[c+11|0]=g;H[e+275|0]=0;H[e+276|0]=0;H[e+277|0]=0;H[e+278|0]=0;J[e+272>>2]=0;J[e+336>>2]=h;J[5996]=0;c=$(3,104)|0;f=J[5996];J[5996]=0;ic:{jc:{if((f|0)!=1){J[5996]=0;f=ba(147,c|0,2,e+332|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break Xb}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;J[e+268>>2]=f;g=f+12|0;J[e+264>>2]=g;c=$(3,8)|0;h=J[5996];J[5996]=0;if((h|0)==1){break fc}J[e+240>>2]=c;h=c+8|0;J[e+248>>2]=h;J[c+4>>2]=f;J[c>>2]=g;J[e+244>>2]=h;J[e+264>>2]=0;J[e+268>>2]=0;J[5996]=0;f=$(3,104)|0;c=J[5996];J[5996]=0;if((c|0)==1){break jc}J[5996]=0;c=ba(146,f|0,12,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(f);break Yb}J[e+348>>2]=c;g=c+12|0;J[e+344>>2]=g;f=J[e+312>>2];kc:{if(f>>>0>2]){J[f+4>>2]=c;J[f>>2]=g;J[e+312>>2]=f+8;J[e+344>>2]=0;J[e+348>>2]=0;break kc}J[5996]=0;aa(144,e+308|0,e+344|0);c=J[5996];J[5996]=0;if((c|0)==1){break ic}c=J[e+348>>2];if(!c){break kc}f=J[c+4>>2];J[c+4>>2]=f-1;if(f){break kc}Xa[J[J[c>>2]+8>>2]](c);bb(c);}g=J[e+240>>2];if(g){c=J[e+244>>2];f=g;if((c|0)!=(f|0)){while(1){c=c-8|0;f=J[c+4>>2];lc:{if(!f){break lc}h=J[f+4>>2];J[f+4>>2]=h-1;if(h){break lc}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(g|0)){continue}break}f=J[e+240>>2];}J[e+244>>2]=g;$a(f);}c=J[e+268>>2];mc:{if(!c){break mc}f=J[c+4>>2];J[c+4>>2]=f-1;if(f){break mc}Xa[J[J[c>>2]+8>>2]](c);bb(c);}g=J[e+332>>2];if(g){f=J[e+336>>2];if((g|0)!=(f|0)){while(1){c=f-12|0;if(H[f-1|0]<0){$a(J[c>>2]);}f=c;if((c|0)!=(g|0)){continue}break}}J[e+336>>2]=g;$a(g);}d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break Xb}b=Z()|0;break Yb}b=Z()|0;mb(e+344|0);break Yb}b=Z()|0;rb(e+332|0);if((g|0)>=0){break b}$a(f);break b}H[e+244|0]=0;J[e+240>>2]=677931888;H[e+251|0]=4;if(d>>>0<4){break Sb}c=J[b>>2];if(!(K[e+240|0]!=K[c|0]|K[e+241|0]!=K[c+1|0]|(K[e+242|0]!=K[c+2|0]|K[e+243|0]!=K[c+3|0]))){g=d-4|0;J[b+4>>2]=g;J[b>>2]=c+4;if((g|0)<=0){break Zb}f=J[b>>2];c=J[b>>2];d=0;while(1){if(K[c+d|0]!=41){d=d+1|0;if((g|0)!=(d|0)){continue}break Zb}break}if(d-18>>>0<4294967279){break Zb}nc:{if(d>>>0<=10){H[e+251|0]=d;c=e+240|0;break nc}J[5996]=0;g=(d|15)+1|0;c=$(3,g|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break ec}J[e+240>>2]=c;J[e+244>>2]=d;J[e+248>>2]=g|-2147483648;}H[fb(c,f,d)+d|0]=0;J[e+272>>2]=J[e+244>>2];c=K[e+247|0]|K[e+248|0]<<8|(K[e+249|0]<<16|K[e+250|0]<<24);H[e+275|0]=c;H[e+276|0]=c>>>8;H[e+277|0]=c>>>16;H[e+278|0]=c>>>24;J[5996]=0;f=J[e+240>>2];g=H[e+251|0];J[e+340>>2]=0;J[e+332>>2]=0;J[e+336>>2]=0;c=$(3,12)|0;h=J[5996];J[5996]=0;if((h|0)!=1){J[e+332>>2]=c;h=c+12|0;J[e+340>>2]=h;J[c>>2]=f;J[c+4>>2]=J[e+272>>2];f=K[e+275|0]|K[e+276|0]<<8|(K[e+277|0]<<16|K[e+278|0]<<24);H[c+7|0]=f;H[c+8|0]=f>>>8;H[c+9|0]=f>>>16;H[c+10|0]=f>>>24;H[c+11|0]=g;H[e+275|0]=0;H[e+276|0]=0;H[e+277|0]=0;H[e+278|0]=0;J[e+272>>2]=0;J[e+336>>2]=h;J[5996]=0;c=$(3,104)|0;f=J[5996];J[5996]=0;oc:{pc:{if((f|0)!=1){J[5996]=0;f=ba(147,c|0,3,e+332|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(c);break _b}J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[5996]=0;J[e+268>>2]=f;g=f+12|0;J[e+264>>2]=g;c=$(3,8)|0;h=J[5996];J[5996]=0;if((h|0)==1){break dc}J[e+240>>2]=c;h=c+8|0;J[e+248>>2]=h;J[c+4>>2]=f;J[c>>2]=g;J[e+244>>2]=h;J[e+264>>2]=0;J[e+268>>2]=0;J[5996]=0;f=$(3,104)|0;c=J[5996];J[5996]=0;if((c|0)==1){break pc}J[5996]=0;c=ba(146,f|0,12,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(f);break $b}J[e+348>>2]=c;g=c+12|0;J[e+344>>2]=g;f=J[e+312>>2];qc:{if(f>>>0>2]){J[f+4>>2]=c;J[f>>2]=g;J[e+312>>2]=f+8;J[e+344>>2]=0;J[e+348>>2]=0;break qc}J[5996]=0;aa(144,e+308|0,e+344|0);c=J[5996];J[5996]=0;if((c|0)==1){break oc}c=J[e+348>>2];if(!c){break qc}f=J[c+4>>2];J[c+4>>2]=f-1;if(f){break qc}Xa[J[J[c>>2]+8>>2]](c);bb(c);}g=J[e+240>>2];if(g){c=J[e+244>>2];f=g;if((c|0)!=(f|0)){while(1){c=c-8|0;f=J[c+4>>2];rc:{if(!f){break rc}h=J[f+4>>2];J[f+4>>2]=h-1;if(h){break rc}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((c|0)!=(g|0)){continue}break}f=J[e+240>>2];}J[e+244>>2]=g;$a(f);}c=J[e+268>>2];sc:{if(!c){break sc}f=J[c+4>>2];J[c+4>>2]=f-1;if(f){break sc}Xa[J[J[c>>2]+8>>2]](c);bb(c);}g=J[e+332>>2];if(g){f=J[e+336>>2];if((g|0)!=(f|0)){while(1){c=f-12|0;if(H[f-1|0]<0){$a(J[c>>2]);}f=c;if((c|0)!=(g|0)){continue}break}}J[e+336>>2]=g;$a(g);}d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break _b}b=Z()|0;break $b}b=Z()|0;mb(e+344|0);break $b}b=Z()|0;rb(e+332|0);if((g|0)>=0){break b}$a(f);break b}H[e+245|0]=0;H[e+244|0]=K[5287];J[e+240>>2]=K[5283]|K[5284]<<8|(K[5285]<<16|K[5286]<<24);H[e+251|0]=5;if(d>>>0<5){break Rb}tc:{c=J[b>>2];if(K[e+240|0]!=K[c|0]|K[e+241|0]!=K[c+1|0]|(K[e+242|0]!=K[c+2|0]|K[e+243|0]!=K[c+3|0])){break tc}if(K[e+244|0]!=K[c+4|0]){break tc}g=d-5|0;J[b+4>>2]=g;J[b>>2]=c+5;if((g|0)<=0){break ac}f=J[b>>2];c=J[b>>2];d=0;while(1){if(K[c+d|0]!=41){d=d+1|0;if((g|0)!=(d|0)){continue}break ac}break}if(d-18>>>0<4294967279){break ac}uc:{if(d>>>0<=10){H[e+251|0]=d;c=e+240|0;break uc}J[5996]=0;g=(d|15)+1|0;c=$(3,g|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break cc}J[e+240>>2]=c;J[e+244>>2]=d;J[e+248>>2]=g|-2147483648;}H[fb(c,f,d)+d|0]=0;J[e+344>>2]=J[e+244>>2];c=K[e+247|0]|K[e+248|0]<<8|(K[e+249|0]<<16|K[e+250|0]<<24);H[e+347|0]=c;H[e+348|0]=c>>>8;H[e+349|0]=c>>>16;H[e+350|0]=c>>>24;J[5996]=0;f=J[e+240>>2];g=H[e+251|0];J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;c=$(3,12)|0;h=J[5996];J[5996]=0;if((h|0)!=1){J[e+240>>2]=c;h=c+12|0;J[e+248>>2]=h;J[c>>2]=f;J[c+4>>2]=J[e+344>>2];f=K[e+347|0]|K[e+348|0]<<8|(K[e+349|0]<<16|K[e+350|0]<<24);H[c+7|0]=f;H[c+8|0]=f>>>8;H[c+9|0]=f>>>16;H[c+10|0]=f>>>24;H[c+11|0]=g;H[e+347|0]=0;H[e+348|0]=0;H[e+349|0]=0;H[e+350|0]=0;J[e+344>>2]=0;J[e+244>>2]=h;J[5996]=0;f=$(3,104)|0;c=J[5996];J[5996]=0;vc:{wc:{if((c|0)!=1){J[5996]=0;c=ba(147,f|0,2,e+240|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){b=Z()|0;$a(f);break vc}J[e+336>>2]=c;g=c+12|0;J[e+332>>2]=g;f=J[e+312>>2];xc:{if(f>>>0>2]){J[f+4>>2]=c;J[f>>2]=g;J[e+312>>2]=f+8;J[e+332>>2]=0;J[e+336>>2]=0;break xc}J[5996]=0;aa(144,e+308|0,e+332|0);c=J[5996];J[5996]=0;if((c|0)==1){break wc}c=J[e+336>>2];if(!c){break xc}f=J[c+4>>2];J[c+4>>2]=f-1;if(f){break xc}Xa[J[J[c>>2]+8>>2]](c);bb(c);}g=J[e+240>>2];if(g){f=J[e+244>>2];if((g|0)!=(f|0)){while(1){c=f-12|0;if(H[f-1|0]<0){$a(J[c>>2]);}f=c;if((c|0)!=(g|0)){continue}break}}J[e+244>>2]=g;$a(g);}d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break vc}b=Z()|0;mb(e+332|0);}rb(e+240|0);break b}b=Z()|0;rb(e+240|0);if((g|0)>=0){break b}$a(f);break b}H[e+245|0]=0;H[e+244|0]=K[5319];H[e+251|0]=5;f=K[5315]|K[5316]<<8|(K[5317]<<16|K[5318]<<24);J[e+240>>2]=f;c=J[b>>2];if(K[c|0]!=(f&255)|K[e+241|0]!=K[c+1|0]|(K[e+242|0]!=K[c+2|0]|K[e+243|0]!=K[c+3|0])){break Qb}if(K[e+244|0]!=K[c+4|0]){break Qb}J[b+4>>2]=d-5;J[b>>2]=c+5;d=J[b>>2];c=J[b+4>>2];J[5996]=0;f=e+240|0;Na(148,f|0,d|0,c|0);d=J[5996];J[5996]=0;if((d|0)==1){break bc}yc:{zc:{Ac:{Bc:{Cc:{if(K[e+256|0]){J[5996]=0;d=e+332|0;aa(149,d|0,f|0);c=J[5996];J[5996]=0;if((c|0)==1){break Cc}J[5996]=0;c=e+344|0;ea(150,c|0,3,d|0);f=J[5996];J[5996]=0;if((f|0)==1){break Bc}J[5996]=0;aa(151,e+308|0,c|0);f=J[5996];J[5996]=0;if((f|0)==1){break Ac}mb(c);rb(d);d=J[e+252>>2]+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];if(!K[e+256|0]|H[e+251|0]>=0){break m}$a(J[e+240>>2]);break m}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break yc}b=Z()|0;break zc}b=Z()|0;mb(e+344|0);}rb(e+332|0);}if(!K[e+256|0]|H[e+251|0]>=0){break b}$a(J[e+240>>2]);break b}b=Z()|0;break b}b=Z()|0;break Yb}b=Z()|0;break b}b=Z()|0;break $b}b=Z()|0;break b}b=Z()|0;break b}J[a>>2]=0;J[a+4>>2]=0;break l}lb(e+240|0);mb(e+264|0);}rb(e+332|0);break b}J[a>>2]=0;J[a+4>>2]=0;break l}lb(e+240|0);mb(e+264|0);}rb(e+332|0);break b}J[a>>2]=0;J[a+4>>2]=0;break l}H[e+244|0]=0;J[e+240>>2]=677931888;H[e+251|0]=4;}H[e+245|0]=0;H[e+244|0]=K[5287];H[e+251|0]=5;J[e+240>>2]=K[5283]|K[5284]<<8|(K[5285]<<16|K[5286]<<24);}H[e+245|0]=0;H[e+244|0]=K[5319];H[e+251|0]=5;J[e+240>>2]=K[5315]|K[5316]<<8|(K[5317]<<16|K[5318]<<24);}J[5996]=0;d=_(30,e+228|0,5355)|0;c=J[5996];J[5996]=0;Dc:{Ec:{Fc:{if((c|0)!=1){c=vb(d,b);if(H[e+239|0]<0){$a(J[d>>2]);}if(!c){break Dc}d=J[b>>2];c=J[b+4>>2];J[5996]=0;bd(e+240|0,d,c,32);d=J[5996];J[5996]=0;if((d|0)==1){break Fc}if(K[e+256|0]){break Ec}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}b=Z()|0;break b}J[5996]=0;d=e+332|0;ea(153,d|0,6,e+240|0);c=J[5996];J[5996]=0;Gc:{Hc:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,d|0);c=J[5996];J[5996]=0;if((c|0)==1){break Hc}mb(d);d=J[e+252>>2]+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];if(!K[e+256|0]){break m}d=J[e+240>>2];if(!d){break m}$a(d);break m}b=Z()|0;break Gc}b=Z()|0;mb(e+332|0);}if(!K[e+256|0]){break b}a=J[e+240>>2];if(!a){break b}$a(a);break b}J[5996]=0;d=_(30,e+216|0,5372)|0;c=J[5996];J[5996]=0;Ic:{Jc:{Kc:{if((c|0)!=1){c=vb(d,b);if(H[e+227|0]<0){$a(J[d>>2]);}if(!c){break Ic}d=J[b>>2];c=J[b+4>>2];J[5996]=0;bd(e+240|0,d,c,20);d=J[5996];J[5996]=0;if((d|0)==1){break Kc}if(K[e+256|0]){break Jc}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}b=Z()|0;break b}J[5996]=0;d=e+332|0;ea(153,d|0,8,e+240|0);c=J[5996];J[5996]=0;Lc:{Mc:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,d|0);c=J[5996];J[5996]=0;if((c|0)==1){break Mc}mb(d);d=J[e+252>>2]+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];if(!K[e+256|0]){break m}d=J[e+240>>2];if(!d){break m}$a(d);break m}b=Z()|0;break Lc}b=Z()|0;mb(e+332|0);}if(!K[e+256|0]){break b}a=J[e+240>>2];if(!a){break b}$a(a);break b}J[5996]=0;d=_(30,e+204|0,5346)|0;c=J[5996];J[5996]=0;Nc:{Oc:{Pc:{if((c|0)!=1){c=vb(d,b);if(H[e+215|0]<0){$a(J[d>>2]);}if(!c){break Nc}d=J[b>>2];c=J[b+4>>2];J[5996]=0;bd(e+240|0,d,c,32);d=J[5996];J[5996]=0;if((d|0)==1){break Pc}if(K[e+256|0]){break Oc}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}b=Z()|0;break b}J[5996]=0;d=e+332|0;ea(153,d|0,7,e+240|0);c=J[5996];J[5996]=0;Qc:{Rc:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,d|0);c=J[5996];J[5996]=0;if((c|0)==1){break Rc}mb(d);d=J[e+252>>2]+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];if(!K[e+256|0]){break m}d=J[e+240>>2];if(!d){break m}$a(d);break m}b=Z()|0;break Qc}b=Z()|0;mb(e+332|0);}if(!K[e+256|0]){break b}a=J[e+240>>2];if(!a){break b}$a(a);break b}J[5996]=0;d=_(30,e+192|0,5363)|0;c=J[5996];J[5996]=0;Sc:{Tc:{Uc:{if((c|0)!=1){c=vb(d,b);if(H[e+203|0]<0){$a(J[d>>2]);}if(!c){break Sc}d=J[b>>2];c=J[b+4>>2];J[5996]=0;bd(e+240|0,d,c,20);d=J[5996];J[5996]=0;if((d|0)==1){break Uc}if(K[e+256|0]){break Tc}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}b=Z()|0;break b}J[5996]=0;d=e+332|0;ea(153,d|0,9,e+240|0);c=J[5996];J[5996]=0;Vc:{Wc:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,d|0);c=J[5996];J[5996]=0;if((c|0)==1){break Wc}mb(d);d=J[e+252>>2]+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];if(!K[e+256|0]){break m}d=J[e+240>>2];if(!d){break m}$a(d);break m}b=Z()|0;break Vc}b=Z()|0;mb(e+332|0);}if(!K[e+256|0]){break b}a=J[e+240>>2];if(!a){break b}$a(a);break b}J[5996]=0;d=_(30,e+180|0,5258)|0;c=J[5996];J[5996]=0;Xc:{Yc:{Zc:{_c:{$c:{if((c|0)!=1){c=vb(d,b);if(H[e+191|0]<0){$a(J[d>>2]);}if(!c){break _c}f=J[b+4>>2];ad:{if((f|0)<=0){break ad}c=J[b>>2];d=0;while(1){g=c+d|0;if(K[g|0]!=41){d=d+1|0;if((f|0)!=(d|0)){continue}break ad}break}if(d){break $c}}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[5996]=0;c=ba(154,e+168|0,c|0,g|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Yc}f=hd(c,e+240|0);if(H[e+179|0]<0){$a(J[c>>2]);}if(!f){break Zc}f=J[e+244>>2];g=f;c=J[e+240>>2];h=c- -2147483648|0;f=f-(c>>>0<2147483648)|0;if((f|0)==-1&h>>>0<2147483649|(f|0)!=-1){break Zc}J[5996]=0;f=e+332|0;Ae(f,5,c,g);c=J[5996];J[5996]=0;bd:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,f|0);c=J[5996];J[5996]=0;if((c|0)==1){break bd}mb(f);d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break b}b=Z()|0;mb(e+332|0);break b}J[5996]=0;d=_(30,e+156|0,5265)|0;c=J[5996];J[5996]=0;cd:{dd:{ed:{fd:{if((c|0)!=1){c=vb(d,b);if(H[e+167|0]<0){$a(J[d>>2]);}if(!c){break ed}f=J[b+4>>2];gd:{if((f|0)<=0){break gd}c=J[b>>2];d=0;while(1){g=c+d|0;if(K[g|0]!=41){d=d+1|0;if((f|0)!=(d|0)){continue}break gd}break}if(d){break fd}}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[5996]=0;c=ba(154,e+144|0,c|0,g|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break cd}f=hd(c,e+240|0);if(H[e+155|0]<0){$a(J[c>>2]);}if(!f){break dd}f=J[e+244>>2];g=f;c=J[e+240>>2];h=c- -2147483648|0;f=f-(c>>>0<2147483648)|0;if((f|0)==-1&h>>>0<2147483649|(f|0)!=-1){break dd}J[5996]=0;f=e+332|0;Ae(f,4,c,g);c=J[5996];J[5996]=0;hd:{if((c|0)!=1){J[5996]=0;aa(151,e+308|0,f|0);c=J[5996];J[5996]=0;if((c|0)==1){break hd}mb(f);d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];break m}b=Z()|0;break b}b=Z()|0;mb(e+332|0);break b}J[5996]=0;d=_(30,e+132|0,5289)|0;c=J[5996];J[5996]=0;id:{if((c|0)!=1){c=vb(d,b);if(H[e+143|0]<0){$a(J[d>>2]);}if(!c){break Xc}f=J[b+4>>2];jd:{if((f|0)<=0){break jd}c=J[b>>2];d=0;while(1){g=c+d|0;h=K[g|0];if((h|0)!=44){if((h|0)==41){break jd}d=d+1|0;if((f|0)>(d|0)){continue}break jd}break}if(d){break id}}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[5996]=0;c=ba(154,e+120|0,c|0,g|0)|0;f=J[5996];J[5996]=0;kd:{if((f|0)!=1){f=hd(c,m);if(H[e+131|0]<0){$a(J[c>>2]);}if(f){break kd}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}d=d+1|0;l=J[b+4>>2]-d|0;J[b+4>>2]=l;f=d+J[b>>2]|0;J[b>>2]=f;J[e+340>>2]=0;J[e+332>>2]=0;J[e+336>>2]=0;ld:{md:{nd:{od:{pd:{qd:{while(1){d=0;g=(l|0)<=0;if(g){break od}rd:{while(1){c=K[d+f|0];if((c|0)==44){c=d;break rd}if((c|0)!=41){d=d+1|0;if((l|0)>(d|0)){continue}}break}c=0;if(g){break od}while(1){if(K[c+f|0]==41){d=-1;break rd}c=c+1|0;if((l|0)!=(c|0)){continue}break}break od}if((c|0)<=0){break od}J[5996]=0;ea(156,e+240|0,f|0,c+f|0);f=J[5996];J[5996]=0;if((f|0)==1){break ld}if(!K[e+252|0]){break od}f=J[e+336>>2];sd:{if(f>>>0>2]){g=J[e+244>>2];J[f>>2]=J[e+240>>2];J[f+4>>2]=g;J[f+8>>2]=J[e+248>>2];J[e+248>>2]=0;J[e+240>>2]=0;J[e+244>>2]=0;J[e+336>>2]=f+12;l=1;g=0;break sd}J[5996]=0;aa(157,e+332|0,e+240|0);f=J[5996];J[5996]=0;if((f|0)==1){break qd}l=K[e+252|0];g=K[e+251|0];}c=c+1|0;J[b+4>>2]=J[b+4>>2]-c;f=c+J[b>>2]|0;J[b>>2]=f;if(!(!(l&255)|g<<24>>24>=0)){$a(J[e+240>>2]);f=J[b>>2];}if((d|0)!=-1){l=J[b+4>>2];continue}break}d=J[e+336>>2];c=J[e+332>>2];f=(d-c|0)/12|0;if((c|0)!=(d|0)&f>>>0<21){break pd}break od}b=Z()|0;if(!K[e+252|0]|H[e+251|0]>=0){break c}$a(J[e+240>>2]);break c}d=J[e+296>>2];c=J[e+300>>2];if(!((!!d&(c|0)>=0|(c|0)>0)&(!c&d>>>0<=f>>>0))){break od}J[5996]=0;f=e+240|0;g=e+332|0;Ka(158,f|0,25,g|0,d|0,c|0);d=J[5996];J[5996]=0;if((d|0)==1){break nd}J[5996]=0;aa(151,e+308|0,f|0);d=J[5996];J[5996]=0;if((d|0)==1){break md}mb(f);rb(g);break m}J[a>>2]=0;J[a+4>>2]=0;rb(e+332|0);break l}b=Z()|0;break c}b=Z()|0;mb(e+240|0);break c}b=Z()|0;break c}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[5996]=0;d=_(30,e+108|0,5302)|0;c=J[5996];J[5996]=0;td:{ud:{if((c|0)!=1){c=vb(d,b);if(H[e+119|0]<0){$a(J[d>>2]);}if(!c){break td}f=J[b+4>>2];vd:{if((f|0)<=0){break vd}c=J[b>>2];d=0;while(1){g=c+d|0;h=K[g|0];if((h|0)!=44){if((h|0)==41){break vd}d=d+1|0;if((f|0)>(d|0)){continue}break vd}break}if(d){break ud}}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}J[5996]=0;c=ba(154,e+96|0,c|0,g|0)|0;f=J[5996];J[5996]=0;wd:{if((f|0)!=1){f=hd(c,m);if(H[e+107|0]<0){$a(J[c>>2]);}if(f){break wd}J[a>>2]=0;J[a+4>>2]=0;break l}b=Z()|0;break b}c=J[e+300>>2];if(!J[e+296>>2]&(c|0)<=0|(c|0)<0){J[a>>2]=0;J[a+4>>2]=0;break l}d=d+1|0;J[b+4>>2]=J[b+4>>2]-d;J[b>>2]=d+J[b>>2];J[5996]=0;d=e+320|0;ga(159,d|0,19,1,m|0);c=J[5996];J[5996]=0;if((c|0)==1){break k}J[5996]=0;ga(160,d|0,0,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break m}b=Z()|0;break b}J[5996]=0;d=_(30,e+84|0,5251)|0;c=J[5996];J[5996]=0;xd:{yd:{zd:{Ad:{Bd:{Cd:{Dd:{if((c|0)!=1){c=vb(d,b);if(H[e+95|0]<0){$a(J[d>>2]);}if(!c){break xd}J[5996]=0;d=e+320|0;ga(160,d|0,14,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Dd}J[5996]=0;ga(160,d|0,21,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Cd}J[5996]=0;ga(160,d|0,0,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Bd}J[5996]=0;ga(160,d|0,20,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Ad}J[5996]=0;ga(160,d|0,0,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break zd}J[5996]=0;ga(160,d|0,20,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break yd}J[5996]=0;ga(160,d|0,0,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break m}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}J[5996]=0;d=_(30,e+72|0,5272)|0;c=J[5996];J[5996]=0;if((c|0)==1){break j}c=vb(d,b);if(H[e+83|0]<0){$a(J[d>>2]);}Ed:{if(c){J[5996]=0;ga(160,e+320|0,11,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e+60|0,5339)|0;c=J[5996];J[5996]=0;if((c|0)==1){break i}c=vb(d,b);if(H[e+71|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,13,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e+48|0,5244)|0;c=J[5996];J[5996]=0;if((c|0)==1){break h}c=vb(d,b);if(H[e+59|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,12,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e+36|0,5333)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}c=vb(d,b);if(H[e+47|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,15,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e+24|0,5327)|0;c=J[5996];J[5996]=0;if((c|0)==1){break f}c=vb(d,b);if(H[e+35|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,16,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e+12|0,5321)|0;c=J[5996];J[5996]=0;if((c|0)==1){break e}c=vb(d,b);if(H[e+23|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,17,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[5996]=0;d=_(30,e|0,5296)|0;c=J[5996];J[5996]=0;if((c|0)==1){break d}c=vb(d,b);if(H[e+11|0]<0){$a(J[d>>2]);}if(c){J[5996]=0;ga(160,e+320|0,18,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break Ed}b=Z()|0;break b}J[a>>2]=0;J[a+4>>2]=0;break l}J[5996]=0;d=e+320|0;ga(160,d|0,21,-1,-1);c=J[5996];J[5996]=0;Fd:{Gd:{if((c|0)!=1){J[5996]=0;ga(160,d|0,0,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Gd}J[5996]=0;ga(160,d|0,20,-1,-1);c=J[5996];J[5996]=0;if((c|0)==1){break Fd}J[5996]=0;ga(160,d|0,0,-1,-1);d=J[5996];J[5996]=0;if((d|0)!=1){break m}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}c=J[e+324>>2];f=J[e+320>>2];if((c|0)!=(f|0)){continue}break}d=J[e+308>>2];if((J[e+312>>2]-d|0)!=8){J[5996]=0;ga(44,4122,2210,1561,2344);a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}if(J[b+4>>2]){J[a>>2]=0;J[a+4>>2]=0;break l}J[a>>2]=J[d>>2];J[a+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;}a=J[e+308>>2];if(a){d=J[e+312>>2];if((a|0)!=(d|0)){while(1){d=d-8|0;b=J[d+4>>2];Hd:{if(!b){break Hd}c=J[b+4>>2];J[b+4>>2]=c-1;if(c){break Hd}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((a|0)!=(d|0)){continue}break}a=J[e+308>>2];}$a(a);}a=J[e+320>>2];if(a){J[e+324>>2]=a;$a(a);}Ua=e+352|0;return}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}b=Z()|0;break b}rb(e+332|0);}lb(e+308|0);a=J[e+320>>2];if(a){J[e+324>>2]=a;$a(a);}da(b|0);B();}B();}function hn(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0;f=Ua-128|0;Ua=f;H[f+127|0]=b;g=f+116|0;fb(g,b?3764:5575,b);H[b|g]=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{switch(J[c>>2]){case 10:J[5996]=0;b=ba(99,d|0,0,2553)|0;c=J[5996];J[5996]=0;if((c|0)==1){break u}d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b;case 11:J[5996]=0;b=ba(99,d|0,0,1681)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 12:E:{F:{G:{b=J[J[c+32>>2]>>2];switch(J[b>>2]-2|0){case 1:break F;case 0:break G;default:break E}}b=J[b+8>>2];if(H[b+11|0]>=0){J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;break c}c=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,f+96|0,b|0,c|0);b=J[5996];J[5996]=0;if((b|0)!=1){break c}a=Z()|0;break a}b=J[b+8>>2];if(H[b+11|0]>=0){J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;break d}c=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,f+96|0,b|0,c|0);b=J[5996];J[5996]=0;if((b|0)!=1){break d}a=Z()|0;break a}J[5996]=0;b=ba(99,d|0,0,2541)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 13:J[5996]=0;b=ba(99,d|0,0,2522)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 14:J[5996]=0;b=ba(99,d|0,0,1271)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 15:J[5996]=0;b=ba(99,d|0,0,2170)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 16:J[5996]=0;b=ba(99,d|0,0,2029)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 17:if(J[J[J[c+32>>2]+8>>2]>>2]!=1){break C}J[5996]=0;b=ba(99,d|0,0,1392)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 22:b=J[c+32>>2];if(!J[J[b>>2]>>2]){J[5996]=0;b=ba(99,d+12|0,0,2096)|0;c=J[5996];J[5996]=0;if((c|0)!=1){e=J[b>>2];c=K[d+19|0]|K[d+20|0]<<8|(K[d+21|0]<<16|K[d+22|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[f+96>>2]=J[d+16>>2];c=K[d+23|0];J[b+8>>2]=0;J[b>>2]=0;J[b+4>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a}if(J[J[b+8>>2]>>2]){break x}J[5996]=0;b=ba(99,d|0,0,1295)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 2:b=J[c+8>>2];if(H[b+11|0]>=0){J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;break e}c=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,f+96|0,b|0,c|0);b=J[5996];J[5996]=0;if((b|0)!=1){break e}a=Z()|0;break a;case 3:b=J[c+8>>2];if(H[b+11|0]>=0){J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;break f}c=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,f+96|0,b|0,c|0);b=J[5996];J[5996]=0;if((b|0)!=1){break f}a=Z()|0;break a;case 5:J[5996]=0;b=_(97,f+116|0,5258)|0;d=J[5996];J[5996]=0;H:{I:{J:{K:{L:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=f- -64|0;aa(119,b|0,c+4|0);c=J[5996];J[5996]=0;if((c|0)==1){break L}J[5996]=0;d=b;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:d)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break K}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break J}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break H}a=Z()|0;break I}a=Z()|0;if(H[f+107|0]>=0){break I}$a(J[f+96>>2]);}if(H[f+75|0]>=0){break H}$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a;case 4:J[5996]=0;b=_(97,f+116|0,5265)|0;d=J[5996];J[5996]=0;M:{N:{O:{P:{Q:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=f- -64|0;aa(119,b|0,c+4|0);c=J[5996];J[5996]=0;if((c|0)==1){break Q}J[5996]=0;d=b;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:d)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break P}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break O}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break M}a=Z()|0;break N}a=Z()|0;if(H[f+107|0]>=0){break N}$a(J[f+96>>2]);}if(H[f+75|0]>=0){break M}$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a;case 7:J[5996]=0;b=_(97,f+116|0,5346)|0;d=J[5996];J[5996]=0;R:{S:{T:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;d=J[c+24>>2];b=J[c+20>>2];J[f+72>>2]=0;J[f+64>>2]=0;J[f+68>>2]=0;J[5996]=0;c=d-b|0;aa(101,f- -64|0,c<<1);e=J[5996];J[5996]=0;if((e|0)==1){break h}U:{if(b>>>0>>0){d=b+c|0;while(1){c=K[b|0];J[5996]=0;e=f- -64|0;aa(98,e|0,H[(c>>>4|0)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break U}J[5996]=0;aa(98,e|0,H[(c&15)+6976|0]);c=J[5996];J[5996]=0;if((c|0)==1){break U}b=b+1|0;if((d|0)!=(b|0)){continue}break}}J[5996]=0;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:f- -64|0)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break T}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break S}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}break h}a=Z()|0;break a}a=Z()|0;break R}a=Z()|0;if(H[f+107|0]>=0){break R}$a(J[f+96>>2]);}break g;case 9:J[5996]=0;b=_(97,f+116|0,5363)|0;d=J[5996];J[5996]=0;V:{W:{X:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;d=J[c+24>>2];b=J[c+20>>2];J[f+72>>2]=0;J[f+64>>2]=0;J[f+68>>2]=0;J[5996]=0;c=d-b|0;aa(101,f- -64|0,c<<1);e=J[5996];J[5996]=0;if((e|0)==1){break j}Y:{if(b>>>0>>0){d=b+c|0;while(1){c=K[b|0];J[5996]=0;e=f- -64|0;aa(98,e|0,H[(c>>>4|0)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break Y}J[5996]=0;aa(98,e|0,H[(c&15)+6976|0]);c=J[5996];J[5996]=0;if((c|0)==1){break Y}b=b+1|0;if((d|0)!=(b|0)){continue}break}}J[5996]=0;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:f- -64|0)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break X}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break W}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}break j}a=Z()|0;break a}a=Z()|0;break V}a=Z()|0;if(H[f+107|0]>=0){break V}$a(J[f+96>>2]);}break i;case 6:J[5996]=0;b=_(97,f+116|0,5355)|0;d=J[5996];J[5996]=0;Z:{_:{$:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;d=J[c+24>>2];b=J[c+20>>2];J[f+72>>2]=0;J[f+64>>2]=0;J[f+68>>2]=0;J[5996]=0;c=d-b|0;aa(101,f- -64|0,c<<1);e=J[5996];J[5996]=0;if((e|0)==1){break l}aa:{if(b>>>0>>0){d=b+c|0;while(1){c=K[b|0];J[5996]=0;e=f- -64|0;aa(98,e|0,H[(c>>>4|0)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break aa}J[5996]=0;aa(98,e|0,H[(c&15)+6976|0]);c=J[5996];J[5996]=0;if((c|0)==1){break aa}b=b+1|0;if((d|0)!=(b|0)){continue}break}}J[5996]=0;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:f- -64|0)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break $}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break _}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}break l}a=Z()|0;break a}a=Z()|0;break Z}a=Z()|0;if(H[f+107|0]>=0){break Z}$a(J[f+96>>2]);}break k;case 8:J[5996]=0;b=_(97,f+116|0,5372)|0;d=J[5996];J[5996]=0;ba:{ca:{da:{if((d|0)!=1){J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;d=J[c+24>>2];b=J[c+20>>2];J[f+72>>2]=0;J[f+64>>2]=0;J[f+68>>2]=0;J[5996]=0;c=d-b|0;aa(101,f- -64|0,c<<1);e=J[5996];J[5996]=0;if((e|0)==1){break n}ea:{if(b>>>0>>0){d=b+c|0;while(1){c=K[b|0];J[5996]=0;e=f- -64|0;aa(98,e|0,H[(c>>>4|0)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break ea}J[5996]=0;aa(98,e|0,H[(c&15)+6976|0]);c=J[5996];J[5996]=0;if((c|0)==1){break ea}b=b+1|0;if((d|0)!=(b|0)){continue}break}}J[5996]=0;b=K[f+75|0];c=b<<24>>24<0;c=ba(100,f+80|0,(c?J[f+64>>2]:f- -64|0)|0,(c?J[f+68>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break da}J[f+104>>2]=J[c+8>>2];b=J[c+4>>2];J[f+96>>2]=J[c>>2];J[f+100>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break ca}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}break n}a=Z()|0;break a}a=Z()|0;break ba}a=Z()|0;if(H[f+107|0]>=0){break ba}$a(J[f+96>>2]);}break m;case 1:J[5996]=0;b=_(97,f+116|0,4180)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;c=K[f+127|0];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a;case 24:break s;case 25:break v;case 23:break w;case 20:break y;case 21:break z;case 19:break A;case 18:break B;case 0:break D;default:break t}}J[5996]=0;b=_(97,f+116|0,4350)|0;c=J[5996];J[5996]=0;if((c|0)!=1){d=J[b>>2];J[f+96>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+99|0]=c;H[f+100|0]=c>>>8;H[f+101|0]=c>>>16;H[f+102|0]=c>>>24;c=K[f+127|0];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+96>>2];b=K[f+99|0]|K[f+100|0]<<8|(K[f+101|0]<<16|K[f+102|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a}J[5996]=0;b=_(97,f+116|0,5244)|0;c=J[5996];J[5996]=0;fa:{ga:{ha:{ia:{ja:{ka:{la:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break la}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ka}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ja}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ia}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break fa}a=Z()|0;break ga}a=Z()|0;break ha}a=Z()|0;if(H[f+107|0]>=0){break ha}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break ga}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break fa}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5339)|0;c=J[5996];J[5996]=0;ma:{na:{oa:{pa:{qa:{ra:{sa:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break sa}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ra}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break qa}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break pa}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break ma}a=Z()|0;break na}a=Z()|0;break oa}a=Z()|0;if(H[f+107|0]>=0){break oa}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break na}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break ma}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5333)|0;c=J[5996];J[5996]=0;ta:{ua:{va:{wa:{xa:{ya:{za:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break za}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ya}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break xa}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break wa}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break ta}a=Z()|0;break ua}a=Z()|0;break va}a=Z()|0;if(H[f+107|0]>=0){break va}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break ua}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break ta}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5321)|0;c=J[5996];J[5996]=0;Aa:{Ba:{Ca:{Da:{Ea:{Fa:{Ga:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ga}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Fa}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ea}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Da}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break Aa}a=Z()|0;break Ba}a=Z()|0;break Ca}a=Z()|0;if(H[f+107|0]>=0){break Ca}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break Ba}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Aa}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5327)|0;c=J[5996];J[5996]=0;Ha:{Ia:{Ja:{Ka:{La:{Ma:{Na:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Na}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ma}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break La}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Ka}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break Ha}a=Z()|0;break Ia}a=Z()|0;break Ja}a=Z()|0;if(H[f+107|0]>=0){break Ja}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break Ia}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Ha}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5296)|0;c=J[5996];J[5996]=0;Oa:{Pa:{Qa:{Ra:{Sa:{Ta:{Ua:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ua}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ta}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Sa}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Ra}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break Oa}a=Z()|0;break Pa}a=Z()|0;break Qa}a=Z()|0;if(H[f+107|0]>=0){break Qa}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break Pa}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Oa}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}if(!J[J[J[c+32>>2]+16>>2]>>2]){J[5996]=0;b=_(97,f+116|0,5272)|0;c=J[5996];J[5996]=0;Va:{Wa:{Xa:{Ya:{Za:{_a:{$a:{if((c|0)!=1){J[f+56>>2]=J[b+8>>2];c=J[b+4>>2];J[f+48>>2]=J[b>>2];J[f+52>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+48|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break $a}J[f+72>>2]=J[c+8>>2];b=J[c+4>>2];J[f+64>>2]=J[c>>2];J[f+68>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break _a}J[f+88>>2]=J[e+8>>2];b=J[e+4>>2];J[f+80>>2]=J[e>>2];J[f+84>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=d+12|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?h:i)|0,(d?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Za}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Ya}h=J[b>>2];J[f+24>>2]=J[b+4>>2];g=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+27|0]=g;H[f+28|0]=g>>>8;H[f+29|0]=g>>>16;H[f+30|0]=g>>>24;J[b>>2]=0;J[b+4>>2]=0;g=K[b+11|0];J[b+8>>2]=0;J[a>>2]=h;J[a+4>>2]=J[f+24>>2];b=K[f+27|0]|K[f+28|0]<<8|(K[f+29|0]<<16|K[f+30|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=g;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break Va}a=Z()|0;break Wa}a=Z()|0;break Xa}a=Z()|0;if(H[f+107|0]>=0){break Xa}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break Wa}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Va}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break a}$a(J[f+48>>2]);break a}J[5996]=0;b=_(97,f+116|0,5251)|0;c=J[5996];J[5996]=0;ab:{bb:{cb:{db:{eb:{fb:{gb:{hb:{ib:{jb:{kb:{if((c|0)!=1){J[f+16>>2]=J[b+8>>2];c=J[b+4>>2];J[f+8>>2]=J[b>>2];J[f+12>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;c=J[d>>2];e=J[d+4>>2];b=K[d+11|0];J[5996]=0;h=c;c=b<<24>>24<0;c=ba(100,f+8|0,(c?h:d)|0,(c?e:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break kb}J[f+32>>2]=J[c+8>>2];b=J[c+4>>2];J[f+24>>2]=J[c>>2];J[f+28>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=_(97,f+24|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break jb}J[f+56>>2]=J[e+8>>2];b=J[e+4>>2];J[f+48>>2]=J[e>>2];J[f+52>>2]=b;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;g=J[d+16>>2];h=J[d+12>>2];b=K[d+23|0];J[5996]=0;i=h;h=b<<24>>24<0;g=ba(100,f+48|0,(h?i:d+12|0)|0,(h?g:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ib}J[f+72>>2]=J[g+8>>2];b=J[g+4>>2];J[f+64>>2]=J[g>>2];J[f+68>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;h=_(97,f- -64|0,4354)|0;b=J[5996];J[5996]=0;if((b|0)==1){break hb}J[f+88>>2]=J[h+8>>2];b=J[h+4>>2];J[f+80>>2]=J[h>>2];J[f+84>>2]=b;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;i=J[d+28>>2];j=J[d+24>>2];b=K[d+35|0];J[5996]=0;k=d+24|0;d=b<<24>>24<0;d=ba(100,f+80|0,(d?j:k)|0,(d?i:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break gb}J[f+104>>2]=J[d+8>>2];b=J[d+4>>2];J[f+96>>2]=J[d>>2];J[f+100>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=_(97,f+96|0,5242)|0;i=J[5996];J[5996]=0;if((i|0)==1){break fb}j=J[b>>2];J[f+40>>2]=J[b+4>>2];i=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+43|0]=i;H[f+44|0]=i>>>8;H[f+45|0]=i>>>16;H[f+46|0]=i>>>24;J[b>>2]=0;J[b+4>>2]=0;i=K[b+11|0];J[b+8>>2]=0;J[a>>2]=j;J[a+4>>2]=J[f+40>>2];b=K[f+43|0]|K[f+44|0]<<8|(K[f+45|0]<<16|K[f+46|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=i;if(H[d+11|0]<0){$a(J[d>>2]);}if(H[h+11|0]<0){$a(J[h>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+11|0]>=0){break b}$a(J[c>>2]);break b}a=Z()|0;break a}a=Z()|0;break ab}a=Z()|0;break bb}a=Z()|0;break cb}a=Z()|0;break db}a=Z()|0;break eb}a=Z()|0;if(H[f+107|0]>=0){break eb}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break db}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break cb}$a(J[f+64>>2]);}if(H[f+59|0]>=0){break bb}$a(J[f+48>>2]);}if(H[f+35|0]>=0){break ab}$a(J[f+24>>2]);}if(H[f+19|0]>=0){break a}$a(J[f+8>>2]);break a}J[5996]=0;b=_(97,f+116|0,5289)|0;d=J[5996];J[5996]=0;if((d|0)==1){break o}J[f+72>>2]=J[b+8>>2];d=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=f+96|0;aa(119,b|0,c+4|0);d=J[5996];J[5996]=0;if((d|0)==1){break q}J[5996]=0;e=b;b=K[f+107|0];d=b<<24>>24<0;b=ba(100,f- -64|0,(d?J[f+96>>2]:e)|0,(d?J[f+100>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break r}J[f+88>>2]=J[b+8>>2];d=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;lb:{if(H[f+107|0]>=0){break lb}$a(J[f+96>>2]);if(H[b+11|0]>=0){break lb}$a(J[b>>2]);}mb:{nb:{ob:{pb:{qb:{b=J[c+8>>2];d=J[c+12>>2];if((b|0)!=(d|0)){while(1){rb:{if(H[b+11|0]>=0){J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;break rb}c=J[b+4>>2];e=J[b>>2];J[5996]=0;ea(40,f+96|0,e|0,c|0);c=J[5996];J[5996]=0;if((c|0)!=1){break rb}a=Z()|0;break nb}J[5996]=0;H[f+108|0]=1;c=ba(99,f+96|0,0,4354)|0;e=J[5996];J[5996]=0;if((e|0)==1){break qb}J[f+56>>2]=J[c+8>>2];e=J[c+4>>2];J[f+48>>2]=J[c>>2];J[f+52>>2]=e;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;e=K[f+59|0];g=e<<24>>24<0;ba(100,f+80|0,(g?J[f+48>>2]:f+48|0)|0,(g?J[f+52>>2]:e)|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break pb}if(H[f+59|0]<0){$a(J[f+48>>2]);}if(!(!K[f+108|0]|H[f+107|0]>=0)){$a(J[c>>2]);}b=b+12|0;if((d|0)!=(b|0)){continue}break}}J[5996]=0;b=_(97,f+80|0,5242)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break mb}a=Z()|0;break nb}a=Z()|0;break ob}a=Z()|0;if(H[f+59|0]>=0){break ob}$a(J[f+48>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break nb}$a(J[f+96>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}d=J[b>>2];J[f+48>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=c;H[f+52|0]=c>>>8;H[f+53|0]=c>>>16;H[f+54|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a}J[5996]=0;ga(44,2350,2210,725,5107);a=J[5996];J[5996]=0;if((a|0)==1){a=Z()|0;break a}B();}J[5996]=0;b=_(97,f+116|0,5302)|0;g=J[5996];J[5996]=0;sb:{tb:{ub:{vb:{wb:{xb:{yb:{if((g|0)!=1){J[f+88>>2]=J[b+8>>2];g=J[b+4>>2];J[f+80>>2]=J[b>>2];J[f+84>>2]=g;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=f- -64|0;aa(119,b|0,c+4|0);c=J[5996];J[5996]=0;if((c|0)==1){break yb}J[5996]=0;h=b;b=K[f+75|0];c=b<<24>>24<0;b=ba(100,f+80|0,(c?J[f+64>>2]:h)|0,(c?J[f+68>>2]:b)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break xb}J[f+104>>2]=J[b+8>>2];c=J[b+4>>2];J[f+96>>2]=J[b>>2];J[f+100>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;zb:{if(H[f+75|0]>=0){break zb}$a(J[f+64>>2]);if(H[b+11|0]>=0){break zb}$a(J[b>>2]);}if(e){c=P(e,12)+d|0;while(1){J[5996]=0;b=ba(99,d|0,0,4354)|0;d=J[5996];J[5996]=0;if((d|0)==1){break vb}J[f+72>>2]=J[b+8>>2];d=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;d=K[f+75|0];e=d<<24>>24<0;ba(100,f+96|0,(e?J[f+64>>2]:f- -64|0)|0,(e?J[f+68>>2]:d)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break ub}if(H[f+75|0]<0){$a(J[f+64>>2]);}d=b+12|0;if((c|0)!=(d|0)){continue}break}}J[5996]=0;b=_(97,f+96|0,5242)|0;c=J[5996];J[5996]=0;if((c|0)==1){break tb}d=J[b>>2];J[f+64>>2]=J[b+4>>2];c=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+67|0]=c;H[f+68|0]=c>>>8;H[f+69|0]=c>>>16;H[f+70|0]=c>>>24;J[b>>2]=0;J[b+4>>2]=0;c=K[b+11|0];J[b+8>>2]=0;J[a>>2]=d;J[a+4>>2]=J[f+64>>2];b=K[f+67|0]|K[f+68|0]<<8|(K[f+69|0]<<16|K[f+70|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=c;break b}a=Z()|0;break a}a=Z()|0;break wb}a=Z()|0;if(H[f+75|0]>=0){break wb}$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}a=Z()|0;break sb}a=Z()|0;if(H[f+75|0]>=0){break sb}$a(J[f+64>>2]);break sb}a=Z()|0;}if(H[f+107|0]>=0){break a}$a(J[f+96>>2]);break a}a=Z()|0;if(H[f+107|0]>=0){break p}$a(J[f+96>>2]);break p}a=Z()|0;}if(H[f+75|0]>=0){break a}$a(J[f+64>>2]);break a}a=Z()|0;break a}a=Z()|0;}if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}a=Z()|0;}if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}a=Z()|0;}if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}a=Z()|0;}if(H[f+75|0]<0){$a(J[f+64>>2]);}if(H[f+91|0]>=0){break a}$a(J[f+80>>2]);break a}J[5996]=0;H[f+108|0]=1;b=_(97,f+116|0,5315)|0;c=J[5996];J[5996]=0;Ab:{Bb:{Cb:{Db:{if((c|0)!=1){J[f+72>>2]=J[b+8>>2];c=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=K[f+107|0];c=b<<24>>24<0;c=ba(100,f- -64|0,(c?J[f+96>>2]:f+96|0)|0,(c?J[f+100>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Db}J[f+88>>2]=J[c+8>>2];b=J[c+4>>2];J[f+80>>2]=J[c>>2];J[f+84>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+80|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Cb}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[c+11|0]<0){$a(J[c>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break b}$a(J[f+96>>2]);break b}a=Z()|0;break Ab}a=Z()|0;break Bb}a=Z()|0;if(H[f+91|0]>=0){break Bb}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Ab}$a(J[f+64>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break a}$a(J[f+96>>2]);break a}J[5996]=0;H[f+108|0]=1;b=_(97,f+116|0,5283)|0;c=J[5996];J[5996]=0;Eb:{Fb:{Gb:{Hb:{if((c|0)!=1){J[f+72>>2]=J[b+8>>2];c=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=K[f+107|0];c=b<<24>>24<0;c=ba(100,f- -64|0,(c?J[f+96>>2]:f+96|0)|0,(c?J[f+100>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Hb}J[f+88>>2]=J[c+8>>2];b=J[c+4>>2];J[f+80>>2]=J[c>>2];J[f+84>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+80|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Gb}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[c+11|0]<0){$a(J[c>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break b}$a(J[f+96>>2]);break b}a=Z()|0;break Eb}a=Z()|0;break Fb}a=Z()|0;if(H[f+91|0]>=0){break Fb}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Eb}$a(J[f+64>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break a}$a(J[f+96>>2]);break a}J[5996]=0;H[f+108|0]=1;b=_(97,f+116|0,5310)|0;c=J[5996];J[5996]=0;Ib:{Jb:{Kb:{Lb:{if((c|0)!=1){J[f+72>>2]=J[b+8>>2];c=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=K[f+107|0];c=b<<24>>24<0;c=ba(100,f- -64|0,(c?J[f+96>>2]:f+96|0)|0,(c?J[f+100>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Lb}J[f+88>>2]=J[c+8>>2];b=J[c+4>>2];J[f+80>>2]=J[c>>2];J[f+84>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+80|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Kb}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[c+11|0]<0){$a(J[c>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break b}$a(J[f+96>>2]);break b}a=Z()|0;break Ib}a=Z()|0;break Jb}a=Z()|0;if(H[f+91|0]>=0){break Jb}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Ib}$a(J[f+64>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break a}$a(J[f+96>>2]);break a}J[5996]=0;H[f+108|0]=1;b=_(97,f+116|0,5279)|0;c=J[5996];J[5996]=0;Mb:{Nb:{Ob:{Pb:{if((c|0)!=1){J[f+72>>2]=J[b+8>>2];c=J[b+4>>2];J[f+64>>2]=J[b>>2];J[f+68>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;b=K[f+107|0];c=b<<24>>24<0;c=ba(100,f- -64|0,(c?J[f+96>>2]:f+96|0)|0,(c?J[f+100>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Pb}J[f+88>>2]=J[c+8>>2];b=J[c+4>>2];J[f+80>>2]=J[c>>2];J[f+84>>2]=b;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[5996]=0;b=_(97,f+80|0,5242)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ob}e=J[b>>2];J[f+48>>2]=J[b+4>>2];d=K[b+7|0]|K[b+8|0]<<8|(K[b+9|0]<<16|K[b+10|0]<<24);H[f+51|0]=d;H[f+52|0]=d>>>8;H[f+53|0]=d>>>16;H[f+54|0]=d>>>24;J[b>>2]=0;J[b+4>>2]=0;d=K[b+11|0];J[b+8>>2]=0;J[a>>2]=e;J[a+4>>2]=J[f+48>>2];b=K[f+51|0]|K[f+52|0]<<8|(K[f+53|0]<<16|K[f+54|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+12|0]=1;H[a+11|0]=d;if(H[c+11|0]<0){$a(J[c>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break b}$a(J[f+96>>2]);break b}a=Z()|0;break Mb}a=Z()|0;break Nb}a=Z()|0;if(H[f+91|0]>=0){break Nb}$a(J[f+80>>2]);}if(H[f+75|0]>=0){break Mb}$a(J[f+64>>2]);}if(!K[f+108|0]|H[f+107|0]>=0){break a}$a(J[f+96>>2]);break a}if(H[f+127|0]<0){$a(J[f+116>>2]);}Ua=f+128|0;return}if(H[f+127|0]<0){$a(J[f+116>>2]);}da(a|0);B();}function dn(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;h=Ua-112|0;Ua=h;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{switch(J[c>>2]){case 2:f=J[c+8>>2];c=cb(4);J[h+48>>2]=c;b=c+4|0;J[h+56>>2]=b;H[c|0]=2;H[c+1|0]=80;H[c+2|0]=75;H[c+3|0]=98;J[h+52>>2]=b;J[5996]=0;H[h+16|0]=0;d=h+48|0;ea(126,d|0,29,h+16|0);b=J[5996];J[5996]=0;if((b|0)==1){break c}e=J[h+48>>2];c=K[f+11|0];b=c<<24>>24<0;eb(e+4|0,b?J[f>>2]:f,b?J[f+4>>2]:c);H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;J[5996]=0;_(19,a|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){g=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}if(!e){break a}$a(e);break a}if(!e){break d}$a(e);break d;case 3:d=J[c+8>>2];c=cb(3);J[h+48>>2]=c;b=c+3|0;J[h+56>>2]=b;H[c+2|0]=104;H[c|0]=80;H[c+1|0]=75;J[h+52>>2]=b;J[5996]=0;H[h+16|0]=0;ea(126,h+48|0,17,h+16|0);b=J[5996];J[5996]=0;if((b|0)==1){g=Z()|0;a=J[h+48>>2];if(!a){break a}$a(a);break a}f=J[h+48>>2];c=K[d+11|0];b=c<<24>>24<0;eb(f+3|0,b?J[d>>2]:d,b?J[d+4>>2]:c);H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a|0]=2;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=118;H[a+5|0]=169;J[5996]=0;i=_(19,a|0,h+48|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){k:{g=K[i|0]|K[i+1|0]<<8|(K[i+2|0]<<16|K[i+3|0]<<24);e=g-29|0;c=g>>>0<29?g:e;b=c+1|0;d=a+4|0;if(b>>>0>(g>>>0<=28?28:K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24))>>>0){J[5996]=0;aa(124,i|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break k}g=K[i|0]|K[i+1|0]<<8|(K[i+2|0]<<16|K[i+3|0]<<24);e=g-29|0;}b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);a=g>>>0<29;b=c+(a?d:b)|0;eb(b+1|0,b,(a?g:e)-c|0);a=(K[i|0]|K[i+1|0]<<8|(K[i+2|0]<<16|K[i+3|0]<<24))+1|0;H[i|0]=a;H[i+1|0]=a>>>8;H[i+2|0]=a>>>16;H[i+3|0]=a>>>24;H[b|0]=136;if(!f){break d}$a(f);break d}}g=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}if(!f){break a}$a(f);break a;case 4:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;b=J[c+4>>2];J[5996]=0;e=nc(a,b,0);b=J[5996];J[5996]=0;if((b|0)!=1){l:{f=K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24);b=f-29|0;d=f>>>0<29?f:b;c=d+1|0;if(c>>>0>(f>>>0<=28?28:K[e+4|0]|K[e+5|0]<<8|(K[e+6|0]<<16|K[e+7|0]<<24))>>>0){J[5996]=0;aa(124,e|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break l}f=K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24);b=f-29|0;}a=f>>>0<29;c=d+(a?e+4|0:K[e+8|0]|K[e+9|0]<<8|(K[e+10|0]<<16|K[e+11|0]<<24))|0;eb(c+1|0,c,(a?f:b)-d|0);a=(K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24))+1|0;H[e|0]=a;H[e+1|0]=a>>>8;H[e+2|0]=a>>>16;H[e+3|0]=a>>>24;H[c|0]=178;break d}}break b;case 5:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;b=J[c+4>>2];J[5996]=0;e=nc(a,b,0);b=J[5996];J[5996]=0;if((b|0)!=1){m:{f=K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24);b=f-29|0;d=f>>>0<29?f:b;c=d+1|0;if(c>>>0>(f>>>0<=28?28:K[e+4|0]|K[e+5|0]<<8|(K[e+6|0]<<16|K[e+7|0]<<24))>>>0){J[5996]=0;aa(124,e|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break m}f=K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24);b=f-29|0;}a=f>>>0<29;c=d+(a?e+4|0:K[e+8|0]|K[e+9|0]<<8|(K[e+10|0]<<16|K[e+11|0]<<24))|0;eb(c+1|0,c,(a?f:b)-d|0);a=(K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24))+1|0;H[e|0]=a;H[e+1|0]=a>>>8;H[e+2|0]=a>>>16;H[e+3|0]=a>>>24;H[c|0]=177;break d}}break b;case 8:J[h+48>>2]=32;J[h+16>>2]=136;J[h+80>>2]=166;J[h+4>>2]=b?136:135;vd(a,h+48|0,h+16|0,h+80|0,c+20|0,h+4|0);break d;case 7:J[h+48>>2]=32;J[h+16>>2]=136;J[h+80>>2]=170;J[h+4>>2]=b?136:135;vd(a,h+48|0,h+16|0,h+80|0,c+20|0,h+4|0);break d;case 9:J[h+48>>2]=32;J[h+16>>2]=136;J[h+80>>2]=169;J[h+4>>2]=b?136:135;vd(a,h+48|0,h+16|0,h+80|0,c+20|0,h+4|0);break d;case 10:H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+4|0]=107;H[a|0]=1;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);e=-28;f=1;b=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);l=b>>>0<29;n:{j=l?b:b-29|0;b=j+1|0;if(b>>>0>=29){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break n}n=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=f-29|0;}i=a+4|0;b=f>>>0<29;g=(b?i:n)+1|0;eb(j+g|0,g,(b?f:e)-1|0);b=j+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;o:{if(!j){break o}b=l?d+4|0:c;c=j&7;p:{if(!c){f=b;break p}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(j>>>0<8){break o}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}g=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=g-29|0;d=g>>>0<29?g:n;b=d+1|0;if(b>>>0>(g>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break n}g=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=g-29|0;}b=g>>>0<29;c=d+(b?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(c+1|0,c,(b?g:n)-d|0);b=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;H[c|0]=108;break d}break b;case 11:H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+4|0]=124;H[a|0]=1;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);e=-28;f=1;b=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);i=b>>>0<29;q:{l=i?b:b-29|0;b=l+1|0;if(b>>>0>=29){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break q}n=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=f-29|0;}b=f>>>0<29;g=(b?a+4|0:n)+1|0;eb(l+g|0,g,(b?f:e)-1|0);b=l+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;if(!l){break d}a=i?d+4|0:c;b=l&7;r:{if(!b){f=a;break r}d=0;f=a;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((b|0)!=(d|0)){continue}break}}if(l>>>0<8){break d}a=a+l|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((a|0)!=(f|0)){continue}break}break d}break b;case 12:J[h+48>>2]=b?173:172;te(a,d,h+48|0);break d;case 13:H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a|0]=2;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=118;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+5|0]=99;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);e=-27;f=2;b=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);l=b>>>0<29;s:{j=l?b:b-29|0;b=j+2|0;if(b>>>0>=29){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break s}n=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=f-29|0;}i=a+4|0;b=f>>>0<29;g=(b?i:n)+2|0;eb(j+g|0,g,(b?f:e)-2|0);b=j+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;t:{if(!j){break t}b=l?d+4|0:c;c=j&7;u:{if(!c){f=b;break u}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(j>>>0<8){break t}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}g=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=g-29|0;d=g>>>0<29?g:n;b=d+1|0;if(b>>>0>(g>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break s}g=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=g-29|0;}b=g>>>0<29;c=d+(b?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(c+1|0,c,(b?g:n)-d|0);b=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;H[c|0]=104;break d}break b;case 14:b=J[J[J[c+32>>2]>>2]+80>>2];if(!(Wb(1239,1)&(b^-1))){J[h+48>>2]=105;te(a,d,h+48|0);break d}H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;J[h+72>>2]=K[a+28|0]|K[a+29|0]<<8|(K[a+30|0]<<16|K[a+31|0]<<24);b=K[a+24|0]|K[a+25|0]<<8|(K[a+26|0]<<16|K[a+27|0]<<24);c=h- -64|0;J[c>>2]=K[a+20|0]|K[a+21|0]<<8|(K[a+22|0]<<16|K[a+23|0]<<24);J[c+4>>2]=b;b=K[a+16|0]|K[a+17|0]<<8|(K[a+18|0]<<16|K[a+19|0]<<24);J[h+56>>2]=K[a+12|0]|K[a+13|0]<<8|(K[a+14|0]<<16|K[a+15|0]<<24);J[h+60>>2]=b;b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);J[h+48>>2]=K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24);J[h+52>>2]=b;b=K[d+28|0]|K[d+29|0]<<8|(K[d+30|0]<<16|K[d+31|0]<<24);H[a+28|0]=b;H[a+29|0]=b>>>8;H[a+30|0]=b>>>16;H[a+31|0]=b>>>24;e=K[d+24|0]|K[d+25|0]<<8|(K[d+26|0]<<16|K[d+27|0]<<24);b=K[d+20|0]|K[d+21|0]<<8|(K[d+22|0]<<16|K[d+23|0]<<24);H[a+20|0]=b;H[a+21|0]=b>>>8;H[a+22|0]=b>>>16;H[a+23|0]=b>>>24;H[a+24|0]=e;H[a+25|0]=e>>>8;H[a+26|0]=e>>>16;H[a+27|0]=e>>>24;e=K[d+16|0]|K[d+17|0]<<8|(K[d+18|0]<<16|K[d+19|0]<<24);b=K[d+12|0]|K[d+13|0]<<8|(K[d+14|0]<<16|K[d+15|0]<<24);H[a+12|0]=b;H[a+13|0]=b>>>8;H[a+14|0]=b>>>16;H[a+15|0]=b>>>24;H[a+16|0]=e;H[a+17|0]=e>>>8;H[a+18|0]=e>>>16;H[a+19|0]=e>>>24;e=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);b=K[d+4|0]|K[d+5|0]<<8|(K[d+6|0]<<16|K[d+7|0]<<24);H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;H[a+8|0]=e;H[a+9|0]=e>>>8;H[a+10|0]=e>>>16;H[a+11|0]=e>>>24;b=J[h+72>>2];H[d+28|0]=b;H[d+29|0]=b>>>8;H[d+30|0]=b>>>16;H[d+31|0]=b>>>24;e=J[c+4>>2];b=J[c>>2];H[d+20|0]=b;H[d+21|0]=b>>>8;H[d+22|0]=b>>>16;H[d+23|0]=b>>>24;H[d+24|0]=e;H[d+25|0]=e>>>8;H[d+26|0]=e>>>16;H[d+27|0]=e>>>24;c=J[h+60>>2];b=J[h+56>>2];H[d+12|0]=b;H[d+13|0]=b>>>8;H[d+14|0]=b>>>16;H[d+15|0]=b>>>24;H[d+16|0]=c;H[d+17|0]=c>>>8;H[d+18|0]=c>>>16;H[d+19|0]=c>>>24;c=J[h+52>>2];b=J[h+48>>2];H[d+4|0]=b;H[d+5|0]=b>>>8;H[d+6|0]=b>>>16;H[d+7|0]=b>>>24;H[d+8|0]=c;H[d+9|0]=c>>>8;H[d+10|0]=c>>>16;H[d+11|0]=c>>>24;J[a>>2]=J[d>>2];J[d>>2]=0;break d;case 15:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;J[5996]=0;c=_(127,a|0,130)|0;b=J[5996];J[5996]=0;if((b|0)!=1){v:{J[5996]=0;c=_(127,c|0,146)|0;b=J[5996];J[5996]=0;if((b|0)==1){break v}J[5996]=0;k=_(127,c|0,99)|0;b=J[5996];J[5996]=0;if((b|0)==1){break v}e=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);c=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);l=c>>>0<29;f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;j=l?c:c-29|0;i=f>>>0<29?f:b;c=j+i|0;if(c>>>0>(f>>>0<=28?28:K[k+4|0]|K[k+5|0]<<8|(K[k+6|0]<<16|K[k+7|0]<<24))>>>0){J[5996]=0;aa(124,k|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break v}f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?k+4|0:K[k+8|0]|K[k+9|0]<<8|(K[k+10|0]<<16|K[k+11|0]<<24))|0;eb(j+g|0,g,(c?f:b)-i|0);b=j+(K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24))|0;H[k|0]=b;H[k+1|0]=b>>>8;H[k+2|0]=b>>>16;H[k+3|0]=b>>>24;w:{if(!j){break w}b=l?d+4|0:e;c=j&7;x:{if(!c){f=b;break x}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(j>>>0<8){break w}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;_(127,k|0,104)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break d}}}break b;case 16:J[h+48>>2]=146;te(a,d,h+48|0);break d;case 1:H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+4|0]=81;H[a|0]=1;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;break d;case 0:H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+4|0]=0;H[a|0]=1;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;break d;case 17:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);n=-29;b=0;i=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);e=i>>>0<29;y:{l=e?i:i-29|0;if(l>>>0>=29){J[5996]=0;aa(124,a|0,l+(l>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break y}f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=f-29|0;b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);}i=a+4|0;k=b;b=f>>>0<29;g=b?i:k;eb(l+g|0,g,b?f:n);b=l+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;z:{if(!l){break z}b=e?d+4|0:c;c=l&7;A:{if(!c){f=b;break A}n=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(l>>>0<8){break z}b=b+l|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}c=K[d+40|0]|K[d+41|0]<<8|(K[d+42|0]<<16|K[d+43|0]<<24);b=K[d+32|0]|K[d+33|0]<<8|(K[d+34|0]<<16|K[d+35|0]<<24);j=b>>>0<29;f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=f-29|0;k=j?b:b-29|0;l=f>>>0<29?f:e;b=k+l|0;if(b>>>0>(f>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){J[5996]=0;aa(124,a|0,b+(b>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break y}f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=f-29|0;}b=f>>>0<29;g=l+(b?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(k+g|0,g,(b?f:e)-l|0);b=k+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;if(!k){break d}a=j?d+36|0:c;b=k&7;B:{if(!b){f=a;break B}d=0;f=a;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((b|0)!=(d|0)){continue}break}}if(k>>>0<8){break d}a=a+k|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((a|0)!=(f|0)){continue}break}break d}break b;case 18:J[h+48>>2]=154;se(a,d,d+32|0,h+48|0);break d;case 19:J[h+48>>2]=155;se(a,d,d+32|0,h+48|0);break d;case 21:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);n=-29;b=0;i=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);e=i>>>0<29;i=e?i:i-29|0;C:{if(i>>>0>=29){J[5996]=0;aa(124,a|0,i+(i>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break C}f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=f-29|0;b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);}j=a+4|0;k=b;b=f>>>0<29;g=b?j:k;eb(i+g|0,g,b?f:n);b=i+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;D:{if(!i){break D}b=e?d+4|0:c;c=i&7;E:{if(!c){f=b;break E}n=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(i>>>0<8){break D}b=b+i|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;c=_(127,a|0,115)|0;b=J[5996];J[5996]=0;if((b|0)==1){break C}J[5996]=0;m=_(127,c|0,100)|0;b=J[5996];J[5996]=0;if((b|0)==1){break C}e=K[d+40|0]|K[d+41|0]<<8|(K[d+42|0]<<16|K[d+43|0]<<24);c=K[d+32|0]|K[d+33|0]<<8|(K[d+34|0]<<16|K[d+35|0]<<24);l=c>>>0<29;f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;k=l?c:c-29|0;i=f>>>0<29?f:b;c=k+i|0;if(c>>>0>(f>>>0<=28?28:K[j|0]|K[j+1|0]<<8|(K[j+2|0]<<16|K[j+3|0]<<24))>>>0){J[5996]=0;aa(124,m|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break C}f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?j:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(k+g|0,g,(c?f:b)-i|0);b=k+(K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24))|0;H[m|0]=b;H[m+1|0]=b>>>8;H[m+2|0]=b>>>16;H[m+3|0]=b>>>24;F:{if(!k){break F}b=l?d+36|0:e;c=k&7;G:{if(!c){f=b;break G}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(k>>>0<8){break F}b=b+k|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;_(127,m|0,104)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break d}}break b;case 20:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);n=-29;b=0;i=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);e=i>>>0<29;i=e?i:i-29|0;H:{if(i>>>0>=29){J[5996]=0;aa(124,a|0,i+(i>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break H}f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=f-29|0;b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);}j=a+4|0;k=b;b=f>>>0<29;g=b?j:k;eb(i+g|0,g,b?f:n);b=i+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;I:{if(!i){break I}b=e?d+4|0:c;c=i&7;J:{if(!c){f=b;break J}n=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(i>>>0<8){break I}b=b+i|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;m=_(127,a|0,100)|0;b=J[5996];J[5996]=0;if((b|0)==1){break H}e=K[d+40|0]|K[d+41|0]<<8|(K[d+42|0]<<16|K[d+43|0]<<24);c=K[d+32|0]|K[d+33|0]<<8|(K[d+34|0]<<16|K[d+35|0]<<24);l=c>>>0<29;f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;k=l?c:c-29|0;i=f>>>0<29?f:b;c=k+i|0;if(c>>>0>(f>>>0<=28?28:K[j|0]|K[j+1|0]<<8|(K[j+2|0]<<16|K[j+3|0]<<24))>>>0){J[5996]=0;aa(124,m|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break H}f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?j:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(k+g|0,g,(c?f:b)-i|0);b=k+(K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24))|0;H[m|0]=b;H[m+1|0]=b>>>8;H[m+2|0]=b>>>16;H[m+3|0]=b>>>24;K:{if(!k){break K}b=l?d+36|0:e;c=k&7;L:{if(!c){f=b;break L}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(k>>>0<8){break K}b=b+k|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;_(127,m|0,104)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break d}}break b;case 22:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;J[5996]=0;k=_(127,a|0,99)|0;b=J[5996];J[5996]=0;if((b|0)!=1){M:{e=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);c=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);l=c>>>0<29;f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;j=l?c:c-29|0;i=f>>>0<29?f:b;c=j+i|0;if(c>>>0>(f>>>0<=28?28:K[k+4|0]|K[k+5|0]<<8|(K[k+6|0]<<16|K[k+7|0]<<24))>>>0){J[5996]=0;aa(124,k|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break M}f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?k+4|0:K[k+8|0]|K[k+9|0]<<8|(K[k+10|0]<<16|K[k+11|0]<<24))|0;eb(j+g|0,g,(c?f:b)-i|0);b=j+(K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24))|0;H[k|0]=b;H[k+1|0]=b>>>8;H[k+2|0]=b>>>16;H[k+3|0]=b>>>24;N:{if(!j){break N}b=l?d+4|0:e;c=j&7;O:{if(!c){f=b;break O}f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(j>>>0<8){break N}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;k=_(127,k|0,103)|0;b=J[5996];J[5996]=0;if((b|0)==1){break M}e=K[d+40|0]|K[d+41|0]<<8|(K[d+42|0]<<16|K[d+43|0]<<24);c=K[d+32|0]|K[d+33|0]<<8|(K[d+34|0]<<16|K[d+35|0]<<24);l=c>>>0<29;f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;j=l?c:c-29|0;i=f>>>0<29?f:b;c=j+i|0;if(c>>>0>(f>>>0<=28?28:K[k+4|0]|K[k+5|0]<<8|(K[k+6|0]<<16|K[k+7|0]<<24))>>>0){J[5996]=0;aa(124,k|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break M}f=K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?k+4|0:K[k+8|0]|K[k+9|0]<<8|(K[k+10|0]<<16|K[k+11|0]<<24))|0;eb(j+g|0,g,(c?f:b)-i|0);b=j+(K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24))|0;H[k|0]=b;H[k+1|0]=b>>>8;H[k+2|0]=b>>>16;H[k+3|0]=b>>>24;P:{if(!j){break P}b=l?d+36|0:e;c=j&7;Q:{if(!c){f=b;break Q}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(j>>>0<8){break P}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;_(127,k|0,104)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break d}}}break b;case 23:H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;c=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);n=-29;b=0;i=K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24);e=i>>>0<29;i=e?i:i-29|0;R:{if(i>>>0>=29){J[5996]=0;aa(124,a|0,i+(i>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break R}f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=f-29|0;b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);}k=a+4|0;m=b;b=f>>>0<29;g=b?k:m;eb(i+g|0,g,b?f:n);b=i+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;S:{if(!i){break S}b=e?d+4|0:c;c=i&7;T:{if(!c){f=b;break T}n=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(i>>>0<8){break S}b=b+i|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;m=_(127,a|0,100)|0;b=J[5996];J[5996]=0;if((b|0)==1){break R}e=K[d+72|0]|K[d+73|0]<<8|(K[d+74|0]<<16|K[d+75|0]<<24);c=K[d+64|0]|K[d+65|0]<<8|(K[d+66|0]<<16|K[d+67|0]<<24);l=c>>>0<29;f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;j=l?c:c-29|0;i=f>>>0<29?f:b;c=j+i|0;if(c>>>0>(f>>>0<=28?28:K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24))>>>0){J[5996]=0;aa(124,m|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break R}f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?k:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(j+g|0,g,(c?f:b)-i|0);b=j+(K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24))|0;H[m|0]=b;H[m+1|0]=b>>>8;H[m+2|0]=b>>>16;H[m+3|0]=b>>>24;U:{if(!j){break U}b=l?d+68|0:e;c=j&7;V:{if(!c){f=b;break V}n=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;n=n+1|0;if((c|0)!=(n|0)){continue}break}}if(j>>>0<8){break U}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;m=_(127,m|0,103)|0;b=J[5996];J[5996]=0;if((b|0)==1){break R}e=K[d+40|0]|K[d+41|0]<<8|(K[d+42|0]<<16|K[d+43|0]<<24);c=K[d+32|0]|K[d+33|0]<<8|(K[d+34|0]<<16|K[d+35|0]<<24);l=c>>>0<29;f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;j=l?c:c-29|0;i=f>>>0<29?f:b;c=j+i|0;if(c>>>0>(f>>>0<=28?28:K[k|0]|K[k+1|0]<<8|(K[k+2|0]<<16|K[k+3|0]<<24))>>>0){J[5996]=0;aa(124,m|0,c+(c>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break R}f=K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24);b=f-29|0;}c=f>>>0<29;g=i+(c?k:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(j+g|0,g,(c?f:b)-i|0);b=j+(K[m|0]|K[m+1|0]<<8|(K[m+2|0]<<16|K[m+3|0]<<24))|0;H[m|0]=b;H[m+1|0]=b>>>8;H[m+2|0]=b>>>16;H[m+3|0]=b>>>24;W:{if(!j){break W}b=l?d+36|0:e;c=j&7;X:{if(!c){f=b;break X}d=0;f=b;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((c|0)!=(d|0)){continue}break}}if(j>>>0<8){break W}b=b+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((b|0)!=(f|0)){continue}break}}J[5996]=0;_(127,m|0,104)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break d}}break b;case 25:J[h+72>>2]=0;J[h+76>>2]=0;d=h- -64|0;J[d>>2]=0;J[d+4>>2]=0;J[h+56>>2]=0;J[h+60>>2]=0;J[h+48>>2]=0;J[h+52>>2]=0;d=J[c+4>>2];J[5996]=0;o=nc(h+48|0,d,0);d=J[5996];J[5996]=0;if((d|0)==1){g=Z()|0;if(M[h+48>>2]<29){break a}$a(J[h+56>>2]);break a}e=J[c+8>>2];m=J[c+12>>2];if((e|0)==(m|0)){c=e;break g}l=o+4|0;i=h+20|0;while(1){Y:{J[5996]=0;f=$(3,4)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Y}J[h+4>>2]=f;d=f+4|0;J[h+12>>2]=d;H[f|0]=2;H[f+1|0]=80;H[f+2|0]=75;H[f+3|0]=98;J[h+8>>2]=d;J[5996]=0;H[h+80|0]=0;ea(126,h+4|0,29,h+80|0);d=J[5996];J[5996]=0;if((d|0)==1){g=Z()|0;a=J[h+4>>2];if(!a){break f}$a(a);break f}d=0;j=K[e+11|0];f=j<<24>>24<0;eb(J[h+4>>2]+4|0,f?J[e>>2]:e,f?J[e+4>>2]:j);J[h+40>>2]=0;J[h+44>>2]=0;J[h+32>>2]=0;J[h+36>>2]=0;J[h+24>>2]=0;J[h+28>>2]=0;J[h+16>>2]=0;J[h+20>>2]=0;n=-29;j=J[o+8>>2];f=0;p=J[o>>2];k=p>>>0<29;p=k?p:p-29|0;if(p>>>0>=29){J[5996]=0;aa(124,h+16|0,p+(p>>>1|0)|0);d=J[5996];J[5996]=0;if((d|0)==1){break i}f=J[h+16>>2];n=f-29|0;g=J[h+24>>2];}else {g=d;}d=f>>>0<29;g=d?i:g;eb(g+p|0,g,d?f:n);J[h+16>>2]=p+J[h+16>>2];Z:{if(!p){break Z}d=0;k=k?l:j;f=k;j=p&7;if(j){while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}}if(p>>>0<8){break Z}d=k+p|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((d|0)!=(f|0)){continue}break}}J[5996]=0;f=_(19,h+16|0,h+4|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break i}J[h+104>>2]=K[l+24|0]|K[l+25|0]<<8|(K[l+26|0]<<16|K[l+27|0]<<24);d=K[l+20|0]|K[l+21|0]<<8|(K[l+22|0]<<16|K[l+23|0]<<24);J[h+96>>2]=K[l+16|0]|K[l+17|0]<<8|(K[l+18|0]<<16|K[l+19|0]<<24);J[h+100>>2]=d;d=K[l+12|0]|K[l+13|0]<<8|(K[l+14|0]<<16|K[l+15|0]<<24);J[h+88>>2]=K[l+8|0]|K[l+9|0]<<8|(K[l+10|0]<<16|K[l+11|0]<<24);J[h+92>>2]=d;d=K[l+4|0]|K[l+5|0]<<8|(K[l+6|0]<<16|K[l+7|0]<<24);J[h+80>>2]=K[l|0]|K[l+1|0]<<8|(K[l+2|0]<<16|K[l+3|0]<<24);J[h+84>>2]=d;J[l+24>>2]=J[i+24>>2];d=J[i+20>>2];J[l+16>>2]=J[i+16>>2];J[l+20>>2]=d;d=J[i+12>>2];J[l+8>>2]=J[i+8>>2];J[l+12>>2]=d;d=J[i+4>>2];J[l>>2]=J[i>>2];J[l+4>>2]=d;d=J[h+104>>2];H[i+24|0]=d;H[i+25|0]=d>>>8;H[i+26|0]=d>>>16;H[i+27|0]=d>>>24;j=J[h+100>>2];d=J[h+96>>2];H[i+16|0]=d;H[i+17|0]=d>>>8;H[i+18|0]=d>>>16;H[i+19|0]=d>>>24;H[i+20|0]=j;H[i+21|0]=j>>>8;H[i+22|0]=j>>>16;H[i+23|0]=j>>>24;j=J[h+92>>2];d=J[h+88>>2];H[i+8|0]=d;H[i+9|0]=d>>>8;H[i+10|0]=d>>>16;H[i+11|0]=d>>>24;H[i+12|0]=j;H[i+13|0]=j>>>8;H[i+14|0]=j>>>16;H[i+15|0]=j>>>24;j=J[h+84>>2];d=J[h+80>>2];H[i|0]=d;H[i+1|0]=d>>>8;H[i+2|0]=d>>>16;H[i+3|0]=d>>>24;H[i+4|0]=j;H[i+5|0]=j>>>8;H[i+6|0]=j>>>16;H[i+7|0]=j>>>24;d=J[o>>2];J[o>>2]=J[f>>2];J[f>>2]=d;if(d>>>0>=29){$a(J[h+24>>2]);J[h+24>>2]=0;}d=J[h+4>>2];if(d){$a(d);}e=e+12|0;if((m|0)!=(e|0)){continue}break h}break}g=Z()|0;break f;case 24:J[h+72>>2]=0;J[h+76>>2]=0;f=h- -64|0;J[f>>2]=0;J[f+4>>2]=0;J[h+56>>2]=0;J[h+60>>2]=0;J[h+48>>2]=0;J[h+52>>2]=0;n=J[h+76>>2];J[h+40>>2]=n;k=J[h+72>>2];f=J[h+68>>2];m=f;J[h+32>>2]=f;J[h+36>>2]=k;j=J[h+64>>2];i=J[h+60>>2];J[h+24>>2]=i;J[h+28>>2]=j;l=J[h+56>>2];f=J[h+52>>2];J[h+16>>2]=f;J[h+20>>2]=l;J[h+76>>2]=K[d+28|0]|K[d+29|0]<<8|(K[d+30|0]<<16|K[d+31|0]<<24);o=K[d+24|0]|K[d+25|0]<<8|(K[d+26|0]<<16|K[d+27|0]<<24);J[h+68>>2]=K[d+20|0]|K[d+21|0]<<8|(K[d+22|0]<<16|K[d+23|0]<<24);J[h+72>>2]=o;o=K[d+16|0]|K[d+17|0]<<8|(K[d+18|0]<<16|K[d+19|0]<<24);J[h+60>>2]=K[d+12|0]|K[d+13|0]<<8|(K[d+14|0]<<16|K[d+15|0]<<24);J[h+64>>2]=o;o=K[d+8|0]|K[d+9|0]<<8|(K[d+10|0]<<16|K[d+11|0]<<24);J[h+52>>2]=K[d+4|0]|K[d+5|0]<<8|(K[d+6|0]<<16|K[d+7|0]<<24);J[h+56>>2]=o;H[d+28|0]=n;H[d+29|0]=n>>>8;H[d+30|0]=n>>>16;H[d+31|0]=n>>>24;H[d+20|0]=m;H[d+21|0]=m>>>8;H[d+22|0]=m>>>16;H[d+23|0]=m>>>24;H[d+24|0]=k;H[d+25|0]=k>>>8;H[d+26|0]=k>>>16;H[d+27|0]=k>>>24;H[d+12|0]=i;H[d+13|0]=i>>>8;H[d+14|0]=i>>>16;H[d+15|0]=i>>>24;H[d+16|0]=j;H[d+17|0]=j>>>8;H[d+18|0]=j>>>16;H[d+19|0]=j>>>24;H[d+4|0]=f;H[d+5|0]=f>>>8;H[d+6|0]=f>>>16;H[d+7|0]=f>>>24;H[d+8|0]=l;H[d+9|0]=l>>>8;H[d+10|0]=l>>>16;H[d+11|0]=l>>>24;g=J[d>>2];J[h+48>>2]=g;J[d>>2]=0;j=h+48|4;_:{$:{if(e>>>0>=2){n=1;while(1){J[5996]=0;J[h+4>>2]=147;ga(128,h+16|0,h+48|0,(n<<5)+d|0,h+4|0);f=J[5996];J[5996]=0;if((f|0)==1){break $}J[h+104>>2]=K[j+24|0]|K[j+25|0]<<8|(K[j+26|0]<<16|K[j+27|0]<<24);f=K[j+20|0]|K[j+21|0]<<8|(K[j+22|0]<<16|K[j+23|0]<<24);J[h+96>>2]=K[j+16|0]|K[j+17|0]<<8|(K[j+18|0]<<16|K[j+19|0]<<24);J[h+100>>2]=f;f=K[j+12|0]|K[j+13|0]<<8|(K[j+14|0]<<16|K[j+15|0]<<24);J[h+88>>2]=K[j+8|0]|K[j+9|0]<<8|(K[j+10|0]<<16|K[j+11|0]<<24);J[h+92>>2]=f;f=K[j+4|0]|K[j+5|0]<<8|(K[j+6|0]<<16|K[j+7|0]<<24);J[h+80>>2]=K[j|0]|K[j+1|0]<<8|(K[j+2|0]<<16|K[j+3|0]<<24);J[h+84>>2]=f;J[j+24>>2]=J[h+44>>2];f=J[h+40>>2];J[j+16>>2]=J[h+36>>2];J[j+20>>2]=f;f=J[h+32>>2];J[j+8>>2]=J[h+28>>2];J[j+12>>2]=f;f=J[h+24>>2];J[j>>2]=J[h+20>>2];J[j+4>>2]=f;f=J[h+104>>2];H[h+44|0]=f;H[h+45|0]=f>>>8;H[h+46|0]=f>>>16;H[h+47|0]=f>>>24;i=J[h+100>>2];f=J[h+96>>2];H[h+36|0]=f;H[h+37|0]=f>>>8;H[h+38|0]=f>>>16;H[h+39|0]=f>>>24;H[h+40|0]=i;H[h+41|0]=i>>>8;H[h+42|0]=i>>>16;H[h+43|0]=i>>>24;i=J[h+92>>2];f=J[h+88>>2];H[h+28|0]=f;H[h+29|0]=f>>>8;H[h+30|0]=f>>>16;H[h+31|0]=f>>>24;H[h+32|0]=i;H[h+33|0]=i>>>8;H[h+34|0]=i>>>16;H[h+35|0]=i>>>24;i=J[h+84>>2];f=J[h+80>>2];H[h+20|0]=f;H[h+21|0]=f>>>8;H[h+22|0]=f>>>16;H[h+23|0]=f>>>24;H[h+24|0]=i;H[h+25|0]=i>>>8;H[h+26|0]=i>>>16;H[h+27|0]=i>>>24;f=J[h+48>>2];J[h+48>>2]=J[h+16>>2];J[h+16>>2]=f;if(f>>>0>=29){$a(J[h+24>>2]);}n=n+1|0;if((n|0)!=(e|0)){continue}break}g=J[h+48>>2];}H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;n=-29;i=J[h+56>>2];d=0;aa:{k=a+4|0;f=g>>>0<29;l=f?g:g-29|0;ba:{if(l>>>0>=29){J[5996]=0;aa(124,a|0,l+(l>>>1|0)|0);d=J[5996];J[5996]=0;if((d|0)==1){break ba}d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);n=d-29|0;p=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);}e=d>>>0<29;g=e?k:p;eb(g+l|0,g,e?d:n);d=l+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=d;H[a+1|0]=d>>>8;H[a+2|0]=d>>>16;H[a+3|0]=d>>>24;ca:{if(!l){break ca}e=f?j:i;i=l&7;da:{if(!i){f=e;break da}d=0;f=e;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((i|0)!=(d|0)){continue}break}}if(l>>>0<8){break ca}d=e+l|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((d|0)!=(f|0)){continue}break}}c=J[c+4>>2];J[5996]=0;d=nc(a,c,0);c=J[5996];J[5996]=0;if((c|0)==1){break ba}J[5996]=0;_(127,d|0,(b?136:135)|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break aa}}g=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0<29){break _}$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;break _}if(M[h+48>>2]<29){break d}$a(J[h+56>>2]);break d}g=Z()|0;}if(M[h+48>>2]<29){break a}$a(J[h+56>>2]);break a;default:la(2350,2210,624,5107);B();case 6:break j}}J[h+48>>2]=32;J[h+16>>2]=136;J[h+80>>2]=168;J[h+4>>2]=b?136:135;vd(a,h+48|0,h+16|0,h+80|0,c+20|0,h+4|0);break d}g=Z()|0;if(M[h+16>>2]>=29){$a(J[h+24>>2]);J[h+24>>2]=0;}a=J[h+4>>2];if(!a){break f}$a(a);break f}e=J[c+8>>2];c=J[c+12>>2];}H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;l=J[o+8>>2];d=-29;i=(c-e|0)/12|0;n=0;f=0;c=J[o>>2];e=c>>>0<29;j=e?c:c-29|0;ea:{if(j>>>0>=29){J[5996]=0;aa(124,a|0,j+(j>>>1|0)|0);c=J[5996];J[5996]=0;if((c|0)==1){break ea}n=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);f=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=f-29|0;}c=f>>>0<29;g=c?a+4|0:n;eb(j+g|0,g,c?f:d);c=j+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;fa:{if(!j){break fa}c=e?o+4|0:l;e=j&7;ga:{if(!e){f=c;break ga}d=0;f=c;while(1){H[g|0]=K[f|0];f=f+1|0;g=g+1|0;d=d+1|0;if((e|0)!=(d|0)){continue}break}}if(j>>>0<8){break fa}c=c+j|0;while(1){H[g|0]=K[f|0];H[g+1|0]=K[f+1|0];H[g+2|0]=K[f+2|0];H[g+3|0]=K[f+3|0];H[g+4|0]=K[f+4|0];H[g+5|0]=K[f+5|0];H[g+6|0]=K[f+6|0];H[g+7|0]=K[f+7|0];g=g+8|0;f=f+8|0;if((c|0)!=(f|0)){continue}break}}J[5996]=0;d=nc(a,i,0);c=J[5996];J[5996]=0;if((c|0)==1){break ea}J[5996]=0;_(127,d|0,(b?175:174)|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break e}}g=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0<29){break f}$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}if(M[o>>2]<29){break a}$a(J[o+8>>2]);break a}if(M[o>>2]<29){break d}$a(J[o+8>>2]);}Ua=h+112|0;return}g=Z()|0;a=J[h+48>>2];if(!a){break a}$a(a);break a}g=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0<29){break a}$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}da(g|0);B();}function Um(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;c=Ua-496|0;Ua=c;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{E:{F:{G:{H:{I:{J:{K:{L:{M:{N:{O:{P:{Q:{R:{S:{T:{U:{V:{W:{X:{Y:{e=J[b>>2];switch(J[e>>2]-1|0){case 23:break z;case 22:break A;case 21:break B;case 20:break C;case 19:break D;case 18:break E;case 17:break F;case 16:break G;case 14:break H;case 15:break I;case 13:break J;case 12:break K;case 11:break L;case 10:break M;case 9:break N;case 0:break O;case 8:break Q;case 6:break R;case 7:break S;case 5:break T;case 3:break U;case 4:break V;case 24:break W;case 2:break X;case 1:break Y;default:break P}}e=J[e+8>>2];Z:{if(H[e+11|0]>=0){J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;break Z}Zc(c+448|0,J[e>>2],J[e+4>>2]);}J[5996]=0;H[c+460|0]=1;e=ba(99,c+448|0,0,5283)|0;d=J[5996];J[5996]=0;_:{$:{aa:{ba:{if((d|0)!=1){J[c+472>>2]=J[e+8>>2];d=J[e+4>>2];J[c+464>>2]=J[e>>2];J[c+468>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+464|0,5242)|0;f=J[5996];J[5996]=0;if((f|0)==1){break ba}J[c+488>>2]=J[d+8>>2];f=J[d+4>>2];J[c+480>>2]=J[d>>2];J[c+484>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;ea(161,a|0,b|0,c+480|0);a=J[5996];J[5996]=0;if((a|0)==1){break aa}if(H[c+491|0]<0){$a(J[c+480>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(!K[c+460|0]|H[e+11|0]>=0){break y}$a(J[e>>2]);break y}b=Z()|0;break _}b=Z()|0;break $}b=Z()|0;if(H[c+491|0]>=0){break $}$a(J[c+480>>2]);}if(H[c+475|0]>=0){break _}$a(J[c+464>>2]);}break c}e=J[e+8>>2];ca:{if(H[e+11|0]>=0){J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;break ca}Zc(c+448|0,J[e>>2],J[e+4>>2]);}J[5996]=0;H[c+460|0]=1;e=ba(99,c+448|0,0,5315)|0;d=J[5996];J[5996]=0;da:{ea:{fa:{ga:{if((d|0)!=1){J[c+472>>2]=J[e+8>>2];d=J[e+4>>2];J[c+464>>2]=J[e>>2];J[c+468>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+464|0,5242)|0;f=J[5996];J[5996]=0;if((f|0)==1){break ga}J[c+440>>2]=J[d+8>>2];f=J[d+4>>2];J[c+432>>2]=J[d>>2];J[c+436>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;ea(161,a|0,b|0,c+432|0);a=J[5996];J[5996]=0;if((a|0)==1){break fa}if(H[c+443|0]<0){$a(J[c+432>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(!K[c+460|0]|H[e+11|0]>=0){break y}$a(J[e>>2]);break y}b=Z()|0;break da}b=Z()|0;break ea}b=Z()|0;if(H[c+443|0]>=0){break ea}$a(J[c+432>>2]);}if(H[c+475|0]>=0){break da}$a(J[c+464>>2]);}break c}d=c+384|0;Kc(d,J[e+4>>2]);J[5996]=0;e=ba(99,d|0,0,5289)|0;d=J[5996];J[5996]=0;ha:{ia:{ja:{ka:{la:{ma:{na:{oa:{pa:{qa:{if((d|0)!=1){J[c+408>>2]=J[e+8>>2];d=J[e+4>>2];J[c+400>>2]=J[e>>2];J[c+404>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+400|0,5417)|0;f=J[5996];J[5996]=0;if((f|0)==1){break qa}J[c+472>>2]=J[d+8>>2];f=J[d+4>>2];J[c+464>>2]=J[d>>2];J[c+468>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;f=J[b>>2];g=J[f+12>>2];f=J[f+8>>2];J[5996]=0;h=c+368|0;aa(115,h|0,(g-f|0)/12|0);f=J[5996];J[5996]=0;if((f|0)==1){break pa}J[5996]=0;f=K[c+379|0];g=f<<24>>24<0;f=ba(100,c+464|0,(g?J[c+368>>2]:h)|0,(g?J[c+372>>2]:f)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break oa}J[c+456>>2]=J[f+8>>2];g=J[f+4>>2];J[c+448>>2]=J[f>>2];J[c+452>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;J[5996]=0;g=_(97,c+448|0,5242)|0;h=J[5996];J[5996]=0;if((h|0)==1){break na}J[c+424>>2]=J[g+8>>2];h=J[g+4>>2];J[c+416>>2]=J[g>>2];J[c+420>>2]=h;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;ea(161,a|0,b|0,c+416|0);a=J[5996];J[5996]=0;if((a|0)==1){break ma}if(H[c+427|0]<0){$a(J[c+416>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[c+379|0]<0){$a(J[c+368>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]>=0){break y}$a(J[e>>2]);break y}b=Z()|0;break ha}b=Z()|0;break ia}b=Z()|0;break ja}b=Z()|0;break ka}b=Z()|0;break la}b=Z()|0;if(H[c+427|0]>=0){break la}$a(J[c+416>>2]);}if(H[c+459|0]>=0){break ka}$a(J[c+448>>2]);}if(H[c+379|0]>=0){break ja}$a(J[c+368>>2]);}if(H[c+475|0]>=0){break ia}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break ha}$a(J[c+400>>2]);}if(H[c+395|0]>=0){break a}$a(J[c+384>>2]);break a}d=c+464|0;Kc(d,J[e+4>>2]);J[5996]=0;e=ba(99,d|0,0,5258)|0;d=J[5996];J[5996]=0;ra:{sa:{ta:{ua:{if((d|0)!=1){J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+448|0,5242)|0;f=J[5996];J[5996]=0;if((f|0)==1){break ua}J[c+360>>2]=J[d+8>>2];f=J[d+4>>2];J[c+352>>2]=J[d>>2];J[c+356>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;ea(161,a|0,b|0,c+352|0);a=J[5996];J[5996]=0;if((a|0)==1){break ta}if(H[c+363|0]<0){$a(J[c+352>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]>=0){break y}$a(J[e>>2]);break y}b=Z()|0;break ra}b=Z()|0;break sa}b=Z()|0;if(H[c+363|0]>=0){break sa}$a(J[c+352>>2]);}if(H[c+459|0]>=0){break ra}$a(J[c+448>>2]);}break b}d=c+464|0;Kc(d,J[e+4>>2]);J[5996]=0;e=ba(99,d|0,0,5265)|0;d=J[5996];J[5996]=0;va:{wa:{xa:{ya:{if((d|0)!=1){J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+448|0,5242)|0;f=J[5996];J[5996]=0;if((f|0)==1){break ya}J[c+344>>2]=J[d+8>>2];f=J[d+4>>2];J[c+336>>2]=J[d>>2];J[c+340>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;ea(161,a|0,b|0,c+336|0);a=J[5996];J[5996]=0;if((a|0)==1){break xa}if(H[c+347|0]<0){$a(J[c+336>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]>=0){break y}$a(J[e>>2]);break y}b=Z()|0;break va}b=Z()|0;break wa}b=Z()|0;if(H[c+347|0]>=0){break wa}$a(J[c+336>>2]);}if(H[c+459|0]>=0){break va}$a(J[c+448>>2]);}break b}H[c+328|0]=0;J[c+320>>2]=845244531;J[c+324>>2]=690501173;H[c+331|0]=8;J[5996]=0;ea(161,a|0,b|0,c+320|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+331|0]>=0){break y}$a(J[c+320>>2]);break y}b=Z()|0;if(H[c+331|0]>=0){break a}$a(J[c+320>>2]);break a}e=cb(16);J[c+308>>2]=e;J[c+312>>2]=11;J[c+316>>2]=-2147483632;d=K[5239]|K[5240]<<8|(K[5241]<<16|K[5242]<<24);H[e+7|0]=d;H[e+8|0]=d>>>8;H[e+9|0]=d>>>16;H[e+10|0]=d>>>24;d=K[5236]|K[5237]<<8|(K[5238]<<16|K[5239]<<24);f=K[5232]|K[5233]<<8|(K[5234]<<16|K[5235]<<24);H[e|0]=f;H[e+1|0]=f>>>8;H[e+2|0]=f>>>16;H[e+3|0]=f>>>24;H[e+4|0]=d;H[e+5|0]=d>>>8;H[e+6|0]=d>>>16;H[e+7|0]=d>>>24;H[e+11|0]=0;J[5996]=0;ea(161,a|0,b|0,c+308|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+319|0]>=0){break y}$a(J[c+308>>2]);break y}b=Z()|0;if(H[c+319|0]>=0){break a}$a(J[c+308>>2]);break a}H[c+304|0]=K[5220];H[c+307|0]=9;H[c+305|0]=0;J[5996]=0;e=K[5216]|K[5217]<<8|(K[5218]<<16|K[5219]<<24);J[c+296>>2]=K[5212]|K[5213]<<8|(K[5214]<<16|K[5215]<<24);J[c+300>>2]=e;ea(161,a|0,b|0,c+296|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+307|0]>=0){break y}$a(J[c+296>>2]);break y}b=Z()|0;if(H[c+307|0]>=0){break a}$a(J[c+296>>2]);break a}H[c+288|0]=K[5230];H[c+291|0]=9;H[c+289|0]=0;J[5996]=0;e=K[5226]|K[5227]<<8|(K[5228]<<16|K[5229]<<24);J[c+280>>2]=K[5222]|K[5223]<<8|(K[5224]<<16|K[5225]<<24);J[c+284>>2]=e;ea(161,a|0,b|0,c+280|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+291|0]>=0){break y}$a(J[c+280>>2]);break y}b=Z()|0;if(H[c+291|0]>=0){break a}$a(J[c+280>>2]);break a}H[c+272|0]=K[2354];H[c+279|0]=5;H[c+273|0]=0;J[5996]=0;J[c+268>>2]=K[2350]|K[2351]<<8|(K[2352]<<16|K[2353]<<24);ea(161,a|0,b|0,c+268|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+279|0]>=0){break y}$a(J[c+268>>2]);break y}b=Z()|0;if(H[c+279|0]>=0){break a}$a(J[c+268>>2]);break a}H[c+260|0]=0;J[c+256>>2]=1702195828;H[c+267|0]=4;J[5996]=0;ea(161,a|0,b|0,c+256|0);a=J[5996];J[5996]=0;if((a|0)!=1){if(H[c+267|0]>=0){break y}$a(J[c+256>>2]);break y}b=Z()|0;if(H[c+267|0]>=0){break a}$a(J[c+256>>2]);break a}H[c+255|0]=2;H[c+246|0]=0;I[c+244>>1]=14945;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+244|0);d=J[5996];J[5996]=0;za:{Aa:{Ba:{Ca:{Da:{Ea:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ea}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break Da}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ca}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;Fa:{if(H[c+411|0]>=0){break Fa}$a(J[c+400>>2]);if(H[b+11|0]>=0){break Fa}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+255|0]>=0){break y}$a(J[c+244>>2]);break y}b=Z()|0;break za}b=Z()|0;break Aa}b=Z()|0;break Ba}b=Z()|0;if(H[c+411|0]>=0){break Ba}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break Aa}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break za}$a(J[c+464>>2]);}if(H[c+255|0]>=0){break a}$a(J[c+244>>2]);break a}H[c+243|0]=2;H[c+234|0]=0;I[c+232>>1]=14963;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+232|0);d=J[5996];J[5996]=0;Ga:{Ha:{Ia:{Ja:{Ka:{La:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break La}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ka}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ja}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;Ma:{if(H[c+411|0]>=0){break Ma}$a(J[c+400>>2]);if(H[b+11|0]>=0){break Ma}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+243|0]>=0){break y}$a(J[c+232>>2]);break y}b=Z()|0;break Ga}b=Z()|0;break Ha}b=Z()|0;break Ia}b=Z()|0;if(H[c+411|0]>=0){break Ia}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break Ha}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break Ga}$a(J[c+464>>2]);}if(H[c+243|0]>=0){break a}$a(J[c+232>>2]);break a}H[c+231|0]=2;H[c+222|0]=0;I[c+220>>1]=14947;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+220|0);d=J[5996];J[5996]=0;Na:{Oa:{Pa:{Qa:{Ra:{Sa:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Sa}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ra}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Qa}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;Ta:{if(H[c+411|0]>=0){break Ta}$a(J[c+400>>2]);if(H[b+11|0]>=0){break Ta}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+231|0]>=0){break y}$a(J[c+220>>2]);break y}b=Z()|0;break Na}b=Z()|0;break Oa}b=Z()|0;break Pa}b=Z()|0;if(H[c+411|0]>=0){break Pa}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break Oa}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break Na}$a(J[c+464>>2]);}if(H[c+231|0]>=0){break a}$a(J[c+220>>2]);break a}H[c+219|0]=2;H[c+210|0]=0;I[c+208>>1]=14948;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+208|0);d=J[5996];J[5996]=0;Ua:{Va:{Wa:{Xa:{Ya:{Za:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Za}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ya}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Xa}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;_a:{if(H[c+411|0]>=0){break _a}$a(J[c+400>>2]);if(H[b+11|0]>=0){break _a}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+219|0]>=0){break y}$a(J[c+208>>2]);break y}b=Z()|0;break Ua}b=Z()|0;break Va}b=Z()|0;break Wa}b=Z()|0;if(H[c+411|0]>=0){break Wa}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break Va}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break Ua}$a(J[c+464>>2]);}if(H[c+219|0]>=0){break a}$a(J[c+208>>2]);break a}H[c+207|0]=2;H[c+198|0]=0;I[c+196>>1]=14966;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+196|0);d=J[5996];J[5996]=0;$a:{ab:{bb:{cb:{db:{eb:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break eb}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break db}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break cb}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;fb:{if(H[c+411|0]>=0){break fb}$a(J[c+400>>2]);if(H[b+11|0]>=0){break fb}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+207|0]>=0){break y}$a(J[c+196>>2]);break y}b=Z()|0;break $a}b=Z()|0;break ab}b=Z()|0;break bb}b=Z()|0;if(H[c+411|0]>=0){break bb}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break ab}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break $a}$a(J[c+464>>2]);}if(H[c+207|0]>=0){break a}$a(J[c+196>>2]);break a}H[c+195|0]=2;H[c+186|0]=0;I[c+184>>1]=14958;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+184|0);d=J[5996];J[5996]=0;gb:{hb:{ib:{jb:{kb:{lb:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break lb}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break kb}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break jb}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;mb:{if(H[c+411|0]>=0){break mb}$a(J[c+400>>2]);if(H[b+11|0]>=0){break mb}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+195|0]>=0){break y}$a(J[c+184>>2]);break y}b=Z()|0;break gb}b=Z()|0;break hb}b=Z()|0;break ib}b=Z()|0;if(H[c+411|0]>=0){break ib}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break hb}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break gb}$a(J[c+464>>2]);}if(H[c+195|0]>=0){break a}$a(J[c+184>>2]);break a}H[c+183|0]=2;H[c+174|0]=0;I[c+172>>1]=14954;J[5996]=0;e=c+464|0;ea(161,e|0,b|0,c+172|0);d=J[5996];J[5996]=0;nb:{ob:{pb:{qb:{rb:{sb:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,5574)|0;d=J[5996];J[5996]=0;if((d|0)==1){break sb}J[c+456>>2]=J[e+8>>2];d=J[e+4>>2];J[c+448>>2]=J[e>>2];J[c+452>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;d=c+400|0;aa(141,d|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break rb}J[5996]=0;f=d;b=K[c+411|0];d=b<<24>>24<0;b=ba(100,c+448|0,(d?J[c+400>>2]:f)|0,(d?J[c+404>>2]:b)|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break qb}d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;tb:{if(H[c+411|0]>=0){break tb}$a(J[c+400>>2]);if(H[b+11|0]>=0){break tb}$a(J[b>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+183|0]>=0){break y}$a(J[c+172>>2]);break y}b=Z()|0;break nb}b=Z()|0;break ob}b=Z()|0;break pb}b=Z()|0;if(H[c+411|0]>=0){break pb}$a(J[c+400>>2]);}if(H[c+459|0]>=0){break ob}$a(J[c+448>>2]);}if(H[c+475|0]>=0){break nb}$a(J[c+464>>2]);}if(H[c+183|0]>=0){break a}$a(J[c+172>>2]);break a}H[c+164|0]=K[1271];H[c+171|0]=5;H[c+165|0]=0;J[5996]=0;J[c+160>>2]=K[1267]|K[1268]<<8|(K[1269]<<16|K[1270]<<24);e=c+368|0;ea(161,e|0,b|0,c+160|0);d=J[5996];J[5996]=0;ub:{vb:{wb:{xb:{yb:{zb:{Ab:{Bb:{Cb:{Db:{Eb:{Fb:{Gb:{Hb:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Hb}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break Gb}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Fb}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Eb}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break Db}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Cb}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Bb}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+171|0]>=0){break y}$a(J[c+160>>2]);break y}b=Z()|0;break ub}b=Z()|0;break vb}b=Z()|0;break wb}b=Z()|0;break xb}b=Z()|0;break yb}b=Z()|0;break zb}b=Z()|0;break Ab}b=Z()|0;if(H[c+459|0]>=0){break Ab}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break zb}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break yb}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break xb}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break wb}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break vb}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break ub}$a(J[c+368>>2]);}if(H[c+171|0]>=0){break a}$a(J[c+160>>2]);break a}H[c+120|0]=K[2551];H[c+127|0]=5;H[c+121|0]=0;J[5996]=0;J[c+116>>2]=K[2547]|K[2548]<<8|(K[2549]<<16|K[2550]<<24);e=c+368|0;ea(161,e|0,b|0,c+116|0);d=J[5996];J[5996]=0;Ib:{Jb:{Kb:{Lb:{Mb:{Nb:{Ob:{Pb:{Qb:{Rb:{Sb:{Tb:{Ub:{Vb:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Vb}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break Ub}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Tb}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Sb}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break Rb}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Qb}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Pb}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+127|0]>=0){break y}$a(J[c+116>>2]);break y}b=Z()|0;break Ib}b=Z()|0;break Jb}b=Z()|0;break Kb}b=Z()|0;break Lb}b=Z()|0;break Mb}b=Z()|0;break Nb}b=Z()|0;break Ob}b=Z()|0;if(H[c+459|0]>=0){break Ob}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break Nb}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break Mb}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break Lb}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break Kb}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break Jb}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break Ib}$a(J[c+368>>2]);}if(H[c+127|0]>=0){break a}$a(J[c+116>>2]);break a}H[c+115|0]=4;H[c+108|0]=0;J[c+104>>2]=1650422383;J[5996]=0;e=c+368|0;ea(161,e|0,b|0,c+104|0);d=J[5996];J[5996]=0;Wb:{Xb:{Yb:{Zb:{_b:{$b:{ac:{bc:{cc:{dc:{ec:{fc:{gc:{hc:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break hc}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break gc}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break fc}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ec}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break dc}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break cc}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break bc}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+115|0]>=0){break y}$a(J[c+104>>2]);break y}b=Z()|0;break Wb}b=Z()|0;break Xb}b=Z()|0;break Yb}b=Z()|0;break Zb}b=Z()|0;break _b}b=Z()|0;break $b}b=Z()|0;break ac}b=Z()|0;if(H[c+459|0]>=0){break ac}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break $b}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break _b}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break Zb}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break Yb}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break Xb}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break Wb}$a(J[c+368>>2]);}if(H[c+115|0]>=0){break a}$a(J[c+104>>2]);break a}H[c+103|0]=4;H[c+96|0]=0;J[c+92>>2]=1667199599;J[5996]=0;e=c+368|0;ea(161,e|0,b|0,c+92|0);d=J[5996];J[5996]=0;ic:{jc:{kc:{lc:{mc:{nc:{oc:{pc:{qc:{rc:{sc:{tc:{uc:{vc:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break vc}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break uc}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break tc}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break sc}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break rc}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break qc}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break pc}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+103|0]>=0){break y}$a(J[c+92>>2]);break y}b=Z()|0;break ic}b=Z()|0;break jc}b=Z()|0;break kc}b=Z()|0;break lc}b=Z()|0;break mc}b=Z()|0;break nc}b=Z()|0;break oc}b=Z()|0;if(H[c+459|0]>=0){break oc}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break nc}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break mc}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break lc}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break kc}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break jc}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break ic}$a(J[c+368>>2]);}if(H[c+103|0]>=0){break a}$a(J[c+92>>2]);break a}H[c+91|0]=4;H[c+84|0]=0;J[c+80>>2]=1683976815;J[5996]=0;e=c+368|0;ea(161,e|0,b|0,c+80|0);d=J[5996];J[5996]=0;wc:{xc:{yc:{zc:{Ac:{Bc:{Cc:{Dc:{Ec:{Fc:{Gc:{Hc:{Ic:{Jc:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Jc}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break Ic}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Hc}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Gc}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break Fc}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Ec}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Dc}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+91|0]>=0){break y}$a(J[c+80>>2]);break y}b=Z()|0;break wc}b=Z()|0;break xc}b=Z()|0;break yc}b=Z()|0;break zc}b=Z()|0;break Ac}b=Z()|0;break Bc}b=Z()|0;break Cc}b=Z()|0;if(H[c+459|0]>=0){break Cc}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break Bc}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break Ac}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break zc}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break yc}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break xc}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break wc}$a(J[c+368>>2]);}if(H[c+91|0]>=0){break a}$a(J[c+80>>2]);break a}H[c+79|0]=4;H[c+72|0]=0;J[c+68>>2]=1767862895;J[5996]=0;e=c+368|0;ea(161,e|0,b|0,c+68|0);d=J[5996];J[5996]=0;Kc:{Lc:{Mc:{Nc:{Oc:{Pc:{Qc:{Rc:{Sc:{Tc:{Uc:{Vc:{Wc:{Xc:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3673)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Xc}J[c+392>>2]=J[e+8>>2];d=J[e+4>>2];J[c+384>>2]=J[e>>2];J[c+388>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+144|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break Wc}J[5996]=0;g=f;d=K[c+155|0];f=d<<24>>24<0;d=ba(100,c+384|0,(f?J[c+144>>2]:g)|0,(f?J[c+148>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Vc}J[c+408>>2]=J[d+8>>2];f=J[d+4>>2];J[c+400>>2]=J[d>>2];J[c+404>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+400|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Uc}J[c+472>>2]=J[f+8>>2];g=J[f+4>>2];J[c+464>>2]=J[f>>2];J[c+468>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;g=c+128|0;aa(141,g|0,b+8|0);b=J[5996];J[5996]=0;if((b|0)==1){break Tc}J[5996]=0;h=g;b=K[c+139|0];g=b<<24>>24<0;g=ba(100,c+464|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break Sc}J[c+456>>2]=J[g+8>>2];b=J[g+4>>2];J[c+448>>2]=J[g>>2];J[c+452>>2]=b;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Rc}h=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=h;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+155|0]<0){$a(J[c+144>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+79|0]>=0){break y}$a(J[c+68>>2]);break y}b=Z()|0;break Kc}b=Z()|0;break Lc}b=Z()|0;break Mc}b=Z()|0;break Nc}b=Z()|0;break Oc}b=Z()|0;break Pc}b=Z()|0;break Qc}b=Z()|0;if(H[c+459|0]>=0){break Qc}$a(J[c+448>>2]);}if(H[c+139|0]>=0){break Pc}$a(J[c+128>>2]);}if(H[c+475|0]>=0){break Oc}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break Nc}$a(J[c+400>>2]);}if(H[c+155|0]>=0){break Mc}$a(J[c+144>>2]);}if(H[c+395|0]>=0){break Lc}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break Kc}$a(J[c+368>>2]);}if(H[c+79|0]>=0){break a}$a(J[c+68>>2]);break a}I[c- -64>>1]=K[2600]|K[2601]<<8;I[c+66>>1]=2560;J[5996]=0;e=K[2596]|K[2597]<<8|(K[2598]<<16|K[2599]<<24);J[c+56>>2]=K[2592]|K[2593]<<8|(K[2594]<<16|K[2595]<<24);J[c+60>>2]=e;e=c+128|0;ea(161,e|0,b|0,c+56|0);d=J[5996];J[5996]=0;Yc:{Zc:{_c:{$c:{ad:{bd:{cd:{dd:{ed:{fd:{gd:{hd:{id:{jd:{kd:{ld:{md:{nd:{od:{pd:{if((d|0)!=1){J[5996]=0;e=_(97,e|0,3623)|0;d=J[5996];J[5996]=0;if((d|0)==1){break pd}J[c+152>>2]=J[e+8>>2];d=J[e+4>>2];J[c+144>>2]=J[e>>2];J[c+148>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;d=J[J[b>>2]+32>>2];J[5996]=0;f=c+40|0;aa(141,f|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break od}J[5996]=0;g=f;d=K[c+51|0];f=d<<24>>24<0;d=ba(100,c+144|0,(f?J[c+40>>2]:g)|0,(f?J[c+44>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break nd}J[c+376>>2]=J[d+8>>2];f=J[d+4>>2];J[c+368>>2]=J[d>>2];J[c+372>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=_(97,c+368|0,3613)|0;g=J[5996];J[5996]=0;if((g|0)==1){break md}J[c+392>>2]=J[f+8>>2];g=J[f+4>>2];J[c+384>>2]=J[f>>2];J[c+388>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;g=J[J[b>>2]+32>>2];J[5996]=0;h=c+28|0;aa(141,h|0,g+8|0);g=J[5996];J[5996]=0;if((g|0)==1){break ld}J[5996]=0;i=h;g=K[c+39|0];h=g<<24>>24<0;g=ba(100,c+384|0,(h?J[c+28>>2]:i)|0,(h?J[c+32>>2]:g)|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break kd}J[c+408>>2]=J[g+8>>2];h=J[g+4>>2];J[c+400>>2]=J[g>>2];J[c+404>>2]=h;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;h=_(97,c+400|0,3603)|0;i=J[5996];J[5996]=0;if((i|0)==1){break jd}J[c+472>>2]=J[h+8>>2];i=J[h+4>>2];J[c+464>>2]=J[h>>2];J[c+468>>2]=i;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;b=J[J[b>>2]+32>>2];J[5996]=0;i=c+16|0;aa(141,i|0,b+16|0);b=J[5996];J[5996]=0;if((b|0)==1){break id}J[5996]=0;j=i;b=K[c+27|0];i=b<<24>>24<0;i=ba(100,c+464|0,(i?J[c+16>>2]:j)|0,(i?J[c+20>>2]:b)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break hd}J[c+456>>2]=J[i+8>>2];b=J[i+4>>2];J[c+448>>2]=J[i>>2];J[c+452>>2]=b;J[i>>2]=0;J[i+4>>2]=0;J[i+8>>2]=0;J[5996]=0;b=_(97,c+448|0,3570)|0;j=J[5996];J[5996]=0;if((j|0)==1){break gd}j=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=j;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if(H[c+27|0]<0){$a(J[c+16>>2]);}if(H[i+11|0]<0){$a(J[i>>2]);}if(H[h+11|0]<0){$a(J[h>>2]);}if(H[c+39|0]<0){$a(J[c+28>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[c+51|0]<0){$a(J[c+40>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}if(H[c+67|0]>=0){break y}$a(J[c+56>>2]);break y}b=Z()|0;break Yc}b=Z()|0;break Zc}b=Z()|0;break _c}b=Z()|0;break $c}b=Z()|0;break ad}b=Z()|0;break bd}b=Z()|0;break cd}b=Z()|0;break dd}b=Z()|0;break ed}b=Z()|0;break fd}b=Z()|0;if(H[c+459|0]>=0){break fd}$a(J[c+448>>2]);}if(H[c+27|0]>=0){break ed}$a(J[c+16>>2]);}if(H[c+475|0]>=0){break dd}$a(J[c+464>>2]);}if(H[c+411|0]>=0){break cd}$a(J[c+400>>2]);}if(H[c+39|0]>=0){break bd}$a(J[c+28>>2]);}if(H[c+395|0]>=0){break ad}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break $c}$a(J[c+368>>2]);}if(H[c+51|0]>=0){break _c}$a(J[c+40>>2]);}if(H[c+155|0]>=0){break Zc}$a(J[c+144>>2]);}if(H[c+139|0]>=0){break Yc}$a(J[c+128>>2]);}if(H[c+67|0]>=0){break a}$a(J[c+56>>2]);break a}d=c+144|0;Kc(d,J[e+4>>2]);J[5996]=0;e=ba(99,d|0,0,5302)|0;d=J[5996];J[5996]=0;if((d|0)==1){break x}J[c+376>>2]=J[e+8>>2];d=J[e+4>>2];J[c+368>>2]=J[e>>2];J[c+372>>2]=d;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;d=_(97,c+368|0,5417)|0;f=J[5996];J[5996]=0;if((f|0)==1){break w}J[c+392>>2]=J[d+8>>2];f=J[d+4>>2];J[c+384>>2]=J[d>>2];J[c+388>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;f=J[b>>2];g=J[f+36>>2];f=J[f+32>>2];J[5996]=0;h=c+128|0;aa(115,h|0,g-f>>3);f=J[5996];J[5996]=0;if((f|0)==1){break v}J[5996]=0;f=K[c+139|0];g=f<<24>>24<0;f=ba(100,c+384|0,(g?J[c+128>>2]:h)|0,(g?J[c+132>>2]:f)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break u}J[c+408>>2]=J[f+8>>2];g=J[f+4>>2];J[c+400>>2]=J[f>>2];J[c+404>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;J[5996]=0;g=_(97,c+400|0,5242)|0;h=J[5996];J[5996]=0;if((h|0)==1){break t}J[c+8>>2]=J[g+8>>2];h=J[g+4>>2];J[c>>2]=J[g>>2];J[c+4>>2]=h;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;h=c+464|0;ea(161,h|0,b|0,c|0);i=J[5996];J[5996]=0;if((i|0)==1){break s}J[5996]=0;h=_(97,h|0,3726)|0;i=J[5996];J[5996]=0;if((i|0)==1){break r}J[c+456>>2]=J[h+8>>2];i=J[h+4>>2];J[c+448>>2]=J[h>>2];J[c+452>>2]=i;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;if(H[c+11|0]<0){$a(J[c>>2]);}if(H[g+11|0]<0){$a(J[g>>2]);}if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}if(H[e+11|0]<0){$a(J[e>>2]);}b=J[b>>2];d=J[b+32>>2];f=J[b+36>>2];if((d|0)!=(f|0)){while(1){J[5996]=0;b=c+28|0;aa(141,b|0,d|0);e=J[5996];J[5996]=0;if((e|0)==1){break k}J[5996]=0;b=ba(99,b|0,0,3708)|0;e=J[5996];J[5996]=0;if((e|0)==1){break j}J[c+48>>2]=J[b+8>>2];e=J[b+4>>2];J[c+40>>2]=J[b>>2];J[c+44>>2]=e;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;e=_(97,c+40|0,3713)|0;g=J[5996];J[5996]=0;if((g|0)==1){break i}J[c+136>>2]=J[e+8>>2];g=J[e+4>>2];J[c+128>>2]=J[e>>2];J[c+132>>2]=g;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;g=K[c+139|0];h=g<<24>>24<0;ba(100,c+448|0,(h?J[c+128>>2]:c+128|0)|0,(h?J[c+132>>2]:g)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break h}if(H[c+139|0]<0){$a(J[c+128>>2]);}if(H[c+51|0]<0){$a(J[e>>2]);}if(H[c+39|0]<0){$a(J[b>>2]);}d=d+8|0;if((f|0)!=(d|0)){continue}break}}J[5996]=0;b=_(97,c+448|0,3575)|0;e=J[5996];J[5996]=0;if((e|0)==1){break e}e=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=e;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;}Ua=c+496|0;return}b=Z()|0;break l}b=Z()|0;break m}b=Z()|0;break n}b=Z()|0;break o}b=Z()|0;break p}b=Z()|0;break q}b=Z()|0;if(H[c+475|0]>=0){break q}$a(J[c+464>>2]);}if(H[c+11|0]>=0){break p}$a(J[c>>2]);}if(H[c+411|0]>=0){break o}$a(J[c+400>>2]);}if(H[c+139|0]>=0){break n}$a(J[c+128>>2]);}if(H[c+395|0]>=0){break m}$a(J[c+384>>2]);}if(H[c+379|0]>=0){break l}$a(J[c+368>>2]);}if(H[c+155|0]>=0){break a}$a(J[c+144>>2]);break a}b=Z()|0;break d}b=Z()|0;break f}b=Z()|0;break g}b=Z()|0;if(H[c+139|0]>=0){break g}$a(J[c+128>>2]);}if(H[c+51|0]>=0){break f}$a(J[c+40>>2]);}if(H[c+39|0]>=0){break d}$a(J[c+28>>2]);break d}b=Z()|0;}if(H[c+459|0]>=0){break a}$a(J[c+448>>2]);break a}if(!K[c+460|0]|H[c+459|0]>=0){break a}$a(J[c+448>>2]);break a}if(H[c+475|0]>=0){break a}$a(J[c+464>>2]);}da(b|0);B();}function ze(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;h=Ua-48|0;Ua=h;J[h+24>>2]=0;J[h+16>>2]=0;J[h+20>>2]=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{switch(J[a>>2]){case 1:J[5996]=0;b=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break d}J[5996]=0;a=_(32,h+28|0,a+28|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break u}J[b+4>>2]=0;J[b+8>>2]=0;J[b>>2]=2;J[b+12>>2]=0;J[b+16>>2]=J[a>>2];J[b+20>>2]=J[a+4>>2];J[b+24>>2]=J[a+8>>2];J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;J[b+44>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[5996]=0;aa(33,c|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break d}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=b;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;g=e+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)==1){break d}break a}f=f-a|0;i=f>>1;g=f>>>0>=2147483644?1073741823:g>>>0>>0?i:g;if(g){if(g>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break d}J[5996]=0;j=$(3,g<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break d}}e=(e<<2)+j|0;J[e>>2]=b;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(g<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 2:a=J[a+52>>2];J[5996]=0;b=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break e}J[b+4>>2]=0;J[b+8>>2]=0;J[b>>2]=4;J[b+40>>2]=a;J[b+44>>2]=0;J[b+12>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[5996]=0;aa(33,c|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break e}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=b;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;g=e+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break e}f=f-a|0;i=f>>1;g=f>>>0>=2147483644?1073741823:g>>>0>>0?i:g;if(g){if(g>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break e}J[5996]=0;j=$(3,g<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break e}}e=(e<<2)+j|0;J[e>>2]=b;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(g<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 3:a=J[a+52>>2];J[5996]=0;b=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break f}J[b+4>>2]=0;J[b+8>>2]=0;J[b>>2]=5;J[b+40>>2]=a;J[b+44>>2]=0;J[b+12>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[5996]=0;aa(33,c|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break f}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=b;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;g=e+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break f}f=f-a|0;i=f>>1;g=f>>>0>=2147483644?1073741823:g>>>0>>0?i:g;if(g){if(g>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break f}J[5996]=0;j=$(3,g<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break f}}e=(e<<2)+j|0;J[e>>2]=b;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(g<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 5:b=J[a+20>>2];a=J[a+16>>2];J[5996]=0;g=ia(36,c|0,7,a|0,b|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=g;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;b=e+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break g}f=f-a|0;i=f>>1;b=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;if(b){if(b>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break g}J[5996]=0;j=$(3,b<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}}e=(e<<2)+j|0;J[e>>2]=g;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(b<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 4:b=J[a+20>>2];a=J[a+16>>2];J[5996]=0;g=ia(36,c|0,6,a|0,b|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break h}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=g;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;b=e+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break h}f=f-a|0;i=f>>1;b=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;if(b){if(b>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break h}J[5996]=0;j=$(3,b<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break h}}e=(e<<2)+j|0;J[e>>2]=g;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(b<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 7:b=J[a+20>>2];a=J[a+16>>2];J[5996]=0;g=ia(36,c|0,8,a|0,b|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break i}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=g;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;b=e+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break i}f=f-a|0;i=f>>1;b=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;if(b){if(b>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break i}J[5996]=0;j=$(3,b<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break i}}e=(e<<2)+j|0;J[e>>2]=g;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(b<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 6:b=J[a+20>>2];a=J[a+16>>2];J[5996]=0;g=ia(36,c|0,9,a|0,b|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break j}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=g;J[h+20>>2]=d+4;break o}a=J[h+16>>2];e=d-a>>2;b=e+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break j}f=f-a|0;i=f>>1;b=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;if(b){if(b>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break j}J[5996]=0;j=$(3,b<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break j}}e=(e<<2)+j|0;J[e>>2]=g;f=e+4|0;if((a|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((a|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(b<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o;case 8:d=J[a+4>>2];if((J[a+8>>2]-d|0)!=112){break m}J[5996]=0;g=ba(37,d|0,b|0,c|0)|0;d=J[5996];J[5996]=0;w:{x:{y:{z:{A:{B:{C:{if((d|0)!=1){a=J[a+4>>2];J[5996]=0;f=ba(37,a+56|0,b|0,c|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break C}if(!g|!f){break m}J[5996]=0;a=$(3,8)|0;b=J[5996];J[5996]=0;if((b|0)==1){break z}J[a+4>>2]=f;J[a>>2]=g;J[5996]=0;b=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break y}J[b+16>>2]=0;J[b+20>>2]=0;J[b+4>>2]=a;J[b>>2]=10;a=a+8|0;J[b+12>>2]=a;J[b+8>>2]=a;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[5996]=0;aa(33,c|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break k}e=J[h+20>>2];d=J[h+24>>2];if(e>>>0>=d>>>0){break B}J[e>>2]=b;J[h+20>>2]=e+4;break A}c=Z()|0;break c}c=Z()|0;break c}i=J[h+16>>2];k=e-i>>2;a=k+1|0;if(a>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break k}d=d-i|0;j=d>>1;j=d>>>0>=2147483644?1073741823:a>>>0>>0?j:a;D:{if(!j){a=0;break D}if(j>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break k}J[5996]=0;a=$(3,j<<2)|0;d=J[5996];J[5996]=0;if((d|0)==1){break k}}d=(k<<2)+a|0;J[d>>2]=b;b=d+4|0;if((e|0)!=(i|0)){while(1){d=d-4|0;e=e-4|0;J[d>>2]=J[e>>2];if((e|0)!=(i|0)){continue}break}e=J[h+16>>2];}J[h+24>>2]=(j<<2)+a;J[h+20>>2]=b;J[h+16>>2]=d;if(!e){break A}$a(e);}J[5996]=0;b=$(3,12)|0;a=J[5996];J[5996]=0;if((a|0)==1){break x}J[b+4>>2]=f;J[b>>2]=g;J[b+8>>2]=J[6079];J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break w}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=12;J[a+48>>2]=0;J[a+52>>2]=1072693248;b=b+12|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break l}d=J[h+20>>2];f=J[h+24>>2];if(d>>>0>>0){J[d>>2]=a;J[h+20>>2]=d+4;break o}b=J[h+16>>2];e=d-b>>2;g=e+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break l}f=f-b|0;i=f>>1;g=f>>>0>=2147483644?1073741823:g>>>0>>0?i:g;E:{if(!g){j=0;break E}if(g>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break l}J[5996]=0;j=$(3,g<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break l}}e=(e<<2)+j|0;J[e>>2]=a;f=e+4|0;if((b|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((b|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(g<<2)+j;J[h+20>>2]=f;J[h+16>>2]=e;if(!d){break n}$a(d);break o}c=Z()|0;break c}c=Z()|0;$a(a);break c}c=Z()|0;break c}c=Z()|0;$a(b);break c;case 9:d=J[a+4>>2];if((J[a+8>>2]-d|0)!=112){break m}g=J[a+40>>2];f=J[g+4>>2];i=J[g>>2];j=i+f|0;if(f>>>0>j>>>0){break m}J[5996]=0;g=ba(37,d|0,b|0,c|0)|0;d=J[5996];J[5996]=0;F:{G:{if((d|0)!=1){d=J[a+4>>2];J[5996]=0;f=ba(37,d+56|0,b|0,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break G}if(!g|!f){break m}o=+(i>>>0)/+(j>>>0);e=J[a+4>>2];if(J[e>>2]!=8){break p}d=J[e+4>>2];if((J[e+8>>2]-d|0)==112){break F}break p}c=Z()|0;break c}c=Z()|0;break c}J[5996]=0;i=ba(37,d|0,b|0,c|0)|0;d=J[5996];J[5996]=0;H:{I:{J:{if((d|0)!=1){d=J[J[a+4>>2]+4>>2];J[5996]=0;j=ba(37,d+56|0,b|0,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break J}e=0;if(!i|!j){break m}J[5996]=0;d=$(3,12)|0;e=J[5996];J[5996]=0;if((e|0)==1){break I}J[h+28>>2]=d;e=d+12|0;J[h+36>>2]=e;J[d+8>>2]=f;J[d+4>>2]=j;J[d>>2]=i;J[5996]=0;J[h+32>>2]=e;d=ya(38,c|0,12,h+28|0,+o)|0;e=J[5996];J[5996]=0;if((e|0)==1){break H}J[5996]=0;aa(39,h+16|0,d|0);d=J[5996];J[5996]=0;if((d|0)==1){break H}d=J[h+28>>2];if(d){$a(d);}e=J[a+4>>2];break p}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;a=J[h+28>>2];if(!a){break c}$a(a);break c;case 0:break m;case 10:break v;default:break o}}g=J[a+4>>2];l=J[a+8>>2];if((g|0)==(l|0)){break s}while(1){K:{J[5996]=0;d=ba(37,g|0,b|0,c|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break K}L:{if(e>>>0>>0){J[e>>2]=d;e=e+4|0;break L}n=e-f>>2;i=n+1|0;if(i>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break r}j=j-f|0;k=j>>1;k=j>>>0>=2147483644?1073741823:i>>>0>>0?k:i;M:{if(!k){j=0;break M}if(k>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break r}J[5996]=0;j=$(3,k<<2)|0;i=J[5996];J[5996]=0;if((i|0)==1){break K}}i=(n<<2)+j|0;J[i>>2]=d;d=i;if((e|0)!=(f|0)){while(1){d=d-4|0;e=e-4|0;J[d>>2]=J[e>>2];if((e|0)!=(f|0)){continue}break}}j=(k<<2)+j|0;e=i+4|0;if(f){$a(f);}f=d;}g=g+56|0;if((l|0)!=(g|0)){continue}break t}break}c=Z()|0;break q}c=Z()|0;$a(b);break c}if((e|0)==(f|0)){f=e;break s}d=f;while(1){if(J[d>>2]){d=d+4|0;if((e|0)!=(d|0)){continue}break s}break}e=0;if(!f){break m}$a(f);break m}N:{O:{n=J[a+8>>2];i=J[a+4>>2];P:{if((n-i|0)/56>>>0>20){break P}Q:{R:{if((i|0)!=(n|0)){d=i;while(1){if(J[d>>2]!=1){break P}d=d+56|0;if((n|0)!=(d|0)){continue}break}break R}J[h+12>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;break Q}J[h+12>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;q=h+12|0;while(1){b=J[i+28>>2];S:{T:{d=J[h+8>>2];if((d|0)!=J[h+12>>2]){if(H[b+11|0]>=0){g=J[b+4>>2];J[d>>2]=J[b>>2];J[d+4>>2]=g;J[d+8>>2]=J[b+8>>2];break T}g=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,d|0,b|0,g|0);b=J[5996];J[5996]=0;if((b|0)!=1){break T}c=Z()|0;J[h+8>>2]=d;break N}U:{V:{W:{X:{g=J[h+4>>2];k=(d-g|0)/12|0;l=k+1|0;Y:{if(l>>>0>=357913942){J[5996]=0;ca(41);break Y}J[h+44>>2]=q;m=k<<1;m=k>>>0>=178956970?357913941:l>>>0>>0?m:l;if(!m){l=0;break W}if(m>>>0<357913942){break X}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}c=Z()|0;break N}J[5996]=0;l=$(3,P(m,12)|0)|0;p=J[5996];J[5996]=0;if((p|0)==1){break V}}J[h+28>>2]=l;k=P(k,12)+l|0;J[h+36>>2]=k;l=P(m,12)+l|0;J[h+40>>2]=l;J[h+32>>2]=k;Z:{if(H[b+11|0]>=0){m=J[b+4>>2];J[k>>2]=J[b>>2];J[k+4>>2]=m;J[k+8>>2]=J[b+8>>2];break Z}d=J[b+4>>2];b=J[b>>2];J[5996]=0;ea(40,k|0,b|0,d|0);b=J[5996];J[5996]=0;if((b|0)==1){break U}g=J[h+4>>2];d=J[h+8>>2];}m=k+12|0;if((d|0)==(g|0)){b=g;}else {while(1){d=d-12|0;p=J[d+4>>2];k=k-12|0;b=k;J[b>>2]=J[d>>2];J[b+4>>2]=p;J[b+8>>2]=J[d+8>>2];J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;if((d|0)!=(g|0)){continue}break}g=J[h+8>>2];b=J[h+4>>2];}J[h+32>>2]=b;J[h+4>>2]=k;J[h+8>>2]=m;d=J[h+12>>2];J[h+12>>2]=l;J[h+40>>2]=d;J[h+28>>2]=b;if((b|0)!=(g|0)){while(1){d=g-12|0;J[h+36>>2]=d;if(H[g-1|0]<0){$a(J[d>>2]);}g=d;if((d|0)!=(b|0)){continue}break}g=b;}if(!g){break S}$a(g);break S}c=Z()|0;break N}c=Z()|0;a=J[h+36>>2];d=J[h+32>>2];if((a|0)!=(d|0)){while(1){b=a-12|0;J[h+36>>2]=b;if(H[a-1|0]>=0){a=b;}else {$a(J[b>>2]);a=J[h+36>>2];}if((d|0)!=(a|0)){continue}break}}a=J[h+28>>2];if(a){$a(a);}break N}J[h+8>>2]=d+12;}i=i+56|0;if((n|0)!=(i|0)){continue}break}}b=J[a+52>>2];J[5996]=0;i=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break O}d=J[h+12>>2];J[h+12>>2]=0;g=J[h+4>>2];k=J[h+8>>2];J[h+4>>2]=0;J[h+8>>2]=0;J[i+4>>2]=0;J[i+8>>2]=0;J[i>>2]=3;J[i+12>>2]=0;J[i+40>>2]=b;J[i+44>>2]=0;J[i+36>>2]=0;J[i+28>>2]=0;J[i+32>>2]=0;J[i+24>>2]=d;J[i+16>>2]=g;J[i+20>>2]=k;J[5996]=0;aa(33,c|0,i|0);b=J[5996];J[5996]=0;if((b|0)==1){break O}d=J[h+20>>2];k=J[h+24>>2];_:{if(d>>>0>>0){J[d>>2]=i;J[h+20>>2]=d+4;break _}b=J[h+16>>2];n=d-b>>2;g=n+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break O}k=k-b|0;l=k>>1;k=k>>>0>=2147483644?1073741823:g>>>0>>0?l:g;$:{if(!k){l=0;break $}if(k>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break O}J[5996]=0;l=$(3,k<<2)|0;g=J[5996];J[5996]=0;if((g|0)==1){break O}}g=(n<<2)+l|0;J[g>>2]=i;i=g+4|0;if((b|0)!=(d|0)){while(1){g=g-4|0;d=d-4|0;J[g>>2]=J[d>>2];if((b|0)!=(d|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(k<<2)+l;J[h+20>>2]=i;J[h+16>>2]=g;if(!d){break _}$a(d);}b=J[h+4>>2];if(!b){break P}d=b;g=J[h+8>>2];if((d|0)!=(g|0)){while(1){d=g-12|0;if(H[g-1|0]<0){$a(J[d>>2]);}g=d;if((d|0)!=(b|0)){continue}break}d=J[h+4>>2];}J[h+8>>2]=b;$a(d);}b=J[a+52>>2];aa:{if((b|0)!=1&(b|0)!=((J[a+8>>2]-J[a+4>>2]|0)/56|0)){break aa}ba:{ca:{da:{ea:{fa:{ga:{b=e-f|0;if(b>>>0>=5){while(1){k=J[a+52>>2];J[5996]=0;i=$(3,8)|0;d=J[5996];J[5996]=0;if((d|0)==1){break ga}d=e-8|0;J[i>>2]=J[d>>2];e=e-4|0;J[i+4>>2]=J[e>>2];J[5996]=0;g=$(3,56)|0;l=J[5996];J[5996]=0;if((l|0)==1){break fa}J[g+16>>2]=0;J[g+20>>2]=0;J[g+4>>2]=i;J[g>>2]=(k|0)==1?11:10;i=i+8|0;J[g+12>>2]=i;J[g+8>>2]=i;J[g+24>>2]=0;J[g+28>>2]=0;J[g+32>>2]=0;J[g+36>>2]=0;J[g+40>>2]=0;J[g+44>>2]=0;O[g+48>>3]=1/+(b>>2>>>0);J[5996]=0;aa(33,c|0,g|0);b=J[5996];J[5996]=0;if((b|0)==1){c=Z()|0;break q}J[5996]=0;i=$(3,4)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ea}J[i>>2]=g;J[5996]=0;b=$(3,56)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ca}J[b+16>>2]=0;J[b+20>>2]=0;J[b+4>>2]=i;J[b>>2]=21;g=i+4|0;J[b+12>>2]=g;J[b+8>>2]=g;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[5996]=0;aa(33,c|0,b|0);g=J[5996];J[5996]=0;if((g|0)==1){break da}ha:{if(d>>>0>>0){J[d>>2]=b;break ha}ia:{ja:{i=d-f>>2;g=i+1|0;ka:{if(g>>>0>=1073741824){J[5996]=0;ca(34);break ka}e=j-f|0;j=e>>1;e=e>>>0>=2147483644?1073741823:g>>>0>>0?j:g;if(!e){j=0;break ia}if(e>>>0<1073741824){break ja}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}c=Z()|0;break q}J[5996]=0;j=$(3,e<<2)|0;g=J[5996];J[5996]=0;if((g|0)==1){break da}}g=(i<<2)+j|0;J[g>>2]=b;j=(e<<2)+j|0;e=g+4|0;la:{if((d|0)!=(f|0)){while(1){g=g-4|0;d=d-4|0;J[g>>2]=J[d>>2];if((d|0)!=(f|0)){continue}break}if(!f){break la}}$a(f);}f=g;}b=e-f|0;if(b>>>0>4){continue}break}}j=J[f>>2];d=J[h+20>>2];if((d|0)==J[h+24>>2]){break ba}J[d>>2]=j;J[h+20>>2]=d+4;break aa}c=Z()|0;break q}c=Z()|0;$a(i);break q}c=Z()|0;break q}c=Z()|0;break q}c=Z()|0;$a(i);break q}k=J[h+16>>2];b=d-k|0;l=b>>2;g=l+1|0;if(g>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break r}i=b>>1;b=b>>>0>=2147483644?1073741823:g>>>0>>0?i:g;ma:{if(!b){i=0;break ma}if(b>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break r}J[5996]=0;i=$(3,b<<2)|0;g=J[5996];J[5996]=0;if((g|0)==1){break r}}g=(l<<2)+i|0;J[g>>2]=j;j=g+4|0;if((d|0)!=(k|0)){while(1){g=g-4|0;d=d-4|0;J[g>>2]=J[d>>2];if((d|0)!=(k|0)){continue}break}d=J[h+16>>2];}J[h+24>>2]=(b<<2)+i;J[h+20>>2]=j;J[h+16>>2]=g;if(!d){break aa}$a(d);}j=J[a+52>>2];b=0;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;na:{oa:{if((d|0)==1){break oa}g=e-f|0;k=g>>2;i=0;d=0;if((e|0)!=(f|0)){if((g|0)<0){J[5996]=0;ca(34);b=J[5996];J[5996]=0;if((b|0)!=1){break a}break na}J[5996]=0;d=$(3,g|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break na}g=(g-4&-4)+4|0;e=fb(d,f,g);b=e+(k<<2)|0;i=e+g|0;}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=d;J[a>>2]=13;O[a+48>>3]=+(j>>>0)/+(k>>>0);J[a+12>>2]=b;J[a+8>>2]=i;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=j;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break oa}e=J[h+20>>2];d=J[h+24>>2];pa:{if(e>>>0>>0){J[e>>2]=a;J[h+20>>2]=e+4;break pa}g=J[h+16>>2];j=e-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break oa}d=d-g|0;i=d>>1;i=d>>>0>=2147483644?1073741823:b>>>0>>0?i:b;qa:{if(!i){b=0;break qa}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break oa}J[5996]=0;b=$(3,i<<2)|0;d=J[5996];J[5996]=0;if((d|0)==1){break oa}}d=(j<<2)+b|0;J[d>>2]=a;a=d+4|0;if((e|0)!=(g|0)){while(1){d=d-4|0;e=e-4|0;J[d>>2]=J[e>>2];if((e|0)!=(g|0)){continue}break}e=J[h+16>>2];}J[h+24>>2]=(i<<2)+b;J[h+20>>2]=a;J[h+16>>2]=d;if(!e){break pa}$a(e);}if(!f){break o}$a(f);break o}c=Z()|0;break q}c=Z()|0;$a(a);break q}c=Z()|0;}rb(h+4|0);break q}c=Z()|0;}if(!f){break c}$a(f);break c}ra:{sa:{ta:{ua:{va:{wa:{xa:{ya:{za:{if(J[e+56>>2]!=8){break za}d=J[e+60>>2];if((J[e- -64>>2]-d|0)!=112){break za}J[5996]=0;d=ba(37,d|0,b|0,c|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break ya}a=J[J[a+4>>2]+60>>2];J[5996]=0;b=ba(37,a+56|0,b|0,c|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break xa}e=0;if(!d|!b){break m}J[5996]=0;a=$(3,12)|0;e=J[5996];J[5996]=0;if((e|0)==1){break wa}J[h+28>>2]=a;e=a+12|0;J[h+36>>2]=e;J[a+8>>2]=g;J[a+4>>2]=b;J[a>>2]=d;J[5996]=0;J[h+32>>2]=e;a=Sa(42,c|0,h+28|0,+(1-o))|0;b=J[5996];J[5996]=0;if((b|0)==1){break va}J[5996]=0;aa(39,h+16|0,a|0);a=J[5996];J[5996]=0;if((a|0)==1){break va}a=J[h+28>>2];if(!a){break za}$a(a);}J[5996]=0;a=$(3,12)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ua}J[h+28>>2]=a;b=a+12|0;J[h+36>>2]=b;J[a>>2]=g;d=J[6080];J[a+8>>2]=f;J[a+4>>2]=d;J[5996]=0;J[h+32>>2]=b;a=ya(38,c|0,12,h+28|0,+o)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ta}J[5996]=0;aa(39,h+16|0,a|0);a=J[5996];J[5996]=0;if((a|0)==1){break ta}a=J[h+28>>2];if(a){$a(a);}J[5996]=0;a=$(3,8)|0;b=J[5996];J[5996]=0;if((b|0)==1){break sa}J[h+28>>2]=a;b=a+8|0;J[h+36>>2]=b;J[a+4>>2]=f;J[a>>2]=g;J[5996]=0;J[h+32>>2]=b;a=ya(38,c|0,11,h+28|0,+o)|0;b=J[5996];J[5996]=0;if((b|0)==1){break ra}J[5996]=0;aa(39,h+16|0,a|0);a=J[5996];J[5996]=0;if((a|0)==1){break ra}a=J[h+28>>2];if(!a){break o}$a(a);break o}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;a=J[h+28>>2];if(!a){break c}$a(a);break c}c=Z()|0;break c}c=Z()|0;a=J[h+28>>2];if(!a){break c}$a(a);break c}c=Z()|0;break c}c=Z()|0;a=J[h+28>>2];if(!a){break c}$a(a);break c}f=J[h+20>>2];e=J[h+16>>2];}Aa:{Ba:{Ca:{Da:{if((f-e|0)==4){break Da}b=J[h+24>>2];J[h+24>>2]=0;J[h+16>>2]=0;J[h+20>>2]=0;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ca}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=e;J[a>>2]=20;J[a+12>>2]=b;J[a+8>>2]=f;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Aa}e=J[h+20>>2];g=J[h+24>>2];if(e>>>0>>0){J[e>>2]=a;J[h+20>>2]=e+4;break Da}b=J[h+16>>2];f=e-b>>2;d=f+1|0;if(d>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Aa}g=g-b|0;i=g>>1;g=g>>>0>=2147483644?1073741823:d>>>0>>0?i:d;Ea:{if(!g){j=0;break Ea}if(g>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Aa}J[5996]=0;j=$(3,g<<2)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Aa}}d=(f<<2)+j|0;J[d>>2]=a;a=d+4|0;if((b|0)!=(e|0)){while(1){d=d-4|0;e=e-4|0;J[d>>2]=J[e>>2];if((b|0)!=(e|0)){continue}break}e=J[h+16>>2];}J[h+24>>2]=(g<<2)+j;J[h+20>>2]=a;J[h+16>>2]=d;if(!e){break Da}$a(e);}J[5996]=0;e=$(3,56)|0;a=J[5996];J[5996]=0;if((a|0)!=1){a=J[h+24>>2];J[h+24>>2]=0;b=J[h+16>>2];d=J[h+20>>2];J[h+16>>2]=0;J[h+20>>2]=0;J[e+16>>2]=0;J[e+20>>2]=0;J[e+12>>2]=a;J[e+4>>2]=b;J[e+8>>2]=d;J[e>>2]=21;J[e+24>>2]=0;J[e+28>>2]=0;J[e+32>>2]=0;J[e+36>>2]=0;J[e+40>>2]=0;J[e+44>>2]=0;J[5996]=0;aa(33,c|0,e|0);a=J[5996];J[5996]=0;if((a|0)!=1){break Ba}}c=Z()|0;break c}c=Z()|0;if(!e){break b}$a(e);break c}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;Fa:{Ga:{Ha:{Ia:{Ja:{Ka:{La:{Ma:{Na:{Oa:{Pa:{Qa:{Ra:{Sa:{Ta:{if((d|0)!=1){J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=15;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Fa}d=J[e+8>>2];f=J[e+12>>2];Ua:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break Ua}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Fa}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;Va:{if(!i){b=0;break Va}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Fa}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Fa}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break Ua}$a(d);}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ta}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=17;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ga}d=J[e+8>>2];f=J[e+12>>2];Wa:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break Wa}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ga}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;Xa:{if(!i){b=0;break Xa}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ga}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Ga}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break Wa}$a(d);}J[5996]=0;a=J[6080];b=$(3,8)|0;d=J[5996];J[5996]=0;if((d|0)==1){c=Z()|0;break c}J[b+4>>2]=a;J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Sa}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=10;b=b+8|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ha}d=J[e+8>>2];f=J[e+12>>2];Ya:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break Ya}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ha}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;Za:{if(!i){b=0;break Za}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ha}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Ha}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break Ya}$a(d);}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Ra}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=19;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ia}d=J[e+8>>2];f=J[e+12>>2];_a:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break _a}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ia}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;$a:{if(!i){b=0;break $a}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ia}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Ia}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break _a}$a(d);}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Qa}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=16;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ja}d=J[e+8>>2];f=J[e+12>>2];ab:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break ab}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ja}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;bb:{if(!i){b=0;break bb}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ja}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Ja}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break ab}$a(d);}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Pa}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=18;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ka}d=J[e+8>>2];f=J[e+12>>2];cb:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break cb}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ka}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;db:{if(!i){b=0;break db}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ka}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break Ka}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break cb}$a(d);}J[5996]=0;a=J[6079];b=$(3,8)|0;d=J[5996];J[5996]=0;if((d|0)==1){c=Z()|0;break c}J[b+4>>2]=a;J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Oa}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=11;J[a+48>>2]=0;J[a+52>>2]=1072693248;b=b+8|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break La}d=J[e+8>>2];f=J[e+12>>2];eb:{if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break eb}g=J[e+4>>2];j=d-g>>2;b=j+1|0;if(b>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break La}f=f-g|0;i=f>>1;i=f>>>0>=2147483644?1073741823:b>>>0>>0?i:b;fb:{if(!i){b=0;break fb}if(i>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break La}J[5996]=0;b=$(3,i<<2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break La}}f=(j<<2)+b|0;J[f>>2]=a;a=f+4|0;if((d|0)!=(g|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(i<<2)+b;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break eb}$a(d);}J[5996]=0;b=$(3,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){c=Z()|0;break c}J[b>>2]=e;J[5996]=0;a=$(3,56)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Na}J[a+16>>2]=0;J[a+20>>2]=0;J[a+4>>2]=b;J[a>>2]=14;b=b+4|0;J[a+12>>2]=b;J[a+8>>2]=b;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[5996]=0;aa(33,c|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break Ma}d=J[e+8>>2];g=J[e+12>>2];if(d>>>0>>0){J[d>>2]=a;J[e+8>>2]=d+4;break m}b=J[e+4>>2];f=d-b>>2;c=f+1|0;if(c>>>0>=1073741824){J[5996]=0;ca(34);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ma}g=g-b|0;i=g>>1;c=g>>>0>=2147483644?1073741823:c>>>0>>0?i:c;gb:{if(!c){j=0;break gb}if(c>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break Ma}J[5996]=0;j=$(3,c<<2)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Ma}}f=(f<<2)+j|0;J[f>>2]=a;a=f+4|0;if((b|0)!=(d|0)){while(1){f=f-4|0;d=d-4|0;J[f>>2]=J[d>>2];if((b|0)!=(d|0)){continue}break}d=J[e+4>>2];}J[e+12>>2]=(c<<2)+j;J[e+8>>2]=a;J[e+4>>2]=f;if(!d){break m}$a(d);break m}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;$a(b);break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}a=J[h+16>>2];if(a){J[h+20>>2]=a;$a(a);}Ua=h+48|0;return e|0}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;break c}c=Z()|0;}a=J[h+16>>2];if(!a){break b}J[h+20>>2]=a;$a(a);}da(c|0);B();}B();}function yn(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0;a:{b:{c:{if(J[a>>2]!=24){break c}c=J[a+32>>2];g=J[a+36>>2];if((c|0)==(g|0)){break c}while(1){j=J[J[c>>2]+80>>2];d:{if(f>>>0>i>>>0){J[i>>2]=j;i=i+4|0;break d}h=i-b>>2;d=h+1|0;if(d>>>0>=1073741824){J[5996]=0;ca(94);a=J[5996];J[5996]=0;if((a|0)==1){break b}break a}e=f-b|0;f=e>>1;f=e>>>0>=2147483644?1073741823:d>>>0>>0?f:d;e:{if(!f){e=0;break e}if(f>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break b}J[5996]=0;e=$(3,f<<2)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=(h<<2)+e|0;J[d>>2]=j;v=d;if((b|0)!=(i|0)){while(1){v=v-4|0;i=i-4|0;J[v>>2]=J[i>>2];if((b|0)!=(i|0)){continue}break}}f=(f<<2)+e|0;i=d+4|0;if(b){$a(b);}b=v;}c=c+8|0;if((g|0)!=(c|0)){continue}break}}j=J[a+36>>2];f=J[a+32>>2];c=j-f|0;f:{if((f|0)==(j|0)){d=0;h=0;break f}h=J[J[f>>2]+80>>2];if(c>>>0<9){d=0;break f}d=J[J[f+8>>2]+80>>2];if(c>>>0<17){break f}m=J[J[f+16>>2]+80>>2];}s=c>>3;k=J[a+24>>2];o=J[a+20>>2];e=k-o|0;u=J[a+12>>2];w=J[a+8>>2];x=u-w|0;g=(x|0)/12|0;n=J[a+4>>2];g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{b=J[a>>2];a=b&-2;switch(a-6|0){case 2:break t;case 0:break u;default:break s}}if((e|0)==32){break r}e=2369;a=39;g=3984;break h}if((e|0)==20){break r}e=2369;a=41;g=4224;break h}e=2369;if((k|0)!=(o|0)){a=43;g=4337;break h}if((a|0)!=4){break r}if((n|0)>0){break q}a=47;g=3134;break h}v:{switch(b-24|0){case 1:if(g>>>0>n-1>>>0){break p}e=2369;a=49;g=1397;break h;case 0:if(s>>>0>n-1>>>0){break n}e=2369;a=51;g=1654;break h;default:break v}}e=2369;if(n){a=53;g=4330;break h}if(b-17>>>0>5){break q}if((c|0)==16){break o}a=58;g=4003;break h}if(b-10>>>0>=7){if((b|0)!=23){break p}if((c|0)==24){break n}a=60;g=3946;break h}if((c|0)==8){break n}a=64;g=4090;break h}if((b|0)==24|(f|0)==(j|0)){break o}e=2369;a=66;g=4311;break h}if((a|0)==2){if((x|0)==12){break m}e=2369;a=70;g=4063;break h}if((b|0)!=25){break n}if(g-1>>>0<20){break l}e=2369;a=72;g=4240;break h}if((u|0)==(w|0)){break m}e=2369;a=74;g=4299;break h}c=10;f=2108;e=2369;a=247;g=2350;w:{switch(b|0){case 3:c=9;f=2119;break k;case 4:J[5996]=0;a=_(54,2295,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2278,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2129,6)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}b=c|(n&4194304?a:b);break i;case 5:J[5996]=0;a=_(54,2174,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2170,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2129,6)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}b=c|((n>>>0<5e8?b:0)|(n>>>0>499999999?a:0));break i;case 6:case 7:case 8:case 9:c=7;f=2153;break k;case 1:c=7;f=2136;break k;case 0:c=9;f=2098;break k;case 10:J[5996]=0;a=_(54,2777,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,3557,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2161,5)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,1600,6)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,1239,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}b=(c|d)&h|(e|(b&(h^-1)?0:a));break i;case 11:J[5996]=0;a=_(54,2777,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,1958,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2161,5)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,1197,7)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}b=(c|d)&h|(b&(h^-1)?0:a);break i;case 12:J[5996]=0;a=_(54,3557,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,3310,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2161,5)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,2035,6)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,1419,2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}b=(c|d)&h|(e|(b&(h^-1)?0:a));break i;case 13:J[5996]=0;b=_(54,3557,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;c=_(54,1028,2)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,1959,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,1029,1)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,2451,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}J[5996]=0;f=_(54,2315,1)|0;j=J[5996];J[5996]=0;if((j|0)==1){break g}J[5996]=0;j=_(54,2161,5)|0;g=J[5996];J[5996]=0;if((g|0)==1){break g}J[5996]=0;g=_(54,1640,2)|0;i=J[5996];J[5996]=0;if((i|0)==1){break g}J[5996]=0;i=_(54,1208,3)|0;n=J[5996];J[5996]=0;if((n|0)==1){break g}k=a;a=h^-1;b=(g|j)&h|(i|((a&d?0:k)|(a&c?0:b)|(a&f?0:e)));break i;case 14:J[5996]=0;a=_(54,2796,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,3557,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2161,5)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,1486,5)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,1205,2)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}b=(c|d)&h|(e|(b&(h^-1)?0:a));break i;case 15:J[5996]=0;a=_(54,3557,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2028,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,2451,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,2315,1)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,2161,5)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}J[5996]=0;f=_(54,1430,4)|0;j=J[5996];J[5996]=0;if((j|0)==1){break g}J[5996]=0;j=_(54,1208,3)|0;g=J[5996];J[5996]=0;if((g|0)==1){break g}g=c;c=h^-1;b=(e|f)&h|(j|((c&d?0:g)|(b&c?0:a)));break i;case 16:J[5996]=0;a=_(54,2161,5)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,1607,9)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}J[5996]=0;c=_(54,1149,2)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}b=c|(a|b)&h;break i;case 17:J[5996]=0;j=_(54,3540,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;g=_(54,2796,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;i=_(54,2029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;n=_(54,2029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;m=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;s=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;k=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;o=_(54,1024,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;u=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2315,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2315,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}e=h^-1;f=d^-1;x:{if(f&b){c=0;J[5996]=0;b=_(54,1681,1)|0;w=J[5996];J[5996]=0;if((w|0)==1){break g}if(b&e){break x}}c=a;}J[5996]=0;w=_(54,1149,2)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;x=_(54,2167,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2165,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;q=_(54,2165,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=0;p=d&h;y:{if(q&(p^-1)){break y}J[5996]=0;b=_(54,2295,1)|0;q=J[5996];J[5996]=0;if((q|0)==1){break g}if(!(b&e)){b=0;J[5996]=0;q=_(54,2278,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break g}if(!(f&q)){break y}}J[5996]=0;b=_(54,2278,1)|0;q=J[5996];J[5996]=0;if((q|0)==1){break g}if(!(b&e)){b=0;J[5996]=0;q=_(54,2295,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break g}if(!(f&q)){break y}}J[5996]=0;b=_(54,2174,1)|0;q=J[5996];J[5996]=0;if((q|0)==1){break g}if(!(b&e)){b=0;J[5996]=0;q=_(54,2170,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break g}if(!(f&q)){break y}}J[5996]=0;b=_(54,2170,1)|0;q=J[5996];J[5996]=0;if((q|0)==1){break g}if(!(b&e)){b=0;J[5996]=0;q=_(54,2174,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break g}if(!(f&q)){break y}}b=a;}a=d|h;b=d&w|(o&p|(h&i|(e&g?0:d&j)|(e&m?0:d&n))|(k&(a^-1)?0:a&s)|a&u|c)|a&x|b;break i;case 18:J[5996]=0;i=_(54,3557,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;n=_(54,2777,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;m=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;s=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;k=_(54,2029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;o=_(54,2029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;u=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;w=_(54,2451,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;x=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;q=_(54,2031,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2315,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;e=_(54,2315,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=d^-1;c=h^-1;f=d&h;g=f^-1;z:{A:{if(!(g&e)){break A}J[5996]=0;e=_(54,2297,2)|0;j=J[5996];J[5996]=0;if((j|0)==1){break g}if(!(c&e)){break A}j=0;J[5996]=0;e=_(54,2297,2)|0;p=J[5996];J[5996]=0;if((p|0)==1){break g}if(b&e){break z}}j=a;}J[5996]=0;p=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;r=_(54,1149,2)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;y=_(54,2167,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2165,1)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}e=0;J[5996]=0;l=_(54,2165,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}B:{if(g&l){break B}J[5996]=0;e=_(54,2295,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&e)){e=0;J[5996]=0;l=_(54,2278,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!(b&l)){break B}}J[5996]=0;e=_(54,2278,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&e)){e=0;J[5996]=0;l=_(54,2295,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!(b&l)){break B}}J[5996]=0;e=_(54,2174,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&e)){e=0;J[5996]=0;l=_(54,2170,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!(b&l)){break B}}J[5996]=0;e=_(54,2170,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&e)){e=0;J[5996]=0;l=_(54,2174,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!(b&l)){break B}}e=a;}a=d|h;b=r|(f&q|(h&k|(b&n?0:h&i)|(s&(a^-1)?0:a&m)|(c&u?0:d&o))|(g&x?0:f&w)|j|a&p)|a&y|e;break i;case 19:J[5996]=0;a=_(54,3557,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2504,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}c=0;if(!((h^-1)&b)){J[5996]=0;b=_(54,2501,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}c=b&(d^-1)?0:a;}J[5996]=0;e=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;j=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;g=_(54,2049,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}f=0;J[5996]=0;b=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}a=d&h;k=b;b=d|h;d=b^-1;if(!(k&d)){J[5996]=0;f=_(54,2451,1)|0;h=J[5996];J[5996]=0;if((h|0)==1){break g}f=f&(a^-1)?0:a&g;}J[5996]=0;g=_(54,2340,3)|0;h=J[5996];J[5996]=0;if((h|0)==1){break g}J[5996]=0;h=_(54,1148,3)|0;i=J[5996];J[5996]=0;if((i|0)==1){break g}J[5996]=0;i=_(54,2167,4)|0;n=J[5996];J[5996]=0;if((n|0)==1){break g}J[5996]=0;n=_(54,2165,1)|0;m=J[5996];J[5996]=0;if((m|0)==1){break g}b=a&n|(b&i|(h|(a&g|((d&j?0:b&e)|c|f))));break i;case 21:J[5996]=0;e=_(54,3557,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;f=_(54,1293,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;j=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;g=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2049,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;c=_(54,2451,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=d&h;i=h^-1;C:{if(i&c){a=d|h;c=0;break C}J[5996]=0;c=_(54,1681,1)|0;n=J[5996];J[5996]=0;if((n|0)==1){break g}k=a&b;a=d|h;c=c&(a^-1)?0:k;}J[5996]=0;n=_(54,1650,3)|0;m=J[5996];J[5996]=0;if((m|0)==1){break g}J[5996]=0;m=_(54,2468,3)|0;s=J[5996];J[5996]=0;if((s|0)==1){break g}J[5996]=0;s=_(54,1239,1)|0;k=J[5996];J[5996]=0;if((k|0)==1){break g}J[5996]=0;k=_(54,2167,4)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}J[5996]=0;o=_(54,2165,1)|0;u=J[5996];J[5996]=0;if((u|0)==1){break g}b=b&o|(a&k|(s|(d&m|(b&n|(c|((g&(d^-1)?0:h&j)|(f&i?0:d&e)))))));break i;case 20:J[5996]=0;e=_(54,2796,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;f=_(54,1293,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;j=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;g=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2049,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;c=_(54,2451,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=d&h;i=h^-1;D:{if(i&c){a=d|h;c=0;break D}J[5996]=0;c=_(54,1681,1)|0;n=J[5996];J[5996]=0;if((n|0)==1){break g}k=a&b;a=d|h;c=c&(a^-1)?0:k;}J[5996]=0;n=_(54,1394,2)|0;m=J[5996];J[5996]=0;if((m|0)==1){break g}J[5996]=0;m=_(54,1205,2)|0;s=J[5996];J[5996]=0;if((s|0)==1){break g}J[5996]=0;s=_(54,2167,4)|0;k=J[5996];J[5996]=0;if((k|0)==1){break g}J[5996]=0;k=_(54,2165,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}b=b&k|(a&s|(m|(b&n|(c|((g&(d^-1)?0:h&j)|(f&i?0:d&e))))));break i;case 22:J[5996]=0;e=_(54,1643,6)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;b=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;f=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;j=_(54,2451,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;g=_(54,2315,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;i=_(54,2049,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;n=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;m=_(54,2522,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;s=_(54,1239,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;k=_(54,2167,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;o=_(54,2165,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}a=d|h;c=a^-1;l=b;b=d&h;b=a&k|(s|(a&m|((f&(b^-1)?0:l)|b&e|(c&g?0:a&j)))|(c&n?0:b&i))|b&o;break i;case 24:break j;case 2:break k;case 25:break l;case 23:break w;default:break h}}J[5996]=0;s=_(54,2779,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;k=_(54,1293,3)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;o=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;u=_(54,1959,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;w=_(54,1029,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;x=_(54,1295,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2315,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,1681,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}c=h^-1;E:{if(c&b){e=0;J[5996]=0;b=_(54,2315,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}if((d^-1)&b){break E}}e=a&m;}J[5996]=0;q=_(54,2522,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2451,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,1681,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}F:{if(b&c){j=0;J[5996]=0;b=_(54,2315,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}if((d^-1)&b){break F}}j=a&h&m;}J[5996]=0;a=_(54,2049,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2451,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}n=d&h&m;G:{if(b&c){g=d|h;i=m|g;a=0;break G}J[5996]=0;b=_(54,1681,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}g=d|h;i=m|g;a=b&(i^-1)?0:a&n;}J[5996]=0;p=_(54,1681,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;r=_(54,1239,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;y=_(54,2167,4)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;b=_(54,2165,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break g}f=0;J[5996]=0;l=_(54,2165,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}H:{if(l&(n^-1)){break H}J[5996]=0;f=_(54,2295,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&f)){f=0;J[5996]=0;l=_(54,2278,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!((d^-1)&l)){break H}}J[5996]=0;f=_(54,2278,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&f)){f=0;J[5996]=0;l=_(54,2295,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!((d^-1)&l)){break H}}J[5996]=0;f=_(54,2174,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&f)){f=0;J[5996]=0;l=_(54,2170,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!((d^-1)&l)){break H}}J[5996]=0;f=_(54,2170,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break g}if(!(c&f)){f=0;J[5996]=0;l=_(54,2174,1)|0;t=J[5996];J[5996]=0;if((t|0)==1){break g}if(!((d^-1)&l)){break H}}f=b;}b=d&m;d=b|h;b=i&y|(g&p&m|(r|(a|(m&q|(b&x|(n&o|(c&k?0:b&s))|(w&(d^-1)?0:d&u)|e)|j))))|f;break i}c=8;f=2144;}J[5996]=0;b=_(54,f|0,c|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){break i}break g}f=0;J[5996]=0;j=1;c=_(54,2165,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}I:{if((i|0)==(v|0)){a=1;h=0;break I}e=J[v>>2];b=0;J[5996]=0;a=_(54,1293,3)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}d=e^-1;if(d&a){break i}J[5996]=0;g=_(54,2451,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;h=_(54,2049,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;m=_(54,1681,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,1029,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}if(a&d){J[5996]=0;a=_(54,1959,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}f=a&d?2:1;}J[5996]=0;k=_(54,2167,4)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;a=_(54,2165,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}J[5996]=0;j=_(54,2165,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=0;J:{if(j&(c&e^-1)){break J}K:{if(n>>>0<2){break K}J[5996]=0;b=_(54,2295,1)|0;j=J[5996];J[5996]=0;if((j|0)==1){break g}j=c^-1;if(!(j&b)){b=0;J[5996]=0;o=_(54,2278,1)|0;u=J[5996];J[5996]=0;if((u|0)==1){break g}if(!(d&o)){break J}}J[5996]=0;b=_(54,2278,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}if(!(b&j)){b=0;J[5996]=0;o=_(54,2295,1)|0;u=J[5996];J[5996]=0;if((u|0)==1){break g}if(!(d&o)){break J}}J[5996]=0;b=_(54,2174,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}if(!(b&j)){b=0;J[5996]=0;o=_(54,2170,1)|0;u=J[5996];J[5996]=0;if((u|0)==1){break g}if(!(d&o)){break J}}J[5996]=0;b=_(54,2170,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}if(b&j){break K}b=0;J[5996]=0;j=_(54,2174,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break g}if(!(d&j)){break J}}b=a;}a=!(d&g);j=!(d&h);h=!(d&m);c=k&(c|e)|b;b=i-v|0;if(b>>>0<5){break I}b=b>>2;o=b>>>0<=2?2:b;e=1;while(1){m=J[(e<<2)+v>>2];J[5996]=0;b=_(54,1289,3)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}i=m^-1;if(i&b){b=0;break i}J[5996]=0;u=_(54,2451,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break b}J[5996]=0;w=_(54,2049,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break b}J[5996]=0;x=_(54,1681,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break b}J[5996]=0;b=_(54,1029,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}if(b&i){J[5996]=0;b=_(54,1959,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}b=b&i?2:1;}else {b=0;}J[5996]=0;q=_(54,2167,4)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}J[5996]=0;g=_(54,2165,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}J[5996]=0;k=_(54,2165,1)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}d=0;L:{if(k&(c&m^-1)){break L}M:{if(n>>>0<2){break M}J[5996]=0;k=_(54,2295,1)|0;p=J[5996];J[5996]=0;if((p|0)==1){break b}l=k;k=c^-1;if(!(l&k)){J[5996]=0;p=_(54,2278,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(!(i&p)){break L}}J[5996]=0;p=_(54,2278,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(!(k&p)){J[5996]=0;p=_(54,2295,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(!(i&p)){break L}}J[5996]=0;p=_(54,2174,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(!(k&p)){J[5996]=0;p=_(54,2170,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(!(i&p)){break L}}J[5996]=0;p=_(54,2170,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break b}if(k&p){break M}J[5996]=0;k=_(54,2174,1)|0;p=J[5996];J[5996]=0;if((p|0)==1){break b}if(!(i&k)){break L}}d=g;}a=!(i&u)&a;j=!(i&w)&j;h=!(i&x)+h|0;f=b+f|0;c=q&(c|m)|d;e=e+1|0;if((o|0)!=(e|0)){continue}break}}J[5996]=0;b=_(54,1293,3)|0;d=J[5996];J[5996]=0;if((d|0)==1){break g}J[5996]=0;d=_(54,1029,1)|0;e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=_(54,1959,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break g}J[5996]=0;g=_(54,2451,1)|0;i=J[5996];J[5996]=0;if((i|0)==1){break g}J[5996]=0;i=_(54,2049,1)|0;m=J[5996];J[5996]=0;if((m|0)==1){break g}J[5996]=0;m=_(54,1681,1)|0;k=J[5996];J[5996]=0;if((k|0)==1){break g}b=b|c|(f?0:d)|((f|0)==1?e:0)|(a?(h|0)==(s|0)?g:0:0);c=a&j?i:0;a=s-n|0;b=b|(a>>>0<=h>>>0?c:0)|(a+1>>>0<=h>>>0?m:0);}J[5996]=0;c=_(54,3310,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;d=_(54,2796,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;f=_(54,3557,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}J[5996]=0;j=_(54,2777,1)|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}e=2356;a=19;g=4075;N:{O:{k=d;d=b^-1;c=((!(k&d)+!(c&d)|0)+!(d&f)|0)+!(d&j)|0;switch(c|0){case 0:break N;case 1:break O;default:break h}}J[5996]=0;a=_(54,1029,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}P:{if(a&d){break P}J[5996]=0;a=_(54,1959,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break P}a=20;g=4494;break h}J[5996]=0;a=_(54,2029,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}Q:{if(a&d){break Q}J[5996]=0;a=_(54,1029,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break Q}a=21;g=4356;break h}J[5996]=0;a=_(54,2029,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}R:{if(a&d){break R}J[5996]=0;a=_(54,2777,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break R}a=22;g=4771;break h}J[5996]=0;a=_(54,2796,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}S:{if(a&d){break S}J[5996]=0;a=_(54,2522,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break S}a=23;g=4702;break h}J[5996]=0;a=_(54,3310,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}T:{if(a&d){break T}J[5996]=0;a=_(54,1295,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(!(a&d)){break T}a=24;g=4426;break h}J[5996]=0;a=_(54,2796,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}U:{if(a&d){break U}J[5996]=0;a=_(54,1295,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break U}a=25;g=4391;break h}J[5996]=0;a=_(54,2451,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}V:{if(a&d){break V}J[5996]=0;a=_(54,2315,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break V}a=26;g=4563;break h}J[5996]=0;a=_(54,2451,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}W:{if(a&d){break W}J[5996]=0;a=_(54,2522,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(!(a&d)){break W}a=27;g=4737;break h}J[5996]=0;a=_(54,2796,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}X:{if(a&d){break X}J[5996]=0;a=_(54,2451,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break X}a=28;g=4667;break h}J[5996]=0;a=_(54,2522,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}Y:{if(a&d){break Y}J[5996]=0;a=_(54,2315,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){break Y}a=29;g=4598;break h}J[5996]=0;a=_(54,2796,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}Z:{if(a&d){break Z}J[5996]=0;a=_(54,2315,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(!(a&d)){break Z}a=30;g=4633;break h}J[5996]=0;a=_(54,3310,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}_:{if(a&d){break _}J[5996]=0;a=_(54,1681,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(!(a&d)){break _}a=31;g=4460;break h}J[5996]=0;a=_(54,1029,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}if(a&d){c=b;break N}J[5996]=0;a=_(54,2049,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break g}c=b;if(!(a&d)){break N}a=32;g=4529;break h}if(v){$a(v);}return c|0}J[5996]=0;ga(44,g|0,1859,a|0,e|0);a=J[5996];J[5996]=0;if((a|0)!=1){break a}}}a=Z()|0;if(v){$a(v);}da(a|0);B();}B();}function jn(a,b,c,d,e,f,g,h,i,j,k){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0;var l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0;l=Ua-304|0;Ua=l;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{m=Gb(a);if(m>>>0>=2147483632){J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)==1){break s}break a}t:{if(m>>>0<=10){H[l+155|0]=m;n=l+144|0;break t}J[5996]=0;o=(m|15)+1|0;n=$(3,o|0)|0;p=J[5996];J[5996]=0;if((p|0)==1){break s}J[l+144>>2]=n;J[l+148>>2]=m;J[l+152>>2]=o|-2147483648;}H[fb(n,a,m)+m|0]=0;q=J[l+144>>2];a=K[l+155|0];r=a<<24>>24;m=(r|0)<0;p=m?q:l+144|0;s=m?J[l+148>>2]:a;m=p+s|0;n=-1;u:{while(1){if((m|0)==(p|0)){break u}m=m-1|0;o=K[m|0];v=o>>>0<=63;a=o&31;if((o&63)>>>0>=32){o=1<>>32-a;}a=t&9728;if(v&(o&1|(a|0)!=0)){continue}break}n=m-p|0;}a=n+1|0;if(a>>>0>s>>>0){J[5996]=0;ca(108);a=J[5996];J[5996]=0;if((a|0)!=1){break a}m=fa(22864)|0;a=Va;break m}v:{if((r|0)<0){J[l+148>>2]=a;break v}H[l+155|0]=a;q=l+144|0;}H[a+q|0]=0;J[l+12>>2]=0;J[l+16>>2]=0;w:{if(H[l+155|0]>=0){J[l+120>>2]=J[l+152>>2];a=J[l+148>>2];J[l+112>>2]=J[l+144>>2];J[l+116>>2]=a;break w}J[5996]=0;ea(40,l+112|0,J[l+144>>2],J[l+148>>2]);a=J[5996];J[5996]=0;if((a|0)==1){break r}}J[5996]=0;m=l+128|0;aa(109,m|0,l+112|0);a=J[5996];J[5996]=0;if((a|0)==1){break q}n=H[l+139|0];a=(n|0)<0;J[l+180>>2]=a?J[l+132>>2]:n&255;J[l+176>>2]=a?J[l+128>>2]:m;J[5996]=0;aa(29,l+248|0,l+176|0);a=J[5996];J[5996]=0;x:{y:{z:{A:{if((a|0)!=1){if(!J[l+180>>2]){break A}J[l+240>>2]=0;J[l+244>>2]=0;J[l+232>>2]=0;J[l+236>>2]=0;J[l+224>>2]=0;J[l+228>>2]=0;J[l+216>>2]=0;J[l+220>>2]=0;J[l+208>>2]=0;J[l+212>>2]=0;J[l+200>>2]=0;J[l+204>>2]=0;J[l+192>>2]=0;J[l+196>>2]=0;break z}m=Ra(22528,22864)|0;a=Va;if((a|0)!=(wa(22528)|0)){break x}pa(m|0)|0;J[l+240>>2]=0;J[l+244>>2]=0;J[l+232>>2]=0;J[l+236>>2]=0;J[l+224>>2]=0;J[l+228>>2]=0;J[l+216>>2]=0;J[l+220>>2]=0;J[l+208>>2]=0;J[l+212>>2]=0;J[l+200>>2]=0;J[l+204>>2]=0;J[l+192>>2]=0;J[l+196>>2]=0;J[5996]=0;ca(110);a=J[5996];J[5996]=0;if((a|0)!=1){break y}m=fa(22864)|0;a=Va;break x}a=J[l+260>>2];m=J[l+264>>2];J[l+260>>2]=0;J[l+264>>2]=0;J[l+204>>2]=a;J[l+208>>2]=m;a=J[l+268>>2];m=J[l+272>>2];J[l+268>>2]=0;J[l+272>>2]=0;J[l+212>>2]=a;J[l+216>>2]=m;J[l+228>>2]=J[l+284>>2];a=J[l+288>>2];J[l+284>>2]=0;J[l+288>>2]=0;J[l+192>>2]=J[l+248>>2];m=J[l+252>>2];n=J[l+256>>2];J[l+252>>2]=0;J[l+256>>2]=0;J[l+196>>2]=m;J[l+200>>2]=n;m=J[l+280>>2];J[l+220>>2]=J[l+276>>2];J[l+224>>2]=m;J[l+276>>2]=0;J[l+280>>2]=0;J[l+232>>2]=a;J[l+236>>2]=J[l+292>>2];J[l+292>>2]=0;a=J[l+296>>2];J[l+296>>2]=0;J[l+240>>2]=a;J[l+244>>2]=J[l+300>>2];}Fb(l+248|0);}if(!J[l+192>>2]){n=0;break o}J[l+184>>2]=0;J[l+176>>2]=0;J[l+180>>2]=0;J[l+256>>2]=0;J[l+260>>2]=0;J[5996]=0;J[l+248>>2]=0;J[l+252>>2]=0;J[l+264>>2]=1065353216;o=ba(111,l+192|0,l+248|0,l+176|0)|0;a=J[5996];J[5996]=0;B:{if((a|0)!=1){m=J[l+256>>2];if(m){while(1){a=J[m>>2];$a(m);m=a;if(a){continue}break}}a=J[l+248>>2];n=0;J[l+248>>2]=0;if(a){$a(a);}C:{D:{if(o){J[l+252>>2]=0;J[l+256>>2]=0;J[5996]=0;J[l+248>>2]=l+252;a=qa(50,o|0,1,0,l+248|0)|0;m=J[5996];J[5996]=0;if((m|0)==1){break D}J[5996]=0;m=_(54,1639,3)|0;n=J[5996];J[5996]=0;E:{F:{G:{H:{if((n|0)==1){break H}n=J[a>>2];a=J[a+4>>2];J[5996]=0;oa(51,l+160|0,n|0,a|0,m|0,0);a=J[5996];J[5996]=0;if((a|0)==1){break H}m=J[l+164>>2];n=J[l+160>>2];o=m-n|0;if((o|0)!=32){break G}m=J[n>>2];p=J[n+4>>2];J[n>>2]=0;J[n+4>>2]=0;a=J[l+16>>2];J[l+12>>2]=m;J[l+16>>2]=p;I:{if(!a){break I}m=J[a+4>>2];J[a+4>>2]=m-1;if(m){break I}Xa[J[J[a>>2]+8>>2]](a);bb(a);}n=J[l+160>>2];u=O[n+8>>3];m=J[l+164>>2];break F}m=fa(22864)|0;break C}if(!n){break E}}if((m|0)!=(n|0)){while(1){m=m-32|0;a=J[m+4>>2];J:{if(!a){break J}p=J[a+4>>2];J[a+4>>2]=p-1;if(p){break J}Xa[J[J[a>>2]+8>>2]](a);bb(a);}if((m|0)!=(n|0)){continue}break}m=J[l+160>>2];}J[l+164>>2]=n;$a(m);}xd(J[l+252>>2]);n=(o|0)==32;}a=J[l+176>>2];if(!a){break o}m=J[l+180>>2];if((a|0)!=(m|0)){while(1){m=m-4|0;ad(m);if((a|0)!=(m|0)){continue}break}a=J[l+176>>2];}$a(a);break o}m=fa(22864)|0;}a=Va;xd(J[l+252>>2]);break B}m=fa(22864)|0;a=Va;h=J[l+256>>2];if(h){while(1){i=J[h>>2];$a(h);h=i;if(h){continue}break}}h=J[l+248>>2];J[l+248>>2]=0;if(h){$a(h);}}h=J[l+176>>2];if(h){j=J[l+180>>2];i=h;if((j|0)!=(h|0)){while(1){j=j-4|0;ad(j);if((h|0)!=(j|0)){continue}break}i=J[l+176>>2];}J[l+180>>2]=h;$a(i);}Fb(l+192|0);}if(H[l+139|0]>=0){break p}$a(J[l+128>>2]);break p}m=fa(22864)|0;a=Va;break l}m=fa(22864)|0;a=Va;break n}m=fa(22864)|0;a=Va;}if(H[l+123|0]>=0){break n}$a(J[l+112>>2]);break n}Fb(l+192|0);if(H[l+139|0]<0){$a(J[l+128>>2]);}if(H[l+123|0]<0){$a(J[l+112>>2]);}K:{L:{M:{N:{O:{P:{Q:{R:{if(!n){J[5996]=0;a=$(3,16)|0;h=J[5996];J[5996]=0;S:{T:{if((h|0)!=1){H[a+15|0]=0;h=K[2587]|K[2588]<<8|(K[2589]<<16|K[2590]<<24);i=K[2583]|K[2584]<<8|(K[2585]<<16|K[2586]<<24);H[a+7|0]=i;H[a+8|0]=i>>>8;H[a+9|0]=i>>>16;H[a+10|0]=i>>>24;H[a+11|0]=h;H[a+12|0]=h>>>8;H[a+13|0]=h>>>16;H[a+14|0]=h>>>24;h=K[2580]|K[2581]<<8|(K[2582]<<16|K[2583]<<24);i=K[2576]|K[2577]<<8|(K[2578]<<16|K[2579]<<24);H[a|0]=i;H[a+1|0]=i>>>8;H[a+2|0]=i>>>16;H[a+3|0]=i>>>24;H[a+4|0]=h;H[a+5|0]=h>>>8;H[a+6|0]=h>>>16;H[a+7|0]=h>>>24;h=((c|0)>=16?16:c)-1|0;H[fb(b,a,h)+h|0]=0;$a(a);J[5996]=0;k=$(3,16)|0;a=J[5996];J[5996]=0;if((a|0)==1){break T}H[k+15|0]=0;h=K[2587]|K[2588]<<8|(K[2589]<<16|K[2590]<<24);i=h;a=K[2583]|K[2584]<<8|(K[2585]<<16|K[2586]<<24);H[k+7|0]=a;n=a>>>8|0;H[k+8|0]=n;o=a>>>16|0;H[k+9|0]=o;p=a>>>24|0;H[k+10|0]=p;H[k+11|0]=h;H[k+12|0]=h>>>8;H[k+13|0]=h>>>16;H[k+14|0]=h>>>24;j=K[2580]|K[2581]<<8|(K[2582]<<16|K[2583]<<24);h=K[2576]|K[2577]<<8|(K[2578]<<16|K[2579]<<24);H[k|0]=h;H[k+1|0]=h>>>8;H[k+2|0]=h>>>16;H[k+3|0]=h>>>24;H[k+4|0]=j;H[k+5|0]=j>>>8;H[k+6|0]=j>>>16;H[k+7|0]=j>>>24;m=((e|0)>=16?16:e)-1|0;H[fb(d,k,m)+m|0]=0;$a(k);J[5996]=0;k=$(3,16)|0;m=J[5996];J[5996]=0;if((m|0)==1){break S}H[k+15|0]=0;H[k+7|0]=a;H[k+8|0]=n;H[k+9|0]=o;H[k+10|0]=p;a=i;H[k+11|0]=a;H[k+12|0]=a>>>8;H[k+13|0]=a>>>16;H[k+14|0]=a>>>24;H[k|0]=h;H[k+1|0]=h>>>8;H[k+2|0]=h>>>16;H[k+3|0]=h>>>24;a=j;H[k+4|0]=a;H[k+5|0]=a>>>8;H[k+6|0]=a>>>16;H[k+7|0]=a>>>24;a=((g|0)>=16?16:g)-1|0;H[fb(f,k,a)+a|0]=0;$a(k);break R}m=fa(22864)|0;a=Va;break n}m=fa(22864)|0;a=Va;break n}m=fa(22864)|0;a=Va;break n}J[5996]=0;a=J[l+12>>2];J[l+200>>2]=0;J[l+192>>2]=0;J[l+196>>2]=0;p=$(3,12)|0;m=J[5996];J[5996]=0;if((m|0)==1){break K}H[p+8|0]=0;J[p+4>>2]=0;J[p>>2]=a;m=p+12|0;t=m;U:{V:{W:{while(1){X:{r=m-12|0;o=J[r+4>>2];a=J[r>>2];n=J[a+32>>2];s=J[a+36>>2]-n>>3;Y:{if(s>>>0>o>>>0){s=1;J[r+4>>2]=o+1;a=J[a>>2];Z:{if(a-10>>>0<7){break Z}_:{switch(a-17|0){case 0:s=J[J[n+8>>2]>>2]==1;break Z;case 5:if(!J[J[n>>2]>>2]){break Z}s=!J[J[n+8>>2]>>2];break Z;default:break _}}s=0;}a=J[n+(o<<3)>>2];if(m>>>0>>0){H[m+8|0]=s;J[m+4>>2]=0;J[m>>2]=a;m=m+12|0;break Y}$:{r=(m-p|0)/12|0;n=r+1|0;aa:{if(n>>>0>=357913942){J[5996]=0;ca(112);break aa}o=(t-p|0)/12|0;q=o<<1;n=o>>>0>=178956970?357913941:n>>>0>>0?q:n;if(n>>>0<357913942){break $}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}m=fa(22864)|0;break M}J[5996]=0;q=P(n,12);o=$(3,q|0)|0;n=J[5996];J[5996]=0;if((n|0)==1){break N}n=o+P(r,12)|0;H[n+8|0]=s;J[n+4>>2]=0;J[n>>2]=a;a=n;if((m|0)!=(p|0)){while(1){m=m-12|0;r=J[m+4>>2];a=a-12|0;J[a>>2]=J[m>>2];J[a+4>>2]=r;J[a+8>>2]=J[m+8>>2];if((m|0)!=(p|0)){continue}break}}t=o+q|0;m=n+12|0;if(p){$a(p);}p=a;break Y}q=J[l+192>>2];n=(J[l+196>>2]-q|0)/12|0;if(n>>>0>>0){J[5996]=0;ga(44,5135,2210,439,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}m=fa(22864)|0;break M}m=K[m-4|0];J[5996]=0;oa(113,l+248|0,m|0,a|0,(P(n,12)+q|0)+P(s,-12)|0,s|0);m=J[5996];J[5996]=0;ba:{if((m|0)!=1){if(K[l+260|0]){break ba}s=0;break U}m=fa(22864)|0;break M}n=J[l+196>>2];m=J[a+36>>2]-J[a+32>>2]>>3;a=J[l+192>>2];o=((n+P(m,-12)|0)-a|0)/12|0;ca:{if(!P(m,-12)){m=n;break ca}o=a+P(o,12)|0;a=o;m=a+P((P(m,12)|0)/12|0,12)|0;if((n|0)!=(m|0)){while(1){if(H[a+11|0]<0){$a(J[a>>2]);}q=J[m+4>>2];J[a>>2]=J[m>>2];J[a+4>>2]=q;J[a+8>>2]=J[m+8>>2];H[m+11|0]=0;H[m|0]=0;a=a+12|0;m=m+12|0;if((n|0)!=(m|0)){continue}break}n=J[l+196>>2];}m=o+P((a-o|0)/12|0,12)|0;if((n|0)!=(m|0)){while(1){a=n-12|0;if(H[n-1|0]<0){$a(J[a>>2]);}n=a;if((a|0)!=(m|0)){continue}break}}J[l+196>>2]=m;}o=J[l+200>>2];da:{if(o>>>0>m>>>0){a=J[l+252>>2];J[m>>2]=J[l+248>>2];J[m+4>>2]=a;J[m+8>>2]=J[l+256>>2];J[l+256>>2]=0;J[l+248>>2]=0;J[l+252>>2]=0;J[l+196>>2]=m+12;break da}ea:{fa:{n=J[l+192>>2];s=(m-n|0)/12|0;a=s+1|0;ga:{if(a>>>0>=357913942){J[5996]=0;ca(41);break ga}o=(o-n|0)/12|0;q=o<<1;q=o>>>0>=178956970?357913941:a>>>0>>0?q:a;if(!q){o=0;break ea}if(q>>>0<357913942){break fa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}m=fa(22864)|0;break W}J[5996]=0;o=$(3,P(q,12)|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break X}}a=P(s,12)+o|0;s=J[l+252>>2];J[a>>2]=J[l+248>>2];J[a+4>>2]=s;J[a+8>>2]=J[l+256>>2];J[l+256>>2]=0;J[l+248>>2]=0;J[l+252>>2]=0;o=P(q,12)+o|0;q=a+12|0;ha:{if((m|0)==(n|0)){J[l+200>>2]=o;J[l+196>>2]=q;J[l+192>>2]=a;break ha}while(1){m=m-12|0;s=J[m+4>>2];a=a-12|0;J[a>>2]=J[m>>2];J[a+4>>2]=s;J[a+8>>2]=J[m+8>>2];J[m>>2]=0;J[m+4>>2]=0;J[m+8>>2]=0;if((m|0)!=(n|0)){continue}break}J[l+200>>2]=o;n=J[l+196>>2];J[l+196>>2]=q;m=J[l+192>>2];J[l+192>>2]=a;if((m|0)==(n|0)){break ha}while(1){a=n-12|0;if(H[n-1|0]<0){$a(J[a>>2]);}n=a;if((a|0)!=(m|0)){continue}break}}if(!m){break da}$a(m);}if(!(!K[l+260|0]|H[l+259|0]>=0)){$a(J[l+248>>2]);}m=r;}if((m|0)!=(p|0)){continue}break V}break}m=fa(22864)|0;}a=Va;if(!K[l+260|0]|H[l+259|0]>=0){break L}$a(J[l+248>>2]);break L}a=J[l+192>>2];if((J[l+196>>2]-a|0)!=12){J[5996]=0;ga(44,4102,2210,450,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}m=fa(22864)|0;break M}s=J[a>>2];J[l+160>>2]=J[a+4>>2];m=K[a+7|0]|K[a+8|0]<<8|(K[a+9|0]<<16|K[a+10|0]<<24);H[l+163|0]=m;H[l+164|0]=m>>>8;H[l+165|0]=m>>>16;H[l+166|0]=m>>>24;J[a>>2]=0;J[a+4>>2]=0;q=K[a+11|0];J[a+8>>2]=0;}n=J[l+192>>2];if(n){a=J[l+196>>2];m=n;if((a|0)!=(m|0)){while(1){m=a-12|0;if(H[a-1|0]<0){$a(J[m>>2]);}a=m;if((n|0)!=(a|0)){continue}break}m=J[l+192>>2];}J[l+196>>2]=n;$a(m);}if(p){$a(p);}a=K[l+163|0]|K[l+164|0]<<8|(K[l+165|0]<<16|K[l+166|0]<<24);H[l+103|0]=a;H[l+104|0]=a>>>8;H[l+105|0]=a>>>16;H[l+106|0]=a>>>24;J[l+100>>2]=J[l+160>>2];J[l+96>>2]=s;J[l+160>>2]=0;H[l+163|0]=0;H[l+164|0]=0;H[l+165|0]=0;H[l+166|0]=0;H[l+107|0]=q;ia:{ja:{ka:{la:{ma:{na:{oa:{pa:{qa:{ra:{sa:{ta:{ua:{va:{wa:{xa:{ya:{za:{Aa:{Ba:{Ca:{Da:{p=J[l+100>>2];a=q<<24>>24<0;m=a?p:q&255;Ea:{if((m|0)<72){break Ea}o=a?s:l+96|0;n=o+m|0;while(1){a=o;while(1){a=Zb(a,115,m-71|0);if(!a){break Ea}if(Eb(a,5034,72)){a=a+1|0;m=n-a|0;if((m|0)>=72){continue}break Ea}break}if((a|0)==(n|0)){break Ea}a=a-o|0;if((a|0)==-1){break Ea}J[5996]=0;m=l+96|0;ga(114,m|0,a|0,72,4824);a=J[5996];J[5996]=0;if((a|0)==1){break Da}s=J[l+96>>2];n=m;a=K[l+107|0];q=a<<24>>24;m=(q|0)<0;o=m?s:n;p=J[l+100>>2];m=m?p:a;n=o+m|0;if((m|0)>71){continue}break}}Fa:{a=q<<24>>24;m=(a|0)<0?p:q&255;Ga:{if((m|0)<73){break Ga}o=(a|0)<0?s:l+96|0;n=o+m|0;while(1){a=o;while(1){a=Zb(a,104,m-72|0);if(!a){break Ga}if(Eb(a,4960,73)){a=a+1|0;m=n-a|0;if((m|0)>=73){continue}break Ga}break}if((a|0)==(n|0)){break Ga}a=a-o|0;if((a|0)==-1){break Ga}J[5996]=0;m=l+96|0;ga(114,m|0,a|0,73,4813);a=J[5996];J[5996]=0;if((a|0)==1){break Fa}s=J[l+96>>2];n=m;a=K[l+107|0];q=a<<24>>24;m=(q|0)<0;o=m?s:n;p=J[l+100>>2];m=m?p:a;n=o+m|0;if((m|0)>72){continue}break}}Ha:{a=q<<24>>24<0;m=a?p:q&255;Ia:{if((m|0)<51){break Ia}o=a?s:l+96|0;n=o+m|0;while(1){a=o;while(1){a=Zb(a,114,m-50|0);if(!a){break Ia}if(Eb(a,4908,51)){a=a+1|0;m=n-a|0;if((m|0)>=51){continue}break Ia}break}if((a|0)==(n|0)){break Ia}a=a-o|0;if((a|0)==-1){break Ia}J[5996]=0;m=l+96|0;ga(114,m|0,a|0,51,4845);a=J[5996];J[5996]=0;if((a|0)==1){break Ha}s=J[l+96>>2];n=m;a=K[l+107|0];q=a<<24>>24;m=(q|0)<0;o=m?s:n;p=J[l+100>>2];m=m?p:a;n=o+m|0;if((m|0)>50){continue}break}}Ja:{a=q<<24>>24;m=(a|0)<0?p:q&255;Ka:{if((m|0)<49){break Ka}p=(a|0)<0?s:l+96|0;n=p+m|0;while(1){a=p;while(1){a=Zb(a,104,m-48|0);if(!a){break Ka}if(Eb(a,4858,49)){a=a+1|0;m=n-a|0;if((m|0)>=49){continue}break Ka}break}if((a|0)==(n|0)){break Ka}a=a-p|0;if((a|0)==-1){break Ka}J[5996]=0;m=l+96|0;ga(114,m|0,a|0,49,4834);a=J[5996];J[5996]=0;if((a|0)==1){break Ja}n=m;a=K[l+107|0];m=a<<24>>24<0;p=m?J[l+96>>2]:n;m=m?J[l+100>>2]:a;n=p+m|0;if((m|0)>48){continue}break}}J[l+184>>2]=J[l+104>>2];J[l+104>>2]=0;m=J[l+100>>2];a=J[l+96>>2];J[l+176>>2]=a;J[l+180>>2]=m;J[l+96>>2]=0;J[l+100>>2]=0;m=K[l+187|0];n=m<<24>>24;o=(n|0)<0;p=o?a:l+176|0;m=o?J[l+180>>2]:m;o=c-1|0;m=(m|0)<(o|0)?m:o;H[fb(b,p,m)+m|0]=0;La:{if((n|0)>=0){break La}$a(a);if(H[l+107|0]>=0){break La}$a(J[l+96>>2]);}a=J[J[l+12>>2]+84>>2];J[5996]=0;m=l+36|0;aa(115,m|0,a|0);a=J[5996];J[5996]=0;if((a|0)==1){break Ba}J[5996]=0;a=ba(99,m|0,0,5442)|0;m=J[5996];J[5996]=0;if((m|0)==1){break Aa}J[l+56>>2]=J[a+8>>2];m=J[a+4>>2];J[l+48>>2]=J[a>>2];J[l+52>>2]=m;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;J[5996]=0;m=_(97,l+48|0,5422)|0;n=J[5996];J[5996]=0;if((n|0)==1){break za}J[l+72>>2]=J[m+8>>2];n=J[m+4>>2];J[l+64>>2]=J[m>>2];J[l+68>>2]=n;J[m>>2]=0;J[m+4>>2]=0;J[m+8>>2]=0;J[5996]=0;n=l+248|0;Da(116,n|0,+u);o=J[5996];J[5996]=0;if((o|0)==1){break ya}J[5996]=0;p=n;n=K[l+259|0];o=n<<24>>24<0;n=ba(100,l- -64|0,(o?J[l+248>>2]:p)|0,(o?J[l+252>>2]:n)|0)|0;o=J[5996];J[5996]=0;if((o|0)==1){break xa}J[l+88>>2]=J[n+8>>2];o=J[n+4>>2];J[l+80>>2]=J[n>>2];J[l+84>>2]=o;J[n>>2]=0;J[n+4>>2]=0;J[n+8>>2]=0;J[5996]=0;o=_(97,l+80|0,5504)|0;p=J[5996];J[5996]=0;if((p|0)==1){break wa}J[l+136>>2]=J[o+8>>2];p=J[o+4>>2];J[l+128>>2]=J[o>>2];J[l+132>>2]=p;J[o>>2]=0;J[o+4>>2]=0;J[o+8>>2]=0;p=J[J[l+12>>2]+84>>2];J[5996]=0;r=l+192|0;Da(116,r|0,+(u+ +(p>>>0)));p=J[5996];J[5996]=0;if((p|0)==1){break va}J[5996]=0;t=r;p=K[l+203|0];r=p<<24>>24<0;p=ba(100,l+128|0,(r?J[l+192>>2]:t)|0,(r?J[l+196>>2]:p)|0)|0;r=J[5996];J[5996]=0;if((r|0)==1){break ua}J[l+168>>2]=J[p+8>>2];r=J[p+4>>2];J[l+160>>2]=J[p>>2];J[l+164>>2]=r;J[p>>2]=0;J[p+4>>2]=0;J[p+8>>2]=0;J[5996]=0;r=_(97,l+160|0,3567)|0;q=J[5996];J[5996]=0;if((q|0)==1){break ta}J[l+184>>2]=J[r+8>>2];q=J[r+4>>2];J[l+176>>2]=J[r>>2];J[l+180>>2]=q;J[r>>2]=0;J[r+4>>2]=0;J[r+8>>2]=0;if(H[l+203|0]<0){$a(J[l+192>>2]);}if(H[p+11|0]<0){$a(J[p>>2]);}if(H[o+11|0]<0){$a(J[o>>2]);}if(H[l+259|0]<0){$a(J[l+248>>2]);}if(H[n+11|0]<0){$a(J[n>>2]);}if(H[m+11|0]<0){$a(J[m>>2]);}if(H[a+11|0]<0){$a(J[a>>2]);}n=J[l+176>>2];a=K[l+187|0];o=a<<24>>24;m=(o|0)<0;p=m?n:l+176|0;a=m?J[l+180>>2]:a;m=e-1|0;a=(a|0)<(m|0)?a:m;H[fb(d,p,a)+a|0]=0;J[5996]=0;m=l+248|0;aa(117,m|0,J[l+12>>2]);a=J[5996];J[5996]=0;if((a|0)==1){break la}J[l+220>>2]=J[l+276>>2];a=J[l+272>>2];J[l+212>>2]=J[l+268>>2];J[l+216>>2]=a;a=J[l+264>>2];J[l+204>>2]=J[l+260>>2];J[l+208>>2]=a;a=J[l+256>>2];J[l+196>>2]=J[l+252>>2];J[l+200>>2]=a;a=J[l+248>>2];J[l+192>>2]=a;J[5996]=0;p=a>>>0<29;r=p?l+196|0:J[l+200>>2];J[l+248>>2]=r;q=l+24|0;ga(102,q|0,m|0,r+(p?a:a-29|0)|0,0);a=J[5996];J[5996]=0;if((a|0)==1){break ka}a=J[l+24>>2];m=K[l+35|0];p=m<<24>>24;r=(p|0)<0;t=r?a:q;m=r?J[l+28>>2]:m;r=g-1|0;m=(m|0)<(r|0)?m:r;H[fb(f,t,m)+m|0]=0;if((p|0)<0){$a(a);}if(M[l+192>>2]>=29){$a(J[l+200>>2]);}a=J[l+12>>2];m=J[a+80>>2];if(!m|M[a+84>>2]>3600|(J[a+52>>2]+J[a+44>>2]>>>0>201|M[a+68>>2]>100)){break ja}J[5996]=0;p=_(54,2049,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break Q}if((m^-1)&p){break ja}m=J[a+80>>2];J[5996]=0;p=_(54,2165,1)|0;r=J[5996];J[5996]=0;if((r|0)==1){break Q}if(K[a+88|0]|(m^-1)&p){break ja}H[l+252|0]=0;J[l+248>>2]=1702195828;H[l+259|0]=4;a=((k|0)>=5?5:k)-1|0;H[fb(j,l+248|0,a)+a|0]=0;break ia}m=fa(22864)|0;break Ca}m=fa(22864)|0;break Ca}m=fa(22864)|0;break Ca}m=fa(22864)|0;}a=Va;if(H[l+107|0]>=0){break n}$a(J[l+96>>2]);break n}m=fa(22864)|0;a=Va;break n}m=fa(22864)|0;a=Va;break ma}m=fa(22864)|0;a=Va;break na}m=fa(22864)|0;a=Va;break oa}m=fa(22864)|0;a=Va;break pa}m=fa(22864)|0;a=Va;break qa}m=fa(22864)|0;a=Va;break ra}m=fa(22864)|0;a=Va;break sa}m=fa(22864)|0;a=Va;if(H[l+171|0]>=0){break sa}$a(J[l+160>>2]);}if(H[l+203|0]>=0){break ra}$a(J[l+192>>2]);}if(H[l+139|0]>=0){break qa}$a(J[l+128>>2]);}if(H[l+91|0]>=0){break pa}$a(J[l+80>>2]);}if(H[l+259|0]>=0){break oa}$a(J[l+248>>2]);}if(H[l+75|0]>=0){break na}$a(J[l+64>>2]);}if(H[l+59|0]>=0){break ma}$a(J[l+48>>2]);}if(H[l+47|0]>=0){break n}$a(J[l+36>>2]);break n}m=fa(22864)|0;break P}m=fa(22864)|0;a=Va;if(M[l+192>>2]<29){break O}$a(J[l+200>>2]);break O}H[l+252|0]=K[2354];H[l+259|0]=5;H[l+253|0]=0;J[l+248>>2]=K[2350]|K[2351]<<8|(K[2352]<<16|K[2353]<<24);a=((k|0)>=6?6:k)-1|0;H[fb(j,l+248|0,a)+a|0]=0;}J[5996]=0;a=$(118,J[l+12>>2])|0;j=J[5996];J[5996]=0;if((j|0)==1){break Q}Ma:{if(a){H[l+252|0]=0;J[l+248>>2]=1702195828;H[l+259|0]=4;a=((i|0)>=5?5:i)-1|0;H[fb(h,l+248|0,a)+a|0]=0;break Ma}H[l+252|0]=K[2354];H[l+259|0]=5;H[l+253|0]=0;J[l+248>>2]=K[2350]|K[2351]<<8|(K[2352]<<16|K[2353]<<24);a=((i|0)>=6?6:i)-1|0;H[fb(h,l+248|0,a)+a|0]=0;}if((o|0)>=0){break R}$a(n);}a=J[l+16>>2];Na:{if(!a){break Na}b=J[a+4>>2];J[a+4>>2]=b-1;if(b){break Na}Xa[J[J[a>>2]+8>>2]](a);bb(a);}if(H[l+155|0]>=0){break k}$a(J[l+144>>2]);break k}m=fa(22864)|0;}a=Va;}if((o|0)>=0){break n}$a(n);break n}m=fa(22864)|0;}a=Va;}rb(l+192|0);if(!p){break n}$a(p);break n}m=fa(22864)|0;a=Va;rb(l+192|0);}mb(l+12|0);}if(H[l+155|0]>=0){break l}$a(J[l+144>>2]);}if((wa(22864)|0)!=(a|0)){break c}a=pa(m|0)|0;a=Xa[J[J[a>>2]+8>>2]](a)|0;J[5996]=0;i=_(30,l+24|0,a|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break j}J[5996]=0;a=ba(99,i|0,0,5474)|0;h=J[5996];J[5996]=0;if((h|0)==1){break i}J[l+152>>2]=J[a+8>>2];h=J[a+4>>2];J[l+144>>2]=J[a>>2];J[l+148>>2]=h;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;J[5996]=0;h=_(97,l+144|0,2611)|0;j=J[5996];J[5996]=0;if((j|0)==1){break h}J[l+184>>2]=J[h+8>>2];i=J[h+4>>2];J[l+176>>2]=J[h>>2];J[l+180>>2]=i;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;m=b;b=J[l+176>>2];i=K[l+187|0];j=i<<24>>24;k=(j|0)<0;i=k?J[l+180>>2]:i;c=c-1|0;c=(c|0)>(i|0)?i:c;H[fb(m,k?b:l+176|0,c)+c|0]=0;Oa:{if((j|0)>=0){break Oa}$a(b);if(H[h+11|0]>=0){break Oa}$a(J[h>>2]);}if(H[a+11|0]<0){$a(J[a>>2]);}J[5996]=0;a=_(30,l+176|0,5575)|0;b=J[5996];J[5996]=0;if((b|0)==1){break f}i=d;b=J[a>>2];c=K[a+11|0];d=c<<24>>24;h=(d|0)<0;j=h?b:a;a=h?J[a+4>>2]:c;c=e-1|0;a=(a|0)<(c|0)?a:c;H[fb(i,j,a)+a|0]=0;if((d|0)<0){$a(b);}J[5996]=0;a=_(30,l+12|0,5575)|0;b=J[5996];J[5996]=0;if((b|0)==1){break e}b=J[a>>2];c=K[a+11|0];d=c<<24>>24;e=(d|0)<0;h=e?b:a;a=e?J[a+4>>2]:c;c=g-1|0;a=(a|0)<(c|0)?a:c;H[fb(f,h,a)+a|0]=0;if((d|0)<0){$a(b);}ra();}Ua=l+304|0;return}m=Z()|0;break d}m=Z()|0;break g}m=Z()|0;if(H[l+155|0]>=0){break g}$a(J[l+144>>2]);}if(H[i+11|0]>=0){break d}$a(J[i>>2]);break d}m=Z()|0;break d}m=Z()|0;}J[5996]=0;ca(110);a=J[5996];J[5996]=0;if((a|0)==1){break b}}da(m|0);B();}fa(0)|0;Vb();B();}B();}function _g(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0;f=Ua-144|0;Ua=f;l=O[b+24>>3];m=O[b+16>>3];a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{e=J[a>>2];switch(e|0){case 9:break j;case 8:break k;case 2:break l;case 3:break m;case 14:break n;case 15:break o;case 16:break p;case 19:break q;case 18:break r;case 17:break s;case 10:break t;case 11:break u;case 12:break v;case 13:break w;case 0:break x;case 4:case 5:break y;case 1:break z;case 21:break A;case 20:break B;case 6:break h;case 7:break i;default:break g}}d=J[a+4>>2];a=J[a+8>>2];if((d|0)==(a|0)){break g}while(1){_g(J[d>>2],b,c);d=d+4|0;if((a|0)!=(d|0)){continue}break}break g}a=$g(a,m,l,c);d=J[a>>2];c=J[a+4>>2];if((d|0)==(c|0)){break g}while(1){J[f+56>>2]=J[d>>2];a=J[d+4>>2];J[f+60>>2]=a;if(a){J[a+4>>2]=J[a+4>>2]+1;}a=J[f+60>>2];J[f>>2]=J[f+56>>2];J[f+4>>2]=a;Zg(b,d+8|0,f);d=d+32|0;if((c|0)!=(d|0)){continue}break}break g}hc(b,c,1,a+4|0,0,0);break g}n=(e|0)==4?4:5;Yc(f+56|0,n,m,l,0,0);J[5996]=0;d=$(46,n|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break f}J[f+88>>2]=0;J[f+80>>2]=0;J[f+84>>2]=0;H[f+136|0]=0;J[f+132>>2]=f+80;e=J[d+4>>2];h=J[d>>2];k=e-h|0;g=(k|0)/12|0;if((e|0)!=(h|0)){C:{D:{E:{if(g>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)==1){break E}break d}J[5996]=0;e=$(3,k|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break E}J[f+84>>2]=e;J[f+80>>2]=e;J[f+88>>2]=e+P(g,12);g=J[d+4>>2];d=J[d>>2];J[5996]=0;d=ia(48,f+88|0,d|0,g|0,e|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){break C}d=Z()|0;J[f+84>>2]=e;break D}d=Z()|0;}Nc(f+132|0);break c}J[f+84>>2]=d;}J[f+140>>2]=0;J[f+132>>2]=0;J[f+136>>2]=0;e=J[a+8>>2];d=J[a+4>>2];J[5996]=0;aa(49,f+132|0,e-d>>2);e=J[5996];J[5996]=0;if((e|0)!=1){d=J[f+84>>2];e=J[f+80>>2];if((d|0)!=(e|0)){u=a+40|0;d=e;while(1){J[f+128>>2]=0;J[f+120>>2]=0;J[f+124>>2]=0;F:{G:{H:{I:{g=J[a+8>>2];e=J[a+4>>2];q=P(s,12);d=q+d|0;if(g-e>>2==J[d+4>>2]-J[d>>2]>>3){h=0;o=1;j=0;if((e|0)!=(g|0)){break I}break H}J[5996]=0;ga(44,5170,1900,642,2497);a=J[5996];J[5996]=0;if((a|0)!=1){break d}d=Z()|0;break G}J:{K:{while(1){L:{d=j<<3;l=O[d+J[f+68>>2]>>3];m=O[d+J[f+56>>2]>>3];e=J[(j<<2)+e>>2];J[5996]=0;e=qa(50,e|0,+m,+l,c|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break L}d=d+J[q+J[f+80>>2]>>2]|0;g=J[d>>2];d=J[d+4>>2];k=J[e+4>>2];e=J[e>>2];J[5996]=0;oa(51,f+100|0,e|0,k|0,g|0,d|0);e=J[5996];J[5996]=0;if((e|0)==1){break K}g=J[f+128>>2];M:{if(g>>>0>h>>>0){J[h+8>>2]=0;J[h>>2]=0;J[h+4>>2]=0;J[h>>2]=J[f+100>>2];J[h+4>>2]=J[f+104>>2];J[h+8>>2]=J[f+108>>2];J[f+124>>2]=h+12;break M}N:{e=J[f+120>>2];k=(h-e|0)/12|0;d=k+1|0;O:{if(d>>>0>=357913942){J[5996]=0;ca(52);break O}g=(g-e|0)/12|0;i=g<<1;d=g>>>0>=178956970?357913941:d>>>0>>0?i:d;if(d>>>0<357913942){break N}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break d}break J}J[5996]=0;i=P(d,12);g=$(3,i|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break J}d=g+P(k,12)|0;J[d>>2]=J[f+100>>2];J[d+4>>2]=J[f+104>>2];J[d+8>>2]=J[f+108>>2];J[f+108>>2]=0;J[f+100>>2]=0;J[f+104>>2]=0;g=g+i|0;k=d+12|0;P:{if((e|0)==(h|0)){J[f+128>>2]=g;J[f+124>>2]=k;J[f+120>>2]=d;break P}while(1){d=d-12|0;h=h-12|0;J[d>>2]=J[h>>2];J[d+4>>2]=J[h+4>>2];J[d+8>>2]=J[h+8>>2];J[h+8>>2]=0;J[h>>2]=0;J[h+4>>2]=0;if((e|0)!=(h|0)){continue}break}J[f+128>>2]=g;e=J[f+124>>2];J[f+124>>2]=k;h=J[f+120>>2];J[f+120>>2]=d;if((e|0)==(h|0)){break P}while(1){i=e-12|0;k=J[i>>2];if(k){r=e-8|0;d=J[r>>2];g=k;if((d|0)!=(g|0)){while(1){d=d-32|0;e=J[d+4>>2];Q:{if(!e){break Q}g=J[e+4>>2];J[e+4>>2]=g-1;if(g){break Q}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(k|0)){continue}break}g=J[i>>2];}J[r>>2]=k;$a(g);}e=i;if((h|0)!=(e|0)){continue}break}}if(h){$a(h);}g=J[f+100>>2];if(!g){break M}e=g;d=J[f+104>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];R:{if(!e){break R}h=J[e+4>>2];J[e+4>>2]=h-1;if(h){break R}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(g|0)){continue}break}e=J[f+100>>2];}J[f+104>>2]=g;$a(e);}h=J[f+124>>2];e=h-12|0;o=P(J[e+4>>2]-J[e>>2]>>5,o);j=j+1|0;e=J[a+4>>2];if(j>>>0>2]-e>>2>>>0){continue}break H}break}d=Z()|0;break G}d=Z()|0;break G}d=Z()|0;_b(f+100|0);break G}h=0;k=J[f+132>>2];while(1){if((h|0)==(o|0)){break F}if(J[a+8>>2]!=J[a+4>>2]){d=0;g=J[f+120>>2];e=h;while(1){i=P(d,12);j=i+g|0;g=J[j>>2];J[k+(d<<2)>>2]=g+((e>>>0)%(J[j+4>>2]-g>>5>>>0)<<5);j=e;g=J[f+120>>2];e=i+g|0;e=(j>>>0)/(J[e+4>>2]-J[e>>2]>>5>>>0)|0;d=d+1|0;if(d>>>0>2]-J[a+4>>2]>>2>>>0){continue}break}}J[5996]=0;Ea(53,b|0,n|0,f+132|0,0,u|0);e=J[5996];J[5996]=0;h=h+1|0;if((e|0)!=1){continue}break}d=Z()|0;}Xc(f+120|0);break e}g=J[f+120>>2];if(g){d=J[f+124>>2];if((g|0)!=(d|0)){while(1){k=d-12|0;h=J[k>>2];if(h){e=h;i=d-8|0;d=J[i>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];S:{if(!e){break S}j=J[e+4>>2];J[e+4>>2]=j-1;if(j){break S}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(h|0)){continue}break}e=J[k>>2];}J[i>>2]=h;$a(e);}d=k;if((g|0)!=(d|0)){continue}break}g=J[f+120>>2];}$a(g);}s=s+1|0;d=J[f+80>>2];if(s>>>0<(J[f+84>>2]-d|0)/12>>>0){continue}break}}a=J[f+132>>2];if(a){$a(a);d=J[f+80>>2];}if(d){e=d;g=J[f+84>>2];if((e|0)!=(g|0)){while(1){a=g-12|0;b=J[a>>2];if(b){J[g-8>>2]=b;$a(b);}g=a;if((a|0)!=(d|0)){continue}break}e=J[f+80>>2];}J[f+84>>2]=d;$a(e);}a=J[f+68>>2];if(a){J[f+72>>2]=a;$a(a);}a=J[f+56>>2];if(!a){break g}J[f+60>>2]=a;$a(a);break g}d=Z()|0;break e}hc(b,c,0,a+4|0,0,0);break g}Yc(f+56|0,24,m,l,O[a+48>>3],J[a+8>>2]-J[a+4>>2]>>2);J[f+88>>2]=0;J[f+80>>2]=0;J[f+84>>2]=0;J[f+140>>2]=0;J[f+132>>2]=0;J[f+136>>2]=0;T:{U:{V:{W:{X:{Y:{Z:{_:{$:{g=J[a+4>>2];aa:{if((g|0)==J[a+8>>2]){k=-1;e=g;d=0;break aa}l=-1;e=g;k=-1;ba:{while(1){d=h<<3;m=O[d+J[f+68>>2]>>3];p=O[d+J[f+56>>2]>>3];e=J[(h<<2)+e>>2];J[5996]=0;e=qa(50,e|0,+p,+m,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break $}J[5996]=0;d=_(54,1283,5)|0;g=J[5996];J[5996]=0;ca:{da:{ea:{fa:{ga:{if((g|0)==1){break ga}g=J[e>>2];i=J[e+4>>2];J[5996]=0;oa(51,f+120|0,g|0,i|0,d|0,0);d=J[5996];J[5996]=0;if((d|0)==1){break ga}i=1;g=J[f+120>>2];switch(J[f+124>>2]-g>>5){case 0:break da;case 1:break ea;default:break fa}}d=Z()|0;break T}J[5996]=0;ga(44,4164,1900,807,2386);a=J[5996];J[5996]=0;if((a|0)!=1){break d}d=Z()|0;break U}J[5996]=0;aa(55,f+80|0,g|0);d=J[5996];J[5996]=0;if((d|0)==1){break _}J[5996]=0;d=_(54,1277,5)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ca}g=J[e>>2];e=J[e+4>>2];J[5996]=0;oa(51,f+100|0,g|0,e|0,d|0,0);e=J[5996];J[5996]=0;if((e|0)==1){break ca}ha:{ia:{ja:{e=J[f+100>>2];switch(J[f+104>>2]-e>>5){case 0:break ha;case 1:break ia;default:break ja}}J[5996]=0;ga(44,4146,1900,811,2386);a=J[5996];J[5996]=0;if((a|0)!=1){break d}break V}J[5996]=0;aa(55,f+132|0,e|0);e=J[5996];J[5996]=0;if((e|0)==1){break V}i=0;m=O[J[f+136>>2]-8>>3]-O[J[f+84>>2]-8>>3];if(!(m>l)){break ha}k=h;l=m;}g=J[f+100>>2];if(g){e=g;d=J[f+104>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];ka:{if(!e){break ka}j=J[e+4>>2];J[e+4>>2]=j-1;if(j){break ka}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(g|0)){continue}break}e=J[f+100>>2];}J[f+104>>2]=g;$a(e);}g=J[f+120>>2];}if(g){e=g;d=J[f+124>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];la:{if(!e){break la}j=J[e+4>>2];J[e+4>>2]=j-1;if(j){break la}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(g|0)){continue}break}e=J[f+120>>2];}J[f+124>>2]=g;$a(e);}if(i){break W}h=h+1|0;g=J[a+8>>2];e=J[a+4>>2];if(h>>>0>=g-e>>2>>>0){break ba}continue}break}d=Z()|0;break U}d=J[f+80>>2];}J[5996]=0;c=$(3,4)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Z}J[c>>2]=d+(k<<5);d=c+4|0;J[f+128>>2]=d;J[f+124>>2]=d;J[f+120>>2]=c;if((e|0)!=(g|0)){h=0;while(1){ma:{if((h|0)==(k|0)){break ma}c=J[f+132>>2]+(h<<5)|0;i=J[f+128>>2];if(i>>>0>d>>>0){J[d>>2]=c;d=d+4|0;J[f+124>>2]=d;break ma}na:{oa:{g=J[f+120>>2];o=d-g>>2;e=o+1|0;pa:{if(e>>>0>=1073741824){J[5996]=0;ca(56);break pa}i=i-g|0;j=i>>1;i=i>>>0>=2147483644?1073741823:e>>>0>>0?j:e;if(!i){j=0;break na}if(i>>>0<1073741824){break oa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break d}d=Z()|0;break X}J[5996]=0;j=$(3,i<<2)|0;e=J[5996];J[5996]=0;if((e|0)==1){break Y}}e=(o<<2)+j|0;J[e>>2]=c;c=e+4|0;if((d|0)!=(g|0)){while(1){e=e-4|0;d=d-4|0;J[e>>2]=J[d>>2];if((d|0)!=(g|0)){continue}break}d=J[f+120>>2];}J[f+128>>2]=(i<<2)+j;J[f+124>>2]=c;J[f+120>>2]=e;if(d){$a(d);}d=c;}h=h+1|0;if(h>>>0>2]-J[a+4>>2]>>2>>>0){continue}break}}l=O[a+48>>3];J[5996]=0;Ea(53,b|0,24,f+120|0,+l,a+40|0);a=J[5996];J[5996]=0;if((a|0)!=1){a=J[f+120>>2];if(!a){break W}$a(a);break W}d=Z()|0;g=J[f+120>>2];break X}d=Z()|0;break T}d=Z()|0;break U}d=Z()|0;break T}d=Z()|0;}if(!g){break T}$a(g);break T}a=J[f+132>>2];if(a){d=J[f+136>>2];if((a|0)!=(d|0)){while(1){d=d-32|0;b=J[d+4>>2];qa:{if(!b){break qa}c=J[b+4>>2];J[b+4>>2]=c-1;if(c){break qa}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((a|0)!=(d|0)){continue}break}a=J[f+132>>2];}$a(a);}a=J[f+80>>2];if(a){d=J[f+84>>2];if((a|0)!=(d|0)){while(1){d=d-32|0;b=J[d+4>>2];ra:{if(!b){break ra}c=J[b+4>>2];J[b+4>>2]=c-1;if(c){break ra}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((a|0)!=(d|0)){continue}break}a=J[f+80>>2];}$a(a);}a=J[f+68>>2];if(a){J[f+72>>2]=a;$a(a);}a=J[f+56>>2];if(!a){break g}J[f+60>>2]=a;$a(a);break g}d=Z()|0;_b(f+100|0);}_b(f+120|0);}_b(f+132|0);_b(f+80|0);break c}e=J[a+4>>2];d=J[e+4>>2];g=J[e>>2];h=J[e+8>>2];e=cb(12);J[f+56>>2]=e;k=e+12|0;J[f+64>>2]=k;J[e+8>>2]=h;J[e+4>>2]=g;J[e>>2]=d;J[f+60>>2]=k;l=O[a+48>>3];J[5996]=0;ja(57,b|0,c|0,23,a+4|0,+l,0);a=J[5996];J[5996]=0;sa:{if((a|0)==1){break sa}J[5996]=0;ja(57,b|0,c|0,23,f+56|0,+l,0);a=J[5996];J[5996]=0;if((a|0)==1){break sa}$a(e);break g}break a}e=J[a+4>>2];d=J[e>>2];g=J[e+4>>2];e=cb(8);J[f+56>>2]=e;h=e+8|0;J[f+64>>2]=h;J[e>>2]=go(d,g,32);J[e+4>>2]=Wa;J[f+60>>2]=h;d=a+4|0;m=O[a+48>>3];p=1-m;ta:{if(l==0){J[5996]=0;ja(57,b|0,c|0,20,d|0,+m,0);a=J[5996];J[5996]=0;if((a|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,20,f+56|0,+p,0);a=J[5996];J[5996]=0;if((a|0)==1){break ta}}J[5996]=0;ja(57,b|0,c|0,19,d|0,+m,0);a=J[5996];J[5996]=0;if((a|0)==1){break ta}J[5996]=0;a=f+56|0;ja(57,b|0,c|0,19,a|0,+p,0);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,21,d|0,+m,0);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,21,a|0,+p,0);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,22,d|0,+m,0);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,22,a|0,+p,0);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,22,d|0,+m,1);d=J[5996];J[5996]=0;if((d|0)==1){break ta}J[5996]=0;ja(57,b|0,c|0,22,a|0,+p,1);a=J[5996];J[5996]=0;if((a|0)==1){break ta}$a(e);break g}break a}e=J[a+4>>2];d=J[e>>2];g=J[e+4>>2];e=cb(8);J[f+56>>2]=e;h=e+8|0;J[f+64>>2]=h;J[e>>2]=go(d,g,32);J[e+4>>2]=Wa;J[f+60>>2]=h;a=a+4|0;ua:{if(l==0){J[5996]=0;ja(57,b|0,c|0,17,a|0,0,0);d=J[5996];J[5996]=0;if((d|0)==1){break ua}J[5996]=0;ja(57,b|0,c|0,17,f+56|0,0,0);d=J[5996];J[5996]=0;if((d|0)==1){break ua}}J[5996]=0;ja(57,b|0,c|0,18,a|0,0,0);a=J[5996];J[5996]=0;if((a|0)==1){break ua}J[5996]=0;ja(57,b|0,c|0,18,f+56|0,0,0);a=J[5996];J[5996]=0;if((a|0)==1){break ua}$a(e);break g}break a}hc(b,c,14,a+4|0,0,0);break g}hc(b,c,15,a+4|0,0,0);break g}hc(b,c,16,a+4|0,0,0);break g}hc(b,c,13,a+4|0,0,0);break g}hc(b,c,12,a+4|0,0,0);break g}a=a+4|0;hc(b,c,10,a,0,0);hc(b,c,11,a,0,0);break g}e=J[a+40>>2];k=J[a+44>>2];if(!K[24588]){J[6145]=0;J[6146]=0;J[6143]=0;J[6144]=0;J[6141]=0;J[6142]=0;H[24588]=1;}n=Yg(f+56|0);J[5996]=0;d=$(46,25)|0;g=J[5996];J[5996]=0;va:{wa:{if((g|0)!=1){J[f+52>>2]=0;J[f+44>>2]=0;J[f+48>>2]=0;H[f+84|0]=0;J[f+80>>2]=f+44;g=J[d+4>>2];i=J[d>>2];j=g-i|0;h=(j|0)/12|0;if((g|0)!=(i|0)){if(h>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)!=1){break d}break wa}J[5996]=0;g=$(3,j|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break wa}J[f+48>>2]=g;J[f+44>>2]=g;J[f+52>>2]=g+P(h,12);h=J[d+4>>2];d=J[d>>2];J[5996]=0;d=ia(48,f+52|0,d|0,h|0,g|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){d=Z()|0;J[f+48>>2]=g;break va}J[f+48>>2]=d;}J[f+40>>2]=0;J[f+32>>2]=0;J[f+36>>2]=0;d=J[a+8>>2];g=J[a+4>>2];J[5996]=0;aa(49,f+32|0,d-g>>2);d=J[5996];J[5996]=0;xa:{if((d|0)!=1){ya:{za:{d=J[f+48>>2];g=J[f+44>>2];if((d|0)!=(g|0)){u=a+16|0;l=+(e>>>0)+ +(k|0)*4294967296;m=l+1;l=l*73+1;d=g;while(1){J[f+28>>2]=0;J[f+20>>2]=0;J[f+24>>2]=0;g=J[a+8>>2];e=J[a+4>>2];q=P(s,12);d=q+d|0;if(g-e>>2!=J[d+4>>2]-J[d>>2]>>3){break za}h=0;o=1;j=0;Aa:{if((e|0)!=(g|0)){Ba:{Ca:{Da:{while(1){d=j<<3;p=O[d+J[n+12>>2]>>3];v=O[d+J[n>>2]>>3];e=J[(j<<2)+e>>2];J[5996]=0;e=qa(50,e|0,+v,+p,c|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break Ca}d=d+J[q+J[f+44>>2]>>2]|0;g=J[d>>2];d=J[d+4>>2];k=J[e+4>>2];e=J[e>>2];J[5996]=0;oa(51,f+80|0,e|0,k|0,g|0,d|0);e=J[5996];J[5996]=0;if((e|0)!=1){g=J[f+28>>2];Ea:{if(g>>>0>h>>>0){J[h+8>>2]=0;J[h>>2]=0;J[h+4>>2]=0;J[h>>2]=J[f+80>>2];J[h+4>>2]=J[f+84>>2];J[h+8>>2]=J[f+88>>2];J[f+24>>2]=h+12;break Ea}Fa:{e=J[f+20>>2];k=(h-e|0)/12|0;d=k+1|0;Ga:{if(d>>>0>=357913942){J[5996]=0;ca(52);break Ga}g=(g-e|0)/12|0;i=g<<1;d=g>>>0>=178956970?357913941:d>>>0>>0?i:d;if(d>>>0<357913942){break Fa}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break d}break Da}J[5996]=0;i=P(d,12);g=$(3,i|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break Da}d=g+P(k,12)|0;J[d>>2]=J[f+80>>2];J[d+4>>2]=J[f+84>>2];J[d+8>>2]=J[f+88>>2];J[f+88>>2]=0;J[f+80>>2]=0;J[f+84>>2]=0;g=g+i|0;k=d+12|0;Ha:{if((e|0)==(h|0)){J[f+28>>2]=g;J[f+24>>2]=k;J[f+20>>2]=d;break Ha}while(1){d=d-12|0;h=h-12|0;J[d>>2]=J[h>>2];J[d+4>>2]=J[h+4>>2];J[d+8>>2]=J[h+8>>2];J[h+8>>2]=0;J[h>>2]=0;J[h+4>>2]=0;if((e|0)!=(h|0)){continue}break}J[f+28>>2]=g;e=J[f+24>>2];J[f+24>>2]=k;h=J[f+20>>2];J[f+20>>2]=d;if((e|0)==(h|0)){break Ha}while(1){i=e-12|0;k=J[i>>2];if(k){r=e-8|0;d=J[r>>2];g=k;if((d|0)!=(g|0)){while(1){d=d-32|0;e=J[d+4>>2];Ia:{if(!e){break Ia}g=J[e+4>>2];J[e+4>>2]=g-1;if(g){break Ia}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(k|0)){continue}break}g=J[i>>2];}J[r>>2]=k;$a(g);}e=i;if((h|0)!=(e|0)){continue}break}}if(h){$a(h);}g=J[f+80>>2];if(!g){break Ea}e=g;d=J[f+84>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];Ja:{if(!e){break Ja}h=J[e+4>>2];J[e+4>>2]=h-1;if(h){break Ja}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(g|0)){continue}break}e=J[f+80>>2];}J[f+84>>2]=g;$a(e);}h=J[f+24>>2];e=h-12|0;o=P(J[e+4>>2]-J[e>>2]>>5,o);j=j+1|0;e=J[a+4>>2];if(j>>>0>=J[a+8>>2]-e>>2>>>0){break Ba}continue}break}d=Z()|0;break ya}d=Z()|0;_b(f+80|0);break ya}d=Z()|0;break ya}if(!o){break Aa}}k=0;Ka:{La:{Ma:{Na:{while(1){h=J[f+32>>2];if(J[a+8>>2]!=J[a+4>>2]){d=0;g=J[f+20>>2];e=k;while(1){i=P(d,12);j=i+g|0;g=J[j>>2];J[(d<<2)+h>>2]=g+((e>>>0)%(J[j+4>>2]-g>>5>>>0)<<5);j=e;g=J[f+20>>2];e=i+g|0;e=(j>>>0)/(J[e+4>>2]-J[e>>2]>>5>>>0)|0;d=d+1|0;if(d>>>0>2]-J[a+4>>2]>>2>>>0){continue}break}}J[f+108>>2]=0;J[f+100>>2]=0;J[f+104>>2]=0;Oa:{Pa:{q=J[f+36>>2];if((q|0)!=(h|0)){while(1){i=J[h>>2];d=J[f+104>>2];Qa:{if((d|0)!=J[f+108>>2]){J[d>>2]=J[i>>2];e=J[i+4>>2];J[d+4>>2]=e;if(e){J[e+4>>2]=J[e+4>>2]+1;}J[f+104>>2]=d+8;break Qa}Ra:{g=J[f+100>>2];e=d-g|0;r=e>>3;j=r+1|0;Sa:{if(j>>>0>=536870912){J[5996]=0;ca(59);break Sa}t=e>>2;e=e>>>0>=2147483640?536870911:j>>>0>>0?t:j;if(e>>>0<536870912){break Ra}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break d}d=Z()|0;break Ka}J[5996]=0;t=e<<3;j=$(3,t|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break Pa}e=j+(r<<3)|0;J[e>>2]=J[i>>2];i=J[i+4>>2];J[e+4>>2]=i;if(i){J[i+4>>2]=J[i+4>>2]+1;d=J[f+104>>2];}i=j+t|0;j=e+8|0;Ta:{if((d|0)==(g|0)){J[f+108>>2]=i;J[f+104>>2]=j;J[f+100>>2]=e;break Ta}while(1){e=e-8|0;d=d-8|0;J[e>>2]=J[d>>2];J[e+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;if((d|0)!=(g|0)){continue}break}J[f+108>>2]=i;d=J[f+104>>2];J[f+104>>2]=j;g=J[f+100>>2];J[f+100>>2]=e;if((d|0)==(g|0)){break Ta}while(1){d=d-8|0;e=J[d+4>>2];Ua:{if(!e){break Ua}i=J[e+4>>2];J[e+4>>2]=i-1;if(i){break Ua}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(g|0)){continue}break}}if(!g){break Qa}$a(g);}h=h+4|0;if((q|0)!=(h|0)){continue}break}}O[f+88>>3]=m;O[f+80>>3]=l;J[5996]=0;h=$(3,104)|0;e=J[5996];J[5996]=0;if((e|0)!=1){break Oa}break La}d=Z()|0;break Ka}J[h>>2]=7e3;J[h+4>>2]=0;J[h+8>>2]=0;J[5996]=0;J[f+132>>2]=J[f+100>>2];e=J[f+104>>2];d=J[f+108>>2];J[f+108>>2]=0;J[f+136>>2]=e;J[f+140>>2]=d;J[f+100>>2]=0;J[f+104>>2]=0;i=_(32,f+120|0,u|0)|0;e=J[5996];J[5996]=0;if((e|0)!=1){e=J[a+40>>2];J[5996]=0;j=xa(60,h+12|0,25,f+132|0,i|0,e|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break Na}g=J[i>>2];if(g){e=J[f+124>>2];d=g;if((e|0)!=(d|0)){while(1){d=e-12|0;if(H[e-1|0]<0){$a(J[d>>2]);}e=d;if((e|0)!=(g|0)){continue}break}d=J[i>>2];}J[f+124>>2]=g;$a(d);}e=J[f+132>>2];if(e){d=J[f+136>>2];if((e|0)!=(d|0)){while(1){d=d-8|0;g=J[d+4>>2];Va:{if(!g){break Va}i=J[g+4>>2];J[g+4>>2]=i-1;if(i){break Va}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((d|0)!=(e|0)){continue}break}e=J[f+132>>2];}$a(e);}J[f+116>>2]=h;J[f+112>>2]=j;J[5996]=0;e=J[f+116>>2];J[f+8>>2]=J[f+112>>2];J[f+12>>2]=e;ea(61,b|0,f+80|0,f+8|0);e=J[5996];J[5996]=0;if((e|0)==1){break La}e=J[f+100>>2];if(e){d=J[f+104>>2];if((e|0)!=(d|0)){while(1){d=d-8|0;g=J[d+4>>2];Wa:{if(!g){break Wa}h=J[g+4>>2];J[g+4>>2]=h-1;if(h){break Wa}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((d|0)!=(e|0)){continue}break}e=J[f+100>>2];}$a(e);}k=k+1|0;if((o|0)!=(k|0)){continue}break Aa}break}d=Z()|0;break Ma}d=Z()|0;rb(i);}lb(f+132|0);$a(h);break Ka}d=Z()|0;}lb(f+100|0);break ya}g=J[f+20>>2];if(g){d=J[f+24>>2];if((g|0)!=(d|0)){while(1){k=d-12|0;h=J[k>>2];if(h){e=h;i=d-8|0;d=J[i>>2];if((e|0)!=(d|0)){while(1){d=d-32|0;e=J[d+4>>2];Xa:{if(!e){break Xa}j=J[e+4>>2];J[e+4>>2]=j-1;if(j){break Xa}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((d|0)!=(h|0)){continue}break}e=J[k>>2];}J[i>>2]=h;$a(e);}d=k;if((g|0)!=(d|0)){continue}break}g=J[f+20>>2];}$a(g);}s=s+1|0;d=J[f+44>>2];if(s>>>0<(J[f+48>>2]-d|0)/12>>>0){continue}break}}a=J[f+32>>2];if(a){$a(a);d=J[f+44>>2];}if(d){e=d;g=J[f+48>>2];if((e|0)!=(g|0)){while(1){a=g-12|0;b=J[a>>2];if(b){J[g-8>>2]=b;$a(b);}g=a;if((a|0)!=(d|0)){continue}break}e=J[f+44>>2];}J[f+48>>2]=d;$a(e);}a=J[n+12>>2];if(a){J[n+16>>2]=a;$a(a);}a=J[n>>2];if(!a){break g}J[n+4>>2]=a;$a(a);break g}J[5996]=0;ga(44,5170,1900,642,2497);a=J[5996];J[5996]=0;if((a|0)!=1){break d}d=Z()|0;}Xc(f+20|0);break xa}d=Z()|0;}a=J[f+32>>2];if(a){$a(a);}Wc(f+44|0);break b}a=Z()|0;Mc(n);da(a|0);B();}d=Z()|0;}Nc(f+80|0);break b}e=a+4|0;a=a+16|0;Xg(b,c,2,e,a);Xg(b,c,3,e,a);break g}wd(b,c,6,a+4|0,a+28|0);break g}wd(b,c,8,a+4|0,a+28|0);break g}wd(b,c,7,a+4|0,a+28|0);break g}wd(b,c,9,a+4|0,a+28|0);}Ua=f+144|0;return}d=Z()|0;break c}a=J[f+132>>2];if(a){$a(a);}Wc(f+80|0);break c}B();}Mc(f+56|0);da(d|0);B();}Mc(n);da(d|0);B();}a=Z()|0;$a(e);da(a|0);B();}function ig(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,E=0,F=0,G=0;q=Ua-48|0;Ua=q;a:{if(c>>>0<=2){c=c<<2;A=J[c+8972>>2];B=J[c+8960>>2];while(1){c=J[b+4>>2];b:{if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break b}c=gb(b);}if((c|0)==32|c-9>>>0<5){continue}break}t=1;c:{d:{switch(c-43|0){case 0:case 2:break d;default:break c}}t=(c|0)==45?-1:1;c=J[b+4>>2];if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break c}c=gb(b);}e:{f:{while(1){if(H[g+1031|0]==(c|32)){g:{if(g>>>0>6){break g}c=J[b+4>>2];if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break g}c=gb(b);}g=g+1|0;if((g|0)!=8){continue}break f}break}if((g|0)!=3){m=(g|0)==8;if(m){break f}if(!d|g>>>0<4){break e}if(m){break f}}c=J[b+116>>2];if((c|0)>0|(c|0)>=0){J[b+4>>2]=J[b+4>>2]-1;}if(!d|g>>>0<4){break f}c=(c|0)<0;while(1){if(!c){J[b+4>>2]=J[b+4>>2]-1;}g=g-1|0;if(g>>>0>3){continue}break}}l=Ua-16|0;Ua=l;h=(D(Q(Q(t|0)*Q(Infinity))),v(2));b=h&2147483647;h:{if(b-8388608>>>0<=2130706431){c=b;b=b>>>7|0;c=c<<25;d=b+1065353216|0;break h}c=h<<25;d=h>>>7|2147418112;if(b>>>0>=2139095040){break h}c=0;d=0;if(!b){break h}c=b;b=S(b);Cb(l,c,0,0,0,b+81|0);j=J[l>>2];i=J[l+4>>2];c=J[l+8>>2];d=J[l+12>>2]^65536|16265-b<<16;}J[q>>2]=j;J[q+4>>2]=i;J[q+8>>2]=c;J[q+12>>2]=h&-2147483648|d;Ua=l+16|0;j=J[q+8>>2];i=J[q+12>>2];h=J[q>>2];k=J[q+4>>2];break a}i:{j:{k:{if(g){break k}g=0;while(1){if(H[g+2020|0]!=(c|32)){break k}l:{if(g>>>0>1){break l}c=J[b+4>>2];if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break l}c=gb(b);}g=g+1|0;if((g|0)!=3){continue}break}break j}m:{switch(g|0){case 0:n:{if((c|0)!=48){break n}g=J[b+4>>2];o:{if((g|0)!=J[b+104>>2]){J[b+4>>2]=g+1;g=K[g|0];break o}g=gb(b);}if((g&-33)==88){m=0;f=Ua-432|0;Ua=f;c=J[b+4>>2];p:{if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;g=K[c|0];break p}g=gb(b);}q:{r:{while(1){if((g|0)!=48){s:{if((g|0)!=46){break q}c=J[b+4>>2];if((c|0)==J[b+104>>2]){break s}J[b+4>>2]=c+1;g=K[c|0];break r}}else {c=J[b+4>>2];if((c|0)!=J[b+104>>2]){e=1;J[b+4>>2]=c+1;g=K[c|0];}else {e=1;g=gb(b);}continue}break}g=gb(b);}p=1;if((g|0)!=48){break q}while(1){c=r;r=c-1|0;s=s-!c|0;c=J[b+4>>2];t:{if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;g=K[c|0];break t}g=gb(b);}if((g|0)==48){continue}break}e=1;}k=1073676288;u:{while(1){v:{c=g|32;w:{x:{E=g-48|0;if(E>>>0<10){break x}F=(g|0)!=46;if(F&c-97>>>0>5){break u}if(F){break x}if(p){break v}p=1;r=j;s=i;break w}c=(g|0)>57?c-87|0:E;y:{if((i|0)<=0&j>>>0<=7|(i|0)<0){m=c+(m<<4)|0;break y}if(!i&j>>>0<=28){Nb(f+48|0,c);ob(f+32|0,y,z,h,k,0,0,0,1073414144);y=J[f+32>>2];z=J[f+36>>2];h=J[f+40>>2];k=J[f+44>>2];ob(f+16|0,J[f+48>>2],J[f+52>>2],J[f+56>>2],J[f+60>>2],y,z,h,k);Hb(f,J[f+16>>2],J[f+20>>2],J[f+24>>2],J[f+28>>2],l,o,w,x);w=J[f+8>>2];x=J[f+12>>2];l=J[f>>2];o=J[f+4>>2];break y}if(C|!c){break y}ob(f+80|0,y,z,h,k,0,0,0,1073610752);Hb(f- -64|0,J[f+80>>2],J[f+84>>2],J[f+88>>2],J[f+92>>2],l,o,w,x);w=J[f+72>>2];x=J[f+76>>2];C=1;l=J[f+64>>2];o=J[f+68>>2];}j=j+1|0;i=j?i:i+1|0;e=1;}c=J[b+4>>2];if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;g=K[c|0];}else {g=gb(b);}continue}break}g=46;}z:{if(!e){c=J[b+116>>2];A:{B:{if((c|0)>0|(c|0)>=0){c=J[b+4>>2];J[b+4>>2]=c-1;if(!d){break B}J[b+4>>2]=c-2;if(!p){break A}J[b+4>>2]=c-3;break A}if(d){break A}}Yb(b,0,0);}fc(f+96|0,+(t|0)*0);l=J[f+96>>2];o=J[f+100>>2];c=J[f+108>>2];b=J[f+104>>2];break z}if((i|0)<=0&j>>>0<=7|(i|0)<0){h=j;k=i;while(1){m=m<<4;h=h+1|0;k=h?k:k+1|0;if((h|0)!=8|k){continue}break}}C:{D:{E:{if((g&-33)==80){h=hg(b,d);c=Wa;k=c;if(h|(c|0)!=-2147483648){break C}if(d){c=J[b+116>>2];if((c|0)>0|(c|0)>=0){break E}break D}l=0;o=0;Yb(b,0,0);c=0;b=0;break z}h=0;k=0;if(J[b+116>>2]<0){break C}}J[b+4>>2]=J[b+4>>2]-1;}h=0;k=0;}if(!m){fc(f+112|0,+(t|0)*0);l=J[f+112>>2];o=J[f+116>>2];c=J[f+124>>2];b=J[f+120>>2];break z}b=p?r:j;i=(p?s:i)<<2|b>>>30;c=h+(b<<2)|0;b=i+k|0;j=c-32|0;i=(c>>>0>>0?b+1|0:b)-(c>>>0<32)|0;b=i;if(j>>>0>0-A>>>0&(b|0)>=0|(b|0)>0){J[5732]=68;Nb(f+160|0,t);ob(f+144|0,J[f+160>>2],J[f+164>>2],J[f+168>>2],J[f+172>>2],-1,-1,-1,2147418111);ob(f+128|0,J[f+144>>2],J[f+148>>2],J[f+152>>2],J[f+156>>2],-1,-1,-1,2147418111);l=J[f+128>>2];o=J[f+132>>2];c=J[f+140>>2];b=J[f+136>>2];break z}b=A-226|0;c=b>>31;if((i|0)>=(c|0)&b>>>0<=j>>>0|(c|0)<(i|0)){if((m|0)>=0){while(1){Hb(f+416|0,l,o,w,x,0,0,0,-1073807360);b=Rg(l,o,w,x,1073610752);c=(b|0)>=0;b=c;Hb(f+400|0,l,o,w,x,b?J[f+416>>2]:l,b?J[f+420>>2]:o,b?J[f+424>>2]:w,b?J[f+428>>2]:x);b=j;j=b-1|0;i=i-!b|0;w=J[f+408>>2];x=J[f+412>>2];l=J[f+400>>2];o=J[f+404>>2];m=c|m<<1;if((m|0)>=0){continue}break}}b=i-((A>>31)+(j>>>0>>0)|0)|0;c=(j-A|0)+32|0;b=c>>>0<32?b+1|0:b;c=c>>>0>>0&(b|0)<=0|(b|0)<0?(c|0)>0?c:0:B;F:{if((c|0)>=113){Nb(f+384|0,t);r=J[f+392>>2];s=J[f+396>>2];y=J[f+384>>2];z=J[f+388>>2];h=0;b=0;break F}fc(f+352|0,xe(144-c|0));Nb(f+336|0,t);y=J[f+336>>2];z=J[f+340>>2];r=J[f+344>>2];s=J[f+348>>2];kg(f+368|0,J[f+352>>2],J[f+356>>2],J[f+360>>2],J[f+364>>2],y,z,r,s);n=J[f+376>>2];u=J[f+380>>2];h=J[f+372>>2];b=J[f+368>>2];}d=!(m&1)&((yc(l,o,w,x,0,0,0,0)|0)!=0&(c|0)<32);Ec(f+320|0,d+m|0);ob(f+304|0,y,z,r,s,J[f+320>>2],J[f+324>>2],J[f+328>>2],J[f+332>>2]);c=b;Hb(f+272|0,J[f+304>>2],J[f+308>>2],J[f+312>>2],J[f+316>>2],b,h,n,u);b=d;ob(f+288|0,y,z,r,s,b?0:l,b?0:o,b?0:w,b?0:x);Hb(f+256|0,J[f+288>>2],J[f+292>>2],J[f+296>>2],J[f+300>>2],J[f+272>>2],J[f+276>>2],J[f+280>>2],J[f+284>>2]);he(f+240|0,J[f+256>>2],J[f+260>>2],J[f+264>>2],J[f+268>>2],c,h,n,u);b=J[f+240>>2];d=J[f+244>>2];c=J[f+248>>2];h=J[f+252>>2];if(!yc(b,d,c,h,0,0,0,0)){J[5732]=68;}jg(f+224|0,b,d,c,h,j);l=J[f+224>>2];o=J[f+228>>2];c=J[f+236>>2];b=J[f+232>>2];break z}J[5732]=68;Nb(f+208|0,t);ob(f+192|0,J[f+208>>2],J[f+212>>2],J[f+216>>2],J[f+220>>2],0,0,0,65536);ob(f+176|0,J[f+192>>2],J[f+196>>2],J[f+200>>2],J[f+204>>2],0,0,0,65536);l=J[f+176>>2];o=J[f+180>>2];c=J[f+188>>2];b=J[f+184>>2];}J[q+16>>2]=l;J[q+20>>2]=o;J[q+24>>2]=b;J[q+28>>2]=c;Ua=f+432|0;j=J[q+24>>2];i=J[q+28>>2];h=J[q+16>>2];k=J[q+20>>2];break a}if(J[b+116>>2]<0){break n}J[b+4>>2]=J[b+4>>2]-1;}g=b;m=c;f=d;d=0;e=Ua-8976|0;Ua=e;F=0-A|0;E=F-B|0;G:{H:{while(1){if((m|0)!=48){I:{if((m|0)!=46){break G}b=J[g+4>>2];if((b|0)==J[g+104>>2]){break I}J[g+4>>2]=b+1;m=K[b|0];break H}}else {b=J[g+4>>2];if((b|0)!=J[g+104>>2]){J[g+4>>2]=b+1;m=K[b|0];}else {m=gb(g);}d=1;continue}break}m=gb(g);}C=1;if((m|0)!=48){break G}while(1){b=j;j=b-1|0;i=i-!b|0;b=J[g+4>>2];J:{if((b|0)!=J[g+104>>2]){J[g+4>>2]=b+1;m=K[b|0];break J}m=gb(g);}if((m|0)==48){continue}break}d=1;}J[e+784>>2]=0;K:{L:{b=(m|0)==46;c=m-48|0;M:{N:{O:{if(b|c>>>0<=9){while(1){P:{if(b&1){if(!C){j=h;i=k;C=1;break P}b=!d;break O}h=h+1|0;k=h?k:k+1|0;if((p|0)<=2044){u=(m|0)==48?u:h;b=(e+784|0)+(p<<2)|0;if(n){c=(P(J[b>>2],10)+m|0)-48|0;}J[b>>2]=c;d=1;c=n+1|0;b=(c|0)==9;n=b?0:c;p=b+p|0;break P}if((m|0)==48){break P}J[e+8960>>2]=J[e+8960>>2]|1;u=18396;}b=J[g+4>>2];Q:{if((b|0)!=J[g+104>>2]){J[g+4>>2]=b+1;m=K[b|0];break Q}m=gb(g);}b=(m|0)==46;c=m-48|0;if(b|c>>>0<10){continue}break}}j=C?j:h;i=C?i:k;if(!(!d|(m&-33)!=69)){l=hg(g,f);b=Wa;o=b;R:{if(l|(b|0)!=-2147483648){break R}if(!f){break M}l=0;o=0;if(J[g+116>>2]<0){break R}J[g+4>>2]=J[g+4>>2]-1;}i=i+o|0;j=j+l|0;i=j>>>0>>0?i+1|0:i;break L}b=!d;if((m|0)<0){break N}}if(J[g+116>>2]<0){break N}J[g+4>>2]=J[g+4>>2]-1;}if(!b){break L}J[5732]=28;}h=0;k=0;Yb(g,0,0);c=0;b=0;break K}b=J[e+784>>2];if(!b){fc(e,+(t|0)*0);h=J[e>>2];k=J[e+4>>2];c=J[e+12>>2];b=J[e+8>>2];break K}if(!(h>>>0>9&(k|0)>=0|(k|0)>0|((h|0)!=(j|0)|(i|0)!=(k|0))|(b>>>B|0?(B|0)<=30:0))){Nb(e+48|0,t);Ec(e+32|0,b);ob(e+16|0,J[e+48>>2],J[e+52>>2],J[e+56>>2],J[e+60>>2],J[e+32>>2],J[e+36>>2],J[e+40>>2],J[e+44>>2]);h=J[e+16>>2];k=J[e+20>>2];c=J[e+28>>2];b=J[e+24>>2];break K}if(j>>>0>F>>>1>>>0&(i|0)>=0|(i|0)>0){J[5732]=68;Nb(e+96|0,t);ob(e+80|0,J[e+96>>2],J[e+100>>2],J[e+104>>2],J[e+108>>2],-1,-1,-1,2147418111);ob(e- -64|0,J[e+80>>2],J[e+84>>2],J[e+88>>2],J[e+92>>2],-1,-1,-1,2147418111);h=J[e+64>>2];k=J[e+68>>2];c=J[e+76>>2];b=J[e+72>>2];break K}b=A-226|0;c=j>>>0>>0;b=b>>31;if(c&(i|0)<=(b|0)|(b|0)>(i|0)){J[5732]=68;Nb(e+144|0,t);ob(e+128|0,J[e+144>>2],J[e+148>>2],J[e+152>>2],J[e+156>>2],0,0,0,65536);ob(e+112|0,J[e+128>>2],J[e+132>>2],J[e+136>>2],J[e+140>>2],0,0,0,65536);h=J[e+112>>2];k=J[e+116>>2];c=J[e+124>>2];b=J[e+120>>2];break K}if(n){if((n|0)<=8){b=(e+784|0)+(p<<2)|0;g=J[b>>2];while(1){g=P(g,10);n=n+1|0;if((n|0)!=9){continue}break}J[b>>2]=g;}p=p+1|0;}n=j;S:{if((j|0)<(u|0)|(u|0)>=9|(j|0)>17){break S}if((j|0)==9){Nb(e+192|0,t);Ec(e+176|0,J[e+784>>2]);ob(e+160|0,J[e+192>>2],J[e+196>>2],J[e+200>>2],J[e+204>>2],J[e+176>>2],J[e+180>>2],J[e+184>>2],J[e+188>>2]);h=J[e+160>>2];k=J[e+164>>2];c=J[e+172>>2];b=J[e+168>>2];break K}if((n|0)<=8){Nb(e+272|0,t);Ec(e+256|0,J[e+784>>2]);ob(e+240|0,J[e+272>>2],J[e+276>>2],J[e+280>>2],J[e+284>>2],J[e+256>>2],J[e+260>>2],J[e+264>>2],J[e+268>>2]);Nb(e+224|0,J[(0-n<<2)+8960>>2]);Ng(e+208|0,J[e+240>>2],J[e+244>>2],J[e+248>>2],J[e+252>>2],J[e+224>>2],J[e+228>>2],J[e+232>>2],J[e+236>>2]);h=J[e+208>>2];k=J[e+212>>2];c=J[e+220>>2];b=J[e+216>>2];break K}b=(P(n,-3)+B|0)+27|0;c=J[e+784>>2];if(c>>>b|0?(b|0)<=30:0){break S}Nb(e+352|0,t);Ec(e+336|0,c);ob(e+320|0,J[e+352>>2],J[e+356>>2],J[e+360>>2],J[e+364>>2],J[e+336>>2],J[e+340>>2],J[e+344>>2],J[e+348>>2]);Nb(e+304|0,J[(n<<2)+8888>>2]);ob(e+288|0,J[e+320>>2],J[e+324>>2],J[e+328>>2],J[e+332>>2],J[e+304>>2],J[e+308>>2],J[e+312>>2],J[e+316>>2]);h=J[e+288>>2];k=J[e+292>>2];c=J[e+300>>2];b=J[e+296>>2];break K}while(1){b=p;p=b-1|0;if(!J[(e+784|0)+(p<<2)>>2]){continue}break}u=0;d=(n|0)%9|0;T:{if(!d){c=0;break T}c=0;d=(n|0)<0?d+9|0:d;U:{if(!b){b=0;break U}j=J[(0-d<<2)+8960>>2];l=1e9/(j|0)|0;m=0;g=0;while(1){h=m;i=e+784|0;k=i+(g<<2)|0;m=J[k>>2];p=(m>>>0)/(j>>>0)|0;h=h+p|0;J[k>>2]=h;h=!h&(c|0)==(g|0);c=h?c+1&2047:c;n=h?n-9|0:n;m=P(l,m-P(j,p)|0);g=g+1|0;if((g|0)!=(b|0)){continue}break}if(!m){break U}J[i+(b<<2)>>2]=m;b=b+1|0;}n=(n-d|0)+9|0;}while(1){g=(e+784|0)+(c<<2)|0;V:{while(1){W:{if((n|0)<36){break W}if((n|0)!=36){break V}if(M[g>>2]<=10384592){break W}n=36;break V}p=b+2047|0;d=0;while(1){h=b;l=p&2047;m=(e+784|0)+(l<<2)|0;b=J[m>>2];k=b>>>3|0;j=d;d=b<<29;j=j+d|0;b=k;i=d>>>0>j>>>0?b+1|0:b;if(!i&j>>>0<1000000001){d=0;}else {d=eo(j,i,1e9);b=co(d,Wa,-1e9,-1);j=b+j|0;}J[m>>2]=j;b=(c|0)==(l|0)?h:j?h:l;j=h-1&2047;b=(j|0)!=(l|0)?h:b;p=l-1|0;if((c|0)!=(l|0)){continue}break}u=u-29|0;b=h;if(!d){continue}break}c=c-1&2047;if((c|0)==(b|0)){g=(b+2046&2047)<<2;b=e+784|0;h=g+b|0;J[h>>2]=J[h>>2]|J[b+(j<<2)>>2];b=j;}n=n+9|0;J[(e+784|0)+(c<<2)>>2]=d;continue}break}X:{Y:while(1){j=b+1&2047;l=(e+784|0)+((b-1&2047)<<2)|0;while(1){h=(n|0)>45?9:1;Z:{while(1){d=c;g=0;_:{while(1){$:{c=d+g&2047;if((c|0)==(b|0)){break $}c=J[(e+784|0)+(c<<2)>>2];i=J[(g<<2)+8912>>2];if(c>>>0>>0){break $}if(c>>>0>i>>>0){break _}g=g+1|0;if((g|0)!=4){continue}}break}if((n|0)!=36){break _}g=0;j=0;i=0;h=0;k=0;while(1){c=d+g&2047;if((c|0)==(b|0)){b=b+1&2047;J[(e+(b<<2)|0)+780>>2]=0;}Ec(e+768|0,J[(e+784|0)+(c<<2)>>2]);ob(e+752|0,j,i,h,k,0,0,1342177280,1075633366);Hb(e+736|0,J[e+752>>2],J[e+756>>2],J[e+760>>2],J[e+764>>2],J[e+768>>2],J[e+772>>2],J[e+776>>2],J[e+780>>2]);h=J[e+744>>2];k=J[e+748>>2];j=J[e+736>>2];i=J[e+740>>2];g=g+1|0;if((g|0)!=4){continue}break}Nb(e+720|0,t);ob(e+704|0,j,i,h,k,J[e+720>>2],J[e+724>>2],J[e+728>>2],J[e+732>>2]);h=J[e+712>>2];k=J[e+716>>2];j=0;i=0;l=J[e+704>>2];o=J[e+708>>2];p=u+113|0;g=p-A|0;m=(g|0)<(B|0);c=m?(g|0)>0?g:0:B;if((c|0)<=112){break Z}break X}u=h+u|0;c=b;if((b|0)==(d|0)){continue}break}k=1e9>>>h|0;m=-1<>2];i=i+(f>>>h|0)|0;J[g>>2]=i;i=!i&(c|0)==(d|0);c=i?c+1&2047:c;n=i?n-9|0:n;g=P(k,f&m);d=d+1&2047;if((d|0)!=(b|0)){continue}break}if(!g){continue}if((c|0)!=(j|0)){J[p+(b<<2)>>2]=g;b=j;continue Y}J[l>>2]=J[l>>2]|1;continue}break}break}fc(e+656|0,xe(225-c|0));kg(e+688|0,J[e+656>>2],J[e+660>>2],J[e+664>>2],J[e+668>>2],l,o,h,k);y=J[e+696>>2];z=J[e+700>>2];w=J[e+688>>2];x=J[e+692>>2];fc(e+640|0,xe(113-c|0));Hg(e+672|0,l,o,h,k,J[e+640>>2],J[e+644>>2],J[e+648>>2],J[e+652>>2]);j=J[e+672>>2];i=J[e+676>>2];r=J[e+680>>2];s=J[e+684>>2];he(e+624|0,l,o,h,k,j,i,r,s);Hb(e+608|0,w,x,y,z,J[e+624>>2],J[e+628>>2],J[e+632>>2],J[e+636>>2]);h=J[e+616>>2];k=J[e+620>>2];l=J[e+608>>2];o=J[e+612>>2];}n=d+4&2047;aa:{if((n|0)==(b|0)){break aa}n=J[(e+784|0)+(n<<2)>>2];ba:{if(n>>>0<=499999999){if(!n&(d+5&2047)==(b|0)){break ba}fc(e+496|0,+(t|0)*.25);Hb(e+480|0,j,i,r,s,J[e+496>>2],J[e+500>>2],J[e+504>>2],J[e+508>>2]);r=J[e+488>>2];s=J[e+492>>2];j=J[e+480>>2];i=J[e+484>>2];break ba}if((n|0)!=5e8){fc(e+592|0,+(t|0)*.75);Hb(e+576|0,j,i,r,s,J[e+592>>2],J[e+596>>2],J[e+600>>2],J[e+604>>2]);r=J[e+584>>2];s=J[e+588>>2];j=J[e+576>>2];i=J[e+580>>2];break ba}G=+(t|0);if((d+5&2047)==(b|0)){fc(e+528|0,G*.5);Hb(e+512|0,j,i,r,s,J[e+528>>2],J[e+532>>2],J[e+536>>2],J[e+540>>2]);r=J[e+520>>2];s=J[e+524>>2];j=J[e+512>>2];i=J[e+516>>2];break ba}fc(e+560|0,G*.75);Hb(e+544|0,j,i,r,s,J[e+560>>2],J[e+564>>2],J[e+568>>2],J[e+572>>2]);r=J[e+552>>2];s=J[e+556>>2];j=J[e+544>>2];i=J[e+548>>2];}if((c|0)>111){break aa}Hg(e+464|0,j,i,r,s,0,0,0,1073676288);if(yc(J[e+464>>2],J[e+468>>2],J[e+472>>2],J[e+476>>2],0,0,0,0)){break aa}Hb(e+448|0,j,i,r,s,0,0,0,1073676288);r=J[e+456>>2];s=J[e+460>>2];j=J[e+448>>2];i=J[e+452>>2];}Hb(e+432|0,l,o,h,k,j,i,r,s);he(e+416|0,J[e+432>>2],J[e+436>>2],J[e+440>>2],J[e+444>>2],w,x,y,z);h=J[e+424>>2];k=J[e+428>>2];l=J[e+416>>2];o=J[e+420>>2];ca:{if((E-2|0)>=(p&2147483647)){break ca}J[e+408>>2]=h;J[e+412>>2]=k&2147483647;J[e+400>>2]=l;J[e+404>>2]=o;ob(e+384|0,l,o,h,k,0,0,0,1073610752);d=Rg(J[e+400>>2],J[e+404>>2],J[e+408>>2],J[e+412>>2],1081081856);b=(d|0)>=0;h=b?J[e+392>>2]:h;k=b?J[e+396>>2]:k;l=b?J[e+384>>2]:l;o=b?J[e+388>>2]:o;u=b+u|0;if(!(m&((c|0)!=(g|0)|(d|0)<0)&(yc(j,i,r,s,0,0,0,0)|0)!=0)&(u+110|0)<=(E|0)){break ca}J[5732]=68;}jg(e+368|0,l,o,h,k,u);h=J[e+368>>2];k=J[e+372>>2];c=J[e+380>>2];b=J[e+376>>2];}J[q+40>>2]=b;J[q+44>>2]=c;J[q+32>>2]=h;J[q+36>>2]=k;Ua=e+8976|0;j=J[q+40>>2];i=J[q+44>>2];h=J[q+32>>2];k=J[q+36>>2];break a;case 3:break j;default:break m}}c=J[b+116>>2];if((c|0)>0|(c|0)>=0){J[b+4>>2]=J[b+4>>2]-1;}break i}da:{c=J[b+4>>2];ea:{if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break ea}c=gb(b);}if((c|0)==40){g=1;break da}i=2147450880;if(J[b+116>>2]<0){break a}J[b+4>>2]=J[b+4>>2]-1;break a}while(1){fa:{c=J[b+4>>2];ga:{if((c|0)!=J[b+104>>2]){J[b+4>>2]=c+1;c=K[c|0];break ga}c=gb(b);}if(!(c-48>>>0<10|c-65>>>0<26|(c|0)==95)){if(c-97>>>0>=26){break fa}}g=g+1|0;continue}break}i=2147450880;if((c|0)==41){break a}c=J[b+116>>2];if((c|0)>0|(c|0)>=0){J[b+4>>2]=J[b+4>>2]-1;}ha:{if(d){if(g){break ha}break a}break i}while(1){if((c|0)>0|(c|0)>=0){J[b+4>>2]=J[b+4>>2]-1;}g=g-1|0;if(g){continue}break}break a}J[5732]=28;Yb(b,0,0);}i=0;}J[a>>2]=h;J[a+4>>2]=k;J[a+8>>2]=j;J[a+12>>2]=i;Ua=q+48|0;}function Bd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;c=Ua-112|0;Ua=c;f=J[b>>2];e=f;i=J[b+4>>2];a:{if(!i){break a}d=f+i|0;while(1){g=K[e|0];b:{if(!((g|0)!=123&(g|0)!=40)){h=h+1|0;break b}if(h){if((g|0)!=125&(g|0)!=41){break b}h=h-1|0;break b}h=0;c:{switch(g-41|0){case 0:case 3:break a;case 1:case 2:break b;default:break c}}if((g|0)==125){break a}}e=e+1|0;if((d|0)!=(e|0)){continue}break}e=d;}J[c+104>>2]=f;d=e-f|0;J[c+108>>2]=d;J[b+4>>2]=i-d;J[b>>2]=e;H[c+18|0]=0;I[c+16>>1]=27504;H[c+27|0]=2;d:{e:{f:{g:{h:{i:{j:{k:{if(K[f+2|0]!=40|d>>>0<4|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break k}if(K[c+17|0]!=K[f+1|0]){break k}b=d-4|0;J[c+108>>2]=b;d=f+3|0;J[c+104>>2]=d;if(!(!b|(b|0)>17)){if(b>>>0>=2147483632){break g}l:{if(b>>>0<=10){H[c+27|0]=b;h=c+16|0;break l}e=(b|15)+1|0;h=cb(e);J[c+24>>2]=e|-2147483648;J[c+16>>2]=h;J[c+20>>2]=b;}H[fb(h,d,b)+b|0]=0;J[c+88>>2]=J[c+20>>2];b=K[c+23|0]|K[c+24|0]<<8|(K[c+25|0]<<16|K[c+26|0]<<24);H[c+91|0]=b;H[c+92|0]=b>>>8;H[c+93|0]=b>>>16;H[c+94|0]=b>>>24;J[5996]=0;d=J[c+16>>2];f=H[c+27|0];J[c+24>>2]=0;J[c+16>>2]=0;J[c+20>>2]=0;b=$(3,12)|0;e=J[5996];J[5996]=0;if((e|0)!=1){J[b>>2]=d;J[b+4>>2]=J[c+88>>2];d=K[c+91|0]|K[c+92|0]<<8|(K[c+93|0]<<16|K[c+94|0]<<24);H[b+7|0]=d;H[b+8|0]=d>>>8;H[b+9|0]=d>>>16;H[b+10|0]=d>>>24;H[b+11|0]=f;J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=1;J[a+12>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;d=b+12|0;J[a+36>>2]=d;J[a+32>>2]=d;J[a+28>>2]=b;J[a+48>>2]=0;J[a+52>>2]=0;break h}e=Z()|0;rb(c+16|0);if((f|0)>=0){break j}$a(d);da(e|0);B();}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}H[c+21|0]=0;H[c+20|0]=K[1777];H[c+27|0]=5;J[c+16>>2]=K[1773]|K[1774]<<8|(K[1775]<<16|K[1776]<<24);m:{b=d>>>0<7;if(b|K[f+5|0]!=40|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break m}if(K[c+17|0]!=K[f+1|0]|K[c+18|0]!=K[f+2|0]|(K[c+19|0]!=K[f+3|0]|K[c+20|0]!=K[f+4|0])){break m}g=d-7|0;J[c+108>>2]=g;d=f+6|0;J[c+104>>2]=d;if(g>>>0>=2147483632){break g}n:{o:{if(g>>>0>=11){b=(g|15)+1|0;e=cb(b);J[c+24>>2]=b|-2147483648;J[c+16>>2]=e;J[c+20>>2]=g;break o}H[c+27|0]=g;e=c+16|0;if(!g){break n}}f=g-1|0;i=g&7;p:{if(!i){b=d;break p}h=0;b=d;while(1){H[e|0]=K[b|0];e=e+1|0;b=b+1|0;h=h+1|0;if((i|0)!=(h|0)){continue}break}}if(f>>>0<7){break n}d=d+g|0;while(1){H[e|0]=K[b|0];H[e+1|0]=K[b+1|0];H[e+2|0]=K[b+2|0];H[e+3|0]=K[b+3|0];H[e+4|0]=K[b+4|0];H[e+5|0]=K[b+5|0];H[e+6|0]=K[b+6|0];H[e+7|0]=K[b+7|0];e=e+8|0;b=b+8|0;if((d|0)!=(b|0)){continue}break}}H[e|0]=0;b=jf(c+16|0,c+88|0);if(H[c+27|0]<0){$a(J[c+16>>2]);}if(!b){J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}b=J[c+88>>2];d=b-1|0;if(J[c+92>>2]==(!b|0)&d>>>0<=2147483646){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=3;J[a+52>>2]=b;J[a+12>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}H[c+21|0]=0;H[c+20|0]=K[1783];H[c+27|0]=5;J[c+16>>2]=K[1779]|K[1780]<<8|(K[1781]<<16|K[1782]<<24);q:{if(K[f+5|0]!=40|b|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break q}if(K[c+17|0]!=K[f+1|0]|K[c+18|0]!=K[f+2|0]|(K[c+19|0]!=K[f+3|0]|K[c+20|0]!=K[f+4|0])){break q}g=d-7|0;J[c+108>>2]=g;d=f+6|0;J[c+104>>2]=d;if(g>>>0>=2147483632){break g}r:{s:{if(g>>>0>=11){b=(g|15)+1|0;e=cb(b);J[c+24>>2]=b|-2147483648;J[c+16>>2]=e;J[c+20>>2]=g;break s}H[c+27|0]=g;e=c+16|0;if(!g){break r}}f=g-1|0;i=g&7;t:{if(!i){b=d;break t}h=0;b=d;while(1){H[e|0]=K[b|0];e=e+1|0;b=b+1|0;h=h+1|0;if((i|0)!=(h|0)){continue}break}}if(f>>>0<7){break r}d=d+g|0;while(1){H[e|0]=K[b|0];H[e+1|0]=K[b+1|0];H[e+2|0]=K[b+2|0];H[e+3|0]=K[b+3|0];H[e+4|0]=K[b+4|0];H[e+5|0]=K[b+5|0];H[e+6|0]=K[b+6|0];H[e+7|0]=K[b+7|0];e=e+8|0;b=b+8|0;if((d|0)!=(b|0)){continue}break}}H[e|0]=0;b=jf(c+16|0,c+88|0);if(H[c+27|0]<0){$a(J[c+16>>2]);}if(!b){J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}b=J[c+88>>2];d=b-1|0;if(J[c+92>>2]==(!b|0)&d>>>0<=2147483646){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=2;J[a+52>>2]=b;J[a+12>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}H[c+22|0]=0;I[c+20>>1]=K[3881]|K[3882]<<8;H[c+27|0]=6;J[c+16>>2]=K[3877]|K[3878]<<8|(K[3879]<<16|K[3880]<<24);u:{if(K[f+6|0]!=40|d>>>0<8|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break u}if(K[c+17|0]!=K[f+1|0]|K[c+18|0]!=K[f+2|0]|(K[c+19|0]!=K[f+3|0]|K[c+20|0]!=K[f+4|0])){break u}if(K[c+21|0]!=K[f+5|0]){break u}b=d-8|0;J[c+108>>2]=b;d=f+7|0;J[c+104>>2]=d;$c(c+16|0,d,b,32);b=J[c+20>>2];d=J[c+16>>2];if((b|0)!=(d|0)){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=7;J[a+16>>2]=d;J[a+12>>2]=0;J[a+20>>2]=b;b=J[c+24>>2];J[a+28>>2]=0;J[a+32>>2]=0;J[a+24>>2]=b;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;if(!b){break h}$a(b);break h}H[c+25|0]=0;H[c+24|0]=K[4198];H[c+27|0]=9;b=K[4194]|K[4195]<<8|(K[4196]<<16|K[4197]<<24);J[c+16>>2]=K[4190]|K[4191]<<8|(K[4192]<<16|K[4193]<<24);J[c+20>>2]=b;v:{if(K[f+9|0]!=40|d>>>0<11|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break v}if(K[c+17|0]!=K[f+1|0]|K[c+18|0]!=K[f+2|0]|(K[c+19|0]!=K[f+3|0]|K[c+20|0]!=K[f+4|0])){break v}if(K[c+21|0]!=K[f+5|0]|K[c+22|0]!=K[f+6|0]|(K[c+23|0]!=K[f+7|0]|K[c+24|0]!=K[f+8|0])){break v}b=d-11|0;J[c+108>>2]=b;d=f+10|0;J[c+104>>2]=d;$c(c+16|0,d,b,20);b=J[c+20>>2];d=J[c+16>>2];if((b|0)!=(d|0)){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=6;J[a+16>>2]=d;J[a+12>>2]=0;J[a+20>>2]=b;b=J[c+24>>2];J[a+28>>2]=0;J[a+32>>2]=0;J[a+24>>2]=b;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;if(!b){break h}$a(b);break h}H[c+27|0]=7;H[c+23|0]=0;J[c+16>>2]=K[3869]|K[3870]<<8|(K[3871]<<16|K[3872]<<24);b=K[3872]|K[3873]<<8|(K[3874]<<16|K[3875]<<24);H[c+19|0]=b;H[c+20|0]=b>>>8;H[c+21|0]=b>>>16;H[c+22|0]=b>>>24;w:{if(K[f+7|0]!=40|d>>>0<9|(K[(d+f|0)-1|0]!=41|K[c+16|0]!=K[f|0])){break w}if(K[c+17|0]!=K[f+1|0]|K[c+18|0]!=K[f+2|0]|(K[c+19|0]!=K[f+3|0]|K[c+20|0]!=K[f+4|0])){break w}if(K[c+21|0]!=K[f+5|0]|K[c+22|0]!=K[f+6|0]){break w}b=d-9|0;J[c+108>>2]=b;d=f+8|0;J[c+104>>2]=d;$c(c+16|0,d,b,32);b=J[c+20>>2];d=J[c+16>>2];if((b|0)!=(d|0)){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=5;J[a+16>>2]=d;J[a+12>>2]=0;J[a+20>>2]=b;b=J[c+24>>2];J[a+28>>2]=0;J[a+32>>2]=0;J[a+24>>2]=b;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;if(!b){break h}$a(b);break h}b=Kb(c+16|0,4182);d=fd(b,c+104|0);if(H[b+11|0]<0){$a(J[b>>2]);}if(d){$c(c+16|0,J[c+104>>2],J[c+108>>2],20);b=J[c+20>>2];d=J[c+16>>2];if((b|0)!=(d|0)){J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=4;J[a+16>>2]=d;J[a+12>>2]=0;J[a+20>>2]=b;b=J[c+24>>2];J[a+28>>2]=0;J[a+32>>2]=0;J[a+24>>2]=b;J[a+36>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;break h}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;if(!b){break h}$a(b);break h}b=Kb(c+16|0,1743);d=fd(b,c+104|0);if(H[b+11|0]<0){$a(J[b>>2]);}if(d){J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;J[c+84>>2]=0;J[c+76>>2]=0;J[c+80>>2]=0;J[5996]=0;b=c+16|0;ea(26,b|0,c+104|0,c+8|0);d=J[5996];J[5996]=0;if((d|0)!=1){J[5996]=0;aa(27,c+88|0,b|0);d=J[5996];J[5996]=0;x:{y:{if((d|0)!=1){Fb(b);b=J[c+92>>2];if(J[b-56>>2]){break y}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break x}e=Z()|0;Fb(c+16|0);break e}J[5996]=0;aa(28,c+76|0,J[c+8>>2]);d=J[5996];J[5996]=0;if((d|0)==1){break f}z:{A:{if(!J[c+108>>2]){break A}B:{C:{while(1){I[c+16>>1]=44;H[c+27|0]=1;b=c+16|0;d=c+104|0;if(!vb(b,d)){break z}J[5996]=0;ea(26,b|0,d|0,c+8|0);d=J[5996];J[5996]=0;if((d|0)==1){break C}J[5996]=0;aa(27,c+88|0,b|0);d=J[5996];J[5996]=0;if((d|0)==1){break B}Fb(b);b=J[c+92>>2];if(!J[b-56>>2]){break z}J[5996]=0;aa(28,c+76|0,J[c+8>>2]);d=J[5996];J[5996]=0;if((d|0)!=1){if(!J[c+108>>2]){break A}continue}break}e=Z()|0;break e}e=Z()|0;break e}e=Z()|0;Fb(c+16|0);break e}J[a>>2]=9;d=J[c+88>>2];J[a+8>>2]=b;J[a+4>>2]=d;J[a+12>>2]=J[c+96>>2];J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+40>>2]=J[c+76>>2];J[a+44>>2]=J[c+80>>2];b=J[c+84>>2];J[a+52>>2]=0;J[a+48>>2]=b;break x}b=J[c+76>>2];J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;if(!b){break x}$a(b);}Oc(c+88|0);break h}e=Z()|0;break e}b=Kb(c+16|0,2464);d=fd(b,c+104|0);if(H[b+11|0]<0){$a(J[b>>2]);}if(d){J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;J[5996]=0;b=c+16|0;aa(29,b|0,c+104|0);d=J[5996];J[5996]=0;D:{if((d|0)!=1){J[5996]=0;aa(27,c+88|0,b|0);d=J[5996];J[5996]=0;E:{F:{G:{if((d|0)!=1){Fb(b);e=J[c+92>>2];if(J[e-56>>2]){if(!J[c+108>>2]){break F}break G}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break E}e=Z()|0;Fb(c+16|0);break D}H:{I:{while(1){J[5996]=0;b=_(30,c+76|0,4354)|0;d=J[5996];J[5996]=0;J:{if((d|0)!=1){d=vb(b,c+104|0);if(H[c+87|0]<0){$a(J[b>>2]);}if(d){break J}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break E}e=Z()|0;break D}J[5996]=0;b=c+16|0;aa(29,b|0,c+104|0);d=J[5996];J[5996]=0;if((d|0)==1){break I}J[5996]=0;aa(27,c+88|0,b|0);d=J[5996];J[5996]=0;if((d|0)==1){break H}Fb(b);e=J[c+92>>2];if(J[e-56>>2]){if(!J[c+108>>2]){break F}continue}break}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break E}e=Z()|0;break D}e=Z()|0;Fb(c+16|0);break D}J[a>>2]=8;b=J[c+88>>2];J[a+8>>2]=e;J[a+4>>2]=b;J[a+12>>2]=J[c+96>>2];J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;}Oc(c+88|0);break h}e=Z()|0;}break d}b=Kb(c+16|0,2197);d=fd(b,c+104|0);if(H[b+11|0]<0){$a(J[b>>2]);}if(!d){break i}e=0;h=J[c+104>>2];b=h;g=J[c+108>>2];K:{if(!g){break K}d=b+g|0;while(1){f=K[b|0];L:{if(!((f|0)!=123&(f|0)!=40)){e=e+1|0;break L}if(e){if((f|0)!=125&(f|0)!=41){break L}e=e-1|0;break L}e=0;M:{switch(f-41|0){case 0:case 3:break K;case 1:case 2:break L;default:break M}}if((f|0)==125){break K}}b=b+1|0;if((d|0)!=(b|0)){continue}break}b=d;}J[c+8>>2]=h;d=b-h|0;J[c+12>>2]=d;J[c+108>>2]=g-d;J[c+104>>2]=b;b=J[c+8>>2];d=Ad(c+16|0,b,b+J[c+12>>2]|0);f=c+4|0;b=0;e=Ua-16|0;Ua=e;g=K[d+11|0];h=g<<24>>24;h=(h|0)<0;g=h?J[d+4>>2]:g;N:{if(!g){break N}h=h?J[d>>2]:d;i=K[h|0];j=i-9&255;if(j>>>0<24&(8388639>>>j&1)){break N}j=K[(g+h|0)-1|0]-9|0;if((j&255)>>>0<24&(8388639>>>j&1)){break N}if((i|0)==45|(Gb(h)|0)!=(g|0)){break N}J[e+12>>2]=0;J[5732]=0;h=qe(H[d+11|0]<0?J[d>>2]:d,e+12|0,10,-1,0);if(f){J[f>>2]=h;}f=J[e+12>>2];if(!f|K[f|0]){break N}b=!J[5732];}Ua=e+16|0;if(H[d+11|0]<0){$a(J[d>>2]);}if(!b){J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}if(!J[c+4>>2]){J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break h}b=0;J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;e=0;O:{P:{Q:{if(J[c+108>>2]){R:{S:{T:{while(1){J[5996]=0;b=_(30,c+76|0,4354)|0;d=J[5996];J[5996]=0;if((d|0)==1){break P}d=vb(b,c+104|0);if(H[c+87|0]<0){$a(J[b>>2]);}if(!d){J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break Q}J[5996]=0;b=c+16|0;aa(29,b|0,c+104|0);d=J[5996];J[5996]=0;if((d|0)==1){break T}J[5996]=0;aa(27,c+88|0,b|0);d=J[5996];J[5996]=0;if((d|0)==1){break S}Fb(b);e=J[c+92>>2];if(J[e-56>>2]){if(!J[c+108>>2]){break R}continue}break}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break Q}e=Z()|0;break O}e=Z()|0;Fb(c+16|0);break O}b=J[c+88>>2];}U:{d=(e-b|0)/56|0;if(d>>>0<=100){f=d;d=J[c+4>>2];if(f>>>0>=d>>>0){break U}}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;break Q}J[a+4>>2]=b;J[a>>2]=10;J[a+8>>2]=e;J[a+12>>2]=J[c+96>>2];J[c+96>>2]=0;J[c+88>>2]=0;J[c+92>>2]=0;J[a+48>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+52>>2]=d;}Oc(c+88|0);break h}e=Z()|0;}Oc(c+88|0);}da(e|0);B();}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;}Ua=c+112|0;return}ub();B();}e=Z()|0;}a=J[c+76>>2];if(a){$a(a);}}Oc(c+88|0);da(e|0);B();}function sn(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;f=Ua-160|0;Ua=f;J[f+152>>2]=0;J[f+144>>2]=0;J[f+148>>2]=0;o=d+1|0;l=1;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{while(1){e=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);if((e|0)==(c|0)){break j}k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{if((c-e|0)<=0|c>>>0<=e>>>0){break A}h=e+1|0;g=0;k=K[e|0];B:{if(k>>>0>78){i=0;break B}i=k;C:{if(i>>>0<76){break C}D:{switch(i-76|0){case 0:if((c-h|0)<=0){break A}h=e+2|0;i=K[e+1|0];break C;case 1:if((c-h|0)<2){break A}h=e+3|0;i=K[e+1|0]|K[e+2|0]<<8;break C;default:break D}}if((c-h|0)<4){break A}h=e+5|0;i=K[e+1|0]|K[e+2|0]<<8|(K[e+3|0]<<16|K[e+4|0]<<24);}g=c-h|0;if((g|0)<0){break A}e=i;if(g>>>0>>0){break A}E:{if(!e){i=0;g=0;break E}if((e|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)==1){break z}break a}J[5996]=0;i=$(3,e|0)|0;j=J[5996];J[5996]=0;g=0;if((j|0)==1){break f}g=fb(i,h,e)+e|0;}h=e+h|0;}e=3;if(k-103>>>0<2){break k}H[b|0]=h;H[b+1|0]=h>>>8;H[b+2|0]=h>>>16;H[b+3|0]=h>>>24;if(!l){break y}e=0;if((d|0)<=0){break x}while(1){J[5996]=0;_(97,f+144|0,5573)|0;h=J[5996];J[5996]=0;if((h|0)==1){break w}e=e+1|0;if((e|0)!=(d|0)){continue}break}break x}b=K[f+155|0];d=b<<24>>24;i=(d|0)<0?J[f+148>>2]:b;c=i+8|0;if(c>>>0>=2147483632){J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break d}F:{if(c>>>0<=10){J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;H[a+11|0]=c;break F}J[5996]=0;e=(c|15)+1|0;b=$(3,e|0)|0;h=J[5996];J[5996]=0;g=0;if((h|0)==1){break f}J[a+4>>2]=c;J[a>>2]=b;J[a+8>>2]=e|-2147483648;a=b;}a=eb(a,(d|0)<0?J[f+144>>2]:f+144|0,i)+i|0;H[a+8|0]=0;H[a|0]=32;H[a+1|0]=91;H[a+2|0]=101;H[a+3|0]=114;H[a+4|0]=114;H[a+5|0]=111;H[a+6|0]=114;H[a+7|0]=93;break c}e=Z()|0;break d}J[5996]=0;aa(98,f+144|0,32);e=J[5996];J[5996]=0;if((e|0)==1){break g}e=K[f+155|0];p=(e<<24>>24<0?J[f+148>>2]:e)-1|0;}G:{H:{I:{J:{K:{m=g-i|0;switch(m|0){case 0:break G;case 33:break I;case 32:break J;case 20:break K;default:break H}}J[5996]=0;j=$(3,20)|0;e=J[5996];J[5996]=0;if((e|0)==1){e=Z()|0;break h}e=j;H[e|0]=153;H[e+1|0]=153;H[e+2|0]=153;H[e+3|0]=153;H[e+4|0]=153;H[e+5|0]=153;H[e+6|0]=153;H[e+7|0]=153;H[e+16|0]=153;H[e+17|0]=153;H[e+18|0]=153;H[e+19|0]=153;H[e+8|0]=153;H[e+9|0]=153;H[e+10|0]=153;H[e+11|0]=153;H[e+12|0]=153;H[e+13|0]=153;H[e+14|0]=153;H[e+15|0]=153;h=i;if((g|0)==(h|0)){break p}while(1){if(K[h|0]==K[e|0]){e=e+1|0;h=h+1|0;if((g|0)!=(h|0)){continue}break p}break}$a(j);if(!(K[i|0]!=80|K[i+1|0]!=75|K[i+2|0]!=104)){L:{M:{while(1){e=g-1|0;if(!K[e|0]){g=e;if((e|0)!=(i|0)){continue}break M}break}g=(g-i|0)-3|0;if(g>>>0<2147483632){break L}}J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break h}N:{O:{P:{Q:{R:{S:{T:{if(g>>>0<=10){H[f+111|0]=g;h=f+100|0;break T}J[5996]=0;e=(g|15)+1|0;h=$(3,e|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break S}J[f+100>>2]=h;J[f+104>>2]=g;J[f+108>>2]=e|-2147483648;}H[eb(h,i+3|0,g)+g|0]=0;J[5996]=0;g=ba(99,f+100|0,0,5383)|0;e=J[5996];J[5996]=0;if((e|0)==1){break R}J[f+120>>2]=J[g+8>>2];e=J[g+4>>2];J[f+112>>2]=J[g>>2];J[f+116>>2]=e;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;e=_(97,f+112|0,3723)|0;h=J[5996];J[5996]=0;if((h|0)==1){break Q}J[f+136>>2]=J[e+8>>2];h=J[e+4>>2];J[f+128>>2]=J[e>>2];J[f+132>>2]=h;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;h=K[f+139|0];j=h<<24>>24<0;ba(100,f+144|0,(j?J[f+128>>2]:f+128|0)|0,(j?J[f+132>>2]:h)|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break P}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+123|0]<0){$a(J[e>>2]);}if(H[f+111|0]<0){$a(J[g>>2]);}if(!l){break m}break l}e=Z()|0;break h}e=Z()|0;break N}e=Z()|0;break O}e=Z()|0;if(H[f+139|0]>=0){break O}$a(J[f+128>>2]);}if(H[f+123|0]>=0){break N}$a(J[f+112>>2]);}if(H[f+111|0]>=0){break h}$a(J[f+100>>2]);break h}J[f+80>>2]=0;J[5996]=0;J[f+72>>2]=0;J[f+76>>2]=0;aa(101,f+72|0,40);e=J[5996];J[5996]=0;if((e|0)==1){break r}if(g>>>0>i>>>0){h=i+20|0;e=i;while(1){g=K[e|0];J[5996]=0;j=f+72|0;aa(98,j|0,H[(g>>>4|0)+6976|0]);k=J[5996];J[5996]=0;if((k|0)==1){break r}J[5996]=0;aa(98,j|0,H[(g&15)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break r}e=e+1|0;if((h|0)!=(e|0)){continue}break}}J[5996]=0;g=ba(99,f+72|0,0,3762)|0;e=J[5996];J[5996]=0;U:{V:{W:{X:{if((e|0)!=1){J[f+96>>2]=J[g+8>>2];e=J[g+4>>2];J[f+88>>2]=J[g>>2];J[f+92>>2]=e;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;e=_(97,f+88|0,3760)|0;h=J[5996];J[5996]=0;if((h|0)==1){break X}J[f+136>>2]=J[e+8>>2];h=J[e+4>>2];J[f+128>>2]=J[e>>2];J[f+132>>2]=h;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;h=K[f+139|0];j=h<<24>>24<0;ba(100,f+144|0,(j?J[f+128>>2]:f+128|0)|0,(j?J[f+132>>2]:h)|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break W}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+99|0]<0){$a(J[e>>2]);}if(H[f+83|0]<0){$a(J[g>>2]);}if(!l){break m}break l}e=Z()|0;break U}e=Z()|0;break V}e=Z()|0;if(H[f+139|0]>=0){break V}$a(J[f+128>>2]);}if(H[f+99|0]>=0){break U}$a(J[f+88>>2]);}break q}J[5996]=0;j=$(3,32)|0;e=J[5996];J[5996]=0;if((e|0)==1){e=Z()|0;break h}e=j;H[e|0]=136;H[e+1|0]=136;H[e+2|0]=136;H[e+3|0]=136;H[e+4|0]=136;H[e+5|0]=136;H[e+6|0]=136;H[e+7|0]=136;H[e+24|0]=136;H[e+25|0]=136;H[e+26|0]=136;H[e+27|0]=136;H[e+28|0]=136;H[e+29|0]=136;H[e+30|0]=136;H[e+31|0]=136;H[e+16|0]=136;H[e+17|0]=136;H[e+18|0]=136;H[e+19|0]=136;H[e+20|0]=136;H[e+21|0]=136;H[e+22|0]=136;H[e+23|0]=136;H[e+8|0]=136;H[e+9|0]=136;H[e+10|0]=136;H[e+11|0]=136;H[e+12|0]=136;H[e+13|0]=136;H[e+14|0]=136;H[e+15|0]=136;h=i;if((g|0)==(h|0)){break p}while(1){q=K[h|0];r=K[e|0];if((q|0)==(r|0)){e=e+1|0;h=h+1|0;if((g|0)!=(h|0)){continue}}break}$a(j);if((q|0)==(r|0)){break o}if(!m){break G}if((m|0)!=33){break H}}if(K[i|0]!=2|K[i+1|0]!=80|(K[i+2|0]!=75|K[i+3|0]!=98)){break H}Y:{if((g|0)!=(i|0)){Z:{while(1){e=g-1|0;if(!K[e|0]){g=e;if((e|0)!=(i|0)){continue}break Z}break}g=(g-i|0)-4|0;if(g>>>0<2147483632){break Y}}g=i;}J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break e}_:{$:{aa:{ba:{ca:{da:{ea:{if(g>>>0<=10){H[f+55|0]=g;h=f+44|0;break ea}J[5996]=0;e=(g|15)+1|0;h=$(3,e|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break da}J[f+44>>2]=h;J[f+48>>2]=g;J[f+52>>2]=e|-2147483648;}H[eb(h,i+4|0,g)+g|0]=0;J[5996]=0;g=ba(99,f+44|0,0,3762)|0;e=J[5996];J[5996]=0;if((e|0)==1){break ca}J[f- -64>>2]=J[g+8>>2];e=J[g+4>>2];J[f+56>>2]=J[g>>2];J[f+60>>2]=e;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;e=_(97,f+56|0,3760)|0;h=J[5996];J[5996]=0;if((h|0)==1){break ba}J[f+136>>2]=J[e+8>>2];h=J[e+4>>2];J[f+128>>2]=J[e>>2];J[f+132>>2]=h;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;h=K[f+139|0];j=h<<24>>24<0;ba(100,f+144|0,(j?J[f+128>>2]:f+128|0)|0,(j?J[f+132>>2]:h)|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break aa}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+67|0]<0){$a(J[e>>2]);}if(H[f+55|0]<0){$a(J[g>>2]);}if(l){break l}break m}e=Z()|0;break h}e=Z()|0;break _}e=Z()|0;break $}e=Z()|0;if(H[f+139|0]>=0){break $}$a(J[f+128>>2]);}if(H[f+67|0]>=0){break _}$a(J[f+56>>2]);}if(H[f+55|0]>=0){break h}$a(J[f+44>>2]);break h}J[f+24>>2]=0;J[5996]=0;J[f+16>>2]=0;J[f+20>>2]=0;aa(101,f+16|0,m<<1);e=J[5996];J[5996]=0;if((e|0)==1){break t}if(g>>>0>i>>>0){h=i+m|0;e=i;while(1){g=K[e|0];J[5996]=0;j=f+16|0;aa(98,j|0,H[(g>>>4|0)+6976|0]);k=J[5996];J[5996]=0;if((k|0)==1){break t}J[5996]=0;aa(98,j|0,H[(g&15)+6976|0]);g=J[5996];J[5996]=0;if((g|0)==1){break t}e=e+1|0;if((h|0)!=(e|0)){continue}break}}J[5996]=0;g=ba(99,f+16|0,0,3762)|0;e=J[5996];J[5996]=0;fa:{ga:{ha:{ia:{if((e|0)!=1){J[f+40>>2]=J[g+8>>2];e=J[g+4>>2];J[f+32>>2]=J[g>>2];J[f+36>>2]=e;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;J[5996]=0;e=_(97,f+32|0,3760)|0;h=J[5996];J[5996]=0;if((h|0)==1){break ia}J[f+136>>2]=J[e+8>>2];h=J[e+4>>2];J[f+128>>2]=J[e>>2];J[f+132>>2]=h;J[e>>2]=0;J[e+4>>2]=0;J[e+8>>2]=0;J[5996]=0;h=K[f+139|0];j=h<<24>>24<0;ba(100,f+144|0,(j?J[f+128>>2]:f+128|0)|0,(j?J[f+132>>2]:h)|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break ha}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+43|0]<0){$a(J[e>>2]);}if(H[f+27|0]<0){$a(J[g>>2]);}if(!l){break m}break l}e=Z()|0;break fa}e=Z()|0;break ga}e=Z()|0;if(H[f+139|0]>=0){break ga}$a(J[f+128>>2]);}if(H[f+43|0]>=0){break fa}$a(J[f+32>>2]);}break s}e=J[(k<<2)+5840>>2];g=Gb(e);if(g>>>0>=2147483632){J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break h}ja:{ka:{la:{ma:{na:{oa:{pa:{qa:{ra:{sa:{ta:{ua:{va:{wa:{xa:{ya:{za:{Aa:{Ba:{if(g>>>0<=10){H[f+139|0]=g;h=f+128|0;break Ba}J[5996]=0;j=(g|15)+1|0;h=$(3,j|0)|0;m=J[5996];J[5996]=0;if((m|0)==1){break Aa}J[f+128>>2]=h;J[f+132>>2]=g;J[f+136>>2]=j|-2147483648;}H[eb(h,e,g)+g|0]=0;J[5996]=0;g=K[f+139|0];e=g<<24>>24<0;g=ba(100,f+144|0,(e?J[f+128>>2]:f+128|0)|0,(e?J[f+132>>2]:g)|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break za}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(k-99>>>0>1){break n}J[5996]=0;aa(98,g|0,10);e=J[5996];J[5996]=0;if((e|0)==1){break g}J[5996]=0;e=f+128|0;ga(102,e|0,b|0,c|0,o|0);h=J[5996];J[5996]=0;if((h|0)==1){break ya}J[5996]=0;j=g;h=e;g=K[f+139|0];e=g<<24>>24<0;j=ba(100,j|0,(e?J[f+128>>2]:h)|0,(e?J[f+132>>2]:g)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break xa}if(H[f+139|0]<0){$a(J[f+128>>2]);}h=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);if((h|0)==(c|0)){break na}if(K[h|0]!=103){break va}e=0;if((d|0)>0){while(1){J[5996]=0;_(97,j|0,5573)|0;g=J[5996];J[5996]=0;if((g|0)==1){break v}e=e+1|0;if((e|0)!=(d|0)){continue}break}h=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);}g=h+1|0;H[b|0]=g;H[b+1|0]=g>>>8;H[b+2|0]=g>>>16;H[b+3|0]=g>>>24;e=J[(K[h|0]<<2)+5840>>2];g=Gb(e);if(g>>>0<2147483632){break wa}J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break h}e=Z()|0;break h}e=Z()|0;if(H[f+139|0]>=0){break h}$a(J[f+128>>2]);break h}e=Z()|0;break h}e=Z()|0;if(H[f+139|0]>=0){break h}$a(J[f+128>>2]);break h}Ca:{if(g>>>0<=10){H[f+11|0]=g;h=f;break Ca}J[5996]=0;k=(g|15)+1|0;h=$(3,k|0)|0;l=J[5996];J[5996]=0;if((l|0)==1){break ua}J[f>>2]=h;J[f+4>>2]=g;J[f+8>>2]=k|-2147483648;}H[eb(h,e,g)+g|0]=0;J[5996]=0;aa(98,f|0,10);g=J[5996];J[5996]=0;if((g|0)==1){break ta}J[f+136>>2]=J[f+8>>2];J[f+8>>2]=0;e=J[f+4>>2];g=J[f>>2];J[f+128>>2]=g;J[f+132>>2]=e;J[f>>2]=0;J[f+4>>2]=0;J[5996]=0;h=g;g=H[f+139|0];e=(g|0)<0;g=ba(100,j|0,(e?h:f+128|0)|0,(e?J[f+132>>2]:g&255)|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break sa}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+11|0]<0){$a(J[f>>2]);}J[5996]=0;e=f+128|0;ga(102,e|0,b|0,c|0,o|0);h=J[5996];J[5996]=0;if((h|0)==1){break qa}J[5996]=0;k=g;h=e;g=K[f+139|0];e=g<<24>>24<0;ba(100,k|0,(e?J[f+128>>2]:h)|0,(e?J[f+132>>2]:g)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break pa}if(H[f+139|0]<0){$a(J[f+128>>2]);}h=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);}if((c|0)==(h|0)|K[h|0]!=104){break na}e=0;if((d|0)>0){while(1){J[5996]=0;_(97,j|0,5573)|0;g=J[5996];J[5996]=0;if((g|0)==1){break u}e=e+1|0;if((e|0)!=(d|0)){continue}break}h=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);}g=h+1|0;H[b|0]=g;H[b+1|0]=g>>>8;H[b+2|0]=g>>>16;H[b+3|0]=g>>>24;e=J[(K[h|0]<<2)+5840>>2];g=Gb(e);if(g>>>0<2147483632){break oa}J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)!=1){break a}e=Z()|0;break h}e=Z()|0;break h}e=Z()|0;break ra}e=Z()|0;if(H[f+139|0]>=0){break ra}$a(J[f+128>>2]);}if(H[f+11|0]>=0){break h}$a(J[f>>2]);break h}e=Z()|0;break h}e=Z()|0;if(H[f+139|0]>=0){break h}$a(J[f+128>>2]);break h}Da:{if(g>>>0<=10){H[f+11|0]=g;h=f;break Da}J[5996]=0;k=(g|15)+1|0;h=$(3,k|0)|0;l=J[5996];J[5996]=0;if((l|0)==1){break ma}J[f>>2]=h;J[f+4>>2]=g;J[f+8>>2]=k|-2147483648;}H[eb(h,e,g)+g|0]=0;J[5996]=0;aa(98,f|0,10);g=J[5996];J[5996]=0;if((g|0)==1){break la}J[f+136>>2]=J[f+8>>2];J[f+8>>2]=0;e=J[f+4>>2];g=J[f>>2];J[f+128>>2]=g;J[f+132>>2]=e;J[f>>2]=0;J[f+4>>2]=0;J[5996]=0;h=g;g=H[f+139|0];e=(g|0)<0;ba(100,j|0,(e?h:f+128|0)|0,(e?J[f+132>>2]:g&255)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break ka}if(H[f+139|0]<0){$a(J[f+128>>2]);}if(H[f+11|0]>=0){break na}$a(J[f>>2]);}g=K[f+155|0];n=g<<24>>24<0?J[f+148>>2]:g;break l}e=Z()|0;break h}e=Z()|0;break ja}e=Z()|0;if(H[f+139|0]>=0){break ja}$a(J[f+128>>2]);}if(H[f+11|0]>=0){break h}$a(J[f>>2]);break h}e=Z()|0;break h}e=Z()|0;break h}e=Z()|0;break h}e=Z()|0;}if(H[f+27|0]>=0){break h}$a(J[f+16>>2]);break h}e=Z()|0;}if(H[f+83|0]>=0){break h}$a(J[f+72>>2]);break h}$a(j);}J[5996]=0;_(97,f+144|0,3719)|0;g=J[5996];J[5996]=0;if((g|0)==1){break g}}if(l){break l}}e=K[f+155|0];g=e<<24>>24;h=(g|0)<0;if((h?J[f+148>>2]:e)-n>>>0<81){break l}e=0;H[(h?J[f+144>>2]:f+144|0)+p|0]=10;n=p+1|0;if((d|0)<=0){break l}while(1){J[5996]=0;ba(99,f+144|0,n|0,5573)|0;g=J[5996];J[5996]=0;if((g|0)==1){break i}e=e+1|0;if((e|0)!=(d|0)){continue}break}}g=K[f+155|0];l=((g<<24>>24<0?J[f+148>>2]:g)|0)==(n|0);e=0;}if(i){$a(i);}if(!e){continue}break}if((e|0)!=3){break c}}Ea:{if(!l){J[5996]=0;aa(98,f+144|0,10);b=J[5996];J[5996]=0;if((b|0)==1){break Ea}}b=J[f+148>>2];J[a>>2]=J[f+144>>2];J[a+4>>2]=b;J[a+8>>2]=J[f+152>>2];break b}e=Z()|0;break d}e=Z()|0;}g=i;break e}g=i;}e=Z()|0;}if(!g){break d}$a(g);}if(H[f+155|0]<0){$a(J[f+144>>2]);}da(e|0);B();}if(H[f+155|0]>=0){break b}$a(J[f+144>>2]);}Ua=f+160|0;return}B();}function ah(){var a=0,b=0,c=0,d=0,e=0,f=0,g=0;while(1){b=a<<4;c=b+22944|0;J[b+22948>>2]=c;J[b+22952>>2]=c;a=a+1|0;if((a|0)!=64){continue}break}Cd(48);a=Ua-16|0;Ua=a;a:{if(Ga(a+12|0,a+8|0)|0){break a}b=sb((J[a+12>>2]<<2)+4|0);J[6181]=b;if(!b){break a}b=sb(J[a+8>>2]);if(b){c=J[6181];J[c+(J[a+12>>2]<<2)>>2]=0;if(!(Fa(c|0,b|0)|0)){break a}}J[6181]=0;}Ua=a+16|0;a=cb(64);J[5998]=a;J[5999]=62;J[6e3]=-2147483584;b=K[3832]|K[3833]<<8|(K[3834]<<16|K[3835]<<24);c=K[3828]|K[3829]<<8|(K[3830]<<16|K[3831]<<24);H[a+54|0]=c;H[a+55|0]=c>>>8;H[a+56|0]=c>>>16;H[a+57|0]=c>>>24;H[a+58|0]=b;H[a+59|0]=b>>>8;H[a+60|0]=b>>>16;H[a+61|0]=b>>>24;b=K[3826]|K[3827]<<8|(K[3828]<<16|K[3829]<<24);c=K[3822]|K[3823]<<8|(K[3824]<<16|K[3825]<<24);H[a+48|0]=c;H[a+49|0]=c>>>8;H[a+50|0]=c>>>16;H[a+51|0]=c>>>24;H[a+52|0]=b;H[a+53|0]=b>>>8;H[a+54|0]=b>>>16;H[a+55|0]=b>>>24;b=K[3818]|K[3819]<<8|(K[3820]<<16|K[3821]<<24);c=K[3814]|K[3815]<<8|(K[3816]<<16|K[3817]<<24);H[a+40|0]=c;H[a+41|0]=c>>>8;H[a+42|0]=c>>>16;H[a+43|0]=c>>>24;H[a+44|0]=b;H[a+45|0]=b>>>8;H[a+46|0]=b>>>16;H[a+47|0]=b>>>24;b=K[3810]|K[3811]<<8|(K[3812]<<16|K[3813]<<24);c=K[3806]|K[3807]<<8|(K[3808]<<16|K[3809]<<24);H[a+32|0]=c;H[a+33|0]=c>>>8;H[a+34|0]=c>>>16;H[a+35|0]=c>>>24;H[a+36|0]=b;H[a+37|0]=b>>>8;H[a+38|0]=b>>>16;H[a+39|0]=b>>>24;b=K[3802]|K[3803]<<8|(K[3804]<<16|K[3805]<<24);c=K[3798]|K[3799]<<8|(K[3800]<<16|K[3801]<<24);H[a+24|0]=c;H[a+25|0]=c>>>8;H[a+26|0]=c>>>16;H[a+27|0]=c>>>24;H[a+28|0]=b;H[a+29|0]=b>>>8;H[a+30|0]=b>>>16;H[a+31|0]=b>>>24;b=K[3794]|K[3795]<<8|(K[3796]<<16|K[3797]<<24);c=K[3790]|K[3791]<<8|(K[3792]<<16|K[3793]<<24);H[a+16|0]=c;H[a+17|0]=c>>>8;H[a+18|0]=c>>>16;H[a+19|0]=c>>>24;H[a+20|0]=b;H[a+21|0]=b>>>8;H[a+22|0]=b>>>16;H[a+23|0]=b>>>24;b=K[3786]|K[3787]<<8|(K[3788]<<16|K[3789]<<24);c=K[3782]|K[3783]<<8|(K[3784]<<16|K[3785]<<24);H[a+8|0]=c;H[a+9|0]=c>>>8;H[a+10|0]=c>>>16;H[a+11|0]=c>>>24;H[a+12|0]=b;H[a+13|0]=b>>>8;H[a+14|0]=b>>>16;H[a+15|0]=b>>>24;b=K[3778]|K[3779]<<8|(K[3780]<<16|K[3781]<<24);c=K[3774]|K[3775]<<8|(K[3776]<<16|K[3777]<<24);H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;H[a+62|0]=0;a=K[24003];b=a<<24>>24;b:{c:{d=(b|0)<0?J[5999]:a;a=d+12|0;if(a>>>0<2147483632){d:{if(a>>>0<=10){J[6004]=0;J[6005]=0;J[6006]=0;H[24027]=a;c=24016;break d}e=(a|15)+1|0;c=cb(e);J[6005]=a;J[6004]=c;J[6006]=e|-2147483648;}a=c;c=(b|0)>=0?23992:J[5998];a=eb(a,c,d)+d|0;H[a+12|0]=0;b=K[5207]|K[5208]<<8|(K[5209]<<16|K[5210]<<24);H[a+8|0]=b;H[a+9|0]=b>>>8;H[a+10|0]=b>>>16;H[a+11|0]=b>>>24;b=K[5203]|K[5204]<<8|(K[5205]<<16|K[5206]<<24);e=K[5199]|K[5200]<<8|(K[5201]<<16|K[5202]<<24);H[a|0]=e;H[a+1|0]=e>>>8;H[a+2|0]=e>>>16;H[a+3|0]=e>>>24;H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;e:{a=d+8|0;f:{if(a>>>0>=2147483632){J[5996]=0;ca(2);b=J[5996];J[5996]=0;a=24028;if((b|0)==1){break f}break c}g:{if(a>>>0<=10){J[6007]=0;J[6008]=0;J[6009]=0;H[24039]=a;b=24028;break g}J[5996]=0;e=(a|15)+1|0;b=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){a=24028;break f}J[6008]=a;J[6007]=b;J[6009]=e|-2147483648;}a=eb(b,c,d)+d|0;H[a+8|0]=0;H[a|0]=32;H[a+1|0]=46;H[a+2|0]=44;H[a+3|0]=59;H[a+4|0]=45;H[a+5|0]=95;H[a+6|0]=63;H[a+7|0]=64;a=d+3|0;if(a>>>0>=2147483632){J[5996]=0;ca(2);b=J[5996];J[5996]=0;a=24040;if((b|0)!=1){break c}break f}h:{if(a>>>0<=10){J[6010]=0;J[6011]=0;J[6012]=0;H[24051]=a;b=24040;break h}J[5996]=0;e=(a|15)+1|0;b=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){a=24040;break f}J[6011]=a;J[6010]=b;J[6012]=e|-2147483648;}a=eb(b,c,d)+d|0;H[a+3|0]=0;H[a+2|0]=K[2557];b=K[2555]|K[2556]<<8;H[a|0]=b;H[a+1|0]=b>>>8;a=d+23|0;if(a>>>0>=2147483632){J[5996]=0;ca(2);b=J[5996];J[5996]=0;a=24052;if((b|0)!=1){break c}break f}J[5996]=0;e=(a|15)+1|0;b=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)!=1){break e}a=24052;}c=Z()|0;while(1){b=a-12|0;if(H[a-1|0]<0){$a(J[b>>2]);}a=b;if((a|0)!=24016){continue}break}da(c|0);B();}J[6014]=a;J[6013]=b;J[6015]=e|-2147483648;a=eb(b,c,d)+d|0;H[a+23|0]=0;b=K[5412]|K[5413]<<8|(K[5414]<<16|K[5415]<<24);c=K[5408]|K[5409]<<8|(K[5410]<<16|K[5411]<<24);H[a+15|0]=c;H[a+16|0]=c>>>8;H[a+17|0]=c>>>16;H[a+18|0]=c>>>24;H[a+19|0]=b;H[a+20|0]=b>>>8;H[a+21|0]=b>>>16;H[a+22|0]=b>>>24;b=K[5405]|K[5406]<<8|(K[5407]<<16|K[5408]<<24);c=K[5401]|K[5402]<<8|(K[5403]<<16|K[5404]<<24);H[a+8|0]=c;H[a+9|0]=c>>>8;H[a+10|0]=c>>>16;H[a+11|0]=c>>>24;H[a+12|0]=b;H[a+13|0]=b>>>8;H[a+14|0]=b>>>16;H[a+15|0]=b>>>24;b=K[5397]|K[5398]<<8|(K[5399]<<16|K[5400]<<24);c=K[5393]|K[5394]<<8|(K[5395]<<16|K[5396]<<24);H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;break b}ub();B();}B();}d=Ua-48|0;Ua=d;J[d+20>>2]=0;J[d+12>>2]=0;J[d+16>>2]=0;J[5996]=0;_(9,24064,d+12|0)|0;a=J[5996];J[5996]=0;i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{if((a|0)!=1){a=J[d+12>>2];if(a){$a(a);}a=cb(32);J[d+36>>2]=a;b=a+32|0;J[d+44>>2]=b;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;J[5996]=0;J[d+40>>2]=b;f=_(9,d+12|0,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break m}H[f+5|0]=1;J[6024]=J[f+8>>2];a=J[f+4>>2];J[6022]=J[f>>2];J[6023]=a;J[6025]=0;J[6026]=0;J[6027]=0;c=J[f+16>>2];b=J[f+12>>2];a=c-b|0;e=(a|0)/12|0;if((b|0)==(c|0)){break n}if(e>>>0<357913942){break r}J[5996]=0;ca(11);a=J[5996];J[5996]=0;if((a|0)==1){break q}B();}e=Z()|0;a=J[d+12>>2];if(!a){break i}$a(a);break i}J[5996]=0;a=$(3,a|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break q}J[6026]=a;J[6025]=a;J[6027]=a+P(e,12);J[5996]=0;b=ia(12,24108,b|0,c|0,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break o}e=Z()|0;J[6026]=a;break p}e=Z()|0;}c=J[6025];if(c){a=J[6026];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;g=J[b>>2];if(g){J[a-8>>2]=g;$a(g);}a=b;if((c|0)!=(a|0)){continue}break}b=J[6025];}J[6026]=c;$a(b);}c=J[f+12>>2];if(!c){break j}a=J[f+16>>2];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;g=J[b>>2];if(g){J[a-8>>2]=g;$a(g);}a=b;if((c|0)!=(a|0)){continue}break}b=J[f+12>>2];}J[f+16>>2]=c;$a(b);break j}J[6026]=b;c=J[f+12>>2];}if(c){a=J[f+16>>2];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;e=J[b>>2];if(e){J[a-8>>2]=e;$a(e);}a=b;if((c|0)!=(a|0)){continue}break}b=J[f+12>>2];}J[f+16>>2]=c;$a(b);}a=J[d+36>>2];if(a){$a(a);}a=cb(1);J[d+36>>2]=a;b=a+1|0;J[d+44>>2]=b;H[a|0]=1;J[5996]=0;J[d+40>>2]=b;_(9,24112,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break l}a=J[d+36>>2];if(a){$a(a);}J[6036]=0;J[6037]=0;J[6034]=1;J[6038]=0;J[6039]=0;H[24142]=0;I[12070]=0;J[6044]=0;J[6045]=0;J[6042]=-1;J[6043]=0;H[24163]=0;H[24164]=0;H[24165]=0;H[24166]=0;J[6040]=0;Ua=d+48|0;break k}e=Z()|0;break j}e=Z()|0;break j}d=Ua-48|0;Ua=d;J[d+20>>2]=0;J[d+12>>2]=0;J[d+16>>2]=0;J[5996]=0;_(9,24184,d+12|0)|0;a=J[5996];J[5996]=0;s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{if((a|0)!=1){a=J[d+12>>2];if(a){$a(a);}a=cb(32);J[d+36>>2]=a;b=a+32|0;J[d+44>>2]=b;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;J[5996]=0;J[d+40>>2]=b;f=_(9,d+12|0,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break w}H[f+5|0]=1;J[6054]=J[f+8>>2];a=J[f+4>>2];J[6052]=J[f>>2];J[6053]=a;J[6055]=0;J[6056]=0;J[6057]=0;c=J[f+16>>2];b=J[f+12>>2];a=c-b|0;e=(a|0)/12|0;if((b|0)==(c|0)){break x}if(e>>>0<357913942){break B}J[5996]=0;ca(11);a=J[5996];J[5996]=0;if((a|0)==1){break A}B();}e=Z()|0;a=J[d+12>>2];if(!a){break i}$a(a);break i}J[5996]=0;a=$(3,a|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break A}J[6056]=a;J[6055]=a;J[6057]=a+P(e,12);J[5996]=0;b=ia(12,24228,b|0,c|0,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break y}e=Z()|0;J[6056]=a;break z}e=Z()|0;}c=J[6055];if(c){a=c;b=J[6056];if((a|0)!=(b|0)){while(1){a=b-12|0;g=J[a>>2];if(g){J[b-8>>2]=g;$a(g);}b=a;if((a|0)!=(c|0)){continue}break}a=J[6055];}J[6056]=c;$a(a);}c=J[f+12>>2];if(!c){break j}a=c;b=J[f+16>>2];if((a|0)!=(b|0)){while(1){a=b-12|0;g=J[a>>2];if(g){J[b-8>>2]=g;$a(g);}b=a;if((a|0)!=(c|0)){continue}break}a=J[f+12>>2];}J[f+16>>2]=c;$a(a);break j}J[6056]=b;c=J[f+12>>2];}if(c){a=c;b=J[f+16>>2];if((a|0)!=(b|0)){while(1){a=b-12|0;e=J[a>>2];if(e){J[b-8>>2]=e;$a(e);}b=a;if((a|0)!=(c|0)){continue}break}a=J[f+12>>2];}J[f+16>>2]=c;$a(a);}a=J[d+36>>2];if(a){$a(a);}a=cb(1);J[d+36>>2]=a;b=a+1|0;J[d+44>>2]=b;H[a|0]=1;J[5996]=0;J[d+40>>2]=b;_(9,24232,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break v}a=J[d+36>>2];if(a){$a(a);}J[6066]=0;J[6067]=0;J[6064]=1;J[6068]=0;J[6069]=0;H[24262]=0;I[12130]=0;J[6074]=0;J[6075]=0;J[6072]=-1;J[6073]=0;H[24283]=0;H[24284]=0;H[24285]=0;H[24286]=0;J[6070]=0;J[6076]=0;J[6077]=0;J[6078]=0;b=cb(56);J[b>>2]=0;J[b+4>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+24>>2]=0;J[b+28>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[b+8>>2]=0;J[b+12>>2]=0;mc(24304,b);a=cb(4);J[a>>2]=b;J[5996]=0;b=$(3,56)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break u}break t}e=Z()|0;break j}e=Z()|0;break j}J[b+16>>2]=0;J[b+20>>2]=0;J[b+4>>2]=a;J[b>>2]=21;a=a+4|0;J[b+12>>2]=a;J[b+8>>2]=a;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;mc(24304,b);J[6079]=b;b=cb(56);J[b+4>>2]=0;J[b+8>>2]=0;J[b>>2]=1;J[b+12>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;mc(24304,b);a=cb(4);J[a>>2]=b;J[5996]=0;b=$(3,56)|0;c=J[5996];J[5996]=0;if((c|0)==1){break t}J[b+16>>2]=0;J[b+20>>2]=0;J[b+4>>2]=a;J[b>>2]=21;a=a+4|0;J[b+12>>2]=a;J[b+8>>2]=a;J[b+24>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[b+36>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;mc(24304,b);J[6080]=b;Ua=d+48|0;break s}b=Z()|0;$a(a);da(b|0);B();}d=Ua-48|0;Ua=d;J[d+20>>2]=0;J[d+12>>2]=0;J[d+16>>2]=0;J[5996]=0;_(9,24592,d+12|0)|0;a=J[5996];J[5996]=0;C:{D:{E:{F:{G:{H:{I:{J:{if((a|0)!=1){a=J[d+12>>2];if(a){$a(a);}a=cb(32);J[d+36>>2]=a;b=a+32|0;J[d+44>>2]=b;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;J[5996]=0;J[d+40>>2]=b;f=_(9,d+12|0,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break E}H[f+5|0]=1;J[6156]=J[f+8>>2];a=J[f+4>>2];J[6154]=J[f>>2];J[6155]=a;J[6157]=0;J[6158]=0;J[6159]=0;c=J[f+16>>2];b=J[f+12>>2];a=c-b|0;e=(a|0)/12|0;if((b|0)==(c|0)){break F}if(e>>>0<357913942){break J}J[5996]=0;ca(11);a=J[5996];J[5996]=0;if((a|0)==1){break I}B();}e=Z()|0;a=J[d+12>>2];if(!a){break i}$a(a);break i}J[5996]=0;a=$(3,a|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break I}J[6158]=a;J[6157]=a;J[6159]=a+P(e,12);J[5996]=0;b=ia(12,24636,b|0,c|0,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break G}e=Z()|0;J[6158]=a;break H}e=Z()|0;}c=J[6157];if(c){a=J[6158];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;g=J[b>>2];if(g){J[a-8>>2]=g;$a(g);}a=b;if((c|0)!=(a|0)){continue}break}b=J[6157];}J[6158]=c;$a(b);}c=J[f+12>>2];if(!c){break j}a=J[f+16>>2];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;g=J[b>>2];if(g){J[a-8>>2]=g;$a(g);}a=b;if((c|0)!=(a|0)){continue}break}b=J[f+12>>2];}J[f+16>>2]=c;$a(b);break j}J[6158]=b;c=J[f+12>>2];}if(c){a=J[f+16>>2];b=c;if((a|0)!=(b|0)){while(1){b=a-12|0;e=J[b>>2];if(e){J[a-8>>2]=e;$a(e);}a=b;if((c|0)!=(a|0)){continue}break}b=J[f+12>>2];}J[f+16>>2]=c;$a(b);}a=J[d+36>>2];if(a){$a(a);}a=cb(1);J[d+36>>2]=a;b=a+1|0;J[d+44>>2]=b;H[a|0]=1;J[5996]=0;J[d+40>>2]=b;_(9,24640,d+36|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break D}a=J[d+36>>2];if(a){$a(a);}J[6168]=0;J[6169]=0;J[6166]=1;J[6170]=0;J[6171]=0;H[24670]=0;I[12334]=0;J[6176]=0;J[6177]=0;J[6174]=-1;J[6175]=0;H[24691]=0;H[24692]=0;H[24693]=0;H[24694]=0;J[6172]=0;Ua=d+48|0;break C}e=Z()|0;break j}e=Z()|0;break j}J[6178]=24816;return}a=J[d+36>>2];if(!a){break i}$a(a);}da(e|0);B();}function fn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;g=Ua-96|0;Ua=g;J[g+36>>2]=0;J[g+28>>2]=0;J[g+32>>2]=0;J[5996]=0;k=$(3,12)|0;c=J[5996];J[5996]=0;a:{if((c|0)!=1){r=g+36|0;H[k+8|0]=0;J[k+4>>2]=0;J[k>>2]=b;f=k+12|0;q=f;b:{while(1){i=f-12|0;c=i;j=J[c+4>>2];n=J[c>>2];d=J[n+32>>2];c:{d:{e:{h=J[n+36>>2]-d>>3;if(h>>>0>j>>>0){b=1;J[c+4>>2]=j+1;e=K[f-4|0];f:{g:{h:{c=J[n>>2];switch(c-11|0){case 0:break g;case 3:break f;default:break h}}b=0;if((j|0)!=1|(c|0)!=17){break f}}b=(e|0)!=0;}j=J[d+(j<<3)>>2];if(f>>>0>>0){H[f+8|0]=b;J[f+4>>2]=0;J[f>>2]=j;f=f+12|0;break c}i:{d=(f-k|0)/12|0;i=d+1|0;j:{if(i>>>0>=357913942){J[5996]=0;ca(121);a=J[5996];J[5996]=0;if((a|0)==1){break j}break a}e=(q-k|0)/12|0;c=e<<1;c=e>>>0>=178956970?357913941:c>>>0>i>>>0?c:i;if(c>>>0<357913942){break i}J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}}l=Z()|0;break b}J[5996]=0;i=P(c,12);h=$(3,i|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break e}c=h+P(d,12)|0;H[c+8|0]=b;J[c+4>>2]=0;J[c>>2]=j;b=c;if((f|0)!=(k|0)){while(1){f=f-12|0;d=f;e=J[d+4>>2];b=b-12|0;J[b>>2]=J[d>>2];J[b+4>>2]=e;J[b+8>>2]=J[d+8>>2];if((d|0)!=(k|0)){continue}break}}q=h+i|0;f=c+12|0;if(k){$a(k);}k=b;break c}e=J[g+28>>2];c=J[g+32>>2]-e>>5;if(c>>>0>>0){J[5996]=0;ga(44,5135,2210,439,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}l=Z()|0;break b}b=K[f-4|0];J[5996]=0;oa(122,g+40|0,b|0,n|0,(e+(c<<5)|0)-(h<<5)|0,h|0);b=J[5996];J[5996]=0;if((b|0)==1){l=Z()|0;break b}b=J[g+64>>2];J[g+16>>2]=J[g+60>>2];J[g+20>>2]=b;J[g+24>>2]=J[g+68>>2];b=J[g+56>>2];J[g+8>>2]=J[g+52>>2];J[g+12>>2]=b;o=J[g+48>>2];m=J[g+44>>2];j=J[g+40>>2];b=J[g+32>>2];e=J[n+36>>2];c=J[n+32>>2];k:{if((e|0)==(c|0)){c=b;break k}e=e-c<<2;c=b-e|0;f=c+(e&-32)|0;if((f|0)!=(b|0)){while(1){d=g- -64|0;J[d>>2]=K[c+28|0]|K[c+29|0]<<8|(K[c+30|0]<<16|K[c+31|0]<<24);e=K[c+24|0]|K[c+25|0]<<8|(K[c+26|0]<<16|K[c+27|0]<<24);J[g+56>>2]=K[c+20|0]|K[c+21|0]<<8|(K[c+22|0]<<16|K[c+23|0]<<24);J[g+60>>2]=e;e=K[c+16|0]|K[c+17|0]<<8|(K[c+18|0]<<16|K[c+19|0]<<24);J[g+48>>2]=K[c+12|0]|K[c+13|0]<<8|(K[c+14|0]<<16|K[c+15|0]<<24);J[g+52>>2]=e;e=K[c+8|0]|K[c+9|0]<<8|(K[c+10|0]<<16|K[c+11|0]<<24);J[g+40>>2]=K[c+4|0]|K[c+5|0]<<8|(K[c+6|0]<<16|K[c+7|0]<<24);J[g+44>>2]=e;e=K[f+28|0]|K[f+29|0]<<8|(K[f+30|0]<<16|K[f+31|0]<<24);H[c+28|0]=e;H[c+29|0]=e>>>8;H[c+30|0]=e>>>16;H[c+31|0]=e>>>24;h=K[f+24|0]|K[f+25|0]<<8|(K[f+26|0]<<16|K[f+27|0]<<24);e=K[f+20|0]|K[f+21|0]<<8|(K[f+22|0]<<16|K[f+23|0]<<24);H[c+20|0]=e;H[c+21|0]=e>>>8;H[c+22|0]=e>>>16;H[c+23|0]=e>>>24;H[c+24|0]=h;H[c+25|0]=h>>>8;H[c+26|0]=h>>>16;H[c+27|0]=h>>>24;h=K[f+16|0]|K[f+17|0]<<8|(K[f+18|0]<<16|K[f+19|0]<<24);e=K[f+12|0]|K[f+13|0]<<8|(K[f+14|0]<<16|K[f+15|0]<<24);H[c+12|0]=e;H[c+13|0]=e>>>8;H[c+14|0]=e>>>16;H[c+15|0]=e>>>24;H[c+16|0]=h;H[c+17|0]=h>>>8;H[c+18|0]=h>>>16;H[c+19|0]=h>>>24;h=K[f+8|0]|K[f+9|0]<<8|(K[f+10|0]<<16|K[f+11|0]<<24);e=K[f+4|0]|K[f+5|0]<<8|(K[f+6|0]<<16|K[f+7|0]<<24);H[c+4|0]=e;H[c+5|0]=e>>>8;H[c+6|0]=e>>>16;H[c+7|0]=e>>>24;H[c+8|0]=h;H[c+9|0]=h>>>8;H[c+10|0]=h>>>16;H[c+11|0]=h>>>24;e=J[d>>2];H[f+28|0]=e;H[f+29|0]=e>>>8;H[f+30|0]=e>>>16;H[f+31|0]=e>>>24;d=J[g+60>>2];e=J[g+56>>2];H[f+20|0]=e;H[f+21|0]=e>>>8;H[f+22|0]=e>>>16;H[f+23|0]=e>>>24;H[f+24|0]=d;H[f+25|0]=d>>>8;H[f+26|0]=d>>>16;H[f+27|0]=d>>>24;d=J[g+52>>2];e=J[g+48>>2];H[f+12|0]=e;H[f+13|0]=e>>>8;H[f+14|0]=e>>>16;H[f+15|0]=e>>>24;H[f+16|0]=d;H[f+17|0]=d>>>8;H[f+18|0]=d>>>16;H[f+19|0]=d>>>24;d=J[g+44>>2];e=J[g+40>>2];H[f+4|0]=e;H[f+5|0]=e>>>8;H[f+6|0]=e>>>16;H[f+7|0]=e>>>24;H[f+8|0]=d;H[f+9|0]=d>>>8;H[f+10|0]=d>>>16;H[f+11|0]=d>>>24;e=J[c>>2];J[c>>2]=J[f>>2];J[f>>2]=e;c=c+32|0;f=f+32|0;if((f|0)!=(b|0)){continue}break}}if((b|0)!=(c|0)){while(1){e=b-32|0;if((K[e|0]|K[e+1|0]<<8|(K[e+2|0]<<16|K[e+3|0]<<24))>>>0>=29){b=b-24|0;$a(K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24));H[b|0]=0;H[b+1|0]=0;H[b+2|0]=0;H[b+3|0]=0;}b=e;if((c|0)!=(b|0)){continue}break}}J[g+32>>2]=c;}f=J[g+36>>2];if(f>>>0>c>>>0){H[c+4|0]=0;H[c+5|0]=0;H[c+6|0]=0;H[c+7|0]=0;H[c+8|0]=0;H[c+9|0]=0;H[c+10|0]=0;H[c+11|0]=0;H[c+28|0]=0;H[c+29|0]=0;H[c+30|0]=0;H[c+31|0]=0;H[c+20|0]=0;H[c+21|0]=0;H[c+22|0]=0;H[c+23|0]=0;H[c+24|0]=0;H[c+25|0]=0;H[c+26|0]=0;H[c+27|0]=0;H[c+12|0]=0;H[c+13|0]=0;H[c+14|0]=0;H[c+15|0]=0;H[c+16|0]=0;H[c+17|0]=0;H[c+18|0]=0;H[c+19|0]=0;H[c+8|0]=o;H[c+9|0]=o>>>8;H[c+10|0]=o>>>16;H[c+11|0]=o>>>24;H[c+4|0]=m;H[c+5|0]=m>>>8;H[c+6|0]=m>>>16;H[c+7|0]=m>>>24;e=J[g+12>>2];b=J[g+8>>2];H[c+12|0]=b;H[c+13|0]=b>>>8;H[c+14|0]=b>>>16;H[c+15|0]=b>>>24;H[c+16|0]=e;H[c+17|0]=e>>>8;H[c+18|0]=e>>>16;H[c+19|0]=e>>>24;e=J[g+20>>2];b=J[g+16>>2];H[c+20|0]=b;H[c+21|0]=b>>>8;H[c+22|0]=b>>>16;H[c+23|0]=b>>>24;H[c+24|0]=e;H[c+25|0]=e>>>8;H[c+26|0]=e>>>16;H[c+27|0]=e>>>24;b=J[g+24>>2];H[c+28|0]=b;H[c+29|0]=b>>>8;H[c+30|0]=b>>>16;H[c+31|0]=b>>>24;J[c>>2]=j;J[g+32>>2]=c+32;break d}l:{m:{n:{p=J[g+28>>2];d=c-p>>5;h=d+1|0;o:{if(h>>>0>=134217728){J[5996]=0;ca(123);break o}J[g+92>>2]=r;e=f-p|0;b=e>>4;h=e>>>0>=2147483616?134217727:b>>>0>h>>>0?b:h;if(!h){b=0;break m}if(h>>>0<134217728){break n}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}break l}J[5996]=0;b=$(3,h<<5)|0;e=J[5996];J[5996]=0;if((e|0)==1){break l}}J[g+76>>2]=b;l=(h<<5)+b|0;J[g+88>>2]=l;h=(d<<5)+b|0;J[g+80>>2]=h;d=h;H[d+24|0]=0;H[d+25|0]=0;H[d+26|0]=0;H[d+27|0]=0;H[d+28|0]=0;H[d+29|0]=0;H[d+30|0]=0;H[d+31|0]=0;H[d+16|0]=0;H[d+17|0]=0;H[d+18|0]=0;H[d+19|0]=0;H[d+20|0]=0;H[d+21|0]=0;H[d+22|0]=0;H[d+23|0]=0;H[d+8|0]=0;H[d+9|0]=0;H[d+10|0]=0;H[d+11|0]=0;H[d+12|0]=0;H[d+13|0]=0;H[d+14|0]=0;H[d+15|0]=0;H[d|0]=0;H[d+1|0]=0;H[d+2|0]=0;H[d+3|0]=0;H[d+4|0]=0;H[d+5|0]=0;H[d+6|0]=0;H[d+7|0]=0;J[g+56>>2]=K[d+28|0]|K[d+29|0]<<8|(K[d+30|0]<<16|K[d+31|0]<<24);b=K[d+24|0]|K[d+25|0]<<8|(K[d+26|0]<<16|K[d+27|0]<<24);J[g+48>>2]=K[d+20|0]|K[d+21|0]<<8|(K[d+22|0]<<16|K[d+23|0]<<24);J[g+52>>2]=b;b=K[d+16|0]|K[d+17|0]<<8|(K[d+18|0]<<16|K[d+19|0]<<24);J[g+40>>2]=K[d+12|0]|K[d+13|0]<<8|(K[d+14|0]<<16|K[d+15|0]<<24);J[g+44>>2]=b;H[d+8|0]=o;H[d+9|0]=o>>>8;H[d+10|0]=o>>>16;H[d+11|0]=o>>>24;H[d+4|0]=m;H[d+5|0]=m>>>8;H[d+6|0]=m>>>16;H[d+7|0]=m>>>24;b=J[g+24>>2];H[d+28|0]=b;H[d+29|0]=b>>>8;H[d+30|0]=b>>>16;H[d+31|0]=b>>>24;e=J[g+20>>2];b=J[g+16>>2];H[d+20|0]=b;H[d+21|0]=b>>>8;H[d+22|0]=b>>>16;H[d+23|0]=b>>>24;H[d+24|0]=e;H[d+25|0]=e>>>8;H[d+26|0]=e>>>16;H[d+27|0]=e>>>24;e=J[g+12>>2];b=J[g+8>>2];H[d+12|0]=b;H[d+13|0]=b>>>8;H[d+14|0]=b>>>16;H[d+15|0]=b>>>24;H[d+16|0]=e;H[d+17|0]=e>>>8;H[d+18|0]=e>>>16;H[d+19|0]=e>>>24;b=J[g+52>>2];J[g+16>>2]=J[g+48>>2];J[g+20>>2]=b;J[g+24>>2]=J[g+56>>2];b=J[g+44>>2];J[g+8>>2]=J[g+40>>2];J[g+12>>2]=b;J[d>>2]=j;b=d+32|0;J[g+84>>2]=b;p:{if((c|0)==(p|0)){e=c;}else {while(1){b=d;d=d-32|0;H[d|0]=0;H[d+1|0]=0;H[d+2|0]=0;H[d+3|0]=0;H[d+4|0]=0;H[d+5|0]=0;H[d+6|0]=0;H[d+7|0]=0;H[d+24|0]=0;H[d+25|0]=0;H[d+26|0]=0;H[d+27|0]=0;H[d+28|0]=0;H[d+29|0]=0;H[d+30|0]=0;H[d+31|0]=0;H[d+16|0]=0;H[d+17|0]=0;H[d+18|0]=0;H[d+19|0]=0;H[d+20|0]=0;H[d+21|0]=0;H[d+22|0]=0;H[d+23|0]=0;H[d+8|0]=0;H[d+9|0]=0;H[d+10|0]=0;H[d+11|0]=0;H[d+12|0]=0;H[d+13|0]=0;H[d+14|0]=0;H[d+15|0]=0;e=c;c=c-32|0;f=K[c|0]|K[c+1|0]<<8|(K[c+2|0]<<16|K[c+3|0]<<24);J[5996]=0;j=f>>>0<29?f:f-29|0;aa(124,d|0,j|0);f=J[5996];J[5996]=0;if((f|0)==1){break p}m=j+(K[d|0]|K[d+1|0]<<8|(K[d+2|0]<<16|K[d+3|0]<<24))|0;H[d|0]=m;H[d+1|0]=m>>>8;H[d+2|0]=m>>>16;H[d+3|0]=m>>>24;f=K[c|0]|K[c+1|0]<<8|(K[c+2|0]<<16|K[c+3|0]<<24);j=f>>>0<29;n=j?f:f-29|0;q:{if(!n){break q}f=b-28|0;b=b-24|0;f=m>>>0<29?f:K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);l=0;b=e-24|0;j=j?e-28|0:K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);b=j;e=n&7;if(e){while(1){H[f|0]=K[b|0];b=b+1|0;f=f+1|0;l=l+1|0;if((e|0)!=(l|0)){continue}break}}if(n>>>0<8){break q}e=j+n|0;while(1){H[f|0]=K[b|0];H[f+1|0]=K[b+1|0];H[f+2|0]=K[b+2|0];H[f+3|0]=K[b+3|0];H[f+4|0]=K[b+4|0];H[f+5|0]=K[b+5|0];H[f+6|0]=K[b+6|0];H[f+7|0]=K[b+7|0];f=f+8|0;b=b+8|0;if((e|0)!=(b|0)){continue}break}}if((c|0)!=(p|0)){continue}break}l=J[g+88>>2];f=J[g+36>>2];b=J[g+84>>2];c=J[g+32>>2];e=J[g+28>>2];}J[g+80>>2]=e;J[g+28>>2]=d;J[g+32>>2]=b;J[g+36>>2]=l;J[g+88>>2]=f;J[g+76>>2]=e;J[g+84>>2]=c;if((c|0)!=(e|0)){while(1){b=c-32|0;J[g+84>>2]=b;if((K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24))>>>0>=29){b=c-24|0;$a(K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24));H[b|0]=0;H[b+1|0]=0;H[b+2|0]=0;H[b+3|0]=0;b=J[g+84>>2];}c=b;if((e|0)!=(c|0)){continue}break}c=J[g+76>>2];}if(!c){break d}$a(c);f=i;break c}l=Z()|0;if((b|0)!=(h|0)){while(1){if((K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24))>>>0>=29){$a(K[b+8|0]|K[b+9|0]<<8|(K[b+10|0]<<16|K[b+11|0]<<24));H[b+8|0]=0;H[b+9|0]=0;H[b+10|0]=0;H[b+11|0]=0;}b=b+32|0;if((h|0)!=(b|0)){continue}break}}b=J[g+84>>2];c=J[g+80>>2];if((b|0)!=(c|0)){while(1){a=b-32|0;J[g+84>>2]=a;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){a=b-24|0;$a(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24));H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;a=J[g+84>>2];}b=a;if((c|0)!=(b|0)){continue}break}}a=J[g+76>>2];if(a){$a(a);}break b}l=Z()|0;if(j>>>0<29){break b}$a(o);break b}l=Z()|0;break b}f=i;}if((f|0)!=(k|0)){continue}break}b=J[g+32>>2];c=J[g+28>>2];if((b-c|0)!=32){J[5996]=0;ga(44,4102,2210,450,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}l=Z()|0;break b}H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;i=g- -64|0;J[i>>2]=K[a+28|0]|K[a+29|0]<<8|(K[a+30|0]<<16|K[a+31|0]<<24);e=K[a+24|0]|K[a+25|0]<<8|(K[a+26|0]<<16|K[a+27|0]<<24);J[g+56>>2]=K[a+20|0]|K[a+21|0]<<8|(K[a+22|0]<<16|K[a+23|0]<<24);J[g+60>>2]=e;e=K[a+16|0]|K[a+17|0]<<8|(K[a+18|0]<<16|K[a+19|0]<<24);J[g+48>>2]=K[a+12|0]|K[a+13|0]<<8|(K[a+14|0]<<16|K[a+15|0]<<24);J[g+52>>2]=e;e=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);J[g+40>>2]=K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24);J[g+44>>2]=e;e=K[c+28|0]|K[c+29|0]<<8|(K[c+30|0]<<16|K[c+31|0]<<24);H[a+28|0]=e;H[a+29|0]=e>>>8;H[a+30|0]=e>>>16;H[a+31|0]=e>>>24;d=K[c+24|0]|K[c+25|0]<<8|(K[c+26|0]<<16|K[c+27|0]<<24);e=K[c+20|0]|K[c+21|0]<<8|(K[c+22|0]<<16|K[c+23|0]<<24);H[a+20|0]=e;H[a+21|0]=e>>>8;H[a+22|0]=e>>>16;H[a+23|0]=e>>>24;H[a+24|0]=d;H[a+25|0]=d>>>8;H[a+26|0]=d>>>16;H[a+27|0]=d>>>24;d=K[c+16|0]|K[c+17|0]<<8|(K[c+18|0]<<16|K[c+19|0]<<24);e=K[c+12|0]|K[c+13|0]<<8|(K[c+14|0]<<16|K[c+15|0]<<24);H[a+12|0]=e;H[a+13|0]=e>>>8;H[a+14|0]=e>>>16;H[a+15|0]=e>>>24;H[a+16|0]=d;H[a+17|0]=d>>>8;H[a+18|0]=d>>>16;H[a+19|0]=d>>>24;d=K[c+8|0]|K[c+9|0]<<8|(K[c+10|0]<<16|K[c+11|0]<<24);e=K[c+4|0]|K[c+5|0]<<8|(K[c+6|0]<<16|K[c+7|0]<<24);H[a+4|0]=e;H[a+5|0]=e>>>8;H[a+6|0]=e>>>16;H[a+7|0]=e>>>24;H[a+8|0]=d;H[a+9|0]=d>>>8;H[a+10|0]=d>>>16;H[a+11|0]=d>>>24;e=J[i>>2];H[c+28|0]=e;H[c+29|0]=e>>>8;H[c+30|0]=e>>>16;H[c+31|0]=e>>>24;i=J[g+60>>2];e=J[g+56>>2];H[c+20|0]=e;H[c+21|0]=e>>>8;H[c+22|0]=e>>>16;H[c+23|0]=e>>>24;H[c+24|0]=i;H[c+25|0]=i>>>8;H[c+26|0]=i>>>16;H[c+27|0]=i>>>24;i=J[g+52>>2];e=J[g+48>>2];H[c+12|0]=e;H[c+13|0]=e>>>8;H[c+14|0]=e>>>16;H[c+15|0]=e>>>24;H[c+16|0]=i;H[c+17|0]=i>>>8;H[c+18|0]=i>>>16;H[c+19|0]=i>>>24;i=J[g+44>>2];e=J[g+40>>2];H[c+4|0]=e;H[c+5|0]=e>>>8;H[c+6|0]=e>>>16;H[c+7|0]=e>>>24;H[c+8|0]=i;H[c+9|0]=i>>>8;H[c+10|0]=i>>>16;H[c+11|0]=i>>>24;J[a>>2]=J[c>>2];J[c>>2]=0;H[a+32|0]=1;if((b|0)!=(c|0)){while(1){a=b-32|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){b=b-24|0;$a(K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24));H[b|0]=0;H[b+1|0]=0;H[b+2|0]=0;H[b+3|0]=0;}b=a;if((c|0)!=(b|0)){continue}break}b=J[g+28>>2];}J[g+32>>2]=c;$a(b);if(k){$a(k);}Ua=g+96|0;return}Qg(g+28|0);if(k){$a(k);}da(l|0);B();}a=Z()|0;Qg(g+28|0);da(a|0);B();}B();}function xn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,C=0,D=0;g=Ua-48|0;Ua=g;J[g+32>>2]=0;J[g+24>>2]=0;J[g+28>>2]=0;J[5996]=0;o=$(3,12)|0;d=J[5996];J[5996]=0;a:{if((d|0)!=1){J[o+4>>2]=0;J[o>>2]=b;r=g+40|0;x=g+12|0;y=o+12|0;f=y;b:{c:{d:{while(1){e:{D=f-12|0;b=D;d=J[b+4>>2];f:{g:{h:{i:{j:{s=J[b>>2];n=J[s+36>>2];z=J[s+32>>2];A=n-z>>3;if(d>>>0>>0){J[b+4>>2]=d+1;i=J[(d<<3)+z>>2];if(f>>>0>>0){J[f+4>>2]=0;J[f>>2]=i;f=f+12|0;break f}k:{e=(f-o|0)/12|0;h=e+1|0;l:{if(h>>>0>=357913942){J[5996]=0;ca(95);a=J[5996];J[5996]=0;if((a|0)==1){break l}break a}d=(y-o|0)/12|0;b=d<<1;b=d>>>0>=178956970?357913941:b>>>0>h>>>0?b:h;if(b>>>0<357913942){break k}J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}}b=Z()|0;break b}J[5996]=0;h=P(b,12);j=$(3,h|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break j}d=j+P(e,12)|0;J[d+4>>2]=0;J[d>>2]=i;b=d;if((f|0)!=(o|0)){while(1){f=f-12|0;e=J[f+4>>2];b=b-12|0;J[b>>2]=J[f>>2];J[b+4>>2]=e;J[b+8>>2]=J[f+8>>2];if((f|0)!=(o|0)){continue}break}}y=h+j|0;f=d+12|0;if(o){$a(o);}o=b;break f}k=J[g+24>>2];j=(J[g+28>>2]-k|0)/12|0;if(j>>>0>>0){J[5996]=0;ga(44,5135,2210,439,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}if(K[s+88|0]?J[c>>2]!=(s|0):0){break h}C=J[s+12>>2];l=J[s+8>>2];J[g+36>>2]=r;J[g+40>>2]=0;J[g+44>>2]=0;v=(C-l|0)/12|0;m=0;b=r;e=0;if((l|0)==(C|0)){break i}while(1){m:{n:{o:{p:{f=r;q:{if((f|0)==(b|0)){break q}d=f;b=e;r:{if(e){while(1){f=b;b=J[b+4>>2];if(b){continue}break r}}while(1){f=J[d+8>>2];b=J[f>>2]==(d|0);d=f;if(b){continue}break}}w=J[l>>2];p=K[l+11|0];h=p<<24>>24;t=(h|0)<0;b=K[f+27|0];u=b<<24>>24<0;s:{d=J[l+4>>2];q=t?d:p;i=u?J[f+20>>2]:b;b=i>>>0>q>>>0?q:i;if(b){b=Eb(u?J[f+16>>2]:f+16|0,t?w:l,b);if(b){break s}}if(i>>>0>>0){break q}break p}if((b|0)>=0){break p}}b=e?f:r;i=e?f+4|0:r;break o}b=r;i=b;if(!e){break o}b=(h|0)>=0;t=b?l:w;w=b?p:d;d=e;while(1){b=d;f=K[d+27|0];u=f<<24>>24<0;p=u?J[d+20>>2]:f;q=p>>>0>>0;t:{u:{v:{w:{h=q?p:w;x:{if(h){f=u?J[d+16>>2]:d+16|0;d=Eb(t,f,h);if(!d){if(p>>>0>w>>>0){break x}break w}if((d|0)>=0){break w}break x}if(p>>>0<=w>>>0){break v}}i=b;d=J[b>>2];if(d){continue}break n}d=Eb(f,t,h);if(d){break u}}if(!q){break o}break t}if((d|0)>=0){break o}}i=b+4|0;d=J[b+4>>2];if(d){continue}break}break n}if(J[i>>2]){break m}}J[5996]=0;f=$(3,28)|0;d=J[5996];J[5996]=0;y:{if((d|0)!=1){h=f+16|0;if(H[l+11|0]>=0){d=J[l+4>>2];J[h>>2]=J[l>>2];J[h+4>>2]=d;J[h+8>>2]=J[l+8>>2];break y}e=J[l+4>>2];d=J[l>>2];J[5996]=0;ea(40,h|0,d|0,e|0);d=J[5996];J[5996]=0;if((d|0)!=1){break y}b=Z()|0;$a(f);Db(J[g+40>>2]);break b}b=Z()|0;Db(e);break b}J[f+8>>2]=b;J[f>>2]=0;J[f+4>>2]=0;J[i>>2]=f;b=J[J[g+36>>2]>>2];if(b){J[g+36>>2]=b;f=J[i>>2];}zd(J[g+40>>2],f);m=J[g+44>>2]+1|0;J[g+44>>2]=m;}l=l+12|0;if((C|0)==(l|0)){break i}b=J[g+36>>2];e=J[g+40>>2];continue}}b=Z()|0;break b}z:{A:{if((m|0)!=(v|0)){break A}if((n|0)!=(z|0)){t=k+P(j,12)|0;m=t+P(A,-12)|0;while(1){d=J[m+8>>2];if(d>>>0>v>>>0){b=J[g+36>>2];J[g+36>>2]=J[m>>2];J[m>>2]=b;b=J[g+40>>2];J[g+40>>2]=J[m+4>>2];J[m+4>>2]=b;b=J[g+44>>2];J[g+44>>2]=d;J[m+8>>2]=b;J[(J[g+44>>2]?J[g+40>>2]+8|0:g+36|0)>>2]=r;J[(b?J[m+4>>2]+8|0:m)>>2]=m+4;}v=d+v|0;j=J[m>>2];u=m+4|0;if((j|0)!=(u|0)){while(1){h=0;d=J[g+40>>2];B:{if(!d){f=r;l=f;break B}e=K[j+27|0];b=e<<24>>24>=0;n=b?j+16|0:J[j+16>>2];p=b?e:J[j+20>>2];l=r;while(1){f=d;b=K[d+27|0];k=b<<24>>24<0;q=k?J[d+20>>2]:b;i=q>>>0

>>0;C:{D:{E:{F:{e=i?q:p;G:{if(e){d=k?J[d+16>>2]:d+16|0;b=Eb(n,d,e);if(!b){if(p>>>0>>0){break G}break F}if((b|0)>=0){break F}break G}if(p>>>0>=q>>>0){break E}}l=f;d=J[f>>2];if(d){continue}break B}b=Eb(d,n,e);if(b){break D}}if(i){break C}h=f;break B}if((b|0)<0){break C}h=f;break B}l=f+4|0;d=J[f+4>>2];if(d){continue}break}}e=j;i=J[e+4>>2];d=i;H:{if(d){while(1){b=d;d=J[d>>2];if(d){continue}break H}}while(1){b=J[e+8>>2];d=J[b>>2]!=(e|0);e=b;if(d){continue}break}}if(!h){e=j;I:{if(i){while(1){d=i;i=J[d>>2];if(i){continue}break I}}while(1){d=J[e+8>>2];h=J[d>>2]!=(e|0);e=d;if(h){continue}break}}if(J[m>>2]==(j|0)){J[m>>2]=d;}J[m+8>>2]=J[m+8>>2]-1;i=J[m+4>>2];J:{K:{e=j;h=J[e>>2];if(h){d=J[e+4>>2];if(!d){break K}while(1){e=d;d=J[d>>2];if(d){continue}break}}h=J[e+4>>2];if(h){break K}h=0;k=1;break J}J[h+8>>2]=J[e+8>>2];k=0;}n=J[e+8>>2];d=J[n>>2];L:{if((e|0)==(d|0)){J[n>>2]=h;if((e|0)==(i|0)){d=0;i=h;break L}d=J[n+4>>2];break L}J[n+4>>2]=h;}p=!K[e+12|0];if((e|0)!=(j|0)){n=J[j+8>>2];J[e+8>>2]=n;J[n+((J[J[j+8>>2]>>2]!=(j|0))<<2)>>2]=e;n=J[j>>2];J[e>>2]=n;J[n+8>>2]=e;n=J[j+4>>2];J[e+4>>2]=n;if(n){J[n+8>>2]=e;}H[e+12|0]=K[j+12|0];i=(i|0)==(j|0)?e:i;}M:{if(p|!i){break M}if(!k){H[h+12|0]=1;break M}N:{O:{while(1){P:{e=K[d+12|0];k=J[d+8>>2];Q:{if(J[k>>2]!=(d|0)){if(!e){H[d+12|0]=1;H[k+12|0]=0;h=J[k+4>>2];e=J[h>>2];J[k+4>>2]=e;if(e){J[e+8>>2]=k;}J[h+8>>2]=J[k+8>>2];e=J[k+8>>2];J[(((k|0)!=J[e>>2])<<2)+e>>2]=h;J[h>>2]=k;J[k+8>>2]=h;e=d;d=J[d>>2];i=(d|0)==(i|0)?e:i;d=J[d+4>>2];}e=J[d>>2];R:{if(!(K[e+12|0]?0:e)){h=J[d+4>>2];if(!(!h|K[h+12|0])){e=d;break R}H[d+12|0]=0;d=J[d+8>>2];if((i|0)==(d|0)){H[i+12|0]=1;break M}if(K[d+12|0]){break Q}H[d+12|0]=1;break M}h=J[d+4>>2];if(!(!h|K[h+12|0])){e=d;break R}H[e+12|0]=1;H[d+12|0]=0;h=J[e+4>>2];J[d>>2]=h;if(h){J[h+8>>2]=d;}J[e+8>>2]=J[d+8>>2];h=J[d+8>>2];J[((J[h>>2]!=(d|0))<<2)+h>>2]=e;J[e+4>>2]=d;J[d+8>>2]=e;h=d;}i=J[e+8>>2];H[e+12|0]=K[i+12|0];H[i+12|0]=1;H[h+12|0]=1;e=J[i+4>>2];d=J[e>>2];J[i+4>>2]=d;if(d){J[d+8>>2]=i;}J[e+8>>2]=J[i+8>>2];d=J[i+8>>2];J[(((i|0)!=J[d>>2])<<2)+d>>2]=e;J[e>>2]=i;J[i+8>>2]=e;break M}if(!e){H[d+12|0]=1;H[k+12|0]=0;e=J[d+4>>2];J[k>>2]=e;if(e){J[e+8>>2]=k;}J[d+8>>2]=J[k+8>>2];e=J[k+8>>2];J[(((k|0)!=J[e>>2])<<2)+e>>2]=d;J[d+4>>2]=k;J[k+8>>2]=d;i=(i|0)==(k|0)?d:i;d=J[k>>2];}h=J[d>>2];if(!(!h|K[h+12|0])){e=d;break N}e=J[d+4>>2];if(K[e+12|0]?0:e){break O}H[d+12|0]=0;d=J[d+8>>2];if(!K[d+12|0]|(d|0)==(i|0)){break P}}e=d;d=J[d+8>>2];d=J[(((e|0)==J[d>>2])<<2)+d>>2];continue}break}H[d+12|0]=1;break M}if(!(K[h+12|0]|!h)){e=d;break N}H[e+12|0]=1;H[d+12|0]=0;h=J[e>>2];J[d+4>>2]=h;if(h){J[h+8>>2]=d;}J[e+8>>2]=J[d+8>>2];h=J[d+8>>2];J[((J[h>>2]!=(d|0))<<2)+h>>2]=e;J[e>>2]=d;J[d+8>>2]=e;h=d;}i=J[e+8>>2];H[e+12|0]=K[i+12|0];H[i+12|0]=1;H[h+12|0]=1;e=J[i>>2];d=J[e+4>>2];J[i>>2]=d;if(d){J[d+8>>2]=i;}J[e+8>>2]=J[i+8>>2];d=J[i+8>>2];J[(((i|0)!=J[d>>2])<<2)+d>>2]=e;J[e+4>>2]=i;J[i+8>>2]=e;}J[j+8>>2]=f;J[j>>2]=0;J[j+4>>2]=0;J[l>>2]=j;d=J[J[g+36>>2]>>2];if(d){J[g+36>>2]=d;j=J[l>>2];}zd(J[g+40>>2],j);J[g+44>>2]=J[g+44>>2]+1;}j=b;if((b|0)!=(u|0)){continue}break}}if(J[g+44>>2]!=(v|0)){break A}m=m+12|0;if((t|0)!=(m|0)){continue}break}}J[g+8>>2]=J[g+36>>2];J[g+16>>2]=v;b=J[g+40>>2];J[g+12>>2]=b;S:{if(!v){J[g+8>>2]=x;break S}J[b+8>>2]=x;J[g+40>>2]=0;J[g+44>>2]=0;J[g+36>>2]=r;}b=1;break z}H[g+8|0]=0;b=0;}H[g+20|0]=b;Db(J[g+40>>2]);if(K[g+20|0]){break g}}H[a+12|0]=0;H[a|0]=0;break c}d=J[g+28>>2];h=J[s+36>>2]-J[s+32>>2]>>3;e=J[g+24>>2];b=((d+P(h,-12)|0)-e|0)/12|0;T:{if(!P(h,-12)){f=d;break T}i=e+P(b,12)|0;f=i;b=f+P((P(h,12)|0)/12|0,12)|0;if((d|0)!=(b|0)){while(1){Db(J[f+4>>2]);J[f>>2]=J[b>>2];h=J[b+4>>2];J[f+4>>2]=h;e=J[b+8>>2];J[f+8>>2]=e;j=f+4|0;U:{if(!e){J[f>>2]=j;break U}J[h+8>>2]=j;J[b+4>>2]=0;J[b+8>>2]=0;J[b>>2]=b+4;}f=f+12|0;b=b+12|0;if((d|0)!=(b|0)){continue}break}d=J[g+28>>2];}f=i+P((f-i|0)/12|0,12)|0;if((f|0)!=(d|0)){while(1){d=d-12|0;Db(J[d+4>>2]);if((d|0)!=(f|0)){continue}break}}J[g+28>>2]=f;}b=J[g+32>>2];V:{if(b>>>0>f>>>0){J[f>>2]=J[g+8>>2];d=J[g+12>>2];J[f+4>>2]=d;b=J[g+16>>2];J[f+8>>2]=b;e=f+4|0;W:{if(!b){J[f>>2]=e;break W}J[d+8>>2]=e;J[g+12>>2]=0;J[g+16>>2]=0;J[g+8>>2]=x;}J[g+28>>2]=f+12;break V}X:{Y:{k=J[g+24>>2];h=(f-k|0)/12|0;e=h+1|0;Z:{if(e>>>0>=357913942){J[5996]=0;ca(96);break Z}d=(b-k|0)/12|0;b=d<<1;d=d>>>0>=178956970?357913941:b>>>0>e>>>0?b:e;if(!d){e=0;break X}if(d>>>0<357913942){break Y}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}break e}J[5996]=0;e=$(3,P(d,12)|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break e}}b=P(h,12)+e|0;J[b>>2]=J[g+8>>2];j=J[g+12>>2];J[b+4>>2]=j;h=J[g+16>>2];J[b+8>>2]=h;d=P(d,12);i=b+4|0;_:{if(!h){J[b>>2]=i;break _}J[j+8>>2]=i;J[g+12>>2]=0;J[g+16>>2]=0;J[g+8>>2]=x;}l=d+e|0;i=b+12|0;$:{if((f|0)==(k|0)){J[g+32>>2]=l;J[g+28>>2]=i;J[g+24>>2]=b;break $}while(1){b=b-12|0;f=f-12|0;J[b>>2]=J[f>>2];j=b+4|0;h=f+4|0;e=J[h>>2];J[j>>2]=e;d=J[f+8>>2];J[b+8>>2]=d;aa:{if(!d){J[b>>2]=j;break aa}J[e+8>>2]=j;J[f>>2]=h;J[f+4>>2]=0;J[f+8>>2]=0;}if((f|0)!=(k|0)){continue}break}J[g+32>>2]=l;d=J[g+28>>2];J[g+28>>2]=i;f=J[g+24>>2];J[g+24>>2]=b;if((d|0)==(f|0)){break $}while(1){d=d-12|0;Db(J[d+4>>2]);if((d|0)!=(f|0)){continue}break}}if(!f){break V}$a(f);}if(K[g+20|0]){Db(J[g+12>>2]);}f=D;}if((f|0)!=(o|0)){continue}break d}break}b=Z()|0;if(!K[g+20|0]){break b}Db(J[g+12>>2]);break b}e=J[g+24>>2];if((J[g+28>>2]-e|0)!=12){J[5996]=0;ga(44,4102,2210,450,2439);a=J[5996];J[5996]=0;if((a|0)!=1){break a}b=Z()|0;break b}J[a>>2]=J[e>>2];c=J[e+4>>2];J[a+4>>2]=c;b=J[e+8>>2];J[a+8>>2]=b;d=a+4|0;ba:{if(!b){J[a>>2]=d;break ba}J[c+8>>2]=d;J[e+4>>2]=0;J[e+8>>2]=0;J[e>>2]=e+4;}H[a+12|0]=1;}a=J[g+24>>2];if(a){f=J[g+28>>2];if((a|0)!=(f|0)){while(1){f=f-12|0;Db(J[f+4>>2]);if((a|0)!=(f|0)){continue}break}}$a(a);}if(o){$a(o);}Ua=g+48|0;return}Ug(g+24|0);if(o){$a(o);}da(b|0);B();}a=Z()|0;Ug(g+24|0);da(a|0);B();}B();}function fg(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;e=Ua-144|0;Ua=e;d=Sb(e,0,144);J[d+76>>2]=-1;J[d+44>>2]=a;J[d+32>>2]=178;J[d+84>>2]=a;s=c;a=0;j=Ua-304|0;Ua=j;a:{b:{c:{d:{if(J[d+4>>2]){break d}Dg(d);if(J[d+4>>2]){break d}break c}h=K[b|0];if(!h){break a}e:{f:{g:{h:{while(1){i:{c=h&255;j:{if((c|0)==32|c-9>>>0<5){while(1){h=b;b=b+1|0;c=K[h+1|0];if((c|0)==32|c-9>>>0<5){continue}break}Yb(d,0,0);while(1){b=J[d+4>>2];k:{if((b|0)!=J[d+104>>2]){J[d+4>>2]=b+1;b=K[b|0];break k}b=gb(d);}if((b|0)==32|b-9>>>0<5){continue}break}b=J[d+4>>2];c=J[d+116>>2];if((c|0)>0|(c|0)>=0){b=b-1|0;J[d+4>>2]=b;}b=b-J[d+44>>2]|0;e=b;i=o+J[d+124>>2]|0;c=b>>31;b=m+J[d+120>>2]|0;i=c+(b>>>0>>0?i+1|0:i)|0;m=b+e|0;o=m>>>0>>0?i+1|0:i;break j}l:{m:{n:{if((c|0)==37){c=K[b+1|0];if((c|0)==42){break n}if((c|0)!=37){break m}}Yb(d,0,0);o:{if(K[b|0]==37){while(1){c=J[d+4>>2];p:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;h=K[c|0];break p}h=gb(d);}if((h|0)==32|h-9>>>0<5){continue}break}b=b+1|0;break o}c=J[d+4>>2];if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;h=K[c|0];break o}h=gb(d);}if(K[b|0]!=(h|0)){b=J[d+116>>2];if((b|0)>0|(b|0)>=0){J[d+4>>2]=J[d+4>>2]-1;}if((h|0)>=0){break a}g=0;if(t){break a}break c}c=J[d+4>>2]-J[d+44>>2]|0;h=c;f=o+J[d+124>>2]|0;e=c>>31;c=m+J[d+120>>2]|0;g=e+(c>>>0>>0?f+1|0:f)|0;m=c+h|0;o=m>>>0>>0?g+1|0:g;h=b;break j}l=0;b=b+2|0;break l}e=c-48|0;if(!(K[b+2|0]!=36|e>>>0>=10)){c=Ua-16|0;J[c+12>>2]=s;f=c;c=(e>>>0>1?(e<<2)-4|0:0)+s|0;J[f+8>>2]=c+4;l=J[c>>2];b=b+3|0;break l}l=J[s>>2];s=s+4|0;b=b+1|0;}c=0;while(1){f=K[b|0];if(f-48>>>0<10){b=b+1|0;c=(P(c,10)+f|0)-48|0;continue}break}r=0;if((f|0)==109){p=0;r=(l|0)!=0;f=K[b+1|0];b=b+1|0;a=0;}h=b+1|0;k=3;g=r;q:{r:{switch((f&255)-65|0){case 39:e=b+2|0;b=K[b+1|0]==104;h=b?e:h;k=b?-2:-1;break q;case 43:e=b+2|0;b=K[b+1|0]==108;h=b?e:h;k=b?3:1;break q;case 51:case 57:k=1;break q;case 11:k=2;break q;case 41:break q;case 0:case 2:case 4:case 5:case 6:case 18:case 23:case 26:case 32:case 34:case 35:case 36:case 37:case 38:case 40:case 45:case 46:case 47:case 50:case 52:case 55:break r;default:break e}}k=0;h=b;}e=K[h|0];b=(e&47)==3;u=b?1:k;q=b?e|32:e;s:{if((q|0)==91){break s}t:{if((q|0)!=110){if((q|0)!=99){break t}c=(c|0)<=1?1:c;break s}gg(l,u,m,o);break j}Yb(d,0,0);while(1){b=J[d+4>>2];u:{if((b|0)!=J[d+104>>2]){J[d+4>>2]=b+1;b=K[b|0];break u}b=gb(d);}if((b|0)==32|b-9>>>0<5){continue}break}b=J[d+4>>2];e=J[d+116>>2];if((e|0)>0|(e|0)>=0){b=b-1|0;J[d+4>>2]=b;}b=b-J[d+44>>2]|0;f=b;i=o+J[d+124>>2]|0;e=b>>31;b=m+J[d+120>>2]|0;o=e+(b>>>0>>0?i+1|0:i)|0;m=b+f|0;o=m>>>0>>0?o+1|0:o;}i=c;n=c>>31;Yb(d,c,n);b=J[d+4>>2];v:{if((b|0)!=J[d+104>>2]){J[d+4>>2]=b+1;break v}if((gb(d)|0)<0){break f}}b=J[d+116>>2];if((b|0)>0|(b|0)>=0){J[d+4>>2]=J[d+4>>2]-1;}b=16;w:{x:{y:{z:{A:{switch(q-88|0){default:b=q-65|0;if(b>>>0>6|!(1<>2]-J[d+44>>2]|0;if(J[d+120>>2]!=(0-c|0)|J[d+124>>2]!=(0-((c>>31)+((c|0)!=0)|0)|0)){break y}break g;case 3:case 11:case 27:if((q|16)==115){Sb(j+32|0,-1,257);H[j+32|0]=0;if((q|0)!=115){break x}H[j+65|0]=0;H[j+46|0]=0;I[j+42>>1]=0;I[j+44>>1]=0;break x}f=K[h+1|0];e=(f|0)==94;Sb(j+32|0,e,257);H[j+32|0]=0;b=e?h+2|0:h+1|0;B:{C:{D:{e=K[(e?2:1)+h|0];if((e|0)!=45){if((e|0)==93){break D}k=(f|0)!=94;break B}k=(f|0)!=94;H[j+78|0]=k;break C}k=(f|0)!=94;H[j+126|0]=k;}b=b+1|0;}h=b;while(1){f=K[h|0];E:{if((f|0)!=45){if(!f){break f}if((f|0)==93){break x}break E}f=45;g=K[h+1|0];if(!g|(g|0)==93){break E}e=h+1|0;b=K[h-1|0];F:{if(g>>>0<=b>>>0){f=g;break F}while(1){b=b+1|0;H[b+(j+32|0)|0]=k;f=K[e|0];if(f>>>0>b>>>0){continue}break}}h=e;}H[(f+j|0)+33|0]=k;h=h+1|0;continue}case 23:b=8;break z;case 12:case 29:b=10;break z;case 1:case 2:case 4:case 5:case 6:case 7:case 8:case 10:case 16:case 18:case 19:case 20:case 21:case 22:case 25:case 26:case 28:case 30:case 31:break w;case 0:case 24:case 32:break z;case 17:break A}}b=0;}e=0;i=0;f=0;g=0;w=0;v=Ua-16|0;Ua=v;G:{if((b|0)==1){J[5732]=28;break G}while(1){c=J[d+4>>2];H:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break H}c=gb(d);}if((c|0)==32|c-9>>>0<5){continue}break}I:{J:{switch(c-43|0){case 0:case 2:break J;default:break I}}w=(c|0)==45?-1:0;c=J[d+4>>2];if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break I}c=gb(d);}K:{L:{M:{N:{if(!((b|0)!=0&(b|0)!=16|(c|0)!=48)){c=J[d+4>>2];O:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break O}c=gb(d);}if((c&-33)==88){b=16;c=J[d+4>>2];P:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break P}c=gb(d);}if(K[c+8641|0]<16){break M}b=J[d+116>>2];if((b|0)>0|(b|0)>=0){J[d+4>>2]=J[d+4>>2]-1;}Yb(d,0,0);break G}if(b){break N}b=8;break M}b=b?b:10;if(b>>>0>K[c+8641|0]){break N}b=J[d+116>>2];if((b|0)>0|(b|0)>=0){J[d+4>>2]=J[d+4>>2]-1;}Yb(d,0,0);J[5732]=28;break G}if((b|0)!=10){break M}f=c-48|0;if(f>>>0<=9){c=0;while(1){c=P(c,10)+f|0;g=c>>>0<429496729;e=J[d+4>>2];Q:{if((e|0)!=J[d+104>>2]){J[d+4>>2]=e+1;b=K[e|0];break Q}b=gb(d);}f=b-48|0;if(g&f>>>0<=9){continue}break}e=c;}if(f>>>0>9){break K}b=co(e,0,10,0);g=Wa;while(1){e=b+f|0;i=e>>>0>>0?g+1|0:g;b=(i|0)==429496729&e>>>0<2576980378|i>>>0<429496729;c=J[d+4>>2];R:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break R}c=gb(d);}k=c-48|0;if(!(b&k>>>0<=9)){b=10;if(k>>>0<=9){break L}break K}b=co(e,i,10,0);g=Wa;f=k;if((g|0)==-1&(f^-1)>>>0>=b>>>0|(g|0)!=-1){continue}break}b=10;break L}if(b-1&b){g=K[c+8641|0];if(g>>>0>>0){while(1){f=P(b,f)+g|0;e=f>>>0<119304647;c=J[d+4>>2];S:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break S}c=gb(d);}g=K[c+8641|0];if(e&g>>>0>>0){continue}break}e=f;}if(b>>>0<=g>>>0){break L}n=b;while(1){f=co(e,i,n,0);k=Wa;g=g&255;if((k|0)==-1&(g^-1)>>>0>>0){break L}i=k;e=f+g|0;i=e>>>0>>0?i+1|0:i;c=J[d+4>>2];T:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break T}c=gb(d);}g=K[c+8641|0];if(b>>>0<=g>>>0){break L}xb(v,n,0,0,0,e,i,0,0);if(!(J[v+8>>2]|J[v+12>>2])){continue}break}break L}k=H[(P(b,23)>>>5&7)+8897|0];f=K[c+8641|0];if(f>>>0>>0){while(1){g=g<>>0<134217728;c=J[d+4>>2];U:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break U}c=gb(d);}f=K[c+8641|0];if(e&f>>>0>>0){continue}break}e=g;}if(b>>>0<=f>>>0){break L}n=k&31;if((k&63)>>>0>=32){g=0;n=-1>>>n|0;}else {g=-1>>>n|0;n=g|(1<>>0>n>>>0){break L}while(1){x=f&255;c=e;f=k&31;if((k&63)>>>0>=32){i=c<>>32-f|i<>2];V:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break V}c=gb(d);}f=K[c+8641|0];if(b>>>0<=f>>>0){break L}if((g|0)==(i|0)&e>>>0<=n>>>0|g>>>0>i>>>0){continue}break}}if(K[c+8641|0]>=b>>>0){break K}while(1){c=J[d+4>>2];W:{if((c|0)!=J[d+104>>2]){J[d+4>>2]=c+1;c=K[c|0];break W}c=gb(d);}if(K[c+8641|0]>>0){continue}break}J[5732]=68;e=-1;i=-1;w=0;}b=J[d+116>>2];if((b|0)>0|(b|0)>=0){J[d+4>>2]=J[d+4>>2]-1;}b=w;f=b^e;e=f-b|0;c=b>>31;i=(c^i)-((b>>>0>f>>>0)+c|0)|0;}Ua=v+16|0;c=J[d+4>>2]-J[d+44>>2]|0;if(J[d+120>>2]==(0-c|0)&J[d+124>>2]==(0-((c>>31)+((c|0)!=0)|0)|0)){break g}if(!(!l|(q|0)!=112)){J[l>>2]=e;break w}gg(l,u,e,i);break w}if(!l){break w}c=J[j+16>>2];f=J[j+20>>2];b=J[j+8>>2];e=J[j+12>>2];X:{switch(u|0){case 0:N[l>>2]=Vf(b,e,c,f);break w;case 1:O[l>>3]=ge(b,e,c,f);break w;case 2:break X;default:break w}}J[l>>2]=b;J[l+4>>2]=e;J[l+8>>2]=c;J[l+12>>2]=f;break w}k=(q|0)!=99;c=k?31:c+1|0;Y:{if((u|0)==1){f=l;if(r){f=sb(c<<2);if(!f){break h}}J[j+296>>2]=0;J[j+300>>2]=0;b=0;while(1){a=f;Z:{while(1){e=J[d+4>>2];_:{if((e|0)!=J[d+104>>2]){J[d+4>>2]=e+1;e=K[e|0];break _}e=gb(d);}if(!K[(e+j|0)+33|0]){break Z}H[j+27|0]=e;e=qd(j+28|0,j+27|0,1,j+296|0);if((e|0)==-2){continue}p=0;if((e|0)==-1){break f}if(a){J[(b<<2)+a>>2]=J[j+28>>2];b=b+1|0;}if(!r|(b|0)!=(c|0)){continue}break}g=1;b=c;c=b<<1|1;f=Vc(a,c<<2);if(f){continue}break e}break}p=0;c=a;if(j+296|0?J[j+296>>2]:0){break f}break Y}if(r){b=0;f=sb(c);if(!f){break h}while(1){a=f;while(1){e=J[d+4>>2];$:{if((e|0)!=J[d+104>>2]){J[d+4>>2]=e+1;e=K[e|0];break $}e=gb(d);}if(!K[(e+j|0)+33|0]){c=0;p=a;break Y}H[a+b|0]=e;b=b+1|0;if((c|0)!=(b|0)){continue}break}g=1;b=c;c=b<<1|1;f=Vc(a,c);if(f){continue}break}p=a;a=0;break e}b=0;if(l){while(1){a=J[d+4>>2];aa:{if((a|0)!=J[d+104>>2]){J[d+4>>2]=a+1;a=K[a|0];break aa}a=gb(d);}if(K[(a+j|0)+33|0]){H[b+l|0]=a;b=b+1|0;continue}else {c=0;a=l;p=a;break Y}}}while(1){a=J[d+4>>2];ba:{if((a|0)!=J[d+104>>2]){J[d+4>>2]=a+1;a=K[a|0];break ba}a=gb(d);}if(K[(a+j|0)+33|0]){continue}break}a=0;p=0;c=0;}f=J[d+4>>2];e=J[d+116>>2];if((e|0)>0|(e|0)>=0){f=f-1|0;J[d+4>>2]=f;}e=f-J[d+44>>2]|0;f=e+J[d+120>>2]|0;g=J[d+124>>2]+(e>>31)|0;g=f>>>0>>0?g+1|0:g;if(!(g|f)|!(k|(f|0)==(i|0)&(g|0)==(n|0))){break i}if(r){J[l>>2]=a;}ca:{if((q|0)==99){break ca}if(c){J[(b<<2)+c>>2]=0;}if(!p){p=0;break ca}H[b+p|0]=0;}a=c;}b=J[d+4>>2]-J[d+44>>2]|0;e=b;f=o+J[d+124>>2]|0;c=b>>31;b=m+J[d+120>>2]|0;i=c+(b>>>0>>0?f+1|0:f)|0;m=b+e|0;o=m>>>0>>0?i+1|0:i;t=((l|0)!=0)+t|0;}b=h+1|0;h=K[h+1|0];if(h){continue}break a}break}a=c;break g}g=1;p=0;a=0;break e}g=r;break b}g=r;}if(t){break b}}t=-1;}if(!g){break a}$a(p);$a(a);}Ua=j+304|0;Ua=d+144|0;return t}function ao(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;d=Ua-320|0;Ua=d;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{if(!K[24336]){J[d+208>>2]=0;J[d+200>>2]=0;J[d+204>>2]=0;J[5996]=0;ba(66,24324,d+200|0,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break w}b=J[d+200>>2];if(b){J[d+204>>2]=b;$a(b);}H[24336]=1;}if(!K[24352]){J[5996]=0;b=d+200|0;ea(68,b|0,1598,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+308|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24340,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break v}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24352]=1;}if(!K[24368]){J[5996]=0;b=d+200|0;ea(68,b|0,1194,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+296|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24356,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break u}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24368]=1;}if(!K[24384]){J[5996]=0;b=d+200|0;ea(68,b|0,2432,6);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+284|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24372,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break t}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24384]=1;}if(!K[24400]){J[5996]=0;b=d+200|0;ea(68,b|0,1492,6);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+272|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24388,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break s}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24400]=1;}if(!K[24416]){J[5996]=0;b=d+200|0;ea(68,b|0,1152,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+260|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24404,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break r}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24416]=1;}if(!K[24432]){J[5996]=0;b=d+200|0;ea(68,b|0,1526,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+248|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24420,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break q}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24432]=1;}if(!K[24448]){J[5996]=0;b=d+200|0;ea(68,b|0,1628,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+236|0,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24436,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break p}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24448]=1;}if(!K[24464]){J[5996]=0;b=d+116|0;ea(68,b|0,1435,7);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+124|0,1183,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;c=ba(69,d+200|0,b|0,2)|0;b=J[5996];J[5996]=0;if((b|0)==1){break c}J[5996]=0;e=d+80|0;ea(68,e|0,1478,7);f=J[5996];J[5996]=0;b=c+12|0;if((f|0)==1){break n}J[5996]=0;ea(68,d+88|0,1172,10);f=J[5996];J[5996]=0;if((f|0)==1){break n}J[5996]=0;f=ba(69,b|0,e|0,2)|0;e=J[5996];J[5996]=0;if((e|0)==1){break n}J[5996]=0;e=d+56|0;ea(68,e|0,1435,7);g=J[5996];J[5996]=0;b=c+24|0;if((g|0)==1){break n}J[5996]=0;ea(68,d- -64|0,1161,10);g=J[5996];J[5996]=0;if((g|0)==1){break n}J[5996]=0;g=ba(69,b|0,e|0,2)|0;e=J[5996];J[5996]=0;if((e|0)==1){break n}J[5996]=0;ba(66,24452,c|0,3)|0;b=J[5996];J[5996]=0;if((b|0)==1){break o}b=J[g>>2];if(b){J[c+28>>2]=b;$a(b);}b=J[f>>2];if(b){J[c+16>>2]=b;$a(b);}b=J[c>>2];if(b){J[c+4>>2]=b;$a(b);}H[24464]=1;}if(!K[24480]){J[5996]=0;b=d+116|0;ea(68,b|0,1628,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+124|0,1617,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+188|0,b|0,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24468,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break m}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24480]=1;}if(!K[24496]){J[5996]=0;b=d+116|0;ea(68,b|0,1462,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+124|0,1453,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+176|0,b|0,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24484,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break l}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24496]=1;}if(!K[24512]){J[5996]=0;b=d+116|0;ea(68,b|0,1443,9);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+124|0,1587,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+164|0,b|0,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24500,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break k}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24512]=1;}if(!K[24528]){J[5996]=0;b=d+116|0;ea(68,b|0,1443,9);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+124|0,1471,6);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;b=ba(69,d+152|0,b|0,2)|0;c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ba(66,24516,b|0,1)|0;c=J[5996];J[5996]=0;if((c|0)==1){break j}c=J[b>>2];if(c){J[b+4>>2]=c;$a(c);}H[24528]=1;}if(!K[24544]){J[5996]=0;b=d+80|0;ea(68,b|0,1535,9);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+88|0,1535,9);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;c=ba(69,d+116|0,b|0,2)|0;b=J[5996];J[5996]=0;if((b|0)==1){break c}J[5996]=0;e=d+56|0;ea(68,e|0,1555,9);f=J[5996];J[5996]=0;b=c+12|0;if((f|0)==1){break h}J[5996]=0;ea(68,d- -64|0,1555,9);f=J[5996];J[5996]=0;if((f|0)==1){break h}J[5996]=0;f=ba(69,b|0,e|0,2)|0;e=J[5996];J[5996]=0;if((e|0)==1){break h}J[5996]=0;e=d+32|0;ea(68,e|0,1545,9);g=J[5996];J[5996]=0;b=c+24|0;if((g|0)==1){break h}J[5996]=0;ea(68,d+40|0,1545,9);g=J[5996];J[5996]=0;if((g|0)==1){break h}J[5996]=0;g=ba(69,b|0,e|0,2)|0;e=J[5996];J[5996]=0;if((e|0)==1){break h}J[5996]=0;ba(66,24532,c|0,3)|0;b=J[5996];J[5996]=0;if((b|0)==1){break i}b=J[g>>2];if(b){J[c+28>>2]=b;$a(b);}b=J[f>>2];if(b){J[c+16>>2]=b;$a(b);}b=J[c>>2];if(b){J[c+4>>2]=b;$a(b);}H[24544]=1;}if(!K[24560]){J[5996]=0;b=d+56|0;ea(68,b|0,1443,9);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d- -64|0,1517,8);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;ea(68,d+72|0,1587,10);c=J[5996];J[5996]=0;if((c|0)==1){break c}J[5996]=0;c=ba(69,d+80|0,b|0,3)|0;b=J[5996];J[5996]=0;if((b|0)==1){break c}J[5996]=0;e=d+32|0;ea(68,e|0,1443,9);f=J[5996];J[5996]=0;b=c+12|0;if((f|0)==1){break f}J[5996]=0;ea(68,d+40|0,1508,8);f=J[5996];J[5996]=0;if((f|0)==1){break f}J[5996]=0;ea(68,d+48|0,1576,10);f=J[5996];J[5996]=0;if((f|0)==1){break f}J[5996]=0;f=ba(69,b|0,e|0,3)|0;e=J[5996];J[5996]=0;if((e|0)==1){break f}J[5996]=0;e=d+8|0;ea(68,e|0,1443,9);g=J[5996];J[5996]=0;b=c+24|0;if((g|0)==1){break f}J[5996]=0;ea(68,d+16|0,1499,8);g=J[5996];J[5996]=0;if((g|0)==1){break f}J[5996]=0;ea(68,d+24|0,1565,10);g=J[5996];J[5996]=0;if((g|0)==1){break f}J[5996]=0;g=ba(69,b|0,e|0,3)|0;e=J[5996];J[5996]=0;if((e|0)==1){break f}J[5996]=0;ba(66,24548,c|0,3)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}b=J[g>>2];if(b){J[c+28>>2]=b;$a(b);}b=J[f>>2];if(b){J[c+16>>2]=b;$a(b);}b=J[c>>2];if(b){J[c+4>>2]=b;$a(b);}H[24560]=1;}if(!(50331647>>>a&1)){break e}Ua=d+320|0;return J[(a<<2)+6864>>2]}e=Z()|0;a=J[d+200>>2];if(!a){break d}J[d+204>>2]=a;$a(a);break d}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[g>>2];if(a){J[c+28>>2]=a;$a(a);}a=J[f>>2];if(a){J[c+16>>2]=a;$a(a);}a=J[c>>2];if(!a){break d}break a}e=Z()|0;while(1){a=b-12|0;d=J[a>>2];if(d){J[b-8>>2]=d;$a(d);}b=a;if((b|0)!=(c|0)){continue}break}break d}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[b>>2];if(!a){break d}break b}e=Z()|0;a=J[g>>2];if(a){J[c+28>>2]=a;$a(a);}a=J[f>>2];if(a){J[c+16>>2]=a;$a(a);}a=J[c>>2];if(!a){break d}break a}e=Z()|0;while(1){a=b-12|0;d=J[a>>2];if(d){J[b-8>>2]=d;$a(d);}b=a;if((b|0)!=(c|0)){continue}break}break d}e=Z()|0;a=J[g>>2];if(a){J[c+28>>2]=a;$a(a);}a=J[f>>2];if(a){J[c+16>>2]=a;$a(a);}a=J[c>>2];if(!a){break d}break a}e=Z()|0;while(1){a=b-12|0;d=J[a>>2];if(d){J[b-8>>2]=d;$a(d);}b=a;if((b|0)!=(c|0)){continue}break}break d}la(2350,1900,622,1759);B();}da(e|0);B();}da(Z()|0);B();}J[b+4>>2]=a;$a(a);da(e|0);B();}J[c+4>>2]=a;$a(a);da(e|0);B();}function wd(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0;h=Ua-144|0;Ua=h;Yc(h+56|0,c,O[a+16>>3],O[a+24>>3],0,0);J[5996]=0;f=$(46,c|0)|0;g=J[5996];J[5996]=0;a:{b:{c:{if((g|0)!=1){J[h+52>>2]=0;J[h+44>>2]=0;J[h+48>>2]=0;H[h+128|0]=0;J[h+124>>2]=h+44;g=J[f+4>>2];j=J[f>>2];k=g-j|0;i=(k|0)/12|0;if((g|0)!=(j|0)){d:{e:{f:{if(i>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)==1){break f}break a}J[5996]=0;g=$(3,k|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break f}J[h+48>>2]=g;J[h+44>>2]=g;J[h+52>>2]=g+P(i,12);i=J[f+4>>2];f=J[f>>2];J[5996]=0;f=ia(48,h+52|0,f|0,i|0,g|0)|0;i=J[5996];J[5996]=0;if((i|0)!=1){break d}f=Z()|0;J[h+48>>2]=g;break e}f=Z()|0;}Nc(h+124|0);break c}J[h+48>>2]=f;}J[h+40>>2]=0;J[h+32>>2]=0;J[h+36>>2]=0;f=J[d+4>>2];g=J[d>>2];J[5996]=0;aa(49,h+32|0,f-g>>2);f=J[5996];J[5996]=0;g:{if((f|0)!=1){f=J[h+48>>2];g=J[h+44>>2];if((f|0)==(g|0)){break b}f=g;h:{while(1){i:{J[h+28>>2]=0;J[h+20>>2]=0;J[h+24>>2]=0;i=J[d+4>>2];g=J[d>>2];n=P(s,12);f=n+f|0;if(i-g>>2!=J[f+4>>2]-J[f>>2]>>3){break i}j=0;r=1;k=0;j:{if((g|0)!=(i|0)){k:{l:{m:{while(1){f=k<<3;v=O[f+J[h+68>>2]>>3];w=O[f+J[h+56>>2]>>3];g=J[(k<<2)+g>>2];J[5996]=0;g=qa(50,g|0,+w,+v,b|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break l}f=f+J[n+J[h+44>>2]>>2]|0;i=J[f>>2];f=J[f+4>>2];m=J[g+4>>2];g=J[g>>2];J[5996]=0;oa(51,h+124|0,g|0,m|0,i|0,f|0);f=J[5996];J[5996]=0;if((f|0)!=1){i=J[h+28>>2];n:{if(i>>>0>j>>>0){J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;J[j>>2]=J[h+124>>2];J[j+4>>2]=J[h+128>>2];J[j+8>>2]=J[h+132>>2];J[h+24>>2]=j+12;break n}o:{g=J[h+20>>2];m=(j-g|0)/12|0;f=m+1|0;p:{if(f>>>0>=357913942){J[5996]=0;ca(52);break p}i=(i-g|0)/12|0;l=i<<1;f=i>>>0>=178956970?357913941:f>>>0>>0?l:f;if(f>>>0<357913942){break o}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}break m}J[5996]=0;l=P(f,12);i=$(3,l|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break m}f=i+P(m,12)|0;J[f>>2]=J[h+124>>2];J[f+4>>2]=J[h+128>>2];J[f+8>>2]=J[h+132>>2];J[h+132>>2]=0;J[h+124>>2]=0;J[h+128>>2]=0;i=i+l|0;m=f+12|0;q:{if((g|0)==(j|0)){J[h+28>>2]=i;J[h+24>>2]=m;J[h+20>>2]=f;break q}while(1){f=f-12|0;j=j-12|0;J[f>>2]=J[j>>2];J[f+4>>2]=J[j+4>>2];J[f+8>>2]=J[j+8>>2];J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;if((g|0)!=(j|0)){continue}break}J[h+28>>2]=i;g=J[h+24>>2];J[h+24>>2]=m;j=J[h+20>>2];J[h+20>>2]=f;if((g|0)==(j|0)){break q}while(1){l=g-12|0;m=J[l>>2];if(m){o=g-8|0;f=J[o>>2];i=m;if((f|0)!=(i|0)){while(1){f=f-32|0;g=J[f+4>>2];r:{if(!g){break r}i=J[g+4>>2];J[g+4>>2]=i-1;if(i){break r}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(m|0)){continue}break}i=J[l>>2];}J[o>>2]=m;$a(i);}g=l;if((j|0)!=(g|0)){continue}break}}if(j){$a(j);}i=J[h+124>>2];if(!i){break n}f=J[h+128>>2];g=i;if((f|0)!=(g|0)){while(1){f=f-32|0;g=J[f+4>>2];s:{if(!g){break s}j=J[g+4>>2];J[g+4>>2]=j-1;if(j){break s}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(i|0)){continue}break}g=J[h+124>>2];}J[h+128>>2]=i;$a(g);}j=J[h+24>>2];f=j-12|0;r=P(J[f+4>>2]-J[f>>2]>>5,r);k=k+1|0;g=J[d>>2];if(k>>>0>=J[d+4>>2]-g>>2>>>0){break k}continue}break}f=Z()|0;break h}f=Z()|0;_b(h+124|0);break h}f=Z()|0;break h}if(!r){break j}}m=0;t:{u:{v:{w:{while(1){j=J[h+32>>2];if(J[d+4>>2]!=J[d>>2]){f=0;i=J[h+20>>2];g=m;while(1){k=P(f,12);l=k+i|0;i=J[l>>2];J[(f<<2)+j>>2]=i+((g>>>0)%(J[l+4>>2]-i>>5>>>0)<<5);l=g;i=J[h+20>>2];g=k+i|0;g=(l>>>0)/(J[g+4>>2]-J[g>>2]>>5>>>0)|0;f=f+1|0;if(f>>>0>2]-J[d>>2]>>2>>>0){continue}break}}J[h+108>>2]=0;J[h+100>>2]=0;J[h+104>>2]=0;f=j;n=J[h+36>>2];if((f|0)!=(n|0)){x:{while(1){y:{k=J[j>>2];f=J[h+104>>2];z:{if((f|0)!=J[h+108>>2]){J[f>>2]=J[k>>2];g=J[k+4>>2];J[f+4>>2]=g;if(g){J[g+4>>2]=J[g+4>>2]+1;}J[h+104>>2]=f+8;break z}A:{i=J[h+100>>2];g=f-i|0;o=g>>3;l=o+1|0;B:{if(l>>>0>=536870912){J[5996]=0;ca(59);break B}p=g>>2;g=g>>>0>=2147483640?536870911:l>>>0

>>0?p:l;if(g>>>0<536870912){break A}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}f=Z()|0;break t}J[5996]=0;p=g<<3;l=$(3,p|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break y}g=l+(o<<3)|0;J[g>>2]=J[k>>2];k=J[k+4>>2];J[g+4>>2]=k;if(k){J[k+4>>2]=J[k+4>>2]+1;f=J[h+104>>2];}k=l+p|0;l=g+8|0;C:{if((f|0)==(i|0)){J[h+108>>2]=k;J[h+104>>2]=l;J[h+100>>2]=g;break C}while(1){g=g-8|0;f=f-8|0;J[g>>2]=J[f>>2];J[g+4>>2]=J[f+4>>2];J[f>>2]=0;J[f+4>>2]=0;if((f|0)!=(i|0)){continue}break}J[h+108>>2]=k;f=J[h+104>>2];J[h+104>>2]=l;i=J[h+100>>2];J[h+100>>2]=g;if((f|0)==(i|0)){break C}while(1){f=f-8|0;g=J[f+4>>2];D:{if(!g){break D}k=J[g+4>>2];J[g+4>>2]=k-1;if(k){break D}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(i|0)){continue}break}}if(!i){break z}$a(i);}j=j+4|0;if((n|0)!=(j|0)){continue}break x}break}f=Z()|0;break t}j=J[h+36>>2];f=J[h+32>>2];}J[5996]=0;va(63,h+80|0,c|0,f|0,j|0,0);f=J[5996];J[5996]=0;if((f|0)==1){break u}J[5996]=0;j=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)==1){break u}J[j>>2]=7e3;J[j+4>>2]=0;J[j+8>>2]=0;p=J[h+100>>2];J[h+112>>2]=p;q=J[h+104>>2];J[h+116>>2]=q;l=J[h+108>>2];f=0;J[h+108>>2]=0;J[h+120>>2]=l;J[h+100>>2]=0;J[h+104>>2]=0;g=J[e>>2];n=J[e+4>>2];E:{if((g|0)==(n|0)){k=0;i=0;break E}o=n-g|0;if((o|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)!=1){break a}f=Z()|0;break v}J[5996]=0;k=$(3,o|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break w}t=n+(g^-1)|0;i=0;f=k;u=o&7;if(u){while(1){H[f|0]=K[g|0];f=f+1|0;g=g+1|0;i=i+1|0;if((u|0)!=(i|0)){continue}break}}i=k+o|0;if(t>>>0<7){break E}while(1){H[f|0]=K[g|0];H[f+1|0]=K[g+1|0];H[f+2|0]=K[g+2|0];H[f+3|0]=K[g+3|0];H[f+4|0]=K[g+4|0];H[f+5|0]=K[g+5|0];H[f+6|0]=K[g+6|0];H[f+7|0]=K[g+7|0];f=f+8|0;g=g+8|0;if((n|0)!=(g|0)){continue}break}l=J[h+120>>2];q=J[h+116>>2];p=J[h+112>>2];}J[j+12>>2]=c;J[j+16>>2]=0;J[j+20>>2]=0;J[j+24>>2]=0;J[j+28>>2]=0;J[j+52>>2]=l;J[j+48>>2]=q;o=j+44|0;J[o>>2]=p;J[j+40>>2]=i;J[j+36>>2]=f;J[j+32>>2]=k;J[h+120>>2]=0;J[h+112>>2]=0;J[h+116>>2]=0;J[5996]=0;i=j+12|0;aa(86,j+56|0,i|0);f=J[5996];J[5996]=0;F:{if((f|0)==1){break F}J[5996]=0;aa(87,j+76|0,i|0);f=J[5996];J[5996]=0;if((f|0)==1){break F}J[5996]=0;f=$(88,i|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break F}J[j+92>>2]=f;g=0;l=0;k=J[j+44>>2];f=k;n=J[j+48>>2];if((f|0)!=(n|0)){while(1){g=J[J[f>>2]+84>>2]+g|0;f=f+8|0;if((n|0)!=(f|0)){continue}break}l=J[J[k>>2]+80>>2];}f=J[j+16>>2];p=J[j+12>>2];q=J[j+20>>2];t=J[j+24>>2];J[5996]=0;f=ka(89,p|0,l|0,g|0,f|0,n-k>>3,(t-q|0)/12|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break F}J[j+96>>2]=f;J[5996]=0;J[h+140>>2]=i;ea(90,h+124|0,i|0,h+140|0);f=J[5996];J[5996]=0;if((f|0)==1){break F}f=K[h+136|0];if(f){Db(J[h+128>>2]);}H[j+100|0]=f^1;J[h+128>>2]=j;J[h+124>>2]=i;J[5996]=0;f=J[h+128>>2];J[h+8>>2]=J[h+124>>2];J[h+12>>2]=f;ea(61,a|0,h+80|0,h+8|0);f=J[5996];J[5996]=0;if((f|0)==1){break u}g=J[h+100>>2];if(g){f=J[h+104>>2];if((g|0)!=(f|0)){while(1){f=f-8|0;i=J[f+4>>2];G:{if(!i){break G}j=J[i+4>>2];J[i+4>>2]=j-1;if(j){break G}Xa[J[J[i>>2]+8>>2]](i);bb(i);}if((f|0)!=(g|0)){continue}break}g=J[h+100>>2];}$a(g);}m=m+1|0;if((r|0)!=(m|0)){continue}break j}break}f=Z()|0;lb(o);a=J[j+32>>2];if(a){J[j+36>>2]=a;$a(a);}rb(j+20|0);break v}f=Z()|0;}lb(h+112|0);$a(j);break t}f=Z()|0;}lb(h+100|0);break h}i=J[h+20>>2];if(i){f=J[h+24>>2];if((i|0)!=(f|0)){while(1){k=f-12|0;j=J[k>>2];if(j){m=f-8|0;f=J[m>>2];g=j;if((f|0)!=(g|0)){while(1){f=f-32|0;g=J[f+4>>2];H:{if(!g){break H}l=J[g+4>>2];J[g+4>>2]=l-1;if(l){break H}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(j|0)){continue}break}g=J[k>>2];}J[m>>2]=j;$a(g);}f=k;if((i|0)!=(f|0)){continue}break}i=J[h+20>>2];}$a(i);}s=s+1|0;f=J[h+44>>2];if(s>>>0<(J[h+48>>2]-f|0)/12>>>0){continue}break b}break}J[5996]=0;ga(44,5170,1900,642,2497);a=J[5996];J[5996]=0;if((a|0)!=1){break a}f=Z()|0;}Xc(h+20|0);break g}f=Z()|0;}a=J[h+32>>2];if(a){$a(a);}Wc(h+44|0);break c}f=Z()|0;}Mc(h+56|0);da(f|0);B();}a=J[h+32>>2];if(a){$a(a);f=J[h+44>>2];}if(f){g=f;i=J[h+48>>2];if((i|0)!=(f|0)){while(1){a=i-12|0;b=J[a>>2];if(b){J[i-8>>2]=b;$a(b);}i=a;if((i|0)!=(f|0)){continue}break}g=J[h+44>>2];}J[h+48>>2]=f;$a(g);}a=J[h+68>>2];if(a){J[h+72>>2]=a;$a(a);}a=J[h+56>>2];if(a){J[h+60>>2]=a;$a(a);}Ua=h+144|0;return}B();}function Wm(a,b,c,d,e,f,g,h,i){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;j=Ua-208|0;Ua=j;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{k=Gb(a);if(k>>>0>=2147483632){J[5996]=0;ca(2);a=J[5996];J[5996]=0;if((a|0)==1){break z}break a}A:{if(k>>>0<=10){H[j+171|0]=k;n=j+160|0;break A}J[5996]=0;m=(k|15)+1|0;n=$(3,m|0)|0;l=J[5996];J[5996]=0;if((l|0)==1){break z}J[j+160>>2]=n;J[j+164>>2]=k;J[j+168>>2]=m|-2147483648;}H[fb(n,a,k)+k|0]=0;l=J[j+160>>2];a=K[j+171|0];p=a<<24>>24;k=(p|0)<0;o=k?l:j+160|0;r=k?J[j+164>>2]:a;k=o+r|0;n=-1;B:{while(1){if((k|0)==(o|0)){break B}k=k-1|0;m=K[k|0];s=m>>>0<=63;a=m&31;if((m&63)>>>0>=32){m=1<>>32-a;a=q;}a=a&9728;if(s&(m&1|(a|0)!=0)){continue}break}n=k-o|0;}a=n+1|0;if(a>>>0>r>>>0){J[5996]=0;ca(108);a=J[5996];J[5996]=0;if((a|0)!=1){break a}k=fa(22864)|0;a=Va;break l}C:{if((p|0)<0){J[j+164>>2]=a;break C}H[j+171|0]=a;l=j+160|0;}H[a+l|0]=0;J[j+152>>2]=0;J[j+156>>2]=0;D:{if(H[j+171|0]>=0){J[j+144>>2]=J[j+168>>2];a=J[j+164>>2];J[j+136>>2]=J[j+160>>2];J[j+140>>2]=a;break D}J[5996]=0;ea(40,j+136|0,J[j+160>>2],J[j+164>>2]);a=J[5996];J[5996]=0;if((a|0)==1){break y}}J[5996]=0;a=j+172|0;aa(109,a|0,j+136|0);k=J[5996];J[5996]=0;if((k|0)==1){break x}m=a;a=H[j+183|0];k=(a|0)<0;J[j+104>>2]=k?J[j+172>>2]:m;J[j+108>>2]=k?J[j+176>>2]:a&255;J[5996]=0;a=J[j+108>>2];J[j+8>>2]=J[j+104>>2];J[j+12>>2]=a;aa(140,j+16|0,j+8|0);a=J[5996];J[5996]=0;if((a|0)==1){break w}a=J[j+20>>2];J[j+156>>2]=a;k=J[j+16>>2];J[j+152>>2]=k;if(H[j+183|0]<0){$a(J[j+172>>2]);}if(H[j+147|0]<0){$a(J[j+136>>2]);}E:{if(!k){break E}n=J[k+80>>2];if(!n|M[k+84>>2]>3600){break E}J[5996]=0;m=_(54,3557,1)|0;l=J[5996];J[5996]=0;if((l|0)==1){break u}if(!((n^-1)&m)){break r}}J[5996]=0;f=$(3,32)|0;g=J[5996];J[5996]=0;if((g|0)==1){break t}H[f+16|0]=0;g=K[2571]|K[2572]<<8|(K[2573]<<16|K[2574]<<24);h=K[2567]|K[2568]<<8|(K[2569]<<16|K[2570]<<24);H[f+8|0]=h;H[f+9|0]=h>>>8;H[f+10|0]=h>>>16;H[f+11|0]=h>>>24;H[f+12|0]=g;H[f+13|0]=g>>>8;H[f+14|0]=g>>>16;H[f+15|0]=g>>>24;g=K[2563]|K[2564]<<8|(K[2565]<<16|K[2566]<<24);h=K[2559]|K[2560]<<8|(K[2561]<<16|K[2562]<<24);H[f|0]=h;H[f+1|0]=h>>>8;H[f+2|0]=h>>>16;H[f+3|0]=h>>>24;H[f+4|0]=g;H[f+5|0]=g>>>8;H[f+6|0]=g>>>16;H[f+7|0]=g>>>24;g=((c|0)>=17?17:c)-1|0;H[fb(b,f,g)+g|0]=0;$a(f);J[5996]=0;f=$(3,32)|0;g=J[5996];J[5996]=0;if((g|0)==1){break s}H[f+16|0]=0;c=K[2571]|K[2572]<<8|(K[2573]<<16|K[2574]<<24);b=f;f=K[2567]|K[2568]<<8|(K[2569]<<16|K[2570]<<24);H[b+8|0]=f;H[b+9|0]=f>>>8;H[b+10|0]=f>>>16;H[b+11|0]=f>>>24;H[b+12|0]=c;H[b+13|0]=c>>>8;H[b+14|0]=c>>>16;H[b+15|0]=c>>>24;c=K[2563]|K[2564]<<8|(K[2565]<<16|K[2566]<<24);f=K[2559]|K[2560]<<8|(K[2561]<<16|K[2562]<<24);H[b|0]=f;H[b+1|0]=f>>>8;H[b+2|0]=f>>>16;H[b+3|0]=f>>>24;H[b+4|0]=c;H[b+5|0]=c>>>8;H[b+6|0]=c>>>16;H[b+7|0]=c>>>24;c=((e|0)>=17?17:e)-1|0;H[fb(d,b,c)+c|0]=0;$a(b);break q}k=fa(22864)|0;a=Va;break k}k=fa(22864)|0;a=Va;break m}k=fa(22864)|0;a=Va;break v}k=fa(22864)|0;a=Va;if(H[j+183|0]>=0){break v}$a(J[j+172>>2]);}if(H[j+147|0]>=0){break m}$a(J[j+136>>2]);break m}k=fa(22864)|0;a=Va;break m}k=fa(22864)|0;a=Va;break m}k=fa(22864)|0;a=Va;break m}a=J[k+84>>2];J[5996]=0;n=j+60|0;aa(115,n|0,a|0);a=J[5996];J[5996]=0;F:{G:{H:{I:{J:{K:{L:{M:{N:{O:{P:{Q:{R:{if((a|0)!=1){J[5996]=0;a=ba(99,n|0,0,5546)|0;n=J[5996];J[5996]=0;if((n|0)==1){break R}J[j+80>>2]=J[a+8>>2];n=J[a+4>>2];J[j+72>>2]=J[a>>2];J[j+76>>2]=n;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;J[5996]=0;n=_(97,j+72|0,3581)|0;m=J[5996];J[5996]=0;if((m|0)==1){break Q}J[j+96>>2]=J[n+8>>2];m=J[n+4>>2];J[j+88>>2]=J[n>>2];J[j+92>>2]=m;J[n>>2]=0;J[n+4>>2]=0;J[n+8>>2]=0;J[5996]=0;m=j+172|0;aa(141,m|0,j+152|0);l=J[5996];J[5996]=0;if((l|0)==1){break P}J[5996]=0;q=m;m=K[j+183|0];l=m<<24>>24<0;m=ba(100,j+88|0,(l?J[j+172>>2]:q)|0,(l?J[j+176>>2]:m)|0)|0;l=J[5996];J[5996]=0;if((l|0)==1){break O}J[j+112>>2]=J[m+8>>2];l=J[m+4>>2];J[j+104>>2]=J[m>>2];J[j+108>>2]=l;J[m>>2]=0;J[m+4>>2]=0;J[m+8>>2]=0;J[5996]=0;l=_(97,j+104|0,3570)|0;o=J[5996];J[5996]=0;if((o|0)==1){break N}J[j+128>>2]=J[l+8>>2];o=J[l+4>>2];J[j+120>>2]=J[l>>2];J[j+124>>2]=o;J[l>>2]=0;J[l+4>>2]=0;J[l+8>>2]=0;if(H[j+183|0]<0){$a(J[j+172>>2]);}if(H[m+11|0]<0){$a(J[m>>2]);}if(H[n+11|0]<0){$a(J[n>>2]);}if(H[a+11|0]<0){$a(J[a>>2]);}n=J[j+120>>2];a=K[j+131|0];m=a<<24>>24;l=(m|0)<0;q=l?n:j+120|0;a=l?J[j+124>>2]:a;l=c-1|0;a=(a|0)<(l|0)?a:l;H[fb(b,q,a)+a|0]=0;J[5996]=0;l=j+172|0;aa(117,l|0,k|0);a=J[5996];J[5996]=0;if((a|0)==1){break I}J[j+44>>2]=J[j+200>>2];a=J[j+196>>2];J[j+36>>2]=J[j+192>>2];J[j+40>>2]=a;a=J[j+188>>2];J[j+28>>2]=J[j+184>>2];J[j+32>>2]=a;a=J[j+180>>2];J[j+20>>2]=J[j+176>>2];J[j+24>>2]=a;a=J[j+172>>2];J[j+16>>2]=a;J[5996]=0;o=a>>>0<29;p=o?j+20|0:J[j+24>>2];J[j+172>>2]=p;r=j+48|0;ga(102,r|0,l|0,p+(o?a:a-29|0)|0,0);a=J[5996];J[5996]=0;if((a|0)==1){break H}a=J[j+48>>2];l=K[j+59|0];o=l<<24>>24;p=(o|0)<0;q=p?a:r;l=p?J[j+52>>2]:l;p=e-1|0;l=(l|0)<(p|0)?l:p;H[fb(d,q,l)+l|0]=0;if((o|0)<0){$a(a);}if(M[j+16>>2]>=29){$a(J[j+24>>2]);k=J[j+152>>2];}a=J[k+80>>2];if(!a|M[k+84>>2]>3600|(J[k+52>>2]+J[k+44>>2]>>>0>201|M[k+68>>2]>100)){break G}J[5996]=0;l=_(54,2049,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break p}if((a^-1)&l){break G}a=J[k+80>>2];J[5996]=0;l=_(54,2165,1)|0;o=J[5996];J[5996]=0;if((o|0)==1){break p}if(K[k+88|0]|(a^-1)&l){break G}H[j+176|0]=0;J[j+172>>2]=1702195828;H[j+183|0]=4;a=((i|0)>=5?5:i)-1|0;H[fb(h,j+172|0,a)+a|0]=0;break F}k=fa(22864)|0;a=Va;break m}k=fa(22864)|0;a=Va;break J}k=fa(22864)|0;a=Va;break K}k=fa(22864)|0;a=Va;break L}k=fa(22864)|0;a=Va;break M}k=fa(22864)|0;a=Va;if(H[j+115|0]>=0){break M}$a(J[j+104>>2]);}if(H[j+183|0]>=0){break L}$a(J[j+172>>2]);}if(H[j+99|0]>=0){break K}$a(J[j+88>>2]);}if(H[j+83|0]>=0){break J}$a(J[j+72>>2]);}if(H[j+71|0]>=0){break m}$a(J[j+60>>2]);break m}k=fa(22864)|0;break o}k=fa(22864)|0;a=Va;if(M[j+16>>2]<29){break n}$a(J[j+24>>2]);break n}H[j+176|0]=K[2354];H[j+183|0]=5;H[j+177|0]=0;J[j+172>>2]=K[2350]|K[2351]<<8|(K[2352]<<16|K[2353]<<24);a=((i|0)>=6?6:i)-1|0;H[fb(h,j+172|0,a)+a|0]=0;}J[5996]=0;a=$(118,k|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break p}S:{if(a){H[j+176|0]=0;J[j+172>>2]=1702195828;H[j+183|0]=4;a=((g|0)>=5?5:g)-1|0;H[fb(f,j+172|0,a)+a|0]=0;break S}H[j+176|0]=K[2354];H[j+183|0]=5;H[j+177|0]=0;J[j+172>>2]=K[2350]|K[2351]<<8|(K[2352]<<16|K[2353]<<24);a=((g|0)>=6?6:g)-1|0;H[fb(f,j+172|0,a)+a|0]=0;}if((m|0)<0){$a(n);}a=J[j+156>>2];}T:{if(!a){break T}b=J[a+4>>2];J[a+4>>2]=b-1;if(b){break T}Xa[J[J[a>>2]+8>>2]](a);bb(a);}if(H[j+171|0]>=0){break j}$a(J[j+160>>2]);break j}k=fa(22864)|0;}a=Va;}if((m|0)>=0){break m}$a(n);}mb(j+152|0);}if(H[j+171|0]>=0){break k}$a(J[j+160>>2]);}if((wa(22864)|0)!=(a|0)){break c}a=pa(k|0)|0;a=Xa[J[J[a>>2]+8>>2]](a)|0;J[5996]=0;g=_(30,j+120|0,a|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break i}J[5996]=0;a=ba(99,g|0,0,5474)|0;f=J[5996];J[5996]=0;if((f|0)==1){break h}J[j+168>>2]=J[a+8>>2];f=J[a+4>>2];J[j+160>>2]=J[a>>2];J[j+164>>2]=f;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;J[5996]=0;f=_(97,j+160|0,2611)|0;h=J[5996];J[5996]=0;if((h|0)==1){break g}J[j+24>>2]=J[f+8>>2];g=J[f+4>>2];J[j+16>>2]=J[f>>2];J[j+20>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;k=b;b=J[j+16>>2];g=K[j+27|0];h=g<<24>>24;i=(h|0)<0;g=i?J[j+20>>2]:g;c=c-1|0;c=(c|0)>(g|0)?g:c;H[fb(k,i?b:j+16|0,c)+c|0]=0;U:{if((h|0)>=0){break U}$a(b);if(H[f+11|0]>=0){break U}$a(J[f>>2]);}if(H[a+11|0]<0){$a(J[a>>2]);}J[5996]=0;a=_(30,j+16|0,5575)|0;b=J[5996];J[5996]=0;if((b|0)==1){break e}g=d;b=J[a>>2];c=K[a+11|0];d=c<<24>>24;f=(d|0)<0;h=f?b:a;a=f?J[a+4>>2]:c;c=e-1|0;a=(a|0)<(c|0)?a:c;H[fb(g,h,a)+a|0]=0;if((d|0)<0){$a(b);}ra();}Ua=j+208|0;return}k=Z()|0;break d}k=Z()|0;break f}k=Z()|0;if(H[j+171|0]>=0){break f}$a(J[j+160>>2]);}if(H[g+11|0]>=0){break d}$a(J[g>>2]);break d}k=Z()|0;}J[5996]=0;ca(110);a=J[5996];J[5996]=0;if((a|0)==1){break b}}da(k|0);B();}fa(0)|0;Vb();B();}B();}function Xg(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0;h=Ua-160|0;Ua=h;Yc(h+48|0,c,O[a+16>>3],O[a+24>>3],0,0);J[5996]=0;g=$(46,c|0)|0;f=J[5996];J[5996]=0;a:{b:{c:{if((f|0)!=1){J[h+44>>2]=0;J[h+36>>2]=0;J[h+40>>2]=0;H[h+140|0]=0;J[h+136>>2]=h+36;f=J[g+4>>2];j=J[g>>2];m=f-j|0;i=(m|0)/12|0;if((f|0)!=(j|0)){d:{e:{f:{if(i>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)==1){break f}break a}J[5996]=0;f=$(3,m|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break f}J[h+40>>2]=f;J[h+36>>2]=f;J[h+44>>2]=f+P(i,12);i=J[g+4>>2];g=J[g>>2];J[5996]=0;g=ia(48,h+44|0,g|0,i|0,f|0)|0;i=J[5996];J[5996]=0;if((i|0)!=1){break d}g=Z()|0;J[h+40>>2]=f;break e}g=Z()|0;}Nc(h+136|0);break c}J[h+40>>2]=g;}J[h+32>>2]=0;J[h+24>>2]=0;J[h+28>>2]=0;f=J[d+4>>2];g=J[d>>2];J[5996]=0;aa(49,h+24|0,f-g>>2);f=J[5996];J[5996]=0;g:{if((f|0)!=1){g=J[h+40>>2];f=J[h+36>>2];if((g|0)==(f|0)){break b}s=h+112|0;g=f;h:{while(1){i:{J[h+20>>2]=0;J[h+12>>2]=0;J[h+16>>2]=0;i=J[d+4>>2];f=J[d>>2];n=P(r,12);g=n+g|0;if(i-f>>2!=J[g+4>>2]-J[g>>2]>>3){break i}j=0;o=1;l=0;j:{if((f|0)!=(i|0)){k:{l:{m:{while(1){g=l<<3;t=O[g+J[h+60>>2]>>3];u=O[g+J[h+48>>2]>>3];f=J[(l<<2)+f>>2];J[5996]=0;f=qa(50,f|0,+u,+t,b|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break l}g=g+J[n+J[h+36>>2]>>2]|0;i=J[g>>2];g=J[g+4>>2];m=J[f+4>>2];f=J[f>>2];J[5996]=0;oa(51,h+136|0,f|0,m|0,i|0,g|0);f=J[5996];J[5996]=0;if((f|0)!=1){i=J[h+20>>2];n:{if(i>>>0>j>>>0){J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;J[j>>2]=J[h+136>>2];J[j+4>>2]=J[h+140>>2];J[j+8>>2]=J[h+144>>2];J[h+16>>2]=j+12;break n}o:{f=J[h+12>>2];m=(j-f|0)/12|0;g=m+1|0;p:{if(g>>>0>=357913942){J[5996]=0;ca(52);break p}i=(i-f|0)/12|0;k=i<<1;g=i>>>0>=178956970?357913941:g>>>0>>0?k:g;if(g>>>0<357913942){break o}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}break m}J[5996]=0;k=P(g,12);i=$(3,k|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break m}g=i+P(m,12)|0;J[g>>2]=J[h+136>>2];J[g+4>>2]=J[h+140>>2];J[g+8>>2]=J[h+144>>2];J[h+144>>2]=0;J[h+136>>2]=0;J[h+140>>2]=0;i=i+k|0;m=g+12|0;q:{if((f|0)==(j|0)){J[h+20>>2]=i;J[h+16>>2]=m;J[h+12>>2]=g;break q}while(1){g=g-12|0;j=j-12|0;J[g>>2]=J[j>>2];J[g+4>>2]=J[j+4>>2];J[g+8>>2]=J[j+8>>2];J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;if((f|0)!=(j|0)){continue}break}J[h+20>>2]=i;f=J[h+16>>2];J[h+16>>2]=m;j=J[h+12>>2];J[h+12>>2]=g;if((f|0)==(j|0)){break q}while(1){k=f-12|0;m=J[k>>2];if(m){p=f-8|0;g=J[p>>2];i=m;if((g|0)!=(i|0)){while(1){g=g-32|0;f=J[g+4>>2];r:{if(!f){break r}i=J[f+4>>2];J[f+4>>2]=i-1;if(i){break r}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((g|0)!=(m|0)){continue}break}i=J[k>>2];}J[p>>2]=m;$a(i);}f=k;if((j|0)!=(f|0)){continue}break}}if(j){$a(j);}i=J[h+136>>2];if(!i){break n}f=i;g=J[h+140>>2];if((f|0)!=(g|0)){while(1){g=g-32|0;f=J[g+4>>2];s:{if(!f){break s}j=J[f+4>>2];J[f+4>>2]=j-1;if(j){break s}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((g|0)!=(i|0)){continue}break}f=J[h+136>>2];}J[h+140>>2]=i;$a(f);}j=J[h+16>>2];f=j-12|0;o=P(J[f+4>>2]-J[f>>2]>>5,o);l=l+1|0;f=J[d>>2];if(l>>>0>=J[d+4>>2]-f>>2>>>0){break k}continue}break}g=Z()|0;break h}g=Z()|0;_b(h+136|0);break h}g=Z()|0;break h}if(!o){break j}}m=0;t:{u:{v:{w:{x:{y:{while(1){j=J[h+24>>2];if(J[d+4>>2]!=J[d>>2]){g=0;i=J[h+12>>2];f=m;while(1){k=P(g,12);l=k+i|0;i=J[l>>2];J[(g<<2)+j>>2]=i+((f>>>0)%(J[l+4>>2]-i>>5>>>0)<<5);l=f;i=J[h+12>>2];f=k+i|0;f=(l>>>0)/(J[f+4>>2]-J[f>>2]>>5>>>0)|0;g=g+1|0;if(g>>>0>2]-J[d>>2]>>2>>>0){continue}break}}J[h+100>>2]=0;J[h+92>>2]=0;J[h+96>>2]=0;g=j;n=J[h+28>>2];if((g|0)!=(n|0)){z:{while(1){A:{k=J[j>>2];g=J[h+96>>2];B:{if((g|0)!=J[h+100>>2]){J[g>>2]=J[k>>2];f=J[k+4>>2];J[g+4>>2]=f;if(f){J[f+4>>2]=J[f+4>>2]+1;}J[h+96>>2]=g+8;break B}C:{i=J[h+92>>2];f=g-i|0;p=f>>3;l=p+1|0;D:{if(l>>>0>=536870912){J[5996]=0;ca(59);break D}q=f>>2;f=f>>>0>=2147483640?536870911:l>>>0>>0?q:l;if(f>>>0<536870912){break C}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}g=Z()|0;break t}J[5996]=0;q=f<<3;l=$(3,q|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break A}f=l+(p<<3)|0;J[f>>2]=J[k>>2];k=J[k+4>>2];J[f+4>>2]=k;if(k){J[k+4>>2]=J[k+4>>2]+1;g=J[h+96>>2];}k=l+q|0;l=f+8|0;E:{if((g|0)==(i|0)){J[h+100>>2]=k;J[h+96>>2]=l;J[h+92>>2]=f;break E}while(1){f=f-8|0;g=g-8|0;J[f>>2]=J[g>>2];J[f+4>>2]=J[g+4>>2];J[g>>2]=0;J[g+4>>2]=0;if((g|0)!=(i|0)){continue}break}J[h+100>>2]=k;g=J[h+96>>2];J[h+96>>2]=l;i=J[h+92>>2];J[h+92>>2]=f;if((g|0)==(i|0)){break E}while(1){g=g-8|0;f=J[g+4>>2];F:{if(!f){break F}k=J[f+4>>2];J[f+4>>2]=k-1;if(k){break F}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((g|0)!=(i|0)){continue}break}}if(!i){break B}$a(i);}j=j+4|0;if((n|0)!=(j|0)){continue}break z}break}g=Z()|0;break t}j=J[h+28>>2];g=J[h+24>>2];}J[5996]=0;va(63,h+72|0,c|0,g|0,j|0,0);f=J[5996];J[5996]=0;if((f|0)==1){break x}J[5996]=0;j=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)==1){break x}J[j>>2]=7e3;J[j+4>>2]=0;J[j+8>>2]=0;J[h+112>>2]=0;J[h+104>>2]=0;J[h+108>>2]=0;J[h+116>>2]=J[h+92>>2];f=J[h+100>>2];g=J[h+96>>2];J[h+100>>2]=0;J[h+120>>2]=g;J[h+124>>2]=f;J[h+92>>2]=0;J[h+96>>2]=0;H[h+132|0]=0;J[h+128>>2]=h+104;k=J[e+4>>2];g=J[e>>2];i=k-g|0;f=(i|0)/12|0;G:{if((g|0)!=(k|0)){if(f>>>0>=357913942){J[5996]=0;ca(41);a=J[5996];J[5996]=0;if((a|0)!=1){break a}g=Z()|0;break v}J[5996]=0;i=$(3,i|0)|0;l=J[5996];J[5996]=0;if((l|0)==1){break G}J[h+108>>2]=i;J[h+104>>2]=i;J[h+112>>2]=i+P(f,12);J[h+156>>2]=i;J[h+152>>2]=i;H[h+148|0]=0;J[h+136>>2]=s;J[h+144>>2]=h+156;J[h+140>>2]=h+152;f=i;while(1){H:{if(H[g+11|0]>=0){l=J[g+4>>2];J[f>>2]=J[g>>2];J[f+4>>2]=l;J[f+8>>2]=J[g+8>>2];break H}l=J[g+4>>2];n=J[g>>2];J[5996]=0;ea(40,f|0,n|0,l|0);f=J[5996];J[5996]=0;if((f|0)==1){break w}f=J[h+156>>2];}f=f+12|0;J[h+156>>2]=f;g=g+12|0;if((k|0)!=(g|0)){continue}break}J[h+108>>2]=f;}J[5996]=0;k=xa(60,j+12|0,c|0,h+116|0,h+104|0,0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break y}i=J[h+104>>2];if(i){f=J[h+108>>2];g=i;if((f|0)!=(g|0)){while(1){g=f-12|0;if(H[f-1|0]<0){$a(J[g>>2]);}f=g;if((i|0)!=(f|0)){continue}break}g=J[h+104>>2];}J[h+108>>2]=i;$a(g);}f=J[h+116>>2];if(f){g=J[h+120>>2];if((f|0)!=(g|0)){while(1){g=g-8|0;i=J[g+4>>2];I:{if(!i){break I}l=J[i+4>>2];J[i+4>>2]=l-1;if(l){break I}Xa[J[J[i>>2]+8>>2]](i);bb(i);}if((f|0)!=(g|0)){continue}break}f=J[h+116>>2];}$a(f);}J[h+140>>2]=j;J[h+136>>2]=k;J[5996]=0;f=J[h+140>>2];J[h>>2]=J[h+136>>2];J[h+4>>2]=f;ea(61,a|0,h+72|0,h|0);f=J[5996];J[5996]=0;if((f|0)==1){break x}f=J[h+92>>2];if(f){g=J[h+96>>2];if((f|0)!=(g|0)){while(1){g=g-8|0;i=J[g+4>>2];J:{if(!i){break J}j=J[i+4>>2];J[i+4>>2]=j-1;if(j){break J}Xa[J[J[i>>2]+8>>2]](i);bb(i);}if((f|0)!=(g|0)){continue}break}f=J[h+92>>2];}$a(f);}m=m+1|0;if((o|0)!=(m|0)){continue}break j}break}g=Z()|0;break v}g=Z()|0;rb(h+104|0);break u}g=Z()|0;break t}g=Z()|0;Wg(h+136|0);J[h+108>>2]=i;}Vg(h+128|0);}lb(h+116|0);$a(j);}lb(h+92|0);break h}i=J[h+12>>2];if(i){g=J[h+16>>2];if((i|0)!=(g|0)){while(1){m=g-12|0;j=J[m>>2];if(j){f=j;k=g-8|0;g=J[k>>2];if((f|0)!=(g|0)){while(1){g=g-32|0;f=J[g+4>>2];K:{if(!f){break K}o=J[f+4>>2];J[f+4>>2]=o-1;if(o){break K}Xa[J[J[f>>2]+8>>2]](f);bb(f);}if((g|0)!=(j|0)){continue}break}f=J[m>>2];}J[k>>2]=j;$a(f);}g=m;if((i|0)!=(g|0)){continue}break}i=J[h+12>>2];}$a(i);}r=r+1|0;g=J[h+36>>2];if(r>>>0<(J[h+40>>2]-g|0)/12>>>0){continue}break b}break}J[5996]=0;ga(44,5170,1900,642,2497);a=J[5996];J[5996]=0;if((a|0)!=1){break a}g=Z()|0;}Xc(h+12|0);break g}g=Z()|0;}a=J[h+24>>2];if(a){$a(a);}Wc(h+36|0);break c}g=Z()|0;}Mc(h+48|0);da(g|0);B();}a=J[h+24>>2];if(a){$a(a);g=J[h+36>>2];}if(g){f=g;i=J[h+40>>2];if((f|0)!=(i|0)){while(1){a=i-12|0;b=J[a>>2];if(b){J[i-8>>2]=b;$a(b);}i=a;if((i|0)!=(g|0)){continue}break}f=J[h+36>>2];}J[h+40>>2]=g;$a(f);}a=J[h+60>>2];if(a){J[h- -64>>2]=a;$a(a);}a=J[h+48>>2];if(a){J[h+52>>2]=a;$a(a);}Ua=h+160|0;return}B();}function Ng(a,b,c,d,e,f,g,h,i){var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,K=0,L=0,N=0,O=0,P=0,Q=0;k=Ua-336|0;Ua=k;m=h;n=i&65535;o=d;p=e&65535;t=(e^i)&-2147483648;r=i>>>16&32767;s=e>>>16&32767;a:{b:{if(r-32767>>>0>4294934529&s-32767>>>0>=4294934530){break b}j=e&2147483647;if(!(!d&(j|0)==2147418112?!(b|c):j>>>0<2147418112)){q=d;t=e|32768;break a}e=i&2147483647;if(!(!h&(e|0)==2147418112?!(f|g):e>>>0<2147418112)){q=h;t=i|32768;b=f;c=g;break a}if(!(b|d|(j^2147418112|c))){if(!(f|h|(e^2147418112|g))){b=0;c=0;t=2147450880;break a}t=t|2147418112;b=0;c=0;break a}if(!(f|h|(e^2147418112|g))){b=0;c=0;break a}if(!(b|d|(c|j))){b=!(f|h|(e|g));q=b?0:q;t=b?2147450880:t;b=0;c=0;break a}if(!(f|h|(e|g))){t=t|2147418112;b=0;c=0;break a}if((j|0)==65535|j>>>0<65535){d=!(o|p);i=d;j=d?b:o;d=d<<6;i=S(i?c:p);d=d+((i|0)==32?S(j)+32|0:i)|0;Cb(k+320|0,b,c,o,p,d-15|0);u=16-d|0;o=J[k+328>>2];p=J[k+332>>2];c=J[k+324>>2];b=J[k+320>>2];}if(e>>>0>65535){break b}d=!(n|m);h=d;i=d?f:m;d=d<<6;h=S(h?g:n);d=d+((h|0)==32?S(i)+32|0:h)|0;Cb(k+304|0,f,g,m,n,d-15|0);u=(d+u|0)-16|0;m=J[k+312>>2];n=J[k+316>>2];f=J[k+304>>2];g=J[k+308>>2];}e=n|65536;z=e;A=m;d=m;j=e<<15|d>>>17;e=d<<15|g>>>17;d=e;i=0-d|0;h=j;j=1963258675-(j+((d|0)!=0)|0)|0;xb(k+288|0,d,h,0,0,i,j,0,0);d=J[k+296>>2];xb(k+272|0,0-d|0,0-(J[k+300>>2]+((d|0)!=0)|0)|0,0,0,i,j,0,0);d=J[k+280>>2];i=d<<1|J[k+276>>2]>>>31;d=J[k+284>>2]<<1|d>>>31;xb(k+256|0,i,d,0,0,e,h,0,0);j=J[k+264>>2];xb(k+240|0,i,d,0,0,0-j|0,0-(J[k+268>>2]+((j|0)!=0)|0)|0,0,0);i=J[k+248>>2];j=i<<1|J[k+244>>2]>>>31;d=J[k+252>>2]<<1|i>>>31;xb(k+224|0,j,d,0,0,e,h,0,0);i=J[k+232>>2];xb(k+208|0,j,d,0,0,0-i|0,0-(J[k+236>>2]+((i|0)!=0)|0)|0,0,0);d=J[k+216>>2];i=d<<1|J[k+212>>2]>>>31;d=J[k+220>>2]<<1|d>>>31;xb(k+192|0,i,d,0,0,e,h,0,0);j=J[k+200>>2];xb(k+176|0,i,d,0,0,0-j|0,0-(J[k+204>>2]+((j|0)!=0)|0)|0,0,0);i=e;e=J[k+184>>2];d=h;m=e<<1|J[k+180>>2]>>>31;h=m-1|0;e=(J[k+188>>2]<<1|e>>>31)-!m|0;xb(k+160|0,i,d,0,0,h,e,0,0);d=h;xb(k+144|0,f<<15,g<<15|f>>>17,0,0,d,e,0,0);w=k+112|0;x=J[k+168>>2];h=J[k+172>>2];m=J[k+160>>2];i=J[k+152>>2];l=m+i|0;n=J[k+164>>2];j=n+J[k+156>>2]|0;j=i>>>0>l>>>0?j+1|0:j;i=j;j=(n|0)==(j|0)&l>>>0>>0|j>>>0>>0;n=j+x|0;j=j>>>0>n>>>0?h+1|0:h;m=!i&l>>>0>1|(i|0)!=0;h=n+m|0;j=m>>>0>h>>>0?j+1|0:j;xb(w,d,e,0,0,0-h|0,0-(((h|0)!=0)+j|0)|0,0,0);xb(k+128|0,1-l|0,0-((l>>>0>1)+i|0)|0,0,0,d,e,0,0);I=(s-r|0)+u|0;e=J[k+116>>2];w=e;d=J[k+112>>2];j=e<<1|d>>>31;i=d<<1;n=j;d=j;h=J[k+140>>2];y=h;e=J[k+136>>2];j=h<<1|e>>>31;l=e<<1|J[k+132>>2]>>>31;h=l+i|0;d=d+j|0;d=h>>>0>>0?d+1|0:d;e=d;d=d-(h>>>0<13927)|0;v=d;x=d;l=0;j=p|65536;K=j;L=o;d=o;j=j<<1|d>>>31;O=d<<1;P=j;E=j;d=co(v,l,j,0);j=Wa;B=d;C=j;u=b<<1;d=c<<1|b>>>31;r=d;j=0;s=j;m=h-13927|0;v=(e|0)==(v|0)&m>>>0>>0|e>>>0>v>>>0;e=(e|0)==(n|0)&h>>>0>>0|e>>>0>>0;d=J[k+120>>2];h=J[k+124>>2]<<1|d>>>31;d=d<<1|w>>>31;l=y>>>31|0;d=l+d|0;j=h;j=d>>>0>>0?j+1|0:j;h=d;d=d+e|0;j=h>>>0>d>>>0?j+1|0:j;e=d;d=d+v|0;l=e>>>0>d>>>0?j+1|0:j;e=d-1|0;D=l-!d|0;y=0;i=co(r,s,D,y);d=i+B|0;h=Wa+C|0;h=d>>>0>>0?h+1|0:h;n=(C|0)==(h|0)&d>>>0>>0|h>>>0>>0;B=e;N=c>>>31|0;G=N|o<<1;v=0;e=co(e,0,G,v);o=e+d|0;j=Wa+h|0;l=0;j=e>>>0>o>>>0?j+1|0:j;p=j;d=(j|0)==(h|0)&d>>>0>o>>>0|h>>>0>j>>>0;e=d;d=d+n|0;l=e>>>0>d>>>0?1:l;e=co(E,s,D,y);d=e+d|0;j=Wa+l|0;n=d;d=d>>>0>>0?j+1|0:j;e=co(E,s,B,v);l=Wa;h=e;e=co(G,v,D,y);i=h+e|0;j=Wa+l|0;j=e>>>0>i>>>0?j+1|0:j;e=j;j=(l|0)==(j|0)&h>>>0>i>>>0|j>>>0>>0;l=n+e|0;d=d+j|0;d=l>>>0>>0?d+1|0:d;n=l;l=d;e=0;d=e+o|0;j=i+p|0;j=d>>>0>>0?j+1|0:j;e=j;h=(j|0)==(p|0)&d>>>0>>0|j>>>0

>>0;j=l;i=h;h=h+n|0;j=i>>>0>h>>>0?j+1|0:j;F=h;l=j;w=d;o=d;C=m;d=co(m,0,G,v);i=Wa;h=d;m=co(x,q,r,q);d=d+m|0;j=Wa+i|0;j=d>>>0>>0?j+1|0:j;m=(i|0)==(j|0)&d>>>0>>0|i>>>0>j>>>0;h=j;H=u&-2;i=co(B,v,H,0);p=i+d|0;j=Wa+j|0;j=i>>>0>p>>>0?j+1|0:j;i=j;d=(j|0)==(h|0)&d>>>0>p>>>0|h>>>0>j>>>0;h=0;j=d+m|0;d=(j>>>0>>0?1:h)+e|0;n=j+o|0;d=n>>>0>>0?d+1|0:d;j=l;o=d;d=(d|0)==(e|0)&n>>>0>>0|d>>>0>>0;e=d;d=d+F|0;j=e>>>0>d>>>0?j+1|0:j;Q=d;w=j;d=co(E,s,C,q);F=Wa;E=d;e=co(D,y,H,q);d=d+e|0;j=Wa+F|0;j=d>>>0>>0?j+1|0:j;m=d;l=co(x,q,G,v);e=d+l|0;h=j;d=j+Wa|0;d=e>>>0>>0?d+1|0:d;s=e;j=co(r,q,B,v);e=e+j|0;l=Wa+d|0;l=e>>>0>>0?l+1|0:l;D=(d|0)==(l|0)&e>>>0>>0|d>>>0>l>>>0;j=(h|0)==(F|0)&m>>>0>>0|h>>>0>>0;d=(d|0)==(h|0)&m>>>0>s>>>0|d>>>0>>0;d=d+j|0;d=d+D|0;h=l;s=h+n|0;j=(d|y)+o|0;j=h>>>0>s>>>0?j+1|0:j;m=j;d=(o|0)==(j|0)&n>>>0>s>>>0|j>>>0>>0;j=w;h=d;d=d+Q|0;j=h>>>0>d>>>0?j+1|0:j;y=d;o=j;d=co(x,q,H,q);x=Wa;n=d;h=co(r,q,C,q);d=d+h|0;j=Wa+x|0;j=d>>>0>>0?j+1|0:j;w=0;h=(j|0)==(x|0)&d>>>0>>0|j>>>0>>0;n=j;d=j+p|0;j=(h|w)+i|0;j=d>>>0>>0?j+1|0:j;i=(i|0)==(j|0)&d>>>0

>>0|i>>>0>j>>>0;h=j;j=e;p=0;e=p+d|0;l=h+j|0;j=0;l=e>>>0

>>0?l+1|0:l;d=(h|0)==(l|0)&d>>>0>e>>>0|h>>>0>l>>>0;e=d;d=d+i|0;j=(e>>>0>d>>>0?1:j)+m|0;l=o;e=d;d=d+s|0;j=e>>>0>d>>>0?j+1|0:j;e=j;h=(m|0)==(j|0)&d>>>0>>0|j>>>0>>0;i=h;h=h+y|0;l=i>>>0>h>>>0?l+1|0:l;i=l;c:{if((l|0)==131071|l>>>0<131071){L=O|N;K=v|P;xb(k+80|0,d,j,h,l,f,g,A,z);l=J[k+84>>2];n=l;j=b<<17;m=0;p=J[k+88>>2];c=m-p|0;b=J[k+80>>2];l=(l|b)!=0;o=c-l|0;p=(j-(J[k+92>>2]+(m>>>0

>>0)|0)|0)-(c>>>0>>0)|0;m=0-b|0;n=0-(((b|0)!=0)+n|0)|0;b=I+16382|0;break c}d=(e&1)<<31|d>>>1;e=h<<31|e>>>1;h=(i&1)<<31|h>>>1;i=i>>>1|0;xb(k+96|0,d,e,h,i,f,g,A,z);o=J[k+100>>2];r=o;n=0;u=J[k+104>>2];m=n-u|0;l=J[k+96>>2];p=(o|l)!=0;o=m-p|0;p=((b<<16)-(J[k+108>>2]+(n>>>0>>0)|0)|0)-(m>>>0

>>0)|0;m=0-l|0;n=0-(((l|0)!=0)+r|0)|0;u=b;r=c;b=I+16383|0;}if((b|0)>=32767){t=t|2147418112;b=0;c=0;break a}d:{if((b|0)>0){l=p<<1|o>>>31;o=o<<1|n>>>31;p=l;u=h;r=i&65535|b<<16;l=n<<1|m>>>31;i=m<<1;break d}if((b|0)<=-113){b=0;c=0;break a}xc(k- -64|0,d,e,h,i,1-b|0);Cb(k+48|0,u,r,L,K,b+112|0);d=J[k+64>>2];e=J[k+68>>2];u=J[k+72>>2];r=J[k+76>>2];xb(k+32|0,f,g,A,z,d,e,u,r);b=J[k+40>>2];c=J[k+56>>2];l=J[k+36>>2];o=b<<1|l>>>31;m=c-o|0;p=J[k+60>>2]-((J[k+44>>2]<<1|b>>>31)+(c>>>0>>0)|0)|0;b=J[k+32>>2];h=l<<1|b>>>31;j=b<<1;i=J[k+52>>2];c=J[k+48>>2];b=(h|0)==(i|0)&j>>>0>c>>>0|h>>>0>i>>>0;o=m-b|0;p=p-(b>>>0>m>>>0)|0;l=i-((c>>>0>>0)+h|0)|0;i=c-j|0;}b=i;xb(k+16|0,f,g,A,z,3,0,0,0);xb(k,f,g,A,z,5,0,0,0);c=0;h=l+c|0;j=d&1;b=b+j|0;h=i>>>0>b>>>0?h+1|0:h;i=b;g=(h|0)==(g|0)&f>>>0>>0|g>>>0>>0;l=p;b=(c|0)==(h|0)&i>>>0>>0|c>>>0>h>>>0;f=b+o|0;l=b>>>0>f>>>0?l+1|0:l;j=e;b=(l|0)==(z|0);b=b&(f|0)==(A|0)?g:b&f>>>0>A>>>0|l>>>0>z>>>0;c=b;b=b+d|0;j=c>>>0>b>>>0?j+1|0:j;c=j;d=(e|0)==(j|0)&b>>>0>>0|e>>>0>j>>>0;j=r;e=d;d=d+u|0;j=e>>>0>d>>>0?j+1|0:j;g=d;e=J[k+20>>2];n=(e|0)==(h|0)&M[k+16>>2]>>0|e>>>0>>0;e=J[k+28>>2];d=J[k+24>>2];e=j>>>0<2147418112&((d|0)==(f|0)&(e|0)==(l|0)?n:(e|0)==(l|0)&d>>>0>>0|e>>>0>>0);d=c;n=e;e=b+e|0;d=n>>>0>e>>>0?d+1|0:d;b=(c|0)==(d|0)&b>>>0>e>>>0|c>>>0>d>>>0;c=b;b=b+g|0;j=c>>>0>b>>>0?j+1|0:j;g=b;c=J[k+4>>2];h=(c|0)==(h|0)&M[k>>2]>>0|c>>>0>>0;c=J[k+12>>2];b=J[k+8>>2];b=j>>>0<2147418112&((b|0)==(f|0)&(c|0)==(l|0)?h:(c|0)==(l|0)&b>>>0>>0|c>>>0>>0);c=b;b=b+e|0;l=c>>>0>b>>>0?d+1|0:d;c=l;e=(d|0)==(l|0)&b>>>0>>0|d>>>0>l>>>0;d=j;f=e;e=e+g|0;d=f>>>0>e>>>0?d+1|0:d;q=e|q;t=d|t;}J[a>>2]=b;J[a+4>>2]=c;J[a+8>>2]=q;J[a+12>>2]=t;Ua=k+336|0;}function hc(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=+e;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;h=Ua-128|0;Ua=h;Yc(h+56|0,c,O[a+16>>3],O[a+24>>3],e,f);J[5996]=0;f=$(46,c|0)|0;g=J[5996];J[5996]=0;a:{b:{c:{if((g|0)!=1){J[h+52>>2]=0;J[h+44>>2]=0;J[h+48>>2]=0;H[h+84|0]=0;J[h+80>>2]=h+44;g=J[f+4>>2];j=J[f>>2];l=g-j|0;i=(l|0)/12|0;if((g|0)!=(j|0)){d:{e:{f:{if(i>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)==1){break f}break a}J[5996]=0;g=$(3,l|0)|0;j=J[5996];J[5996]=0;if((j|0)==1){break f}J[h+48>>2]=g;J[h+44>>2]=g;J[h+52>>2]=g+P(i,12);i=J[f+4>>2];f=J[f>>2];J[5996]=0;f=ia(48,h+52|0,f|0,i|0,g|0)|0;i=J[5996];J[5996]=0;if((i|0)!=1){break d}f=Z()|0;J[h+48>>2]=g;break e}f=Z()|0;}Nc(h+80|0);break c}J[h+48>>2]=f;}J[h+40>>2]=0;J[h+32>>2]=0;J[h+36>>2]=0;f=J[d+4>>2];g=J[d>>2];J[5996]=0;aa(49,h+32|0,f-g>>2);f=J[5996];J[5996]=0;g:{if((f|0)!=1){f=J[h+48>>2];g=J[h+44>>2];if((f|0)==(g|0)){break b}f=g;h:{while(1){i:{J[h+28>>2]=0;J[h+20>>2]=0;J[h+24>>2]=0;i=J[d+4>>2];g=J[d>>2];o=P(r,12);f=o+f|0;if(i-g>>2!=J[f+4>>2]-J[f>>2]>>3){break i}j=0;n=1;m=0;j:{if((g|0)!=(i|0)){k:{l:{m:{while(1){f=m<<3;s=O[f+J[h+68>>2]>>3];t=O[f+J[h+56>>2]>>3];g=J[(m<<2)+g>>2];J[5996]=0;g=qa(50,g|0,+t,+s,b|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break l}f=f+J[o+J[h+44>>2]>>2]|0;i=J[f>>2];f=J[f+4>>2];l=J[g+4>>2];g=J[g>>2];J[5996]=0;oa(51,h+80|0,g|0,l|0,i|0,f|0);f=J[5996];J[5996]=0;if((f|0)!=1){i=J[h+28>>2];n:{if(i>>>0>j>>>0){J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;J[j>>2]=J[h+80>>2];J[j+4>>2]=J[h+84>>2];J[j+8>>2]=J[h+88>>2];J[h+24>>2]=j+12;break n}o:{g=J[h+20>>2];l=(j-g|0)/12|0;f=l+1|0;p:{if(f>>>0>=357913942){J[5996]=0;ca(52);break p}i=(i-g|0)/12|0;k=i<<1;f=i>>>0>=178956970?357913941:f>>>0>>0?k:f;if(f>>>0<357913942){break o}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}break m}J[5996]=0;k=P(f,12);i=$(3,k|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break m}f=i+P(l,12)|0;J[f>>2]=J[h+80>>2];J[f+4>>2]=J[h+84>>2];J[f+8>>2]=J[h+88>>2];J[h+88>>2]=0;J[h+80>>2]=0;J[h+84>>2]=0;i=i+k|0;l=f+12|0;q:{if((g|0)==(j|0)){J[h+28>>2]=i;J[h+24>>2]=l;J[h+20>>2]=f;break q}while(1){f=f-12|0;j=j-12|0;J[f>>2]=J[j>>2];J[f+4>>2]=J[j+4>>2];J[f+8>>2]=J[j+8>>2];J[j+8>>2]=0;J[j>>2]=0;J[j+4>>2]=0;if((g|0)!=(j|0)){continue}break}J[h+28>>2]=i;g=J[h+24>>2];J[h+24>>2]=l;j=J[h+20>>2];J[h+20>>2]=f;if((g|0)==(j|0)){break q}while(1){k=g-12|0;l=J[k>>2];if(l){p=g-8|0;f=J[p>>2];i=l;if((f|0)!=(i|0)){while(1){f=f-32|0;g=J[f+4>>2];r:{if(!g){break r}i=J[g+4>>2];J[g+4>>2]=i-1;if(i){break r}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(l|0)){continue}break}i=J[k>>2];}J[p>>2]=l;$a(i);}g=k;if((j|0)!=(g|0)){continue}break}}if(j){$a(j);}i=J[h+80>>2];if(!i){break n}f=J[h+84>>2];g=i;if((f|0)!=(g|0)){while(1){f=f-32|0;g=J[f+4>>2];s:{if(!g){break s}j=J[g+4>>2];J[g+4>>2]=j-1;if(j){break s}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(i|0)){continue}break}g=J[h+80>>2];}J[h+84>>2]=i;$a(g);}j=J[h+24>>2];f=j-12|0;n=P(J[f+4>>2]-J[f>>2]>>5,n);m=m+1|0;g=J[d>>2];if(m>>>0>=J[d+4>>2]-g>>2>>>0){break k}continue}break}f=Z()|0;break h}f=Z()|0;_b(h+80|0);break h}f=Z()|0;break h}if(!n){break j}}l=0;t:{u:{while(1){j=J[h+32>>2];if(J[d+4>>2]!=J[d>>2]){f=0;i=J[h+20>>2];g=l;while(1){k=P(f,12);m=k+i|0;i=J[m>>2];J[(f<<2)+j>>2]=i+((g>>>0)%(J[m+4>>2]-i>>5>>>0)<<5);m=g;i=J[h+20>>2];g=k+i|0;g=(m>>>0)/(J[g+4>>2]-J[g>>2]>>5>>>0)|0;f=f+1|0;if(f>>>0>2]-J[d>>2]>>2>>>0){continue}break}}J[h+104>>2]=0;J[h+96>>2]=0;J[h+100>>2]=0;f=j;o=J[h+36>>2];if((f|0)!=(o|0)){v:{while(1){w:{k=J[j>>2];f=J[h+100>>2];x:{if((f|0)!=J[h+104>>2]){J[f>>2]=J[k>>2];g=J[k+4>>2];J[f+4>>2]=g;if(g){J[g+4>>2]=J[g+4>>2]+1;}J[h+100>>2]=f+8;break x}y:{i=J[h+96>>2];g=f-i|0;p=g>>3;m=p+1|0;z:{if(m>>>0>=536870912){J[5996]=0;ca(59);break z}q=g>>2;g=g>>>0>=2147483640?536870911:m>>>0>>0?q:m;if(g>>>0<536870912){break y}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break a}f=Z()|0;break t}J[5996]=0;q=g<<3;m=$(3,q|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break w}g=m+(p<<3)|0;J[g>>2]=J[k>>2];k=J[k+4>>2];J[g+4>>2]=k;if(k){J[k+4>>2]=J[k+4>>2]+1;f=J[h+100>>2];}k=m+q|0;m=g+8|0;A:{if((f|0)==(i|0)){J[h+104>>2]=k;J[h+100>>2]=m;J[h+96>>2]=g;break A}while(1){g=g-8|0;f=f-8|0;J[g>>2]=J[f>>2];J[g+4>>2]=J[f+4>>2];J[f>>2]=0;J[f+4>>2]=0;if((f|0)!=(i|0)){continue}break}J[h+104>>2]=k;f=J[h+100>>2];J[h+100>>2]=m;i=J[h+96>>2];J[h+96>>2]=g;if((f|0)==(i|0)){break A}while(1){f=f-8|0;g=J[f+4>>2];B:{if(!g){break B}k=J[g+4>>2];J[g+4>>2]=k-1;if(k){break B}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(i|0)){continue}break}}if(!i){break x}$a(i);}j=j+4|0;if((o|0)!=(j|0)){continue}break v}break}f=Z()|0;break t}j=J[h+36>>2];f=J[h+32>>2];}J[5996]=0;va(63,h+80|0,c|0,f|0,j|0,+e);f=J[5996];J[5996]=0;if((f|0)==1){break u}J[5996]=0;i=$(3,104)|0;f=J[5996];J[5996]=0;if((f|0)==1){break u}J[i>>2]=7e3;J[i+4>>2]=0;J[i+8>>2]=0;J[5996]=0;J[h+116>>2]=J[h+96>>2];f=J[h+104>>2];g=J[h+100>>2];J[h+104>>2]=0;J[h+120>>2]=g;J[h+124>>2]=f;J[h+96>>2]=0;J[h+100>>2]=0;k=ia(64,i+12|0,c|0,h+116|0,0)|0;f=J[5996];J[5996]=0;if((f|0)!=1){g=J[h+116>>2];if(g){f=J[h+120>>2];if((g|0)!=(f|0)){while(1){f=f-8|0;j=J[f+4>>2];C:{if(!j){break C}m=J[j+4>>2];J[j+4>>2]=m-1;if(m){break C}Xa[J[J[j>>2]+8>>2]](j);bb(j);}if((f|0)!=(g|0)){continue}break}g=J[h+116>>2];}$a(g);}J[h+112>>2]=i;J[h+108>>2]=k;J[5996]=0;f=J[h+112>>2];J[h+8>>2]=J[h+108>>2];J[h+12>>2]=f;ea(61,a|0,h+80|0,h+8|0);f=J[5996];J[5996]=0;if((f|0)==1){break u}g=J[h+96>>2];if(g){f=J[h+100>>2];if((g|0)!=(f|0)){while(1){f=f-8|0;i=J[f+4>>2];D:{if(!i){break D}j=J[i+4>>2];J[i+4>>2]=j-1;if(j){break D}Xa[J[J[i>>2]+8>>2]](i);bb(i);}if((f|0)!=(g|0)){continue}break}g=J[h+96>>2];}$a(g);}l=l+1|0;if((n|0)!=(l|0)){continue}break j}break}f=Z()|0;lb(h+116|0);$a(i);break t}f=Z()|0;}lb(h+96|0);break h}i=J[h+20>>2];if(i){f=J[h+24>>2];if((i|0)!=(f|0)){while(1){l=f-12|0;j=J[l>>2];if(j){k=f-8|0;f=J[k>>2];g=j;if((f|0)!=(g|0)){while(1){f=f-32|0;g=J[f+4>>2];E:{if(!g){break E}n=J[g+4>>2];J[g+4>>2]=n-1;if(n){break E}Xa[J[J[g>>2]+8>>2]](g);bb(g);}if((f|0)!=(j|0)){continue}break}g=J[l>>2];}J[k>>2]=j;$a(g);}f=l;if((i|0)!=(f|0)){continue}break}i=J[h+20>>2];}$a(i);}r=r+1|0;f=J[h+44>>2];if(r>>>0<(J[h+48>>2]-f|0)/12>>>0){continue}break b}break}J[5996]=0;ga(44,5170,1900,642,2497);a=J[5996];J[5996]=0;if((a|0)!=1){break a}f=Z()|0;}Xc(h+20|0);break g}f=Z()|0;}a=J[h+32>>2];if(a){$a(a);}Wc(h+44|0);break c}f=Z()|0;}Mc(h+56|0);da(f|0);B();}a=J[h+32>>2];if(a){$a(a);f=J[h+44>>2];}if(f){g=f;i=J[h+48>>2];if((i|0)!=(f|0)){while(1){a=i-12|0;b=J[a>>2];if(b){J[i-8>>2]=b;$a(b);}i=a;if((i|0)!=(f|0)){continue}break}g=J[h+44>>2];}J[h+48>>2]=f;$a(g);}a=J[h+68>>2];if(a){J[h+72>>2]=a;$a(a);}a=J[h+56>>2];if(a){J[h+60>>2]=a;$a(a);}Ua=h+128|0;return}B();}function tk(a,b,c,d,e,f,g,h,i,j,k){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0;var l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;l=Ua-528|0;Ua=l;J[l+520>>2]=k;J[l+524>>2]=b;a:{b:{if(Tb(a,l+524|0)){J[f>>2]=J[f>>2]|4;a=0;break b}J[l+72>>2]=220;t=l+104|0;J[t>>2]=l+112;s=l+72|0;J[t+4>>2]=J[s>>2];o=J[t>>2];J[l+100>>2]=o;J[l+96>>2]=o+400;J[s>>2]=0;J[s+4>>2]=0;J[s+8>>2]=0;p=l+60|0;J[p>>2]=0;J[p+4>>2]=0;J[p+8>>2]=0;m=l+48|0;J[m>>2]=0;J[m+4>>2]=0;J[m+8>>2]=0;n=l+36|0;J[n>>2]=0;J[n+4>>2]=0;J[n+8>>2]=0;q=l+24|0;J[q>>2]=0;J[q+4>>2]=0;J[q+8>>2]=0;b=J[d>>2];J[5996]=0;sa(229,c|0,b|0,l+92|0,l+88|0,l+84|0,s|0,p|0,m|0,n|0,l+20|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[j>>2]=J[i>>2];v=e&512;u=J[l+20>>2];e=0;while(1){c:{d:{e:{f:{g:{if((e|0)==4){break g}J[5996]=0;b=_(202,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(b){break g}h:{i:{j:{k:{l:{switch(H[(l+92|0)+e|0]){case 1:if((e|0)==3){break c}b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[5996]=0;b=ba(230,h|0,1,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(b){J[5996]=0;aa(231,l+12|0,a|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[5996]=0;aa(232,q|0,J[l+12>>2]);b=J[5996];J[5996]=0;if((b|0)!=1){break k}}break a}J[f>>2]=J[f>>2]|4;a=0;break d;case 4:break h;case 2:break i;case 3:break j;case 0:break l;default:break c}}if((e|0)==3){break c}}while(1){J[5996]=0;b=_(202,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(b){break c}b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[5996]=0;b=ba(230,h|0,1,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(!b){break c}J[5996]=0;aa(231,l+12|0,a|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[5996]=0;aa(232,q|0,J[l+12>>2]);b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break a}m:{b=K[m+11|0];if(!((b&128)>>>7|0?J[m+4>>2]:b&127)){break m}b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(J[((K[m+11|0]&128)>>>7|0?J[m>>2]:m)>>2]!=(b|0)){break m}J[5996]=0;$(205,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}H[g|0]=0;b=K[m+11|0];r=((b&128)>>>7|0?J[m+4>>2]:b&127)>>>0>1?m:r;break c}n:{o:{k=J[n+4>>2];b=K[n+11|0];if((b&128)>>>7|0?k:b&127){b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(J[((K[n+11|0]&128)>>>7|0?J[n>>2]:n)>>2]==(b|0)){break o}k=J[n+4>>2];b=K[n+11|0];}c=K[m+11|0];c=(c&128)>>>7|0?J[m+4>>2]:c&127;if(!c|!((b&128)>>>7|0?k:b&127)){break n}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;$(205,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}H[g|0]=1;b=K[n+11|0];r=((b&128)>>>7|0?J[n+4>>2]:b&127)>>>0>1?n:r;break c}b=(b&128)>>>7|0?k:b&127;if(!(b|c)){break c}H[g|0]=!b;break c}if(!(r|e>>>0<2|((e|0)==2&K[l+95|0]!=0|v))){r=0;break c}J[l+12>>2]=Mb(p);p:{if(!e|K[(e+l|0)+91|0]>1){break p}q:{while(1){c=qc(p);b=J[l+12>>2];if((c|0)==(b|0)){break q}b=J[b>>2];J[5996]=0;b=ba(230,h|0,1,b|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(!b){break q}J[l+12>>2]=J[l+12>>2]+4;continue}break}break a}b=Mb(p);b=J[l+12>>2]-b>>2;c=K[q+11|0];if(b>>>0<=((c&128)>>>7|0?J[q+4>>2]:c&127)>>>0){c=Rd(qc(q),0-b|0);d=qc(q);k=Mb(p);b=Ua-16|0;Ua=b;J[b+8>>2]=k;J[b+12>>2]=c;while(1){k=(c|0)!=(d|0);if(!(!k|J[c>>2]!=J[J[b+8>>2]>>2])){J[b+12>>2]=J[b+12>>2]+4;J[b+8>>2]=J[b+8>>2]+4;c=J[b+12>>2];continue}break}Ua=b+16|0;if(!k){break p}}J[l+8>>2]=Mb(p);J[l+12>>2]=J[l+8>>2];}J[l+8>>2]=J[l+12>>2];r:{while(1){if((qc(p)|0)==J[l+8>>2]){break r}J[5996]=0;b=_(202,a|0,l+524|0)|0;c=J[5996];J[5996]=0;s:{if((c|0)==1){break s}if(b){break r}b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break s}if(J[J[l+8>>2]>>2]!=(b|0)){break r}J[5996]=0;$(205,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}J[l+8>>2]=J[l+8>>2]+4;continue}break}break a}if(!v){break c}if((qc(p)|0)==J[l+8>>2]){break c}J[f>>2]=J[f>>2]|4;a=0;break d}b=0;w=J[l+84>>2];c=o;t:{while(1){u:{J[5996]=0;d=_(202,a|0,l+524|0)|0;k=J[5996];J[5996]=0;if((k|0)==1){break u}if(d){break t}d=J[a>>2];J[5996]=0;k=$(203,d|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}J[5996]=0;d=ba(230,h|0,64,k|0)|0;x=J[5996];J[5996]=0;if((x|0)==1){break a}v:{if(d){d=J[j>>2];if((d|0)==J[l+520>>2]){J[5996]=0;ea(233,i|0,j|0,l+520|0);d=J[5996];J[5996]=0;if((d|0)==1){break a}d=J[j>>2];}J[j>>2]=d+4;J[d>>2]=k;b=b+1|0;break v}d=K[s+11|0];if(!((d&128)>>>7|0?J[s+4>>2]:d&127)|!b|(k|0)!=(w|0)){break t}if(J[l+96>>2]==(o|0)){J[5996]=0;ea(226,t|0,l+100|0,l+96|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}o=J[l+100>>2];}c=o+4|0;J[l+100>>2]=c;J[o>>2]=b;o=c;b=0;}J[5996]=0;$(205,a|0)|0;d=J[5996];J[5996]=0;if((d|0)!=1){continue}}break}break a}if(!b|J[t>>2]==(c|0)){break f}if(J[l+96>>2]==(c|0)){J[5996]=0;ea(226,t|0,l+100|0,l+96|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[l+100>>2];}o=c+4|0;J[l+100>>2]=o;J[c>>2]=b;break e}J[l+20>>2]=u;w:{if(!r){break w}k=1;while(1){b=K[r+11|0];if(((b&128)>>>7|0?J[r+4>>2]:b&127)>>>0<=k>>>0){break w}J[5996]=0;b=_(202,a|0,l+524|0)|0;c=J[5996];J[5996]=0;x:{if((c|0)==1){break x}y:{if(!b){b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break x}if(J[(k<<2)+((K[r+11|0]&128)>>>7|0?J[r>>2]:r)>>2]==(b|0)){break y}}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;$(205,a|0)|0;b=J[5996];J[5996]=0;k=k+1|0;if((b|0)!=1){continue}}break}break a}a=1;b=J[t>>2];if((b|0)==(o|0)){break d}a=0;J[l+12>>2]=0;zb(s,b,o,l+12|0);if(J[l+12>>2]){J[f>>2]=J[f>>2]|4;break d}a=1;break d}o=c;}z:{if((u|0)<=0){break z}J[5996]=0;b=_(202,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}A:{if(!b){b=J[a>>2];J[5996]=0;b=$(203,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(J[l+88>>2]==(b|0)){break A}}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;b=$(205,a|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}while(1){if((u|0)<=0){u=0;break z}J[5996]=0;c=_(202,b|0,l+524|0)|0;d=J[5996];J[5996]=0;B:{if((d|0)==1){break B}C:{if(!c){c=J[b>>2];J[5996]=0;c=$(203,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break B}J[5996]=0;c=ba(230,h|0,64,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break B}if(c){break C}}J[f>>2]=J[f>>2]|4;a=0;break d}if(J[j>>2]==J[l+520>>2]){J[5996]=0;ea(233,i|0,j|0,l+520|0);c=J[5996];J[5996]=0;if((c|0)==1){break B}}c=J[b>>2];J[5996]=0;c=$(203,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break B}d=J[j>>2];J[j>>2]=d+4;J[d>>2]=c;J[5996]=0;$(205,b|0)|0;c=J[5996];J[5996]=0;u=u-1|0;if((c|0)!=1){continue}}break}break a}if(J[j>>2]!=J[i>>2]){break c}J[f>>2]=J[f>>2]|4;a=0;}ab(q);ab(n);ab(m);ab(p);ab(s);db(t);break b}e=e+1|0;continue}}break a}Ua=l+528|0;return a|0}a=Z()|0;ab(q);ab(n);ab(m);ab(p);ab(s);db(t);da(a|0);B();}function Ak(a,b,c,d,e,f,g,h,i,j,k){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0;var l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0;l=Ua-528|0;Ua=l;J[l+520>>2]=k;J[l+524>>2]=b;a:{b:{if(Ub(a,l+524|0)){J[f>>2]=J[f>>2]|4;a=0;break b}J[l+76>>2]=220;t=l+104|0;J[t>>2]=l+112;s=l+76|0;J[t+4>>2]=J[s>>2];o=J[t>>2];J[l+100>>2]=o;J[l+96>>2]=o+400;J[s>>2]=0;J[s+4>>2]=0;J[s+8>>2]=0;p=l- -64|0;J[p>>2]=0;J[p+4>>2]=0;J[p+8>>2]=0;m=l+52|0;J[m>>2]=0;J[m+4>>2]=0;J[m+8>>2]=0;n=l+40|0;J[n>>2]=0;J[n+4>>2]=0;J[n+8>>2]=0;q=l+28|0;J[q>>2]=0;J[q+4>>2]=0;J[q+8>>2]=0;b=J[d>>2];J[5996]=0;sa(223,c|0,b|0,l+92|0,l+91|0,l+90|0,s|0,p|0,m|0,n|0,l+24|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[j>>2]=J[i>>2];w=e&512;u=J[l+24>>2];x=K[l+95|0];y=K[l+91|0];z=K[l+90|0];d=o;e=0;while(1){c:{d:{e:{f:{if((e|0)==4){break f}J[5996]=0;b=_(186,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(b){break f}b=0;g:{h:{i:{j:{k:{switch(H[(l+92|0)+e|0]){case 1:if((e|0)==3){break c}b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[h+8>>2];if(J[c+((b&255)<<2)>>2]&1&(b|0)>=0){J[5996]=0;aa(224,l+16|0,a|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[5996]=0;aa(98,q|0,H[l+16|0]);b=J[5996];J[5996]=0;if((b|0)!=1){break j}}break a}J[f>>2]=J[f>>2]|4;a=0;break d;case 4:break g;case 2:break h;case 3:break i;case 0:break k;default:break c}}if((e|0)==3){break c}}while(1){J[5996]=0;b=_(186,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(b){break c}b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[h+8>>2];if(!(J[c+((b&255)<<2)>>2]&1&(b|0)>=0)){break c}J[5996]=0;aa(224,l+16|0,a|0);b=J[5996];J[5996]=0;if((b|0)!=1){J[5996]=0;aa(98,q|0,H[l+16|0]);b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break a}l:{b=K[m+11|0];if(!((b&128)>>>7|0?J[m+4>>2]:b&127)){break l}b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(K[((K[m+11|0]&128)>>>7|0?J[m>>2]:m)|0]!=(b&255)){break l}J[5996]=0;$(189,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}H[g|0]=0;b=K[m+11|0];r=((b&128)>>>7|0?J[m+4>>2]:b&127)>>>0>1?m:r;break c}m:{n:{k=J[n+4>>2];b=K[n+11|0];if((b&128)>>>7|0?k:b&127){b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if(K[((K[n+11|0]&128)>>>7|0?J[n>>2]:n)|0]==(b&255)){break n}k=J[n+4>>2];b=K[n+11|0];}c=K[m+11|0];c=(c&128)>>>7|0?J[m+4>>2]:c&127;if(!c|!((b&128)>>>7|0?k:b&127)){break m}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;$(189,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}H[g|0]=1;b=K[n+11|0];r=((b&128)>>>7|0?J[n+4>>2]:b&127)>>>0>1?n:r;break c}b=(b&128)>>>7|0?k:b&127;if(!(b|c)){break c}H[g|0]=!b;break c}if(!(r|e>>>0<2|((e|0)==2&(x|0)!=0|w))){r=0;break c}J[l+16>>2]=Mb(p);o:{if(!e|K[(e+l|0)+91|0]>1){break o}while(1){p:{c=sc(p);b=J[l+16>>2];if((c|0)==(b|0)){break p}c=J[h+8>>2];b=H[b|0];if((b|0)>=0){b=J[c+((b&255)<<2)>>2]&1;}else {b=0;}if(!b){break p}J[l+16>>2]=J[l+16>>2]+1;continue}break}b=Mb(p);b=J[l+16>>2]-b|0;c=K[q+11|0];if(b>>>0<=((c&128)>>>7|0?J[q+4>>2]:c&127)>>>0){c=Td(sc(q),0-b|0);k=sc(q);v=Mb(p);b=Ua-16|0;Ua=b;J[b+8>>2]=v;J[b+12>>2]=c;while(1){v=(c|0)!=(k|0);if(!(!v|K[c|0]!=K[J[b+8>>2]])){J[b+12>>2]=J[b+12>>2]+1;J[b+8>>2]=J[b+8>>2]+1;c=J[b+12>>2];continue}break}Ua=b+16|0;if(!v){break o}}J[l+12>>2]=Mb(p);J[l+16>>2]=J[l+12>>2];}J[l+12>>2]=J[l+16>>2];q:{while(1){if((sc(p)|0)==J[l+12>>2]){break q}J[5996]=0;b=_(186,a|0,l+524|0)|0;c=J[5996];J[5996]=0;r:{if((c|0)==1){break r}if(b){break q}b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break r}if(K[J[l+12>>2]]!=(b&255)){break q}J[5996]=0;$(189,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}J[l+12>>2]=J[l+12>>2]+1;continue}break}break a}if(!w){break c}if((sc(p)|0)==J[l+12>>2]){break c}J[f>>2]=J[f>>2]|4;a=0;break d}s:{while(1){t:{J[5996]=0;c=_(186,a|0,l+524|0)|0;k=J[5996];J[5996]=0;if((k|0)==1){break t}if(c){break s}c=J[a>>2];J[5996]=0;k=$(187,c|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[h+8>>2];u:{if((k|0)>=0?J[c+((k&255)<<2)>>2]&64:0){c=J[j>>2];if((c|0)==J[l+520>>2]){J[5996]=0;ea(225,i|0,j|0,l+520|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[j>>2];}J[j>>2]=c+1;H[c|0]=k;b=b+1|0;break u}c=K[s+11|0];if(!((c&128)>>>7|0?J[s+4>>2]:c&127)|!b|(k&255)!=(z|0)){break s}if(J[l+96>>2]==(d|0)){J[5996]=0;ea(226,t|0,l+100|0,l+96|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}d=J[l+100>>2];}o=d+4|0;J[l+100>>2]=o;J[d>>2]=b;d=o;b=0;}J[5996]=0;$(189,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){continue}}break}break a}if(!(!b|J[t>>2]==(o|0))){if(J[l+96>>2]==(o|0)){J[5996]=0;ea(226,t|0,l+100|0,l+96|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}o=J[l+100>>2];}c=o+4|0;J[l+100>>2]=c;J[o>>2]=b;o=c;}if((u|0)<=0){break e}J[5996]=0;b=_(186,a|0,l+524|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}v:{if(!b){b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}if((b&255)==(y|0)){break v}}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;b=$(189,a|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}while(1){if((u|0)<=0){u=0;break e}J[5996]=0;c=_(186,b|0,l+524|0)|0;d=J[5996];J[5996]=0;w:{if((d|0)==1){break w}x:{if(!c){c=J[b>>2];J[5996]=0;c=$(187,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break w}d=J[h+8>>2];if((c|0)>=0?J[d+((c&255)<<2)>>2]&64:0){break x}}J[f>>2]=J[f>>2]|4;a=0;break d}if(J[j>>2]==J[l+520>>2]){J[5996]=0;ea(225,i|0,j|0,l+520|0);c=J[5996];J[5996]=0;if((c|0)==1){break w}}c=J[b>>2];J[5996]=0;c=$(187,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break w}d=J[j>>2];J[j>>2]=d+1;H[d|0]=c;J[5996]=0;$(189,b|0)|0;c=J[5996];J[5996]=0;u=u-1|0;if((c|0)!=1){continue}}break}break a}J[l+24>>2]=u;y:{if(!r){break y}k=1;while(1){b=K[r+11|0];if(((b&128)>>>7|0?J[r+4>>2]:b&127)>>>0<=k>>>0){break y}J[5996]=0;b=_(186,a|0,l+524|0)|0;c=J[5996];J[5996]=0;z:{if((c|0)==1){break z}A:{if(!b){b=J[a>>2];J[5996]=0;b=$(187,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break z}if(K[((K[r+11|0]&128)>>>7|0?J[r>>2]:r)+k|0]==(b&255)){break A}}J[f>>2]=J[f>>2]|4;a=0;break d}J[5996]=0;$(189,a|0)|0;b=J[5996];J[5996]=0;k=k+1|0;if((b|0)!=1){continue}}break}break a}a=1;b=J[t>>2];if((b|0)==(o|0)){break d}a=0;J[l+16>>2]=0;zb(s,b,o,l+16|0);if(J[l+16>>2]){J[f>>2]=J[f>>2]|4;break d}a=1;break d}d=o;if(J[j>>2]!=J[i>>2]){break c}J[f>>2]=J[f>>2]|4;a=0;}ab(q);ab(n);ab(m);ab(p);ab(s);db(t);break b}e=e+1|0;continue}}break a}Ua=l+528|0;return a|0}a=Z()|0;ab(q);ab(n);ab(m);ab(p);ab(s);db(t);da(a|0);B();}function An(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;a:{b:{c:{d:{e:{f:{g:{switch(J[b>>2]){case 0:J[a+12>>2]=1;J[a+16>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;J[a>>2]=0;return;case 2:J[a+12>>2]=1;J[a+16>>2]=0;break b;case 3:J[a+12>>2]=1;J[a+16>>2]=0;J[a+4>>2]=1;J[a+8>>2]=0;J[a>>2]=3;return;case 4:case 5:J[a+12>>2]=0;J[a+16>>2]=0;J[a+4>>2]=1;J[a+8>>2]=0;J[a>>2]=1;return;case 6:case 7:case 8:case 9:J[a+12>>2]=0;J[a+16>>2]=0;J[a+4>>2]=1;J[a+8>>2]=0;J[a>>2]=4;return;case 17:b=J[b+32>>2];c=J[b+8>>2];h=J[c+52>>2];b=J[b>>2];f=J[b+52>>2];e=K[b+48|0];g=K[c+48|0];c=J[c+44>>2];b=J[b+44>>2];J[a+12>>2]=0;J[a+16>>2]=0;J[a>>2]=b+c;break a;case 18:b=J[b+32>>2];m=J[b+8>>2];h=J[m+52>>2];j=J[b>>2];f=J[j+52>>2];e=K[j+48|0];g=K[m+48|0];i=J[m+60>>2];d=J[j+60>>2];c=K[j+56|0];b=K[m+56|0];J[a>>2]=(J[j+44>>2]+J[m+44>>2]|0)+1;c=(c|0)!=0&(b|0)!=0;b=c&0;J[a+12>>2]=b|c;J[a+16>>2]=c?d+i|0:0;break a;case 19:b=J[b+32>>2];h=J[b>>2];g=J[h+60>>2];f=K[h+56|0]!=0;c=J[b+8>>2];l=f&K[c+48|0]!=0;e=l?g+J[c+52>>2]|0:0;b=(J[h+44>>2]+J[c+44>>2]|0)+1|0;i=J[c+60>>2];d=K[c+56|0];if(!(!K[h+48|0]|!d)){c=i+J[h+52>>2]|0;e=l?c>>>0>e>>>0?c:e:c;l=1;}J[a>>2]=b;J[a+4>>2]=l;J[a+8>>2]=e;e=f&(d|0)!=0;b=e&0;J[a+12>>2]=b|e;J[a+16>>2]=e?g+i|0:0;return;case 21:b=J[b+32>>2];c=J[b>>2];j=J[c+60>>2];m=J[b+8>>2];e=j+J[m+52>>2]|0;h=K[c+56|0];b=K[m+48|0]!=0&(h|0)!=0;g=(J[c+44>>2]+J[m+44>>2]|0)+3|0;d=b?e:0;h:{if(!K[c+48|0]){break h}if(!b){b=J[c+48>>2];f=b&-256;d=J[c+52>>2];break h}b=1;c=J[c+52>>2];d=c>>>0>e>>>0?c:e;}i=J[m+60>>2];e=K[m+56|0];J[a>>2]=g;c=b&255;b=0;J[a+4>>2]=c|(f|b);J[a+8>>2]=d|p;c=(h|0)!=0&(e|0)!=0;b=c?b:0;J[a+12>>2]=b|c;J[a+16>>2]=c?i+j|0:0;return;case 20:b=J[b+32>>2];i=J[b>>2];c=J[b+8>>2];d=J[i+60>>2]+J[c+52>>2]|0;b=K[c+48|0]!=0&K[i+56|0]!=0;e=(J[i+44>>2]+J[c+44>>2]|0)+2|0;c=b?d:0;i:{if(!K[i+48|0]){break i}if(!b){b=J[i+48>>2];f=b&-256;c=J[i+52>>2];break i}b=1;c=J[i+52>>2];c=c>>>0>d>>>0?c:d;}J[a+12>>2]=0;J[a+16>>2]=0;J[a>>2]=e;J[a+4>>2]=f|b&255;J[a+8>>2]=c|p;return;case 22:b=J[b+32>>2];d=J[b>>2];j=J[b+8>>2];f=J[d+44>>2]+J[j+44>>2]|0;j:{if(!K[d+48|0]){b=J[j+48>>2];h=b&-256;e=J[j+52>>2];break j}if(!K[j+48|0]){b=J[d+48>>2];h=b&-256;e=J[d+52>>2];break j}b=1;e=J[d+52>>2];c=J[j+52>>2];e=c>>>0>>0?e:c;}i=f+3|0;k:{if(!K[d+56|0]){f=J[j+56>>2];g=f&-256;c=J[j+60>>2];break k}if(!K[j+56|0]){f=J[d+56>>2];g=f&-256;c=J[d+60>>2];break k}f=1;d=J[d+60>>2];c=J[j+60>>2];c=c>>>0>>0?d:c;}J[a>>2]=i;J[a+12>>2]=f&255|g&-256;d=0;J[a+16>>2]=d|(c|d);J[a+4>>2]=b&255|h&-256;f=0;J[a+8>>2]=f|(e|f);return;case 23:b=J[b+32>>2];h=J[b+16>>2];f=J[b>>2];g=J[f+60>>2];i=K[f+56|0]!=0;d=i&K[h+48|0]!=0;e=d?J[h+52>>2]+g|0:0;b=J[b+8>>2];c=(J[h+44>>2]+(J[f+44>>2]+J[b+44>>2]|0)|0)+3|0;if(!(!K[b+48|0]|!K[f+48|0])){b=J[f+52>>2]+J[b+52>>2]|0;e=d?b>>>0>e>>>0?b:e:b;d=1;}f=J[h+60>>2];b=K[h+56|0];J[a>>2]=c;J[a+4>>2]=d;J[a+8>>2]=e;e=i&(b|0)!=0;b=e&0;J[a+12>>2]=b|e;J[a+16>>2]=e?f+g|0:0;return;case 25:c=J[b+12>>2];b=J[b+8>>2];J[a>>2]=1;b=(c-b|0)/12|0;c=1;J[a+12>>2]=c;J[a+16>>2]=b;J[a+4>>2]=c;J[a+8>>2]=b;return;case 11:case 12:case 16:d=J[J[b+32>>2]>>2];f=J[d+48>>2];e=J[d+52>>2];c=J[d+44>>2];b=J[d+60>>2];J[a+12>>2]=J[d+56>>2];J[a+16>>2]=b;J[a+4>>2]=f;J[a+8>>2]=e;J[a>>2]=c+1;return;case 10:d=J[J[b+32>>2]>>2];f=J[d+48>>2];e=J[d+52>>2];c=J[d+44>>2];b=J[d+60>>2];J[a+12>>2]=J[d+56>>2];J[a+16>>2]=b;J[a+4>>2]=f;J[a+8>>2]=e;J[a>>2]=c+2;return;case 13:b=J[J[b+32>>2]>>2];e=J[b+48>>2];c=J[b+52>>2];b=J[b+44>>2];J[a+12>>2]=1;J[a+16>>2]=0;J[a+4>>2]=e;J[a+8>>2]=c;J[a>>2]=b+3;return;case 15:b=J[J[b+32>>2]>>2];e=J[b+48>>2];c=J[b+52>>2];b=J[b+44>>2];J[a+12>>2]=1;J[a+16>>2]=0;J[a+4>>2]=e;J[a+8>>2]=c;J[a>>2]=b+4;return;case 14:c=J[J[b+32>>2]>>2];d=J[c+44>>2];f=J[c+80>>2];e=Wb(1239,1);b=J[J[b+32>>2]>>2];c=J[b+48>>2];b=J[b+52>>2];J[a+12>>2]=0;J[a+16>>2]=0;J[a+4>>2]=c;J[a+8>>2]=b;J[a>>2]=d+!(e&(f^-1));return;case 24:c=cb(8);J[c>>2]=1;J[c+4>>2]=0;l=c+8|0;n=J[b+32>>2];p=J[b+36>>2];if((n|0)!=(p|0)){while(1){e=J[n>>2];h=J[e+60>>2];g=K[e+56|0];d=J[c+4>>2];i=c;f=K[c|0];m=J[e+44>>2];J[5996]=0;e=$(3,8)|0;c=J[5996];J[5996]=0;l:{m:{if((c|0)!=1){c=d+h|0;d=(f|0)!=0&(g|0)!=0;f=d&0;J[e>>2]=d|f;J[e+4>>2]=d?c:0;g=e+8|0;c=l-i|0;r=c>>3;if(c>>>0>=9){break m}f=g;break l}f=Z()|0;c=i;break e}j=r>>>0<=2?2:r;l=1;f=g;while(1){q=J[n>>2];c=i+(l<<3)|0;k=J[q+60>>2]+J[c+4>>2]|0;d=c-8|0;o=K[d|0]!=0&K[q+48|0]!=0;h=K[c|0]!=0&K[q+56|0]!=0;c=h?k:0;d=o?J[q+52>>2]+J[d+4>>2]|0:0;c=h?o?c>>>0>d>>>0?c:d:k:d;o=h|o;n:{if(f>>>0>>0){J[f>>2]=o;J[f+4>>2]=c;d=f;break n}h=f-e>>3;k=h+1|0;if(k>>>0>=536870912){J[5996]=0;ca(93);a=J[5996];J[5996]=0;if((a|0)==1){break f}break c}g=g-e|0;d=g>>2;k=g>>>0>=2147483640?536870911:d>>>0>k>>>0?d:k;o:{if(!k){g=0;break o}if(k>>>0>=536870912){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break c}break f}J[5996]=0;g=$(3,k<<3)|0;d=J[5996];J[5996]=0;if((d|0)==1){break f}}d=(h<<3)+g|0;J[d>>2]=o;J[d+4>>2]=c;g=(k<<3)+g|0;c=d;p:{if((e|0)!=(f|0)){while(1){f=f-8|0;h=J[f+4>>2];c=c-8|0;J[c>>2]=J[f>>2];J[c+4>>2]=h;if((e|0)!=(f|0)){continue}break}if(!e){break p}}$a(e);}e=c;}f=d+8|0;l=l+1|0;if((j|0)!=(l|0)){continue}break}}d=(i+(r<<3)|0)-8|0;c=J[n>>2];k=K[d|0]!=0&K[c+48|0]!=0;d=k?J[c+52>>2]+J[d+4>>2]|0:0;q:{if(f>>>0>>0){J[f>>2]=k;J[f+4>>2]=d;l=f+8|0;c=e;break q}r:{s:{h=f-e>>3;j=h+1|0;t:{if(j>>>0>=536870912){J[5996]=0;ca(93);break t}g=g-e|0;c=g>>2;c=g>>>0>=2147483640?536870911:c>>>0>j>>>0?c:j;if(!c){c=0;break r}if(c>>>0<536870912){break s}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break c}break f}J[5996]=0;c=$(3,c<<3)|0;g=J[5996];J[5996]=0;if((g|0)==1){break f}}c=(h<<3)+c|0;J[c>>2]=k;J[c+4>>2]=d;l=c+8|0;if((e|0)!=(f|0)){while(1){f=f-8|0;d=J[f+4>>2];c=c-8|0;J[c>>2]=J[f>>2];J[c+4>>2]=d;if((e|0)!=(f|0)){continue}break}if(!e){break q}}$a(e);}s=(m+s|0)+1|0;$a(i);n=n+8|0;if((p|0)!=(n|0)){continue}break}}b=J[b+4>>2];if(b>>>0<=l-c>>3>>>0){b=(b<<3)+c|0;f=J[b>>2];e=J[b+4>>2];b=J[c+4>>2];J[a+12>>2]=J[c>>2];J[a+16>>2]=b;J[a+4>>2]=f;J[a+8>>2]=e;J[a>>2]=s;$a(c);return}J[5996]=0;ga(44,5118,2210,799,1422);a=J[5996];J[5996]=0;if((a|0)!=1){break c}f=Z()|0;if(!c){break d}break e;default:la(2350,2210,803,1422);B();case 1:break g}}J[a+12>>2]=0;J[a+16>>2]=0;break b}f=Z()|0;if(!e){c=i;break e}$a(e);c=i;}$a(c);}da(f|0);B();}B();}J[a+4>>2]=1;J[a+8>>2]=0;J[a>>2]=0;return}e=(e|0)!=0&(g|0)!=0;b=e&0;J[a+4>>2]=b|e;J[a+8>>2]=e?f+h|0:0;}function Em(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0;e=Ua-80|0;Ua=e;d=cb(32);J[e+68>>2]=d;J[e+72>>2]=19;J[e+76>>2]=-2147483616;f=K[5568]|K[5569]<<8|(K[5570]<<16|K[5571]<<24);H[d+15|0]=f;H[d+16|0]=f>>>8;H[d+17|0]=f>>>16;H[d+18|0]=f>>>24;f=K[5565]|K[5566]<<8|(K[5567]<<16|K[5568]<<24);g=K[5561]|K[5562]<<8|(K[5563]<<16|K[5564]<<24);H[d+8|0]=g;H[d+9|0]=g>>>8;H[d+10|0]=g>>>16;H[d+11|0]=g>>>24;H[d+12|0]=f;H[d+13|0]=f>>>8;H[d+14|0]=f>>>16;H[d+15|0]=f>>>24;f=K[5557]|K[5558]<<8|(K[5559]<<16|K[5560]<<24);g=K[5553]|K[5554]<<8|(K[5555]<<16|K[5556]<<24);H[d|0]=g;H[d+1|0]=g>>>8;H[d+2|0]=g>>>16;H[d+3|0]=g>>>24;H[d+4|0]=f;H[d+5|0]=f>>>8;H[d+6|0]=f>>>16;H[d+7|0]=f>>>24;H[d+19|0]=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{d=J[J[b>>2]+80>>2];q:{if(!d){J[5996]=0;_(97,e+68|0,2603)|0;d=J[5996];J[5996]=0;if((d|0)!=1){break q}break b}J[5996]=0;f=_(54,3557,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break p}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,66);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2796,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break o}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,86);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2777,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break n}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,87);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,3310,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break m}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,75);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,1029,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break l}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,122);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,1959,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break k}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,111);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2029,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break j}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,110);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2522,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break i}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,100);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2315,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break h}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,102);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2451,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break g}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,101);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2049,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break f}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,109);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,1295,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break e}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,117);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,1681,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(!((d^-1)&f)){J[5996]=0;aa(98,e+68|0,115);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+80>>2];J[5996]=0;f=_(54,2165,1)|0;g=J[5996];J[5996]=0;if((g|0)==1){break c}if((d^-1)&f){break q}J[5996]=0;aa(98,e+68|0,107);d=J[5996];J[5996]=0;if((d|0)==1){break b}}d=J[J[b>>2]+84>>2];J[5996]=0;f=e+44|0;aa(115,f|0,d|0);d=J[5996];J[5996]=0;r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{E:{F:{if((d|0)!=1){J[5996]=0;d=ba(99,f|0,0,5487)|0;f=J[5996];J[5996]=0;if((f|0)==1){break F}J[e- -64>>2]=J[d+8>>2];f=J[d+4>>2];J[e+56>>2]=J[d>>2];J[e+60>>2]=f;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;f=K[e+67|0];g=f<<24>>24<0;f=ba(100,e+68|0,(g?J[e+56>>2]:e+56|0)|0,(g?J[e+60>>2]:f)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break E}if(H[e+67|0]<0){$a(J[e+56>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}d=J[b>>2];g=J[d+52>>2];d=J[d+44>>2];J[5996]=0;h=e+32|0;aa(164,h|0,d+g|0);d=J[5996];J[5996]=0;if((d|0)==1){break C}J[5996]=0;d=ba(99,h|0,0,5459)|0;g=J[5996];J[5996]=0;if((g|0)==1){break B}J[e- -64>>2]=J[d+8>>2];g=J[d+4>>2];J[e+56>>2]=J[d>>2];J[e+60>>2]=g;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;h=f;f=K[e+67|0];g=f<<24>>24<0;f=ba(100,h|0,(g?J[e+56>>2]:e+56|0)|0,(g?J[e+60>>2]:f)|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break A}if(H[e+67|0]<0){$a(J[e+56>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}b=J[J[b>>2]+68>>2];J[5996]=0;d=e+20|0;aa(164,d|0,b+1|0);b=J[5996];J[5996]=0;if((b|0)==1){break y}J[5996]=0;b=ba(99,d|0,0,5524)|0;d=J[5996];J[5996]=0;if((d|0)==1){break x}J[e- -64>>2]=J[b+8>>2];d=J[b+4>>2];J[e+56>>2]=J[b>>2];J[e+60>>2]=d;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;h=f;d=K[e+67|0];f=d<<24>>24<0;d=ba(100,h|0,(f?J[e+56>>2]:e+56|0)|0,(f?J[e+60>>2]:d)|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break w}if(H[e+67|0]<0){$a(J[e+56>>2]);}if(H[b+11|0]<0){$a(J[b>>2]);}J[5996]=0;d=_(97,d|0,3759)|0;b=J[5996];J[5996]=0;if((b|0)==1){break u}J[e+16>>2]=J[d+8>>2];b=J[d+4>>2];J[e+8>>2]=J[d>>2];J[e+12>>2]=b;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;f=J[c>>2];g=J[c+4>>2];b=K[c+11|0];J[5996]=0;h=c;c=b<<24>>24<0;b=ba(100,e+8|0,(c?f:h)|0,(c?g:b)|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break t}J[e- -64>>2]=J[b+8>>2];c=J[b+4>>2];J[e+56>>2]=J[b>>2];J[e+60>>2]=c;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[5996]=0;c=_(97,e+56|0,3559)|0;f=J[5996];J[5996]=0;if((f|0)==1){break s}f=J[c+4>>2];J[a>>2]=J[c>>2];J[a+4>>2]=f;J[a+8>>2]=J[c+8>>2];J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;if(H[b+11|0]<0){$a(J[b>>2]);}if(H[d+11|0]<0){$a(J[d>>2]);}Ua=e+80|0;return}b=Z()|0;break a}b=Z()|0;break D}b=Z()|0;if(H[e+67|0]>=0){break D}$a(J[e+56>>2]);}if(H[e+55|0]>=0){break a}$a(J[e+44>>2]);break a}b=Z()|0;break a}b=Z()|0;break z}b=Z()|0;if(H[e+67|0]>=0){break z}$a(J[e+56>>2]);}if(H[e+43|0]>=0){break a}$a(J[e+32>>2]);break a}b=Z()|0;break a}b=Z()|0;break v}b=Z()|0;if(H[e+67|0]>=0){break v}$a(J[e+56>>2]);}if(H[e+31|0]>=0){break a}$a(J[e+20>>2]);break a}b=Z()|0;break a}b=Z()|0;break r}b=Z()|0;if(H[e+67|0]>=0){break r}$a(J[e+56>>2]);}if(H[e+19|0]>=0){break a}$a(J[e+8>>2]);break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;break a}b=Z()|0;}if(H[e+79|0]<0){$a(J[e+68>>2]);}da(b|0);B();}function Gg(a,b,c,d,e,f){a=a|0;b=+b;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0;m=Ua-560|0;Ua=m;J[m+44>>2]=0;A(+b);g=v(1)|0;v(0)|0;a:{if((g|0)<0){s=1;x=1222;b=-b;A(+b);g=v(1)|0;v(0)|0;break a}if(e&2048){s=1;x=1225;break a}s=e&1;x=s?1228:1223;z=!s;}b:{if((g&2146435072)==2146435072){g=s+3|0;Bb(a,32,c,g,e&-65537);wb(a,x,s);d=f&32;wb(a,b!=b?d?2020:3082:d?2300:3355,3);Bb(a,32,c,g,e^8192);o=(c|0)<(g|0)?g:c;break b}u=m+16|0;c:{d:{e:{b=Lg(b,m+44|0);b=b+b;if(b!=0){g=J[m+44>>2];J[m+44>>2]=g-1;w=f|32;if((w|0)!=97){break e}break c}w=f|32;if((w|0)==97){break c}j=J[m+44>>2];l=(d|0)<0?6:d;break d}j=g-29|0;J[m+44>>2]=j;b=b*268435456;l=(d|0)<0?6:d;}q=(m+48|0)+((j|0)>=0?288:0)|0;h=q;while(1){if(b<4294967296&b>=0){d=~~b>>>0;}else {d=0;}J[h>>2]=d;h=h+4|0;b=(b-+(d>>>0))*1e9;if(b!=0){continue}break}f:{if((j|0)<=0){d=j;g=h;i=q;break f}i=q;d=j;while(1){k=(d|0)>=29?29:d;g=h-4|0;g:{if(i>>>0>g>>>0){break g}n=0;while(1){d=J[g>>2];o=k&31;y=n;if((k&63)>>>0>=32){n=d<>>32-o;d=d<>>0>o>>>0?n+1|0:n,1e9);d=co(n,Wa,-1e9,0)+o|0;J[g>>2]=d;g=g-4|0;if(i>>>0<=g>>>0){continue}break}if(!n){break g}i=i-4|0;J[i>>2]=n;}while(1){g=h;if(i>>>0>>0){h=g-4|0;if(!J[h>>2]){continue}}break}d=J[m+44>>2]-k|0;J[m+44>>2]=d;h=g;if((d|0)>0){continue}break}}if((d|0)<0){t=((l+25>>>0)/9|0)+1|0;p=(w|0)==102;while(1){d=0-d|0;o=(d|0)>=9?9:d;h:{if(g>>>0<=i>>>0){h=J[i>>2];break h}n=1e9>>>o|0;k=-1<>2];J[h>>2]=y+(d>>>o|0);d=P(n,d&k);h=h+4|0;if(h>>>0>>0){continue}break}h=J[i>>2];if(!d){break h}J[g>>2]=d;g=g+4|0;}d=o+J[m+44>>2]|0;J[m+44>>2]=d;i=(!h<<2)+i|0;h=p?q:i;g=g-h>>2>(t|0)?h+(t<<2)|0:g;if((d|0)<0){continue}break}}d=0;i:{if(g>>>0<=i>>>0){break i}d=P(q-i>>2,9);h=10;k=J[i>>2];if(k>>>0<10){break i}while(1){d=d+1|0;h=P(h,10);if(k>>>0>=h>>>0){continue}break}}h=(l-((w|0)!=102?d:0)|0)-((w|0)==103&(l|0)!=0)|0;if((h|0)<(P(g-q>>2,9)-9|0)){n=h+9216|0;k=(n|0)/9|0;j=((((j|0)<0?4:292)+m|0)+(k<<2)|0)-4048|0;h=10;o=n+P(k,-9)|0;if((o|0)<=7){while(1){h=P(h,10);o=o+1|0;if((o|0)!=8){continue}break}}n=J[j>>2];t=(n>>>0)/(h>>>0)|0;p=P(t,h);k=j+4|0;j:{if((n|0)==(p|0)&(k|0)==(g|0)){break j}n=n-p|0;k:{if(!(t&1)){b=9007199254740992;if(!(H[j-4|0]&1)|((h|0)!=1e9|i>>>0>=j>>>0)){break k}}b=9007199254740994;}r=(g|0)==(k|0)?1:1.5;k=h>>>1|0;r=k>>>0>n>>>0?.5:(k|0)==(n|0)?r:1.5;if(!(K[x|0]!=45|z)){r=-r;b=-b;}J[j>>2]=p;if(b+r==b){break j}d=h+p|0;J[j>>2]=d;if(d>>>0>=1e9){while(1){J[j>>2]=0;j=j-4|0;if(j>>>0>>0){i=i-4|0;J[i>>2]=0;}d=J[j>>2]+1|0;J[j>>2]=d;if(d>>>0>999999999){continue}break}}d=P(q-i>>2,9);h=10;k=J[i>>2];if(k>>>0<10){break j}while(1){d=d+1|0;h=P(h,10);if(k>>>0>=h>>>0){continue}break}}h=j+4|0;g=g>>>0>h>>>0?h:g;}while(1){k=g;n=g>>>0<=i>>>0;if(!n){g=g-4|0;if(!J[g>>2]){continue}}break}l:{if((w|0)!=103){j=e&8;break l}h=l?l:1;g=(h|0)>(d|0)&(d|0)>-5;l=(g?d^-1:-1)+h|0;f=(g?-1:-2)+f|0;j=e&8;if(j){break l}g=-9;m:{if(n){break m}j=J[k-4>>2];if(!j){break m}o=10;g=0;if((j>>>0)%10|0){break m}while(1){h=g;g=g+1|0;o=P(o,10);if(!((j>>>0)%(o>>>0)|0)){continue}break}g=h^-1;}h=P(k-q>>2,9);if((f&-33)==70){j=0;g=(g+h|0)-9|0;g=(g|0)>0?g:0;l=(g|0)>(l|0)?l:g;break l}j=0;g=((d+h|0)+g|0)-9|0;g=(g|0)>0?g:0;l=(g|0)>(l|0)?l:g;}o=-1;n=j|l;if(((n?2147483645:2147483646)|0)<(l|0)){break b}p=(((n|0)!=0)+l|0)+1|0;h=f&-33;n:{if((h|0)==70){if((p^2147483647)<(d|0)){break b}g=(d|0)>0?d:0;break n}g=d>>31;g=Jc((g^d)-g|0,0,u);if((u-g|0)<=1){while(1){g=g-1|0;H[g|0]=48;if((u-g|0)<2){continue}break}}t=g-2|0;H[t|0]=f;H[g-1|0]=(d|0)<0?45:43;g=u-t|0;if((g|0)>(p^2147483647)){break b}}d=g+p|0;if((d|0)>(s^2147483647)){break b}p=d+s|0;Bb(a,32,c,p,e);wb(a,x,s);Bb(a,48,c,p,e^65536);o:{p:{q:{if((h|0)==70){f=m+16|0;d=f|8;j=f|9;h=i>>>0>q>>>0?q:i;i=h;while(1){g=Jc(J[i>>2],0,j);r:{if((h|0)!=(i|0)){if(m+16>>>0>=g>>>0){break r}while(1){g=g-1|0;H[g|0]=48;if(m+16>>>0>>0){continue}break}break r}if((g|0)!=(j|0)){break r}H[m+24|0]=48;g=d;}wb(a,g,j-g|0);i=i+4|0;if(q>>>0>=i>>>0){continue}break}if(n){wb(a,4352,1);}if((l|0)<=0|i>>>0>=k>>>0){break q}while(1){g=Jc(J[i>>2],0,j);if(g>>>0>m+16>>>0){while(1){g=g-1|0;H[g|0]=48;if(m+16>>>0>>0){continue}break}}wb(a,g,(l|0)>=9?9:l);g=l-9|0;i=i+4|0;if(k>>>0<=i>>>0){break p}d=(l|0)>9;l=g;if(d){continue}break}break p}s:{if((l|0)<0){break s}q=i>>>0>>0?k:i+4|0;f=m+16|0;d=f|8;k=f|9;h=i;while(1){g=Jc(J[h>>2],0,k);if((k|0)==(g|0)){H[m+24|0]=48;g=d;}t:{if((h|0)!=(i|0)){if(m+16>>>0>=g>>>0){break t}while(1){g=g-1|0;H[g|0]=48;if(m+16>>>0>>0){continue}break}break t}wb(a,g,1);g=g+1|0;if(!(j|l)){break t}wb(a,4352,1);}f=k-g|0;wb(a,g,(f|0)<(l|0)?f:l);l=l-f|0;h=h+4|0;if(q>>>0<=h>>>0){break s}if((l|0)>=0){continue}break}}Bb(a,48,l+18|0,18,0);wb(a,t,u-t|0);break o}g=l;}Bb(a,48,g+9|0,9,0);}Bb(a,32,c,p,e^8192);o=(c|0)<(p|0)?p:c;break b}j=(f<<26>>31&9)+x|0;u:{if(d>>>0>11){break u}g=12-d|0;r=16;while(1){r=r*16;g=g-1|0;if(g){continue}break}if(K[j|0]==45){b=-(r+(-b-r));break u}b=b+r-r;}q=s|2;i=f&32;h=J[m+44>>2];g=h>>31;g=Jc((g^h)-g|0,0,u);if((u|0)==(g|0)){H[m+15|0]=48;g=m+15|0;}l=g-2|0;H[l|0]=f+15;H[g-1|0]=(h|0)<0?45:43;g=e&8;h=m+16|0;while(1){f=h;if(R(b)<2147483648){k=~~b;}else {k=-2147483648;}H[h|0]=i|K[k+7488|0];b=(b-+(k|0))*16;h=f+1|0;if(!(!((d|0)>0|g)&b==0|(h-(m+16|0)|0)!=1)){H[f+1|0]=46;h=f+2|0;}if(b!=0){continue}break}o=-1;g=u-l|0;f=g+q|0;if((2147483645-f|0)<(d|0)){break b}k=f;f=m+16|0;i=h-f|0;d=d?(i-2|0)<(d|0)?d+2|0:i:i;h=k+d|0;Bb(a,32,c,h,e);wb(a,j,q);Bb(a,48,c,h,e^65536);wb(a,f,i);Bb(a,48,d-i|0,0,0);wb(a,l,g);Bb(a,32,c,h,e^8192);o=(c|0)<(h|0)?h:c;}Ua=m+560|0;return o|0}function zn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;a:{b:{c:{d:{e:{f:{g:{switch(J[b>>2]){case 1:case 4:case 5:J[a+8>>2]=0;J[a+12>>2]=0;J[a>>2]=1;J[a+4>>2]=0;return;case 2:J[a+8>>2]=1;J[a+12>>2]=1;break a;case 3:J[a+8>>2]=1;J[a+12>>2]=2;J[a>>2]=1;J[a+4>>2]=2;return;case 6:case 7:case 8:case 9:J[a+8>>2]=0;J[a+12>>2]=0;break a;case 23:d=J[b+32>>2];b=J[d+16>>2];c=J[d>>2];e=J[c+76>>2];j=K[c+72|0]!=0;i=j&K[b+64|0]!=0;f=i?J[b+68>>2]+e|0:0;h:{if(!K[c+64|0]){break h}d=J[d+8>>2];if(!K[d+64|0]){break h}c=J[d+68>>2]+J[c+68>>2]|0;f=i?c>>>0>f>>>0?c:f:c;i=1;}d=J[b+76>>2];b=K[b+72|0];J[a>>2]=i;J[a+4>>2]=f;b=j&(b|0)!=0;c=b&0;J[a+8>>2]=b|c;J[a+12>>2]=b?d+e|0:0;return;case 17:b=J[b+32>>2];c=J[b+8>>2];d=J[c+68>>2];b=J[b>>2];f=J[b+68>>2];b=K[b+64|0];e=K[c+64|0];J[a+8>>2]=0;J[a+12>>2]=0;c=d+f|0;b=(b|0)!=0&(e|0)!=0;d=b&0;J[a>>2]=b|d;J[a+4>>2]=b?c:0;return;case 18:c=J[b+32>>2];b=J[c+8>>2];f=J[b+68>>2];d=J[c>>2];e=J[d+68>>2];j=K[d+64|0];g=K[b+64|0];c=J[b+76>>2]+J[d+76>>2]|0;b=K[d+72|0]!=0&K[b+72|0]!=0;d=b&0;J[a+8>>2]=b|d;J[a+12>>2]=b?c:0;b=(j|0)!=0&(g|0)!=0;d=b&0;J[a>>2]=b|d;J[a+4>>2]=b?e+f|0:0;return;case 19:c=J[b+32>>2];b=J[c+8>>2];f=J[b+76>>2];j=K[b+72|0]!=0;d=J[c>>2];i=j&K[d+64|0]!=0;c=i?f+J[d+68>>2]|0:0;e=J[d+76>>2];g=K[d+72|0];if(!(!g|!K[b+64|0])){b=e+J[b+68>>2]|0;c=i?b>>>0>c>>>0?b:c:b;i=1;}J[a>>2]=i;J[a+4>>2]=c;b=j&(g|0)!=0;d=b&0;J[a+8>>2]=b|d;J[a+12>>2]=b?e+f|0:0;return;case 20:b=J[b+32>>2];e=J[b+8>>2];c=J[b>>2];d=J[e+68>>2]+J[c+76>>2]|0;b=K[c+72|0]!=0&K[e+64|0]!=0;e=b?d:0;i:{if(!K[c+64|0]){break i}if(!b){b=J[c+64>>2];f=b&-256;e=J[c+68>>2];break i}b=1;c=J[c+68>>2];e=c>>>0>d>>>0?c:d;}c=e;J[a+8>>2]=0;J[a+12>>2]=0;J[a>>2]=f|b&255;J[a+4>>2]=c|j;return;case 21:b=J[b+32>>2];d=J[b+8>>2];c=J[b>>2];g=J[c+76>>2];e=J[d+68>>2]+g|0;i=K[c+72|0];b=(i|0)!=0&K[d+64|0]!=0;h=b?e:0;j:{if(!K[c+64|0]){break j}if(!b){b=J[c+64>>2];f=b&-256;h=J[c+68>>2];break j}b=1;c=J[c+68>>2];h=c>>>0>e>>>0?c:e;}e=h;c=J[d+76>>2];d=K[d+72|0];h=b&255;b=0;J[a>>2]=h|(f|b);J[a+4>>2]=e|j;e=c+g|0;c=b;b=(i|0)!=0&(d|0)!=0;c=b?c:0;J[a+8>>2]=b|c;J[a+12>>2]=b?e:0;return;case 22:d=J[b+32>>2];b=J[d+8>>2];f=K[b+64|0];c=f?J[b+68>>2]+1|0:0;e=J[d>>2];if(K[e+64|0]){d=J[e+68>>2]+1|0;c=f?c>>>0>>0?d:c:d;f=1;}j=J[b+76>>2]+1|0;b=K[b+72|0];d=b?j:0;if(K[e+72|0]){e=J[e+76>>2]+1|0;d=b?d>>>0>>0?e:d:e;b=1;}j=b;b=0;J[a+8>>2]=j|b;J[a+12>>2]=d;J[a>>2]=b|f;J[a+4>>2]=c;return;case 25:c=J[b+4>>2]+1|0;b=1;J[a+8>>2]=b;J[a+12>>2]=c;break b;case 10:case 11:case 12:case 16:b=J[J[b+32>>2]>>2];c=J[b+68>>2];J[a>>2]=J[b+64>>2];J[a+4>>2]=c;c=J[b+76>>2];J[a+8>>2]=J[b+72>>2];J[a+12>>2]=c;return;case 13:b=J[J[b+32>>2]>>2];c=J[b+68>>2];b=K[b+64|0];J[a+8>>2]=1;J[a+12>>2]=1;j=b;b=!b;J[a>>2]=j|b&0;J[a+4>>2]=b?0:c+1|0;return;case 14:c=J[J[b+32>>2]>>2];b=J[c+64>>2];c=J[c+68>>2];J[a+8>>2]=0;J[a+12>>2]=0;break b;case 15:c=J[J[b+32>>2]>>2];b=J[c+64>>2];c=J[c+68>>2];J[a+8>>2]=1;J[a+12>>2]=1;break b;case 24:c=cb(8);J[c>>2]=1;J[c+4>>2]=0;i=c+8|0;l=J[b+32>>2];o=J[b+36>>2];if((l|0)!=(o|0)){while(1){d=J[l>>2];e=J[d+76>>2];d=K[d+72|0];g=J[c+4>>2];j=c;k=K[c|0];J[5996]=0;f=$(3,8)|0;c=J[5996];J[5996]=0;k:{l:{if((c|0)!=1){c=e+g|0;d=(k|0)!=0&(d|0)!=0;e=d&0;J[f>>2]=d|e;J[f+4>>2]=d?c:0;g=f+8|0;c=i-j|0;k=c>>3;if(c>>>0>=9){break l}d=g;break k}d=Z()|0;c=j;break e}q=k>>>0<=2?2:k;i=1;d=g;while(1){c=J[l>>2];h=j+(i<<3)|0;m=J[c+76>>2]+J[h+4>>2]|0;n=h-8|0;e=K[n|0]!=0&K[c+64|0]!=0;h=K[h|0]!=0&K[c+72|0]!=0;p=h?m:0;c=e?J[c+68>>2]+J[n+4>>2]|0:0;c=h?e?c>>>0

>>0?p:c:m:c;m=e|h;m:{if(d>>>0>>0){J[d>>2]=m;J[d+4>>2]=c;e=d;break m}n=d-f>>3;e=n+1|0;if(e>>>0>=536870912){J[5996]=0;ca(93);a=J[5996];J[5996]=0;if((a|0)==1){break f}break c}g=g-f|0;h=g>>2;h=g>>>0>=2147483640?536870911:e>>>0>>0?h:e;n:{if(!h){g=0;break n}if(h>>>0>=536870912){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break c}break f}J[5996]=0;g=$(3,h<<3)|0;e=J[5996];J[5996]=0;if((e|0)==1){break f}}e=(n<<3)+g|0;J[e>>2]=m;J[e+4>>2]=c;g=(h<<3)+g|0;c=e;o:{if((d|0)!=(f|0)){while(1){d=d-8|0;h=J[d+4>>2];c=c-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=h;if((d|0)!=(f|0)){continue}break}if(!f){break o}}$a(f);}f=c;}d=e+8|0;i=i+1|0;if((q|0)!=(i|0)){continue}break}}c=(j+(k<<3)|0)-8|0;e=J[l>>2];i=K[c|0]!=0&K[e+64|0]!=0;e=i?J[e+68>>2]+J[c+4>>2]|0:0;p:{if(d>>>0>>0){J[d>>2]=i;J[d+4>>2]=e;i=d+8|0;c=f;break p}q:{r:{k=d-f>>3;c=k+1|0;s:{if(c>>>0>=536870912){J[5996]=0;ca(93);break s}g=g-f|0;h=g>>2;c=g>>>0>=2147483640?536870911:c>>>0>>0?h:c;if(!c){c=0;break q}if(c>>>0<536870912){break r}J[5996]=0;ca(35);}a=J[5996];J[5996]=0;if((a|0)!=1){break c}break f}J[5996]=0;c=$(3,c<<3)|0;g=J[5996];J[5996]=0;if((g|0)==1){break f}}c=(k<<3)+c|0;J[c>>2]=i;J[c+4>>2]=e;i=c+8|0;if((d|0)!=(f|0)){while(1){d=d-8|0;e=J[d+4>>2];c=c-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=e;if((d|0)!=(f|0)){continue}break}if(!f){break p}}$a(f);}$a(j);l=l+8|0;if((o|0)!=(l|0)){continue}break}}b=J[b+4>>2];if(b>>>0<=i-c>>3>>>0){b=(b<<3)+c|0;d=J[b>>2];b=J[b+4>>2];f=J[c+4>>2];J[a+8>>2]=J[c>>2];J[a+12>>2]=f;J[a>>2]=d;J[a+4>>2]=b;$a(c);return}J[5996]=0;ga(44,5118,2210,850,2317);a=J[5996];J[5996]=0;if((a|0)!=1){break c}d=Z()|0;if(!c){break d}break e;default:la(2350,2210,854,2317);B();case 0:break g}}J[a+8>>2]=1;J[a+12>>2]=0;J[a>>2]=0;J[a+4>>2]=0;return}d=Z()|0;if(!f){c=j;break e}$a(f);c=j;}$a(c);}da(d|0);B();}B();}J[a>>2]=b;J[a+4>>2]=c;return}J[a>>2]=1;J[a+4>>2]=1;}function Kg(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;h=Ua-80|0;Ua=h;J[h+76>>2]=b;x=h+55|0;q=h+56|0;a:{b:{c:{d:while(1){f=0;e:while(1){k=b;if((p^2147483647)<(f|0)){break c}p=f+p|0;f:{g:{h:{f=b;g=K[f|0];if(g){while(1){i:{b=g&255;j:{if(!b){b=f;break j}if((b|0)!=37){break i}g=f;while(1){if(K[g+1|0]!=37){b=g;break j}f=f+1|0;l=K[g+2|0];b=g+2|0;g=b;if((l|0)==37){continue}break}}f=f-k|0;w=p^2147483647;if((f|0)>(w|0)){break c}if(a){wb(a,k,f);}if(f){continue e}J[h+76>>2]=b;f=b+1|0;o=-1;g=H[b+1|0];if(!(K[b+2|0]!=36|g-48>>>0>=10)){o=g-48|0;r=1;f=b+3|0;}J[h+76>>2]=f;m=0;g=H[f|0];b=g-32|0;k:{if(b>>>0>31){l=f;break k}l=f;b=1<>2]=l;m=b|m;g=H[f+1|0];b=g-32|0;if(b>>>0>=32){break k}f=l;b=1<>>0>=10)){b=b-48|0;n:{if(!a){J[(b<<2)+e>>2]=10;n=0;break n}n=J[(b<<3)+d>>2];}b=l+3|0;r=1;break m}if(r){break h}b=l+1|0;if(!a){J[h+76>>2]=b;r=0;n=0;break l}f=J[c>>2];J[c>>2]=f+4;n=J[f>>2];r=0;}J[h+76>>2]=b;if((n|0)>=0){break l}n=0-n|0;m=m|8192;break l}n=Jg(h+76|0);if((n|0)<0){break c}b=J[h+76>>2];}f=0;i=-1;g=0;o:{if(K[b|0]!=46){break o}if(K[b+1|0]==42){g=H[b+2|0];p:{if(!(K[b+3|0]!=36|g-48>>>0>=10)){g=g-48|0;b=b+4|0;q:{if(!a){J[(g<<2)+e>>2]=10;i=0;break q}i=J[(g<<3)+d>>2];}break p}if(r){break h}b=b+2|0;i=0;if(!a){break p}g=J[c>>2];J[c>>2]=g+4;i=J[g>>2];}J[h+76>>2]=b;g=(i^-1)>>>31|0;break o}J[h+76>>2]=b+1;i=Jg(h+76|0);b=J[h+76>>2];g=1;}t=g;while(1){s=f;j=28;u=b;g=H[b|0];if(g-123>>>0<4294967238){break b}b=b+1|0;f=K[(g+P(f,58)|0)+6959|0];if(f-1>>>0<8){continue}break}J[h+76>>2]=b;r:{if((f|0)!=27){if(!f){break b}if((o|0)>=0){if(!a){J[(o<<2)+e>>2]=f;continue d}f=(o<<3)+d|0;g=J[f+4>>2];J[h+64>>2]=J[f>>2];J[h+68>>2]=g;break r}if(!a){break f}Ig(h- -64|0,f,c);break r}if((o|0)>=0){break b}f=0;if(!a){continue e}}j=-1;if(K[a|0]&32){break a}g=m&-65537;m=m&8192?g:m;o=0;v=1212;l=q;s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{E:{F:{G:{H:{f=H[u|0];f=s?(f&15)==3?f&-33:f:f;switch(f-88|0){case 11:break s;case 9:case 13:case 14:case 15:break t;case 27:break y;case 12:case 17:break B;case 23:break C;case 0:case 32:break D;case 24:break E;case 22:break F;case 29:break G;case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 10:case 16:case 18:case 19:case 20:case 21:case 25:case 26:case 28:case 30:case 31:break g;default:break H}}I:{switch(f-65|0){case 0:case 4:case 5:case 6:break t;case 2:break w;case 1:case 3:break g;default:break I}}if((f|0)==83){break x}break g}g=J[h+64>>2];j=J[h+68>>2];f=1212;break A}f=0;J:{switch(s&255){case 0:J[J[h+64>>2]>>2]=p;continue e;case 1:J[J[h+64>>2]>>2]=p;continue e;case 2:g=J[h+64>>2];J[g>>2]=p;J[g+4>>2]=p>>31;continue e;case 3:I[J[h+64>>2]>>1]=p;continue e;case 4:H[J[h+64>>2]]=p;continue e;case 6:J[J[h+64>>2]>>2]=p;continue e;case 7:break J;default:continue e}}g=J[h+64>>2];J[g>>2]=p;J[g+4>>2]=p>>31;continue e}i=i>>>0<=8?8:i;m=m|8;f=120;}k=q;u=f&32;g=J[h+64>>2];j=J[h+68>>2];if(g|j){while(1){k=k-1|0;H[k|0]=u|K[(g&15)+7488|0];s=!j&g>>>0>15|(j|0)!=0;g=(j&15)<<28|g>>>4;j=j>>>4|0;if(s){continue}break}}if(!(J[h+64>>2]|J[h+68>>2])|!(m&8)){break z}v=(f>>>4|0)+1212|0;o=2;break z}f=q;k=J[h+68>>2];j=k;g=J[h+64>>2];if(k|g){while(1){f=f-1|0;H[f|0]=g&7|48;s=!j&g>>>0>7|(j|0)!=0;g=(j&7)<<29|g>>>3;j=j>>>3|0;if(s){continue}break}}k=f;if(!(m&8)){break z}f=q-f|0;i=(f|0)<(i|0)?i:f+1|0;break z}g=J[h+64>>2];f=J[h+68>>2];j=f;if((f|0)<0){k=0-(f+((g|0)!=0)|0)|0;j=k;g=0-g|0;J[h+64>>2]=g;J[h+68>>2]=k;o=1;f=1212;break A}if(m&2048){o=1;f=1213;break A}o=m&1;f=o?1214:1212;}v=f;k=Jc(g,j,q);}if((i|0)<0?t:0){break c}m=t?m&-65537:m;f=J[h+64>>2];g=J[h+68>>2];if(!(i|(f|g)!=0)){k=q;i=0;break g}f=!(f|g)+(q-k|0)|0;i=(f|0)<(i|0)?i:f;break g}f=J[h+64>>2];k=f?f:4806;f=k;l=i>>>0>=2147483647?2147483647:i;j=Zb(f,0,l);f=j?j-f|0:l;l=f+k|0;if((i|0)>=0){m=g;i=f;break g}m=g;i=f;if(K[l|0]){break c}break g}if(i){g=J[h+64>>2];break v}f=0;Bb(a,32,n,0,m);break u}J[h+12>>2]=0;J[h+8>>2]=J[h+64>>2];g=h+8|0;J[h+64>>2]=g;i=-1;}f=0;K:{while(1){k=J[g>>2];if(!k){break K}k=Mg(h+4|0,k);l=(k|0)<0;if(!(l|k>>>0>i-f>>>0)){g=g+4|0;f=f+k|0;if(i>>>0>f>>>0){continue}break K}break}if(l){break a}}j=61;if((f|0)<0){break b}Bb(a,32,n,f,m);if(!f){f=0;break u}l=0;g=J[h+64>>2];while(1){k=J[g>>2];if(!k){break u}j=h+4|0;k=Mg(j,k);l=k+l|0;if(l>>>0>f>>>0){break u}wb(a,j,k);g=g+4|0;if(f>>>0>l>>>0){continue}break}}Bb(a,32,n,f,m^8192);f=(f|0)<(n|0)?n:f;continue e}if((i|0)<0?t:0){break c}j=61;f=Gg(a,O[h+64>>3],n,i,m,f);if((f|0)>=0){continue e}break b}H[h+55|0]=J[h+64>>2];i=1;k=x;m=g;break g}g=K[f+1|0];f=f+1|0;continue}}j=p;if(a){break a}if(!r){break f}f=1;while(1){a=J[(f<<2)+e>>2];if(a){Ig((f<<3)+d|0,a,c);j=1;f=f+1|0;if((f|0)!=10){continue}break a}break}j=1;if(f>>>0>=10){break a}while(1){if(J[(f<<2)+e>>2]){break h}f=f+1|0;if((f|0)!=10){continue}break}break a}j=28;break b}l=l-k|0;i=(i|0)>(l|0)?i:l;if((i|0)>(o^2147483647)){break c}j=61;g=i+o|0;f=(g|0)<(n|0)?n:g;if((w|0)<(f|0)){break b}Bb(a,32,f,g,m);wb(a,v,o);Bb(a,48,f,g,m^65536);Bb(a,48,i,l,0);wb(a,k,l);Bb(a,32,f,g,m^8192);continue}break}break}j=0;break a}j=61;}J[5732]=j;j=-1;}Ua=h+80|0;return j}function un(a){a=a|0;var b=0,c=0,d=0,e=0,f=0;a:{if(a>>>0<=211){d=J[Eg(7504,7696,a)>>2];break a}if(a>>>0>=4294967292){a=Rb(8);J[5996]=0;d=$(167,a|0)|0;e=J[5996];J[5996]=0;if((e|0)!=1){na(d|0,22716,92);B();}d=Z()|0;ic(a);da(d|0);B();}f=(a>>>0)/210|0;d=P(f,210);e=Eg(7696,7888,a-d|0)-7696>>2;while(1){d=J[(e<<2)+7696>>2]+d|0;a=5;while(1){b:{if((a|0)==47){a=211;while(1){b=(d>>>0)/(a>>>0)|0;if(b>>>0>>0){break a}if((P(a,b)|0)==(d|0)){break b}b=a+10|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+12|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+16|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+18|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+22|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+28|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+30|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+36|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+40|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+42|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+46|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+52|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+58|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+60|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+66|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+70|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+72|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+78|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+82|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+88|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+96|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+100|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+102|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+106|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+108|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+112|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+120|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+126|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+130|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+136|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+138|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+142|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+148|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+150|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+156|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+162|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+166|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+168|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+172|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+178|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+180|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+186|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+190|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+192|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+196|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+198|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((P(b,c)|0)==(d|0)){break b}b=a+208|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+210|0;if((P(b,c)|0)!=(d|0)){continue}break}break b}b=J[(a<<2)+7504>>2];c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+1|0;if((P(b,c)|0)!=(d|0)){continue}}break}d=e+1|0;a=(d|0)==48;e=a?0:d;f=a+f|0;d=P(f,210);continue}}return d|0}function ob(a,b,c,d,e,f,g,h,i){var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0;k=Ua-96|0;Ua=k;u=i&65535;o=(e^i)&-2147483648;r=e&65535;y=r;Q=i>>>16&32767;R=e>>>16&32767;a:{b:{if(Q-32767>>>0>4294934529&R-32767>>>0>=4294934530){break b}s=e&2147483647;q=s;j=d;if(!(!d&(q|0)==2147418112?!(b|c):q>>>0<2147418112)){m=d;o=e|32768;break a}s=i&2147483647;p=s;e=h;if(!(!e&(p|0)==2147418112?!(f|g):p>>>0<2147418112)){m=e;o=i|32768;b=f;c=g;break a}if(!(b|j|(q^2147418112|c))){if(!(e|f|(g|p))){o=2147450880;b=0;c=0;break a}o=o|2147418112;b=0;c=0;break a}if(!(e|f|(p^2147418112|g))){e=b|j;d=c|q;b=0;c=0;if(!(d|e)){o=2147450880;break a}o=o|2147418112;break a}if(!(b|j|(c|q))){b=0;c=0;break a}if(!(e|f|(g|p))){b=0;c=0;break a}if((q|0)==65535|q>>>0<65535){j=!(d|r);i=j?b:d;s=j<<6;e=S(i)+32|0;i=S(j?c:r);i=s+((i|0)==32?e:i)|0;Cb(k+80|0,b,c,d,r,i-15|0);t=16-i|0;d=J[k+88>>2];y=J[k+92>>2];c=J[k+84>>2];b=J[k+80>>2];}if(p>>>0>65535){break b}i=!(h|u);e=i?f:h;r=i<<6;j=S(e)+32|0;e=S(i?g:u);e=r+((e|0)==32?j:e)|0;Cb(k- -64|0,f,g,h,u,e-15|0);t=(t-e|0)+16|0;h=J[k+72>>2];u=J[k+76>>2];f=J[k+64>>2];g=J[k+68>>2];}e=f;f=g<<15|f>>>17;i=e<<15;e=0;v=i&-32768;K=c;s=co(v,e,c,0);e=Wa;z=e;L=f;q=b;c=co(f,0,b,0);b=c+s|0;f=Wa+e|0;i=b;c=b>>>0>>0?f+1|0:f;f=b;j=0;b=co(q,l,v,l);p=j+b|0;e=Wa+f|0;e=b>>>0>p>>>0?e+1|0:e;r=e;M=(f|0)==(e|0)&j>>>0>p>>>0|e>>>0>>0;N=d;w=co(v,l,d,0);O=Wa;b=co(K,l,L,l);x=b+w|0;j=Wa+O|0;j=b>>>0>x>>>0?j+1|0:j;b=u<<15|h>>>17;A=h<<15|g>>>17;d=co(A,0,q,l);B=d+x|0;f=Wa+j|0;f=d>>>0>B>>>0?f+1|0:f;C=f;d=(c|0)==(z|0)&i>>>0>>0|c>>>0>>0;D=c+B|0;f=d+f|0;f=c>>>0>D>>>0?f+1|0:f;u=f;g=D;c=f;E=y|65536;y=co(v,l,E,n);P=Wa;d=co(N,m,L,l);F=d+y|0;e=Wa+P|0;e=d>>>0>F>>>0?e+1|0:e;i=e;G=b|-2147483648;b=co(G,0,q,l);H=b+F|0;f=Wa+e|0;f=b>>>0>H>>>0?f+1|0:f;d=co(A,m,K,l);b=d+H|0;I=f;f=f+Wa|0;z=b;s=b>>>0>>0?f+1|0:f;f=b;b=0;q=b+g|0;e=c+f|0;e=b>>>0>q>>>0?e+1|0:e;v=e;f=e;b=q+M|0;c=b>>>0>>0?f+1|0:f;t=((R+Q|0)+t|0)-16383|0;d=co(G,m,K,l);h=Wa;e=co(E,m,L,l);g=e+d|0;f=Wa+h|0;f=e>>>0>g>>>0?f+1|0:f;n=(h|0)==(f|0)&d>>>0>g>>>0|f>>>0>>0;h=f;e=co(A,m,N,m);d=e+g|0;f=Wa+f|0;f=d>>>0>>0?f+1|0:f;e=f;g=(f|0)==(h|0)&d>>>0>>0|f>>>0>>0;f=0;h=g;g=g+n|0;f=h>>>0>g>>>0?1:f;h=g;g=co(G,m,E,m);h=h+g|0;f=Wa+f|0;M=h;g=g>>>0>h>>>0?f+1|0:f;h=d;l=e;e=(j|0)==(O|0)&w>>>0>x>>>0|j>>>0>>0;f=0;j=(j|0)==(C|0)&x>>>0>B>>>0|j>>>0>C>>>0;n=j;j=e+j|0;e=(n>>>0>j>>>0?1:f)+l|0;f=g;d=d+j|0;e=d>>>0>>0?e+1|0:e;n=e;w=d;d=(e|0)==(l|0)&d>>>0>>0|e>>>0>>0;e=d;d=d+M|0;f=e>>>0>d>>>0?f+1|0:f;j=d;h=f;e=co(A,m,E,m);l=Wa;g=co(G,m,N,m);d=g+e|0;f=Wa+l|0;f=d>>>0>>0?f+1|0:f;g=f;f=(l|0)==(f|0)&d>>>0>>0|f>>>0>>0;x=g+j|0;e=f+h|0;e=g>>>0>x>>>0?e+1|0:e;l=x;h=e;j=d;e=0;d=e+w|0;f=j+n|0;f=d>>>0>>0?f+1|0:f;e=f;g=(n|0)==(f|0)&d>>>0>>0|f>>>0>>0;f=h;h=g;g=g+l|0;f=h>>>0>g>>>0?f+1|0:f;w=g;g=f;h=d;j=e;e=(s|0)==(I|0)&z>>>0>>0|s>>>0>>0;d=(i|0)==(P|0)&y>>>0>F>>>0|i>>>0

>>0;i=(i|0)==(I|0)&F>>>0>H>>>0|i>>>0>I>>>0;d=d+i|0;d=d+e|0;n=s;i=n+h|0;e=d+j|0;f=g;d=i;e=d>>>0>>0?e+1|0:e;h=(e|0)==(j|0)&h>>>0>d>>>0|e>>>0>>0;g=h+w|0;f=h>>>0>g>>>0?f+1|0:f;j=g;g=f;h=d;f=0;i=e;n=(u|0)==(v|0)&q>>>0>>0|u>>>0>v>>>0;l=n;n=n+((u|0)==(C|0)&B>>>0>D>>>0|u>>>0>>0)|0;e=e+(l>>>0>n>>>0?1:f)|0;f=g;d=d+n|0;e=d>>>0>>0?e+1|0:e;h=(e|0)==(i|0)&d>>>0>>0|e>>>0>>0;g=h;h=h+j|0;f=g>>>0>h>>>0?f+1|0:f;i=f;c:{if(f&65536){t=t+1|0;break c}j=r>>>31|0;g=0;f=i<<1|h>>>31;h=h<<1|e>>>31;i=f;f=e<<1|d>>>31;d=d<<1|c>>>31;e=f;f=r<<1|p>>>31;p=p<<1;r=f;f=c<<1|b>>>31;b=b<<1|j;c=f|g;}if((t|0)>=32767){o=o|2147418112;b=0;c=0;break a}d:{if((t|0)<=0){g=1-t|0;if(g>>>0<=127){f=t+127|0;Cb(k+48|0,p,r,b,c,f);Cb(k+32|0,d,e,h,i,f);xc(k+16|0,p,r,b,c,g);xc(k,d,e,h,i,g);p=J[k+32>>2]|J[k+16>>2]|(J[k+48>>2]|J[k+56>>2]|(J[k+52>>2]|J[k+60>>2]))!=0;r=J[k+36>>2]|J[k+20>>2];b=J[k+40>>2]|J[k+24>>2];c=J[k+44>>2]|J[k+28>>2];d=J[k>>2];e=J[k+4>>2];g=J[k+8>>2];f=J[k+12>>2];break d}b=0;c=0;break a}g=h;f=i&65535|t<<16;}m=g|m;o=f|o;if(!(!b&(c|0)==-2147483648?!(p|r):(c|0)>0|(c|0)>=0)){b=d+1|0;j=b?e:e+1|0;e=o;c=j;d=!(j|b);m=d+m|0;o=d>>>0>m>>>0?e+1|0:e;break a}if(b|p|(c^-2147483648|r)){b=d;c=e;break a}f=e;b=d&1;c=b;b=b+d|0;c=c>>>0>b>>>0?f+1|0:f;d=(f|0)==(c|0)&b>>>0>>0|c>>>0>>0;f=o;m=d+m|0;o=m>>>0>>0?f+1|0:f;}J[a>>2]=b;J[a+4>>2]=c;J[a+8>>2]=m;J[a+12>>2]=o;Ua=k+96|0;}function Pg(){var a=0,b=0,c=0;if(K[25020]){return J[6254]}J[6663]=0;J[6662]=22008;J[6662]=14144;J[6662]=12664;a=Ua-16|0;Ua=a;J[6664]=0;J[6665]=0;J[6666]=0;H[26792]=0;J[a+4>>2]=26656;c=J[a+4>>2];b=a+8|0;H[b+4|0]=0;J[b>>2]=c;J[5996]=0;ha(273,26656);c=J[5996];J[5996]=0;a:{if((c|0)!=1){ff(26656,30);H[b+4|0]=1;ef(b);Ua=a+16|0;break a}b=Z()|0;ef(a+8|0);da(b|0);B();}J[5996]=0;b=_(30,26800,3538)|0;a=J[5996];J[5996]=0;b:{c:{d:{if((a|0)!=1){df(26656);J[6581]=0;J[6580]=22008;J[6580]=14144;J[6580]=15252;J[5996]=0;ha(240,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6583]=0;J[6582]=22008;J[6582]=14144;J[6582]=15284;J[5996]=0;ha(241,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6585]=0;J[6584]=22008;J[6584]=14144;H[26348]=0;J[6586]=0;J[6584]=12684;J[6586]=12736;J[5996]=0;ha(242,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6589]=0;J[6588]=22008;J[6588]=14144;J[6588]=14200;J[5996]=0;ha(243,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6591]=0;J[6590]=22008;J[6590]=14144;J[6590]=14348;J[5996]=0;ha(244,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ca(245);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ha(246,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6597]=0;J[6596]=22008;J[6596]=14144;J[6596]=14496;J[5996]=0;ha(247,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6599]=0;J[6598]=22008;J[6598]=14144;J[6598]=14728;J[5996]=0;ha(248,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6601]=0;J[6600]=22008;J[6600]=14144;J[6600]=14612;J[5996]=0;ha(249,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6603]=0;J[6602]=22008;J[6602]=14144;J[6602]=14844;J[5996]=0;ha(250,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6605]=0;J[6604]=22008;J[6604]=14144;I[13212]=11310;J[6604]=13816;J[6607]=0;J[6608]=0;J[6609]=0;J[5996]=0;ha(251,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6611]=0;J[6610]=22008;J[6610]=14144;J[6612]=46;J[6613]=44;J[6610]=13856;J[6614]=0;J[6615]=0;J[6616]=0;J[5996]=0;ha(252,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6619]=0;J[6618]=22008;J[6618]=14144;J[6618]=15316;J[5996]=0;ha(253,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6621]=0;J[6620]=22008;J[6620]=14144;J[6620]=15560;J[5996]=0;ha(254,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6623]=0;J[6622]=22008;J[6622]=14144;J[6622]=15772;J[5996]=0;ha(255,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6625]=0;J[6624]=22008;J[6624]=14144;J[6624]=16004;J[5996]=0;ha(256,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6627]=0;J[6626]=22008;J[6626]=14144;J[6626]=16988;J[5996]=0;ha(257,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6629]=0;J[6628]=22008;J[6628]=14144;J[6628]=17136;J[5996]=0;ha(258,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6631]=0;J[6630]=22008;J[6630]=14144;J[6630]=17252;J[5996]=0;ha(259,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6633]=0;J[6632]=22008;J[6632]=14144;J[6632]=17368;J[5996]=0;ha(260,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6635]=0;J[6634]=22008;J[6634]=14144;J[6634]=17484;J[5996]=0;ha(261,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6637]=0;J[6636]=22008;J[6636]=14144;J[6636]=17648;J[5996]=0;ha(262,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6639]=0;J[6638]=22008;J[6638]=14144;J[6638]=17812;J[5996]=0;ha(263,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6641]=0;J[6640]=22008;J[6640]=14144;J[6640]=17976;J[5996]=0;ha(264,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6643]=0;J[6642]=22008;J[6642]=14144;J[6644]=19232;J[6644]=16252;J[6642]=16204;J[5996]=0;ha(265,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6647]=0;J[6646]=22008;J[6646]=14144;J[6648]=19268;J[6648]=16516;J[6646]=16468;J[5996]=0;ha(266,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ca(267);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ha(268,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ca(269);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[5996]=0;ha(270,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6659]=0;J[6658]=22008;J[6658]=14144;J[6658]=18140;J[5996]=0;ha(271,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}J[6661]=0;J[6660]=22008;J[6660]=14144;J[6660]=18260;J[5996]=0;ha(272,26648);a=J[5996];J[5996]=0;if((a|0)==1){break d}break b}a=Z()|0;break c}a=Z()|0;ab(b);}gf(26656);da(a|0);B();}J[6253]=26648;H[25020]=1;J[6254]=25012;return 25012}function Ek(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0;h=Ua-48|0;Ua=h;J[h+44>>2]=b;J[e>>2]=0;i=J[d+28>>2];J[h>>2]=i;J[i+4>>2]=J[i+4>>2]+1;J[5996]=0;i=$(197,J[h>>2])|0;j=J[5996];J[5996]=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{if((j|0)!=1){j=J[h>>2];k=J[j+4>>2]-1|0;J[j+4>>2]=k;if((k|0)==-1){Xa[J[J[j>>2]+8>>2]](j);}switch(g-65|0){case 54:break j;case 19:break k;case 18:break l;case 17:break m;case 49:break n;case 47:break o;case 45:case 51:break p;case 12:break q;case 44:break r;case 41:break s;case 8:break t;case 7:break u;case 5:break v;case 3:break w;case 35:case 36:break x;case 34:break y;case 1:case 33:case 39:break z;case 0:case 32:break A;case 2:case 4:case 6:case 9:case 10:case 11:case 13:case 14:case 15:case 16:case 20:case 21:case 22:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 37:case 38:case 40:case 42:case 43:case 46:case 48:case 50:case 52:case 53:break d;case 24:break f;case 56:break g;case 23:break h;case 55:break i;default:break e}}c=Z()|0;a=J[h>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}Bf(a,f+24|0,h+44|0,c,e,i);break b}Af(a,f+16|0,h+44|0,c,e,i);break b}g=Xa[J[J[a+8>>2]+12>>2]](a+8|0)|0;i=K[g+11|0];j=a;k=b;b=(i&128)>>>7|0;a=b?J[g>>2]:g;J[h+44>>2]=jc(j,k,c,d,e,f,a,a+((b?J[g+4>>2]:i&127)<<2)|0);break b}a=bc(h+44|0,c,e,i,2);b=J[e>>2];B:{if(!(a-1>>>0>30|b&4)){J[f+12>>2]=a;break B}J[e>>2]=b|4;}break b}g=J[3127];J[h+24>>2]=J[3126];J[h+28>>2]=g;g=J[3125];J[h+16>>2]=J[3124];J[h+20>>2]=g;g=J[3123];J[h+8>>2]=J[3122];J[h+12>>2]=g;g=J[3121];J[h>>2]=J[3120];J[h+4>>2]=g;J[h+44>>2]=jc(a,b,c,d,e,f,h,h+32|0);break b}g=J[3135];J[h+24>>2]=J[3134];J[h+28>>2]=g;g=J[3133];J[h+16>>2]=J[3132];J[h+20>>2]=g;g=J[3131];J[h+8>>2]=J[3130];J[h+12>>2]=g;g=J[3129];J[h>>2]=J[3128];J[h+4>>2]=g;J[h+44>>2]=jc(a,b,c,d,e,f,h,h+32|0);break b}a=bc(h+44|0,c,e,i,2);b=J[e>>2];C:{if(!((a|0)>23|b&4)){J[f+8>>2]=a;break C}J[e>>2]=b|4;}break b}a=bc(h+44|0,c,e,i,2);b=J[e>>2];D:{if(!(a-1>>>0>11|b&4)){J[f+8>>2]=a;break D}J[e>>2]=b|4;}break b}a=bc(h+44|0,c,e,i,3);b=J[e>>2];E:{if(!((a|0)>365|b&4)){J[f+28>>2]=a;break E}J[e>>2]=b|4;}break b}b=bc(h+44|0,c,e,i,2)-1|0;a=J[e>>2];F:{if(!(b>>>0>11|a&4)){J[f+16>>2]=b;break F}J[e>>2]=a|4;}break b}a=bc(h+44|0,c,e,i,2);b=J[e>>2];G:{if(!((a|0)>59|b&4)){J[f+4>>2]=a;break G}J[e>>2]=b|4;}break b}a=h+44|0;b=Ua-16|0;Ua=b;J[b+12>>2]=c;while(1){H:{if(Tb(a,b+12|0)){break H}c=J[a>>2];d=J[c+12>>2];I:{if((d|0)==J[c+16>>2]){c=Xa[J[J[c>>2]+36>>2]](c)|0;break I}c=J[d>>2];}if(!(Xa[J[J[i>>2]+12>>2]](i,1,c)|0)){break H}Hc(a);continue}break}if(Tb(a,b+12|0)){J[e>>2]=J[e>>2]|2;}Ua=b+16|0;break b}d=h+44|0;a=Xa[J[J[a+8>>2]+8>>2]](a+8|0)|0;b=K[a+11|0];g=(b&128)>>>7|0?J[a+4>>2]:b&127;b=K[a+23|0];J:{if((g|0)==(0-((b&128)>>>7|0?J[a+16>>2]:b&127)|0)){J[e>>2]=J[e>>2]|4;break J}c=ld(d,c,a,a+24|0,i,e,0);b=J[f+8>>2];if(!((c|0)!=(a|0)|(b|0)!=12)){J[f+8>>2]=0;break J}if(!((c-a|0)!=12|(b|0)>11)){J[f+8>>2]=b+12;}}break b}g=fb(h,12544,44);J[g+44>>2]=jc(a,b,c,d,e,f,g,g+44|0);break b}J[h+16>>2]=J[3152];g=J[3151];J[h+8>>2]=J[3150];J[h+12>>2]=g;g=J[3149];J[h>>2]=J[3148];J[h+4>>2]=g;J[h+44>>2]=jc(a,b,c,d,e,f,h,h+20|0);break b}a=bc(h+44|0,c,e,i,2);b=J[e>>2];K:{if(!((a|0)>60|b&4)){J[f>>2]=a;break K}J[e>>2]=b|4;}break b}g=J[3163];J[h+24>>2]=J[3162];J[h+28>>2]=g;g=J[3161];J[h+16>>2]=J[3160];J[h+20>>2]=g;g=J[3159];J[h+8>>2]=J[3158];J[h+12>>2]=g;g=J[3157];J[h>>2]=J[3156];J[h+4>>2]=g;J[h+44>>2]=jc(a,b,c,d,e,f,h,h+32|0);break b}a=bc(h+44|0,c,e,i,1);b=J[e>>2];L:{if(!((a|0)>6|b&4)){J[f+24>>2]=a;break L}J[e>>2]=b|4;}break b}a=Xa[J[J[a>>2]+20>>2]](a,b,c,d,e,f)|0;break a}g=Xa[J[J[a+8>>2]+24>>2]](a+8|0)|0;i=K[g+11|0];j=a;k=b;b=(i&128)>>>7|0;a=b?J[g>>2]:g;J[h+44>>2]=jc(j,k,c,d,e,f,a,a+((b?J[g+4>>2]:i&127)<<2)|0);break b}zf(f+20|0,h+44|0,c,e,i);break b}a=bc(h+44|0,c,e,i,4);if(!(K[e|0]&4)){J[f+20>>2]=a-1900;}break b}if((g|0)==37){break c}}J[e>>2]=J[e>>2]|4;break b}a=Ua-16|0;Ua=a;J[a+12>>2]=c;b=6;d=h+44|0;g=a+12|0;M:{N:{if(Tb(d,g)){break N}b=4;c=J[d>>2];f=J[c+12>>2];O:{if((f|0)==J[c+16>>2]){c=Xa[J[J[c>>2]+36>>2]](c)|0;break O}c=J[f>>2];}if((Xa[J[J[i>>2]+52>>2]](i,c,0)|0)!=37){break N}b=2;if(!Tb(Hc(d),g)){break M}}J[e>>2]=J[e>>2]|b;}Ua=a+16|0;}a=J[h+44>>2];}Ua=h+48|0;return a|0}function qh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0;g=J[b+4>>2]-J[b>>2]|0;a:{if(g>>>0<=75){c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;e=c>>>0<29?c:d;f=e+1|0;if(f>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,f+(f>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;}h=c>>>0<29;f=e+(h?a+4|0:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(f+1|0,f,(h?c:d)-e|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[f|0]=g;break a}if(g>>>0<=255){c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;e=c>>>0<29?c:d;f=e+1|0;if(f>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,f+(f>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;}h=a+4|0;g=c>>>0<29;f=e+(g?h:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(f+1|0,f,(g?c:d)-e|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[f|0]=76;g=J[b+4>>2]-J[b>>2]|0;c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;e=c>>>0<29?c:d;f=e+1|0;if(f>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,f+(f>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;}i=h;h=c>>>0<29;f=e+(h?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(f+1|0,f,(h?c:d)-e|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[f|0]=g;break a}c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=c-29|0;f=c>>>0<29?c:e;d=f+1|0;i=c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24);h=a+4|0;if(g>>>0<=65535){if(d>>>0>i>>>0){Ob(a,d+(d>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=c-29|0;}g=c>>>0<29;d=f+(g?h:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(d+1|0,d,(g?c:e)-f|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[d|0]=77;f=J[b+4>>2]-J[b>>2]|0;c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;g=c>>>0<29?c:d;e=g+2|0;if(e>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,e+(e>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;}i=h;h=c>>>0<29;e=g+(h?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(e+2|0,e,(h?c:d)-g|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+2|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[e|0]=f;H[e+1|0]=f>>>8;break a}if(d>>>0>i>>>0){Ob(a,d+(d>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=c-29|0;}g=c>>>0<29;d=f+(g?h:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(d+1|0,d,(g?c:e)-f|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[d|0]=78;f=J[b+4>>2]-J[b>>2]|0;c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;g=c>>>0<29?c:d;e=g+4|0;if(e>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,e+(e>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);d=c-29|0;}i=h;h=c>>>0<29;e=g+(h?i:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(e+4|0,e,(h?c:d)-g|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+4|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[e|0]=f;H[e+1|0]=f>>>8;H[e+2|0]=f>>>16;H[e+3|0]=f>>>24;}d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;f=J[b+4>>2];b=J[b>>2];h=f-b|0;g=d>>>0<29?d:e;c=h+g|0;if(c>>>0>(d>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,c+(c>>>1|0)|0);d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;}i=d>>>0<29;c=g+(i?a+4|0:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(h+c|0,c,(i?d:e)-g|0);d=h+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=d;H[a+1|0]=d>>>8;H[a+2|0]=d>>>16;H[a+3|0]=d>>>24;b:{if((b|0)==(f|0)){break b}e=f+(b^-1)|0;h=h&7;if(h){d=0;while(1){H[c|0]=K[b|0];b=b+1|0;c=c+1|0;d=d+1|0;if((h|0)!=(d|0)){continue}break}}if(e>>>0<7){break b}while(1){H[c|0]=K[b|0];H[c+1|0]=K[b+1|0];H[c+2|0]=K[b+2|0];H[c+3|0]=K[b+3|0];H[c+4|0]=K[b+4|0];H[c+5|0]=K[b+5|0];H[c+6|0]=K[b+6|0];H[c+7|0]=K[b+7|0];c=c+8|0;b=b+8|0;if((f|0)!=(b|0)){continue}break}}return a|0}function Kk(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0;h=Ua-16|0;Ua=h;J[h+12>>2]=b;J[e>>2]=0;i=J[d+28>>2];J[h>>2]=i;J[i+4>>2]=J[i+4>>2]+1;J[5996]=0;i=$(170,J[h>>2])|0;j=J[5996];J[5996]=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{if((j|0)!=1){j=J[h>>2];k=J[j+4>>2]-1|0;J[j+4>>2]=k;if((k|0)==-1){Xa[J[J[j>>2]+8>>2]](j);}switch(g-65|0){case 54:break j;case 19:break k;case 18:break l;case 17:break m;case 49:break n;case 47:break o;case 45:case 51:break p;case 12:break q;case 44:break r;case 41:break s;case 8:break t;case 7:break u;case 5:break v;case 3:break w;case 35:case 36:break x;case 34:break y;case 1:case 33:case 39:break z;case 0:case 32:break A;case 2:case 4:case 6:case 9:case 10:case 11:case 13:case 14:case 15:case 16:case 20:case 21:case 22:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 37:case 38:case 40:case 42:case 43:case 46:case 48:case 50:case 52:case 53:break d;case 24:break f;case 56:break g;case 23:break h;case 55:break i;default:break e}}c=Z()|0;a=J[h>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}Ef(a,f+24|0,h+12|0,c,e,i);break b}Df(a,f+16|0,h+12|0,c,e,i);break b}g=Xa[J[J[a+8>>2]+12>>2]](a+8|0)|0;i=K[g+11|0];j=a;k=b;b=(i&128)>>>7|0;a=b?J[g>>2]:g;J[h+12>>2]=kc(j,k,c,d,e,f,a,a+(b?J[g+4>>2]:i&127)|0);break b}a=cc(h+12|0,c,e,i,2);b=J[e>>2];B:{if(!(a-1>>>0>30|b&4)){J[f+12>>2]=a;break B}J[e>>2]=b|4;}break b}J[h>>2]=623865125;J[h+4>>2]=2032480100;J[h+12>>2]=kc(a,b,c,d,e,f,h,h+8|0);break b}J[h>>2]=623728933;J[h+4>>2]=1680158061;J[h+12>>2]=kc(a,b,c,d,e,f,h,h+8|0);break b}a=cc(h+12|0,c,e,i,2);b=J[e>>2];C:{if(!((a|0)>23|b&4)){J[f+8>>2]=a;break C}J[e>>2]=b|4;}break b}a=cc(h+12|0,c,e,i,2);b=J[e>>2];D:{if(!(a-1>>>0>11|b&4)){J[f+8>>2]=a;break D}J[e>>2]=b|4;}break b}a=cc(h+12|0,c,e,i,3);b=J[e>>2];E:{if(!((a|0)>365|b&4)){J[f+28>>2]=a;break E}J[e>>2]=b|4;}break b}b=cc(h+12|0,c,e,i,2)-1|0;a=J[e>>2];F:{if(!(b>>>0>11|a&4)){J[f+16>>2]=b;break F}J[e>>2]=a|4;}break b}a=cc(h+12|0,c,e,i,2);b=J[e>>2];G:{if(!((a|0)>59|b&4)){J[f+4>>2]=a;break G}J[e>>2]=b|4;}break b}a=h+12|0;b=Ua-16|0;Ua=b;J[b+12>>2]=c;while(1){H:{if(Ub(a,b+12|0)){break H}c=J[a>>2];d=J[c+12>>2];I:{if((d|0)==J[c+16>>2]){c=Xa[J[J[c>>2]+36>>2]](c)|0;break I}c=K[d|0];}d=J[i+8>>2];c=c<<24>>24;if((c|0)>=0){c=J[d+((c&255)<<2)>>2]&1;}else {c=0;}if(!c){break H}Ic(a);continue}break}if(Ub(a,b+12|0)){J[e>>2]=J[e>>2]|2;}Ua=b+16|0;break b}d=h+12|0;a=Xa[J[J[a+8>>2]+8>>2]](a+8|0)|0;b=K[a+11|0];g=(b&128)>>>7|0?J[a+4>>2]:b&127;b=K[a+23|0];J:{if((g|0)==(0-((b&128)>>>7|0?J[a+16>>2]:b&127)|0)){J[e>>2]=J[e>>2]|4;break J}c=nd(d,c,a,a+24|0,i,e,0);b=J[f+8>>2];if(!((c|0)!=(a|0)|(b|0)!=12)){J[f+8>>2]=0;break J}if(!((c-a|0)!=12|(b|0)>11)){J[f+8>>2]=b+12;}}break b}g=K[12456]|K[12457]<<8|(K[12458]<<16|K[12459]<<24);H[h+7|0]=g;H[h+8|0]=g>>>8;H[h+9|0]=g>>>16;H[h+10|0]=g>>>24;g=K[12453]|K[12454]<<8|(K[12455]<<16|K[12456]<<24);J[h>>2]=K[12449]|K[12450]<<8|(K[12451]<<16|K[12452]<<24);J[h+4>>2]=g;J[h+12>>2]=kc(a,b,c,d,e,f,h,h+11|0);break b}H[h+4|0]=K[12464];J[h>>2]=K[12460]|K[12461]<<8|(K[12462]<<16|K[12463]<<24);J[h+12>>2]=kc(a,b,c,d,e,f,h,h+5|0);break b}a=cc(h+12|0,c,e,i,2);b=J[e>>2];K:{if(!((a|0)>60|b&4)){J[f>>2]=a;break K}J[e>>2]=b|4;}break b}J[h>>2]=624576549;J[h+4>>2]=1394948685;J[h+12>>2]=kc(a,b,c,d,e,f,h,h+8|0);break b}a=cc(h+12|0,c,e,i,1);b=J[e>>2];L:{if(!((a|0)>6|b&4)){J[f+24>>2]=a;break L}J[e>>2]=b|4;}break b}a=Xa[J[J[a>>2]+20>>2]](a,b,c,d,e,f)|0;break a}g=Xa[J[J[a+8>>2]+24>>2]](a+8|0)|0;i=K[g+11|0];j=a;k=b;b=(i&128)>>>7|0;a=b?J[g>>2]:g;J[h+12>>2]=kc(j,k,c,d,e,f,a,a+(b?J[g+4>>2]:i&127)|0);break b}Cf(f+20|0,h+12|0,c,e,i);break b}a=cc(h+12|0,c,e,i,4);if(!(K[e|0]&4)){J[f+20>>2]=a-1900;}break b}if((g|0)==37){break c}}J[e>>2]=J[e>>2]|4;break b}a=Ua-16|0;Ua=a;J[a+12>>2]=c;b=6;d=h+12|0;g=a+12|0;M:{N:{if(Ub(d,g)){break N}b=4;c=J[d>>2];f=J[c+12>>2];O:{if((f|0)==J[c+16>>2]){c=Xa[J[J[c>>2]+36>>2]](c)|0;break O}c=K[f|0];}if((Xa[J[J[i>>2]+36>>2]](i,c<<24>>24,0)|0)!=37){break N}b=2;if(!Ub(Ic(d),g)){break M}}J[e>>2]=J[e>>2]|b;}Ua=a+16|0;}a=J[h+12>>2];}Ua=h+16|0;return a|0}function Yc(a,b,c,d,e,f){var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;g=Ua-32|0;Ua=g;if(!K[24588]){J[6145]=0;J[6146]=0;J[6143]=0;J[6144]=0;J[6141]=0;J[6142]=0;H[24588]=1;}i=1-e;a:{b:{c:{d:{e:{f:{switch(b|0){case 10:case 11:case 12:case 16:b=cb(8);J[g+20>>2]=b;f=b+8|0;J[g+28>>2]=f;O[b>>3]=c;J[g+24>>2]=f;J[5996]=0;f=$(3,8)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+8|0;J[g+16>>2]=h;O[f>>3]=d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 13:case 14:case 15:b=cb(8);J[g+20>>2]=b;f=b+8|0;J[g+28>>2]=f;O[b>>3]=c;J[g+24>>2]=f;J[5996]=0;f=$(3,8)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+8|0;J[g+16>>2]=h;J[f>>2]=0;J[f+4>>2]=0;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 17:case 18:b=cb(16);J[g+20>>2]=b;f=b+16|0;J[g+28>>2]=f;O[b+8>>3]=c;O[b>>3]=c;J[g+24>>2]=f;J[5996]=0;f=$(3,16)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+16|0;J[g+16>>2]=h;O[f+8>>3]=d;O[f>>3]=d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 19:b=cb(16);J[g+20>>2]=b;f=b+16|0;J[g+28>>2]=f;i=i*c;O[b+8>>3]=i;c=c*e;O[b>>3]=c;J[g+24>>2]=f;J[5996]=0;f=$(3,16)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+16|0;J[g+16>>2]=h;O[f+8>>3]=c+d;O[f>>3]=i+d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 21:b=cb(16);J[g+20>>2]=b;f=b+16|0;J[g+28>>2]=f;i=i*c;O[b+8>>3]=i;O[b>>3]=c*e;J[g+24>>2]=f;J[5996]=0;f=$(3,16)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+16|0;J[g+16>>2]=h;O[f+8>>3]=d;O[f>>3]=i+d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 20:b=cb(16);J[g+20>>2]=b;f=b+16|0;J[g+28>>2]=f;d=i*c;O[b+8>>3]=d;O[b>>3]=c*e;J[g+24>>2]=f;J[5996]=0;f=$(3,16)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+16|0;J[g+16>>2]=h;J[f+8>>2]=0;J[f+12>>2]=0;O[f>>3]=d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 22:b=cb(16);J[g+20>>2]=b;h=b+16|0;J[g+28>>2]=h;O[b+8>>3]=i*c;O[b>>3]=c*e;J[g+24>>2]=h;J[5996]=0;h=$(3,16)|0;j=J[5996];J[5996]=0;if((j|0)==1){break b}J[g+8>>2]=h;j=h+16|0;J[g+16>>2]=j;O[h+8>>3]=(f|0)==1?d:0;O[h>>3]=f?0:d;J[5996]=0;J[g+12>>2]=j;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(h);$a(b);break e}a=Z()|0;$a(h);break a;case 23:b=cb(24);J[g+20>>2]=b;f=b+24|0;J[g+28>>2]=f;i=i*c;O[b+16>>3]=i;c=c*e;O[b+8>>3]=c;O[b>>3]=c;J[g+24>>2]=f;J[5996]=0;f=$(3,24)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}J[g+8>>2]=f;h=f+24|0;J[g+16>>2]=h;O[f+16>>3]=d;J[f+8>>2]=0;J[f+12>>2]=0;O[f>>3]=i+d;J[5996]=0;J[g+12>>2]=h;ba(65,a|0,g+20|0,g+8|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){$a(f);$a(b);break e}break c;case 24:g:{h:{if(!f){f=0;break h}if(f>>>0>=536870912){break d}e=c*e;h=f<<3;k=cb(h);b=k;l=f&7;if(l){while(1){O[b>>3]=e;b=b+8|0;j=j+1|0;if((l|0)!=(j|0)){continue}break}}m=h+k|0;n=f-1&536870911;if(n>>>0>=7){while(1){O[b+56>>3]=e;O[b+48>>3]=e;O[b+40>>3]=e;O[b+32>>3]=e;O[b+24>>3]=e;O[b+16>>3]=e;O[b+8>>3]=e;O[b>>3]=e;b=b- -64|0;if((m|0)!=(b|0)){continue}break}}j=0;J[5996]=0;h=$(3,h|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break g}c=c*i+d;b=h;if(l){while(1){O[b>>3]=c;b=b+8|0;j=j+1|0;if((l|0)!=(j|0)){continue}break}}f=(f<<3)+h|0;if(n>>>0<7){break h}while(1){O[b+56>>3]=c;O[b+48>>3]=c;O[b+40>>3]=c;O[b+32>>3]=c;O[b+24>>3]=c;O[b+16>>3]=c;O[b+8>>3]=c;O[b>>3]=c;b=b- -64|0;if((f|0)!=(b|0)){continue}break}}J[a+12>>2]=h;J[a+8>>2]=m;J[a+4>>2]=m;J[a>>2]=k;J[a+20>>2]=f;J[a+16>>2]=f;break e}a=Z()|0;$a(k);da(a|0);B();default:la(2350,1900,558,1676);B();case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 25:break f}}Yg(a);}Ua=g+32|0;return}nb();B();}a=Z()|0;$a(f);break a}a=Z()|0;}$a(b);da(a|0);B();}function Zg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;a:{b:{e=J[c>>2];d=J[e+80>>2];c:{if(!d|M[e+84>>2]>3600|(J[e+52>>2]+J[e+44>>2]>>>0>201|M[e+68>>2]>100)){break c}J[5996]=0;h=_(54,2049,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break b}if((d^-1)&h){break c}d=J[e+80>>2];J[5996]=0;h=_(54,2165,1)|0;f=J[5996];J[5996]=0;if((f|0)==1){break b}if(K[e+88|0]|(d^-1)&h){break c}i=O[a+24>>3];k=i==0?0:i*O[b+8>>3];i=O[a+16>>3];g=J[e+84>>2];i=k+((i==0?0:i*O[b>>3])+ +(g>>>0));if(i>1e4){break c}f=J[e+80>>2];d:{e:{d=J[a>>2];h=J[a+4>>2];if((d|0)==(h|0)){break e}e=d;while(1){j=J[e>>2];f:{if(f&(J[j+80>>2]^-1)){break f}k=O[e+24>>3];if(k>>0<=M[j+84>>2]){break c}}e=e+32|0;if((h|0)!=(e|0)){continue}break}e=f^-1;while(1){j=J[d>>2];g:{if(e&J[j+80>>2]){break g}k=O[d+24>>3];if(k>>0>=M[j+84>>2]|i>2];i:{j:{if(j&J[g+80>>2]){break j}k=O[f+56>>3];if(k>2]<=M[J[c>>2]+84>>2]|i>2];J[d>>2]=0;J[f+36>>2]=0;J[e>>2]=g;g=J[e+4>>2];J[e+4>>2]=l;k:{if(!g){break k}l=J[g+4>>2];J[g+4>>2]=l-1;if(l){break k}Xa[J[J[g>>2]+8>>2]](g);bb(g);}g=J[f+60>>2];J[e+24>>2]=J[f+56>>2];J[e+28>>2]=g;g=J[f+52>>2];J[e+16>>2]=J[f+48>>2];J[e+20>>2]=g;g=J[f+44>>2];J[e+8>>2]=J[f+40>>2];J[e+12>>2]=g;e=e+32|0;}g=d+32|0;if((g|0)!=(h|0)){continue}break}h=J[a+4>>2];}if((e|0)==(h|0)){e=h;break d}d=(h-e|0)+e|0;if((h|0)!=(d|0)){while(1){g=J[d>>2];j=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;f=J[e+4>>2];J[e>>2]=g;J[e+4>>2]=j;l:{if(!f){break l}g=J[f+4>>2];J[f+4>>2]=g-1;if(g){break l}Xa[J[J[f>>2]+8>>2]](f);bb(f);}f=J[d+12>>2];J[e+8>>2]=J[d+8>>2];J[e+12>>2]=f;f=J[d+28>>2];J[e+24>>2]=J[d+24>>2];J[e+28>>2]=f;f=J[d+20>>2];J[e+16>>2]=J[d+16>>2];J[e+20>>2]=f;e=e+32|0;d=d+32|0;if((h|0)!=(d|0)){continue}break}h=J[a+4>>2];}if((e|0)!=(h|0)){while(1){h=h-32|0;d=J[h+4>>2];m:{if(!d){break m}f=J[d+4>>2];J[d+4>>2]=f-1;if(f){break m}Xa[J[J[d>>2]+8>>2]](d);bb(d);}if((e|0)!=(h|0)){continue}break}}J[a+4>>2]=e;}f=J[a+8>>2];n:{if(f>>>0>e>>>0){J[e>>2]=J[c>>2];J[e+4>>2]=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;d=J[b+12>>2];J[e+16>>2]=J[b+8>>2];J[e+20>>2]=d;d=J[b+4>>2];J[e+8>>2]=J[b>>2];J[e+12>>2]=d;O[e+24>>3]=i;J[a+4>>2]=e+32;break n}h=J[a>>2];g=e-h>>5;d=g+1|0;if(d>>>0>=134217728){J[5996]=0;ca(62);a=J[5996];J[5996]=0;if((a|0)==1){break b}break a}f=f-h|0;j=f>>4;d=f>>>0>=2147483616?134217727:d>>>0>>0?j:d;if(d>>>0>=134217728){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break b}J[5996]=0;j=d<<5;f=$(3,j|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break b}d=f+(g<<5)|0;J[d>>2]=J[c>>2];J[d+4>>2]=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;g=J[b+12>>2];J[d+16>>2]=J[b+8>>2];J[d+20>>2]=g;g=J[b+4>>2];J[d+8>>2]=J[b>>2];J[d+12>>2]=g;O[d+24>>3]=i;b=f+j|0;f=d+32|0;o:{if((e|0)!=(h|0)){while(1){d=d-32|0;e=e-32|0;J[d>>2]=J[e>>2];J[d+4>>2]=J[e+4>>2];J[e>>2]=0;J[e+4>>2]=0;g=J[e+28>>2];J[d+24>>2]=J[e+24>>2];J[d+28>>2]=g;g=J[e+20>>2];J[d+16>>2]=J[e+16>>2];J[d+20>>2]=g;g=J[e+12>>2];J[d+8>>2]=J[e+8>>2];J[d+12>>2]=g;if((e|0)!=(h|0)){continue}break}J[a+8>>2]=b;b=J[a+4>>2];J[a+4>>2]=f;e=J[a>>2];J[a>>2]=d;if((b|0)==(e|0)){break o}while(1){b=b-32|0;d=J[b+4>>2];p:{if(!d){break p}h=J[d+4>>2];J[d+4>>2]=h-1;if(h){break p}Xa[J[J[d>>2]+8>>2]](d);bb(d);}if((b|0)!=(e|0)){continue}break}break o}J[a+8>>2]=b;J[a+4>>2]=f;J[a>>2]=d;}if(!e){break n}$a(e);}J[a+32>>2]=J[a+32>>2]+1;}a=J[c+4>>2];q:{if(!a){break q}b=J[a+4>>2];J[a+4>>2]=b-1;if(b){break q}Xa[J[J[a>>2]+8>>2]](a);bb(a);}return}a=Z()|0;mb(c);da(a|0);B();}B();}function eh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=Q(0),j=0,k=0,l=0,m=0,n=Q(0),o=0;d=P(a,1540483477);d=P(d>>>24^d,1540483477)^1866966612;d=P(d>>>13^d,1540483477);g=d>>>15^d;a:{b:{c:{d:{h=J[b+4>>2];e:{if(!h){break e}e=J[b>>2];k=fo(h);d=h-1&g;f:{if(k>>>0<=1){break f}d=g;if(d>>>0>>0){break f}d=(d>>>0)%(h>>>0)|0;}f=d;d=J[e+(f<<2)>>2];if(!d){break e}d=J[d>>2];if(!d){break e}if(k>>>0<=1){e=h-1|0;while(1){h=J[d+4>>2];g:{if((h|0)!=(g|0)){if((f|0)==(e&h)){break g}break e}if(J[d+8>>2]==(a|0)){break d}}d=J[d>>2];if(d){continue}break}break e}while(1){e=J[d+4>>2];h:{if((e|0)!=(g|0)){if(e>>>0>=h>>>0){e=(e>>>0)%(h>>>0)|0;}if((e|0)==(f|0)){break h}break e}if(J[d+8>>2]==(a|0)){break d}}d=J[d>>2];if(d){continue}break}}m=ze(a,b,c);if(!m){return 0}d=J[b+4>>2];if(!d){break c}e=d-1|0;if(e&d){c=d>>>0<=g>>>0?(g>>>0)%(d>>>0)|0:g;f=J[J[b>>2]+(c<<2)>>2];if(!f){break c}while(1){f=J[f>>2];if(!f){break c}e=J[f+4>>2];if((e|0)!=(g|0)){if(d>>>0<=e>>>0){e=(e>>>0)%(d>>>0)|0;}if((c|0)!=(e|0)){break c}}if(J[f+8>>2]!=(a|0)){continue}break}break b}c=e&g;f=J[J[b>>2]+(c<<2)>>2];if(!f){break c}while(1){f=J[f>>2];if(!f){break c}h=J[f+4>>2];if((h|0)!=(g|0)&(e&h)!=(c|0)){break c}if(J[f+8>>2]!=(a|0)){continue}break}break b}return J[d+12>>2]}h=cb(16);J[h+8>>2]=a;J[h+4>>2]=g;J[h>>2]=0;J[h+12>>2]=m;k=b+8|0;n=Q(J[b+12>>2]+1>>>0);i=N[b+16>>2];i:{if(!(!d|n>Q(i*Q(d>>>0)))){g=c;break i}e=2;c=(d-1&d)!=0|d>>>0<3|d<<1;i=Q(W(Q(n/i)));j:{if(i=Q(0)){a=~~i>>>0;break j}a=0;}a=a>>>0>>0?c:a;k:{if((a|0)==1){break k}if(!(a&a-1)){e=a;break k}J[5996]=0;e=$(43,a|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break a}d=J[b+4>>2];}l:{m:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break l}c=d>>>0<3;i=Q(W(Q(Q(M[b+12>>2])/N[b+16>>2])));n:{if(i=Q(0)){a=~~i>>>0;break n}a=0;}o:{p:{if(c){break p}if(fo(d)>>>0>1){break p}a=a>>>0<2?a:1<<32-S(a-1|0);break o}J[5996]=0;a=$(43,a|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}}e=a>>>0>>0?e:a;if(e>>>0>=d>>>0){d=J[b+4>>2];break l}if(!e){break m}}if(e>>>0>=1073741824){J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)==1){break a}B();}J[5996]=0;c=$(3,e<<2)|0;a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[b>>2];J[b>>2]=c;if(a){$a(a);}J[b+4>>2]=e;f=0;d=0;j=e-1|0;if(j>>>0>=3){c=e&-4;while(1){a=d<<2;J[a+J[b>>2]>>2]=0;J[J[b>>2]+(a|4)>>2]=0;J[J[b>>2]+(a|8)>>2]=0;J[J[b>>2]+(a|12)>>2]=0;d=d+4|0;if((c|0)!=(d|0)){continue}break}}a=e&3;if(a){while(1){J[J[b>>2]+(d<<2)>>2]=0;d=d+1|0;f=f+1|0;if((a|0)!=(f|0)){continue}break}}d=J[b+8>>2];if(!d){d=e;break l}c=J[d+4>>2];q:{if(e-1&e){c=c>>>0>=e>>>0?(c>>>0)%(e>>>0)|0:c;J[J[b>>2]+(c<<2)>>2]=k;f=J[d>>2];if(f){break q}d=e;break l}c=c&j;J[J[b>>2]+(c<<2)>>2]=k;a=J[d>>2];if(!a){d=e;break l}while(1){f=j&J[a+4>>2];r:{if((f|0)==(c|0)){d=a;break r}l=f<<2;o=l+J[b>>2]|0;if(J[o>>2]){J[d>>2]=J[a>>2];J[a>>2]=J[J[l+J[b>>2]>>2]>>2];J[J[l+J[b>>2]>>2]>>2]=a;break r}J[o>>2]=d;d=a;c=f;}a=J[d>>2];if(a){continue}break}d=e;break l}while(1){a=J[f+4>>2];if(e>>>0<=a>>>0){a=(a>>>0)%(e>>>0)|0;}s:{if((a|0)==(c|0)){d=f;break s}j=a<<2;l=j+J[b>>2]|0;if(!J[l>>2]){J[l>>2]=d;d=f;c=a;break s}J[d>>2]=J[f>>2];J[f>>2]=J[J[j+J[b>>2]>>2]>>2];J[J[j+J[b>>2]>>2]>>2]=f;}f=J[d>>2];if(f){continue}break}d=e;break l}a=J[b>>2];d=0;J[b>>2]=0;if(a){$a(a);}J[b+4>>2]=0;}a=d-1|0;if(!(a&d)){g=a&g;break i}if(d>>>0>g>>>0){break i}g=(g>>>0)%(d>>>0)|0;}a=J[b>>2]+(g<<2)|0;g=J[a>>2];t:{u:{if(!g){J[h>>2]=J[b+8>>2];J[b+8>>2]=h;J[a>>2]=k;a=J[h>>2];if(!a){break t}g=J[a+4>>2];a=d-1|0;v:{if(!(a&d)){g=a&g;break v}if(d>>>0>g>>>0){break v}g=(g>>>0)%(d>>>0)|0;}g=J[b>>2]+(g<<2)|0;break u}J[h>>2]=J[g>>2];}J[g>>2]=h;}J[b+12>>2]=J[b+12>>2]+1;}return m|0}a=Z()|0;$a(h);da(a|0);B();}function bo(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;i=Ua-16|0;Ua=i;J[i+8>>2]=0;J[i+12>>2]=0;k=i+8|0;J[i+4>>2]=k;a:{b:{c:{d:{e:{if((b|0)!=(c|0)){while(1){j=J[b>>2];g=J[j+80>>2];f:{if((g^-1)&d){break f}l=e&g;h=k;g=h;g:{m=J[i+8>>2];f=m;h:{if(!f){break h}while(1){g=f;f=J[g+16>>2];if(f>>>0>l>>>0){h=g;f=J[g>>2];if(f){continue}break h}if(f>>>0>=l>>>0){break g}f=J[g+4>>2];if(f){continue}break}h=g+4|0;}J[5996]=0;f=$(3,56)|0;p=J[5996];J[5996]=0;if((p|0)==1){break e}J[f+16>>2]=l;J[f+24>>2]=j;j=J[b+4>>2];J[f+28>>2]=j;if(j){J[j+4>>2]=J[j+4>>2]+1;}j=J[b+12>>2];J[f+32>>2]=J[b+8>>2];J[f+36>>2]=j;j=J[b+28>>2];J[f+48>>2]=J[b+24>>2];J[f+52>>2]=j;j=J[b+20>>2];J[f+40>>2]=J[b+16>>2];J[f+44>>2]=j;J[f+8>>2]=g;J[f>>2]=0;J[f+4>>2]=0;J[h>>2]=f;g=J[J[i+4>>2]>>2];if(g){J[i+4>>2]=g;f=J[h>>2];}zd(J[i+8>>2],f);J[i+12>>2]=J[i+12>>2]+1;break f}n=O[b+24>>3];o=O[g+48>>3];if(!(n>2]<=M[J[g+24>>2]+84>>2]|n>o)){break f}h=J[b+4>>2];if(h){J[h+4>>2]=J[h+4>>2]+1;}J[g+24>>2]=j;f=J[g+28>>2];J[g+28>>2]=h;i:{if(!f){break i}h=J[f+4>>2];J[f+4>>2]=h-1;if(h){break i}Xa[J[J[f>>2]+8>>2]](f);bb(f);}f=J[b+12>>2];J[g+32>>2]=J[b+8>>2];J[g+36>>2]=f;f=J[b+28>>2];J[g+48>>2]=J[b+24>>2];J[g+52>>2]=f;f=J[b+20>>2];J[g+40>>2]=J[b+16>>2];J[g+44>>2]=f;}b=b+32|0;if((c|0)!=(b|0)){continue}break d}}J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;break a}g=Z()|0;break c}d=J[i+4>>2];J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;if((d|0)==(k|0)){break a}while(1){j:{g=J[a+4>>2];k:{if((g|0)!=J[a+8>>2]){J[g>>2]=J[d+24>>2];b=J[d+28>>2];J[g+4>>2]=b;if(b){J[b+4>>2]=J[b+4>>2]+1;}b=J[d+52>>2];J[g+24>>2]=J[d+48>>2];J[g+28>>2]=b;b=J[d+44>>2];J[g+16>>2]=J[d+40>>2];J[g+20>>2]=b;b=J[d+36>>2];J[g+8>>2]=J[d+32>>2];J[g+12>>2]=b;J[a+4>>2]=g+32;break k}b=J[a>>2];c=g-b|0;f=c>>5;e=f+1|0;if(e>>>0>=134217728){J[5996]=0;ca(62);b=J[5996];J[5996]=0;if((b|0)==1){break j}break b}h=c>>4;e=c>>>0>=2147483616?134217727:e>>>0>>0?h:e;l:{if(!e){c=0;break l}if(e>>>0>=134217728){J[5996]=0;ca(35);b=J[5996];J[5996]=0;if((b|0)!=1){break b}break j}J[5996]=0;c=$(3,e<<5)|0;h=J[5996];J[5996]=0;if((h|0)==1){break j}}f=(f<<5)+c|0;J[f>>2]=J[d+24>>2];h=J[d+28>>2];J[f+4>>2]=h;if(h){J[h+4>>2]=J[h+4>>2]+1;g=J[a+4>>2];b=J[a>>2];}c=(e<<5)+c|0;e=J[d+36>>2];J[f+8>>2]=J[d+32>>2];J[f+12>>2]=e;e=J[d+52>>2];J[f+24>>2]=J[d+48>>2];J[f+28>>2]=e;e=J[d+44>>2];J[f+16>>2]=J[d+40>>2];J[f+20>>2]=e;e=f+32|0;m:{if((b|0)==(g|0)){J[a+8>>2]=c;J[a+4>>2]=e;J[a>>2]=f;break m}while(1){f=f-32|0;g=g-32|0;J[f>>2]=J[g>>2];J[f+4>>2]=J[g+4>>2];J[g>>2]=0;J[g+4>>2]=0;h=J[g+28>>2];J[f+24>>2]=J[g+24>>2];J[f+28>>2]=h;h=J[g+20>>2];J[f+16>>2]=J[g+16>>2];J[f+20>>2]=h;h=J[g+12>>2];J[f+8>>2]=J[g+8>>2];J[f+12>>2]=h;if((b|0)!=(g|0)){continue}break}J[a+8>>2]=c;g=J[a+4>>2];J[a+4>>2]=e;b=J[a>>2];J[a>>2]=f;if((b|0)==(g|0)){break m}while(1){g=g-32|0;c=J[g+4>>2];n:{if(!c){break n}e=J[c+4>>2];J[c+4>>2]=e-1;if(e){break n}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((b|0)!=(g|0)){continue}break}}if(!b){break k}$a(b);}f=J[d+4>>2];o:{if(f){while(1){g=f;f=J[g>>2];if(f){continue}break o}}while(1){g=J[d+8>>2];b=J[g>>2]!=(d|0);d=g;if(b){continue}break}}d=g;if((g|0)!=(k|0)){continue}break a}break}g=Z()|0;_b(a);m=J[i+8>>2];}yd(m);da(g|0);B();}B();}yd(J[i+8>>2]);Ua=i+16|0;}function Hb(a,b,c,d,e,f,g,h,i){var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;j=Ua-112|0;Ua=j;k=i&2147483647;a:{b:{m=e&2147483647;l=2147418112;n=!(b|c);if(!(d|m?m-l>>>0<2147549184:n)){p=k-l|0;if(!h&(p|0)==-2147418112?f|g:(p|0)==-2147418112&(h|0)!=0|p>>>0>2147549184){break b}}if(!(!d&(m|0)==2147418112?n:m>>>0<2147418112)){h=d;i=e|32768;f=b;g=c;break a}if(!(!h&(k|0)==2147418112?!(f|g):k>>>0<2147418112)){i=i|32768;break a}if(!(b|d|(m^2147418112|c))){l=d;d=!(b^f|d^h|(c^g|e^i^-2147483648));h=d?0:l;i=d?2147450880:e;f=d?0:b;g=d?0:c;break a}l=f|h;if(!(l|(k^2147418112|g))){break a}if(!(b|d|(c|m))){if(g|k|l){break a}f=b&f;g=c&g;h=d&h;i=e&i;break a}if(f|h|(g|k)){break b}f=b;g=c;h=d;i=e;break a}l=(k|0)==(m|0);s=l&(d|0)==(h|0)?(c|0)==(g|0)&b>>>0>>0|c>>>0>>0:l&d>>>0>>0|k>>>0>m>>>0;n=s;m=n?f:b;p=n?g:c;l=n?i:e;t=l;n=n?h:d;q=l&65535;d=s?d:h;e=s?e:i;r=e;l=e>>>16&32767;o=t>>>16&32767;if(!o){e=!(n|q);i=e;k=e?m:n;e=e<<6;i=S(i?p:q);e=e+((i|0)==32?S(k)+32|0:i)|0;Cb(j+96|0,m,p,n,q,e-15|0);n=J[j+104>>2];q=J[j+108>>2];p=J[j+100>>2];o=16-e|0;m=J[j+96>>2];}f=s?b:f;g=s?c:g;h=d;i=r&65535;if(!l){b=!(d|i);e=b;k=b?f:d;b=b<<6;e=S(e?g:i);b=b+((e|0)==32?S(k)+32|0:e)|0;Cb(j+80|0,f,g,d,i,b-15|0);l=16-b|0;h=J[j+88>>2];i=J[j+92>>2];g=J[j+84>>2];f=J[j+80>>2];}c=i<<3|h>>>29;b=h<<3|g>>>29;c=c|524288;e=q<<3|n>>>29;q=n<<3|p>>>29;h=e;i=r^t;k=g<<3|f>>>29;d=f<<3;c:{if((l|0)==(o|0)){break c}e=o-l|0;if(e>>>0>127){b=0;c=0;k=0;d=1;break c}Cb(j- -64|0,d,k,b,c,128-e|0);xc(j+48|0,d,k,b,c,e);b=J[j+56>>2];c=J[j+60>>2];k=J[j+52>>2];d=J[j+48>>2]|(J[j+64>>2]|J[j+72>>2]|(J[j+68>>2]|J[j+76>>2]))!=0;}n=d;l=k;r=h|524288;k=p<<3|m>>>29;m=m<<3;d:{if((i|0)<0){f=0;g=0;h=0;i=0;if(!(m^n|b^q|(k^l|c^r))){break a}d=m-n|0;e=k-((m>>>0>>0)+l|0)|0;f=q-b|0;g=(k|0)==(l|0)&m>>>0>>0|k>>>0>>0;h=f-g|0;b=(r-((b>>>0>q>>>0)+c|0)|0)-(f>>>0>>0)|0;i=b;if(b>>>0>524287){break d}c=!(b|h);g=c;i=g?d:h;c=g<<6;g=S(g?e:b);c=c+((g|0)==32?S(i)+32|0:g)|0;f=b;b=c-12|0;Cb(j+32|0,d,e,h,f,b);o=o-b|0;h=J[j+40>>2];i=J[j+44>>2];d=J[j+32>>2];e=J[j+36>>2];break d}k=k+l|0;d=m+n|0;e=d>>>0>>0?k+1|0:k;f=(l|0)==(e|0)&d>>>0>>0|e>>>0>>0;k=c+r|0;b=b+q|0;k=b>>>0>>0?k+1|0:k;h=b+f|0;i=h>>>0>>0?k+1|0:k;if(!(i&1048576)){break d}d=n&1|((e&1)<<31|d>>>1);e=h<<31|e>>>1;o=o+1|0;h=(i&1)<<31|h>>>1;i=i>>>1|0;}c=0;b=t&-2147483648;p=b;if((o|0)>=32767){h=c;i=b|2147418112;f=0;g=0;break a}l=0;e:{if((o|0)>0){l=o;break e}Cb(j+16|0,d,e,h,i,o+127|0);xc(j,d,e,h,i,1-o|0);d=J[j>>2]|(J[j+16>>2]|J[j+24>>2]|(J[j+20>>2]|J[j+28>>2]))!=0;e=J[j+4>>2];h=J[j+8>>2];i=J[j+12>>2];}m=d&7;d=(e&7)<<29|d>>>3;f=(m>>>0>4)+d|0;b=h<<29|e>>>3;g=d>>>0>f>>>0?b+1|0:b;d=(b|0)==(g|0)&d>>>0>f>>>0|b>>>0>g>>>0;b=c|((i&7)<<29|h>>>3);h=d+b|0;i=p|(i>>>3&65535|l<<16);i=b>>>0>h>>>0?i+1|0:i;f:{if((m|0)==4){b=0;k=g+b|0;d=f;c=f&1;f=f+c|0;g=d>>>0>f>>>0?k+1|0:k;b=(b|0)==(g|0)&c>>>0>f>>>0|b>>>0>g>>>0;h=b+h|0;i=b>>>0>h>>>0?i+1|0:i;break f}if(!m){break a}}}J[a>>2]=f;J[a+4>>2]=g;J[a+8>>2]=h;J[a+12>>2]=i;Ua=j+112|0;}function rh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=Ua-16|0;Ua=g;a:{f=c-!b|0;if(!((!f&b-1>>>0>15|(f|0)!=0)&(b&c)!=-1)){d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;c=(d>>>0<29?d:e)+1|0;if(c>>>0>(d>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,c+(c>>>1|0)|0);d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;}c=d>>>0<29;H[(c?a+4|0:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))+(c?d:e)|0]=b+80;b=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;break a}if(!(b|c)){d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;b=(d>>>0<29?d:e)+1|0;if(b>>>0>(d>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,b+(b>>>1|0)|0);d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=d-29|0;}b=d>>>0<29;H[(b?a+4|0:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))+(b?d:e)|0]=0;b=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;break a}J[g+12>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;f=b;b=c>>31;f=f^b;h=f-b|0;b=(b^c)-((f>>>0>>0)+b|0)|0;b:{c:{d:{while(1){j=b;k=h;e:{if(d>>>0>>0){H[d|0]=h;f=d;break e}m=d-i|0;h=m+1|0;if((h|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)==1){break d}break b}f=e-i|0;b=f<<1;n=f>>>0>=1073741823?2147483647:b>>>0>h>>>0?b:h;f:{if(!n){h=0;break f}J[5996]=0;h=$(3,n|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break d}}f=h+m|0;H[f|0]=k;if((d|0)==(i|0)){b=f;}else {o=(i^-1)+d|0;l=0;e=f;b=m&3;if(b){while(1){e=e-1|0;d=d-1|0;H[e|0]=K[d|0];l=l+1|0;if((b|0)!=(l|0)){continue}break}}if(o>>>0>=3){while(1){H[e-1|0]=K[d-1|0];H[e-2|0]=K[d-2|0];H[e-3|0]=K[d-3|0];e=e-4|0;d=d-4|0;H[e|0]=K[d|0];if((d|0)!=(i|0)){continue}break}}d=i;b=h;}i=b;e=h+n|0;if(!d){break e}$a(d);}b=j>>>8|0;h=(j&255)<<24|k>>>8;d=f+1|0;if(!j&k>>>0>=256|j){continue}break}J[g+8>>2]=d;J[g+4>>2]=i;J[g+12>>2]=e;g:{h:{i:{b=H[f|0];if((b|0)<0){h=c>>>24&128;if(d>>>0>>0){H[f+1|0]=h;J[g+8>>2]=f+2;break g}k=d-i|0;f=k+1|0;if((f|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)!=1){break b}break d}c=e-i|0;b=c<<1;c=c>>>0>=1073741823?2147483647:b>>>0>f>>>0?b:f;j:{if(!c){f=0;break j}J[5996]=0;f=$(3,c|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break d}}e=f+k|0;H[e|0]=h;j=c+f|0;h=e+1|0;if((d|0)==(i|0)){break i}c=(i^-1)+d|0;b=k&3;if(b){l=0;while(1){e=e-1|0;d=d-1|0;H[e|0]=K[d|0];l=l+1|0;if((b|0)!=(l|0)){continue}break}}if(c>>>0>=3){while(1){H[e-1|0]=K[d-1|0];H[e-2|0]=K[d-2|0];H[e-3|0]=K[d-3|0];e=e-4|0;d=d-4|0;H[e|0]=K[d|0];if((d|0)!=(i|0)){continue}break}}J[g+12>>2]=j;J[g+8>>2]=h;J[g+4>>2]=f;if(!i){break g}break h}if((c|0)>0|(c|0)>=0){break g}H[f|0]=b|128;break g}J[g+12>>2]=j;J[g+8>>2]=h;J[g+4>>2]=e;}$a(i);}J[5996]=0;_(19,a|0,g+4|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[g+4>>2];if(!b){break a}$a(b);break a}d=Z()|0;a=J[g+4>>2];if(!a){break c}$a(a);da(d|0);B();}d=Z()|0;if(!i){break c}$a(i);}da(d|0);B();}B();}Ua=g+16|0;return a|0}function se(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;k=K[b+8|0]|K[b+9|0]<<8|(K[b+10|0]<<16|K[b+11|0]<<24);f=-29;g=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);i=g>>>0<29;a:{g=i?g:g-29|0;if(g>>>0>=29){J[5996]=0;aa(124,a|0,g+(g>>>1|0)|0);f=J[5996];J[5996]=0;if((f|0)==1){break a}e=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);h=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);f=h-29|0;}j=a+4|0;l=h>>>0<29;e=l?j:e;eb(g+e|0,e,l?h:f);f=g+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=f;H[a+1|0]=f>>>8;H[a+2|0]=f>>>16;H[a+3|0]=f>>>24;b:{if(!g){break b}f=i?b+4|0:k;i=g&7;c:{if(!i){b=f;break c}h=0;b=f;while(1){H[e|0]=K[b|0];b=b+1|0;e=e+1|0;h=h+1|0;if((i|0)!=(h|0)){continue}break}}if(g>>>0<8){break b}f=f+g|0;while(1){H[e|0]=K[b|0];H[e+1|0]=K[b+1|0];H[e+2|0]=K[b+2|0];H[e+3|0]=K[b+3|0];H[e+4|0]=K[b+4|0];H[e+5|0]=K[b+5|0];H[e+6|0]=K[b+6|0];H[e+7|0]=K[b+7|0];e=e+8|0;b=b+8|0;if((f|0)!=(b|0)){continue}break}}k=K[c+8|0]|K[c+9|0]<<8|(K[c+10|0]<<16|K[c+11|0]<<24);e=K[c|0]|K[c+1|0]<<8|(K[c+2|0]<<16|K[c+3|0]<<24);h=e>>>0<29;b=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);f=b-29|0;g=h?e:e-29|0;i=b>>>0<29?b:f;e=g+i|0;if(e>>>0>(b>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){J[5996]=0;aa(124,a|0,e+(e>>>1|0)|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);f=b-29|0;}e=j;j=b>>>0<29;e=i+(j?e:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))|0;eb(g+e|0,e,(j?b:f)-i|0);b=g+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;d:{if(!g){break d}c=h?c+4|0:k;f=g&7;e:{if(!f){b=c;break e}h=0;b=c;while(1){H[e|0]=K[b|0];b=b+1|0;e=e+1|0;h=h+1|0;if((f|0)!=(h|0)){continue}break}}if(g>>>0<8){break d}c=c+g|0;while(1){H[e|0]=K[b|0];H[e+1|0]=K[b+1|0];H[e+2|0]=K[b+2|0];H[e+3|0]=K[b+3|0];H[e+4|0]=K[b+4|0];H[e+5|0]=K[b+5|0];H[e+6|0]=K[b+6|0];H[e+7|0]=K[b+7|0];e=e+8|0;b=b+8|0;if((c|0)!=(b|0)){continue}break}}b=J[d>>2];J[5996]=0;_(127,a|0,b|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}return}b=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}da(b|0);B();}function Zn(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=+d;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;f=Ua+-64|0;Ua=f;J[f+40>>2]=0;J[f+32>>2]=0;J[f+36>>2]=0;k=J[c>>2];n=J[c+4>>2];a:{b:{if((k|0)==(n|0)){c=k;break b}c:{d:{while(1){e:{j=J[k>>2];g=J[f+36>>2];f:{if((g|0)!=J[f+40>>2]){J[g>>2]=J[j>>2];i=J[j+4>>2];J[g+4>>2]=i;if(i){J[i+4>>2]=J[i+4>>2]+1;}J[f+36>>2]=g+8;break f}g:{i=J[f+32>>2];h=g-i|0;o=h>>3;l=o+1|0;h:{if(l>>>0>=536870912){J[5996]=0;ca(59);a=J[5996];J[5996]=0;if((a|0)==1){break h}break d}m=h>>2;h=h>>>0>=2147483640?536870911:l>>>0>>0?m:l;if(h>>>0<536870912){break g}J[5996]=0;ca(35);a=J[5996];J[5996]=0;if((a|0)!=1){break d}}g=Z()|0;break a}J[5996]=0;m=h<<3;l=$(3,m|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break e}h=l+(o<<3)|0;J[h>>2]=J[j>>2];j=J[j+4>>2];J[h+4>>2]=j;if(j){J[j+4>>2]=J[j+4>>2]+1;g=J[f+36>>2];}j=l+m|0;l=h+8|0;i:{if((g|0)==(i|0)){J[f+40>>2]=j;J[f+36>>2]=l;J[f+32>>2]=h;break i}while(1){h=h-8|0;g=g-8|0;J[h>>2]=J[g>>2];J[h+4>>2]=J[g+4>>2];J[g>>2]=0;J[g+4>>2]=0;if((g|0)!=(i|0)){continue}break}J[f+40>>2]=j;g=J[f+36>>2];J[f+36>>2]=l;i=J[f+32>>2];J[f+32>>2]=h;if((g|0)==(i|0)){break i}while(1){g=g-8|0;h=J[g+4>>2];j:{if(!h){break j}j=J[h+4>>2];J[h+4>>2]=j-1;if(j){break j}Xa[J[J[h>>2]+8>>2]](h);bb(h);}if((g|0)!=(i|0)){continue}break}}if(!i){break f}$a(i);}k=k+4|0;if((n|0)!=(k|0)){continue}break c}break}g=Z()|0;break a}B();}k=J[c+4>>2];c=J[c>>2];}J[5996]=0;va(63,f+16|0,b|0,c|0,k|0,+d);c=J[5996];J[5996]=0;k:{if((c|0)==1){break k}J[5996]=0;c=$(3,104)|0;k=J[5996];J[5996]=0;if((k|0)==1){break k}J[c>>2]=7e3;J[c+4>>2]=0;J[c+8>>2]=0;J[f+52>>2]=J[f+32>>2];k=J[f+40>>2];g=J[f+36>>2];J[f+40>>2]=0;J[f+56>>2]=g;J[f+60>>2]=k;J[f+32>>2]=0;J[f+36>>2]=0;e=J[e>>2];J[5996]=0;k=ia(64,c+12|0,b|0,f+52|0,e|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[f+52>>2];if(b){g=J[f+56>>2];if((b|0)!=(g|0)){while(1){g=g-8|0;e=J[g+4>>2];l:{if(!e){break l}i=J[e+4>>2];J[e+4>>2]=i-1;if(i){break l}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((b|0)!=(g|0)){continue}break}b=J[f+52>>2];}$a(b);}J[f+48>>2]=c;J[f+44>>2]=k;J[5996]=0;b=J[f+48>>2];J[f+8>>2]=J[f+44>>2];J[f+12>>2]=b;ea(61,a|0,f+16|0,f+8|0);a=J[5996];J[5996]=0;if((a|0)==1){break k}a=J[f+32>>2];if(a){g=J[f+36>>2];if((a|0)!=(g|0)){while(1){g=g-8|0;b=J[g+4>>2];m:{if(!b){break m}c=J[b+4>>2];J[b+4>>2]=c-1;if(c){break m}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((a|0)!=(g|0)){continue}break}a=J[f+32>>2];}$a(a);}Ua=f- -64|0;return}g=Z()|0;lb(f+52|0);$a(c);break a}g=Z()|0;}lb(f+32|0);da(g|0);B();}function $g(a,b,c,d){a=a|0;b=+b;c=+c;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;g=Ua-48|0;Ua=g;a:{b:{if(J[a>>2]==21){j=d+4|0;c:{d:{e:{f:{e=J[d+4>>2];if(!e){break f}f=j;while(1){g:{h:{i:{i=J[e+16>>2];if(i>>>0>>0){break i}if(a>>>0>>0){break h}k=O[e+24>>3];if(k>3]>2];if(e){continue}break}if((f|0)==(j|0)){break f}e=J[f+16>>2];if(e>>>0>a>>>0){break f}j:{if(a>>>0>e>>>0){break j}k=O[f+24>>3];if(k>b){break f}if(b>k){break j}if(O[f+32>>3]>c){break f}}if(O[f+56>>3]!=b){break e}if(O[f- -64>>3]!=c){break d}l=f+40|0;break a}J[g+40>>2]=0;O[g+32>>3]=c;O[g+24>>3]=b;J[g+16>>2]=0;J[g+8>>2]=0;J[g+12>>2]=0;e=J[a+4>>2];if((e|0)==J[a+8>>2]){J[5996]=0;ga(44,4277,1900,673,1984);a=J[5996];J[5996]=0;if((a|0)!=1){break c}break b}e=J[e>>2];J[5996]=0;ea(45,e|0,g+8|0,d|0);e=J[5996];J[5996]=0;if((e|0)==1){break b}k:{l:{e=j;i=J[e>>2];m:{if(!i){break m}while(1){n:{o:{e=i;f=J[e+16>>2];p:{if(f>>>0>a>>>0){break p}if(a>>>0>f>>>0){break n}k=O[e+24>>3];if(k>b){break p}if(b>k){break n}k=O[e+32>>3];if(!(k>c)){break o}}j=e;i=J[e>>2];if(i){continue}break m}if(!(c>k)){break l}}i=J[e+4>>2];if(i){continue}break}j=e+4|0;}J[5996]=0;h=$(3,80)|0;f=J[5996];J[5996]=0;if((f|0)==1){break b}J[h+16>>2]=a;O[h+32>>3]=c;O[h+24>>3]=b;l=h+40|0;J[l>>2]=J[g+8>>2];J[h+44>>2]=J[g+12>>2];J[h+48>>2]=J[g+16>>2];J[g+16>>2]=0;J[g+8>>2]=0;J[g+12>>2]=0;J[h+72>>2]=J[g+40>>2];i=J[g+36>>2];f=h- -64|0;J[f>>2]=J[g+32>>2];J[f+4>>2]=i;f=J[g+28>>2];J[h+56>>2]=J[g+24>>2];J[h+60>>2]=f;J[h+8>>2]=e;J[h>>2]=0;J[h+4>>2]=0;J[j>>2]=h;e=h;f=J[J[d>>2]>>2];if(f){J[d>>2]=f;e=J[j>>2];}zd(J[d+4>>2],e);J[d+8>>2]=J[d+8>>2]+1;j=J[a+4>>2];if(J[a+8>>2]-j>>>0>=5){f=J[h+72>>2];i=1;e=1;while(1){j=J[(e<<2)+j>>2];J[5996]=0;ea(45,j|0,l|0,d|0);j=J[5996];J[5996]=0;if((j|0)==1){break k}j=f;f=J[h+72>>2];i=(j|0)==(f|0)?i:e;e=e+1|0;j=J[a+4>>2];e=(e|0)==J[a+8>>2]-j>>2?1:e;if((i|0)!=(e|0)){continue}break}}d=J[g+8>>2];if(!d){break a}a=J[g+12>>2];if((d|0)!=(a|0)){while(1){a=a-32|0;e=J[a+4>>2];q:{if(!e){break q}f=J[e+4>>2];J[e+4>>2]=f-1;if(f){break q}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((a|0)!=(d|0)){continue}break}d=J[g+8>>2];}$a(d);break a}J[5996]=0;ga(44,2453,1900,676,1984);a=J[5996];J[5996]=0;if((a|0)!=1){break c}break b}break b}la(1940,1900,668,1984);B();}la(1841,1900,669,1984);}B();}la(3430,1900,664,1984);B();}a=Z()|0;_b(g+8|0);da(a|0);B();}Ua=g+48|0;return l|0}function hk(a,b,c,d,e,f,g,h,i){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;j=Ua-1056|0;Ua=j;J[j+16>>2]=f;J[j+20>>2]=g;J[j+24>>2]=h;J[j+28>>2]=i;a=j+944|0;J[j+940>>2]=a;l=od(a,100,2304,j+16|0);J[j+48>>2]=184;n=j+520|0;J[n>>2]=0;J[n+4>>2]=J[j+48>>2];J[j+48>>2]=184;m=j+512|0;J[m>>2]=0;J[m+4>>2]=J[j+48>>2];a:{b:{c:{d:{if(l>>>0<100){h=j+528|0;break d}a=jb();J[j>>2]=f;J[j+4>>2]=g;J[j+8>>2]=h;J[j+12>>2]=i;l=dc(j+940|0,a,2304,j);if((l|0)!=-1){a=J[j+940>>2];tb(n,a);tb(m,sb(l<<2));h=J[m>>2];if(h){break d}}J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break a}l=Z()|0;break c}f=J[d+28>>2];J[j+508>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;r=$(197,J[j+508>>2])|0;f=J[5996];J[5996]=0;e:{f:{g:{h:{i:{j:{if((f|0)==1){break j}J[5996]=0;ga(208,r|0,a|0,a+l|0,h|0);f=J[5996];J[5996]=0;if((f|0)==1){break j}p=(l|0)>0?K[a|0]==45:p;g=j+484|0;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;a=j+472|0;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;f=j+460|0;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;J[5996]=0;sa(238,c|0,p|0,J[j+508>>2],j+504|0,j+500|0,j+496|0,g|0,a|0,f|0,j+456|0);c=J[5996];J[5996]=0;if((c|0)==1){break i}J[j+36>>2]=184;c=j+40|0;J[c>>2]=0;J[c+4>>2]=J[j+36>>2];i=j+48|0;o=J[j+456>>2];k:{if((o|0)<(l|0)){k=K[f+11|0];q=(l-o<<1)+((k&128)>>>7|0?J[f+4>>2]:k&127)|0;k=K[a+11|0];k=(q+((k&128)>>>7|0?J[a+4>>2]:k&127)|0)+1|0;break k}k=K[f+11|0];q=(k&128)>>>7|0?J[f+4>>2]:k&127;k=K[a+11|0];k=(q+((k&128)>>>7|0?J[a+4>>2]:k&127)|0)+2|0;}k=k+o|0;if(k>>>0<101){break h}tb(c,sb(k<<2));i=J[c>>2];if(i){break h}J[5996]=0;ca(185);b=J[5996];J[5996]=0;if((b|0)!=1){break a}break g}l=Z()|0;break e}l=Z()|0;break f}k=J[d+4>>2];J[5996]=0;ta(239,i|0,j+36|0,j+32|0,k|0,h|0,(l<<2)+h|0,r|0,p|0,j+504|0,J[j+500>>2],J[j+496>>2],g|0,a|0,f|0,o|0);h=J[5996];J[5996]=0;if((h|0)!=1){J[5996]=0;d=ka(219,b|0,i|0,J[j+36>>2],J[j+32>>2],d|0,e|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break b}}}l=Z()|0;db(c);}ab(f);ab(a);ab(g);}a=J[j+508>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}db(m);db(n);da(l|0);B();}db(c);ab(f);ab(a);ab(g);a=J[j+508>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(m);db(n);Ua=j+1056|0;return d|0}B();}function ih(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;c=J[a+4>>2];d=J[a+8>>2];if(c>>>0>>0){d=J[b>>2];J[c+12>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;J[c>>2]=d;J[c+4>>2]=J[b+4>>2];J[c+8>>2]=J[b+8>>2];J[c+12>>2]=J[b+12>>2];J[b+12>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[c+24>>2]=0;J[c+16>>2]=0;J[c+20>>2]=0;J[c+16>>2]=J[b+16>>2];J[c+20>>2]=J[b+20>>2];J[c+24>>2]=J[b+24>>2];J[b+24>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[c+36>>2]=0;J[c+28>>2]=0;J[c+32>>2]=0;J[c+28>>2]=J[b+28>>2];J[c+32>>2]=J[b+32>>2];J[c+36>>2]=J[b+36>>2];J[b+36>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[c+48>>2]=0;J[c+40>>2]=0;J[c+44>>2]=0;J[c+40>>2]=J[b+40>>2];J[c+44>>2]=J[b+44>>2];J[c+48>>2]=J[b+48>>2];J[b+48>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[c+52>>2]=J[b+52>>2];J[a+4>>2]=c+56;return}a:{b:{c:{e=J[a>>2];f=(c-e|0)/56|0;c=f+1|0;if(c>>>0<76695845){d=(d-e|0)/56|0;e=d<<1;c=d>>>0>=38347922?76695844:c>>>0>>0?e:c;if(c>>>0>=76695845){break c}d=P(c,56);e=cb(d);c=e+P(f,56)|0;J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[c+8>>2]=J[b+8>>2];J[c+12>>2]=J[b+12>>2];J[b+12>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[c+16>>2]=J[b+16>>2];J[c+20>>2]=J[b+20>>2];J[c+24>>2]=J[b+24>>2];J[b+24>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[c+28>>2]=J[b+28>>2];J[c+32>>2]=J[b+32>>2];J[c+36>>2]=J[b+36>>2];J[b+36>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[c+40>>2]=J[b+40>>2];J[c+44>>2]=J[b+44>>2];J[c+48>>2]=J[b+48>>2];J[b+48>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[c+52>>2]=J[b+52>>2];d=d+e|0;e=c+56|0;b=J[a+4>>2];f=J[a>>2];if((b|0)==(f|0)){break b}while(1){c=c-56|0;b=b-56|0;J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[c+8>>2]=J[b+8>>2];J[c+12>>2]=J[b+12>>2];J[b+12>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[c+16>>2]=J[b+16>>2];J[c+20>>2]=J[b+20>>2];J[c+24>>2]=J[b+24>>2];J[b+24>>2]=0;J[b+16>>2]=0;J[b+20>>2]=0;J[c+28>>2]=J[b+28>>2];J[c+32>>2]=J[b+32>>2];J[c+36>>2]=J[b+36>>2];J[b+36>>2]=0;J[b+28>>2]=0;J[b+32>>2]=0;J[c+40>>2]=J[b+40>>2];J[c+44>>2]=J[b+44>>2];J[c+48>>2]=J[b+48>>2];J[b+48>>2]=0;J[b+40>>2]=0;J[b+44>>2]=0;J[c+52>>2]=J[b+52>>2];if((b|0)!=(f|0)){continue}break}J[a+8>>2]=d;d=J[a+4>>2];J[a+4>>2]=e;b=J[a>>2];J[a>>2]=c;if((b|0)==(d|0)){break a}while(1){d=Fb(d-56|0);if((d|0)!=(b|0)){continue}break}break a}nb();B();}Pb();B();}J[a+8>>2]=d;J[a+4>>2]=e;J[a>>2]=c;}if(b){$a(b);}}function lk(a,b,c,d,e,f,g,h,i){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;j=Ua-448|0;Ua=j;J[j+16>>2]=f;J[j+20>>2]=g;J[j+24>>2]=h;J[j+28>>2]=i;a=j+336|0;J[j+332>>2]=a;l=od(a,100,2304,j+16|0);J[j+48>>2]=184;n=j+216|0;J[n>>2]=0;J[n+4>>2]=J[j+48>>2];J[j+48>>2]=184;m=j+208|0;J[m>>2]=0;J[m+4>>2]=J[j+48>>2];a:{b:{c:{d:{if(l>>>0<100){h=j+224|0;break d}a=jb();J[j>>2]=f;J[j+4>>2]=g;J[j+8>>2]=h;J[j+12>>2]=i;l=dc(j+332|0,a,2304,j);if((l|0)!=-1){a=J[j+332>>2];tb(n,a);tb(m,sb(l));h=J[m>>2];if(h){break d}}J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break a}l=Z()|0;break c}f=J[d+28>>2];J[j+204>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;r=$(170,J[j+204>>2])|0;f=J[5996];J[5996]=0;e:{f:{g:{h:{i:{j:{if((f|0)==1){break j}J[5996]=0;ga(195,r|0,a|0,a+l|0,h|0);f=J[5996];J[5996]=0;if((f|0)==1){break j}p=(l|0)>0?K[a|0]==45:p;g=j+184|0;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;a=j+172|0;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;f=j+160|0;J[f>>2]=0;J[f+4>>2]=0;J[f+8>>2]=0;J[5996]=0;sa(236,c|0,p|0,J[j+204>>2],j+200|0,j+199|0,j+198|0,g|0,a|0,f|0,j+156|0);c=J[5996];J[5996]=0;if((c|0)==1){break i}J[j+36>>2]=184;c=j+40|0;J[c>>2]=0;J[c+4>>2]=J[j+36>>2];i=j+48|0;o=J[j+156>>2];k:{if((o|0)<(l|0)){k=K[f+11|0];q=(l-o<<1)+((k&128)>>>7|0?J[f+4>>2]:k&127)|0;k=K[a+11|0];k=(q+((k&128)>>>7|0?J[a+4>>2]:k&127)|0)+1|0;break k}k=K[f+11|0];q=(k&128)>>>7|0?J[f+4>>2]:k&127;k=K[a+11|0];k=(q+((k&128)>>>7|0?J[a+4>>2]:k&127)|0)+2|0;}k=k+o|0;if(k>>>0<101){break h}tb(c,sb(k));i=J[c>>2];if(i){break h}J[5996]=0;ca(185);b=J[5996];J[5996]=0;if((b|0)!=1){break a}break g}l=Z()|0;break e}l=Z()|0;break f}k=J[d+4>>2];J[5996]=0;ta(237,i|0,j+36|0,j+32|0,k|0,h|0,h+l|0,r|0,p|0,j+200|0,H[j+199|0],H[j+198|0],g|0,a|0,f|0,o|0);h=J[5996];J[5996]=0;if((h|0)!=1){J[5996]=0;d=ka(213,b|0,i|0,J[j+36>>2],J[j+32>>2],d|0,e|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break b}}}l=Z()|0;db(c);}ab(f);ab(a);ab(g);}a=J[j+204>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}db(m);db(n);da(l|0);B();}db(c);ab(f);ab(a);ab(g);a=J[j+204>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(m);db(n);Ua=j+448|0;return d|0}B();}function Vn(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=+e;var f=0,g=0,h=0,i=0,j=0;a:{b:{if(!(b-19>>>0>=7&e!=0)){f=1-e;c:{switch(b|0){case 24:if((c|0)!=(d|0)){while(1){b=J[c>>2];h=h+O[b+8>>3];g=g+O[b+16>>3];c=c+4|0;if((d|0)!=(c|0)){continue}break}}O[a+8>>3]=g;O[a>>3]=(f==0?0:f*g)+(e==0?0:h*e);return;case 3:J[a+8>>2]=0;J[a+12>>2]=1078034432;J[a>>2]=0;J[a+4>>2]=1079689216;return;case 6:case 7:case 8:case 9:J[a+8>>2]=0;J[a+12>>2]=1077968896;J[a>>2]=0;J[a+4>>2]=1077968896;return;case 10:case 11:case 12:case 16:b=J[c>>2];c=J[b+12>>2];J[a>>2]=J[b+8>>2];J[a+4>>2]=c;c=J[b+20>>2];J[a+8>>2]=J[b+16>>2];J[a+12>>2]=c;return;case 13:e=O[J[c>>2]+8>>3];J[a+8>>2]=0;J[a+12>>2]=1072693248;O[a>>3]=e+2;return;case 14:e=O[J[c>>2]+8>>3];J[a+8>>2]=0;J[a+12>>2]=2146435072;O[a>>3]=e;return;case 15:e=O[J[c>>2]+8>>3];J[a+8>>2]=0;J[a+12>>2]=1072693248;O[a>>3]=e;return;case 0:J[a+8>>2]=0;J[a+12>>2]=0;J[a>>2]=0;J[a+4>>2]=2146435072;return;case 17:e=O[J[c+4>>2]+8>>3];f=O[J[c>>2]+8>>3];J[a+8>>2]=0;J[a+12>>2]=2146435072;O[a>>3]=f+e;return;case 18:b=J[c+4>>2];e=O[b+16>>3];c=J[c>>2];f=O[c+16>>3];O[a>>3]=O[c+8>>3]+O[b+8>>3];O[a+8>>3]=f+e;return;case 19:b=J[c>>2];g=O[b+8>>3];c=J[c+4>>2];h=O[c+8>>3];i=O[c+16>>3];j=O[b+16>>3];O[a+8>>3]=i+j;O[a>>3]=(e==0?0:(g+i)*e)+(f==0?0:f*(j+h));return;case 20:case 21:b=J[c+4>>2];g=O[b+8>>3];c=J[c>>2];h=O[c+8>>3];i=O[c+16>>3];O[a+8>>3]=i+O[b+16>>3];O[a>>3]=(e==0?0:h*e)+(f==0?0:f*(i+g));return;case 22:b=J[c>>2];g=O[b+8>>3];c=J[c+4>>2];h=O[c+8>>3];i=O[c+16>>3]+1;j=O[b+16>>3]+2;O[a+8>>3]=i>3]=(e==0?0:(g+2)*e)+(f==0?0:f*(h+1));return;case 23:b=J[c+8>>2];g=O[b+8>>3];h=O[J[c+4>>2]+8>>3];c=J[c>>2];i=O[c+8>>3];j=O[c+16>>3];O[a+8>>3]=j+O[b+16>>3];O[a>>3]=(e==0?0:(i+h)*e)+(f==0?0:f*(j+g));return;default:a=Rb(8);J[5996]=0;b=_(91,a|0,1318)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break b}b=Z()|0;ic(a);da(b|0);B();case 1:case 4:case 5:break a;case 2:break c}}J[a+8>>2]=0;J[a+12>>2]=1072693248;J[a>>2]=0;J[a+4>>2]=1079132160;return}la(4323,1900,476,1746);B();}na(b|0,22664,92);B();}J[a+8>>2]=0;J[a+12>>2]=2146435072;J[a>>2]=0;J[a+4>>2]=0;}function Hg(a,b,c,d,e,f,g,h,i){var j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;j=Ua-128|0;Ua=j;a:{b:{c:{if(!yc(f,g,h,i,0,0,0,0)){break c}k=i&65535;n=i>>>16&32767;d:{e:{if((n|0)!=32767){l=4;if(n){break e}l=f|h|(g|k)?3:2;break d}l=!(f|h|(g|k));}}s=e>>>16|0;o=s&32767;if((o|0)==32767){break c}if(l){break b}}ob(j+16|0,b,c,d,e,f,g,h,i);b=J[j+16>>2];d=J[j+20>>2];e=J[j+24>>2];c=J[j+28>>2];Ng(j,b,d,e,c,b,d,e,c);d=J[j+8>>2];e=J[j+12>>2];h=J[j>>2];i=J[j+4>>2];break a}l=d;p=e&2147483647;k=p;n=h;m=i&2147483647;if((yc(b,c,l,k,f,g,h,m)|0)<=0){if(yc(b,c,l,k,f,g,h,m)){h=b;i=c;break a}ob(j+112|0,b,c,d,e,0,0,0,0);d=J[j+120>>2];e=J[j+124>>2];h=J[j+112>>2];i=J[j+116>>2];break a}q=i>>>16&32767;if(o){i=c;h=b;}else {ob(j+96|0,b,c,l,p,0,0,0,1081540608);l=J[j+104>>2];h=J[j+108>>2];p=h;o=(h>>>16|0)-120|0;i=J[j+100>>2];h=J[j+96>>2];}if(!q){ob(j+80|0,f,g,n,m,0,0,0,1081540608);n=J[j+88>>2];f=J[j+92>>2];m=f;q=(f>>>16|0)-120|0;g=J[j+84>>2];f=J[j+80>>2];}r=n;t=m&65535|65536;p=p&65535|65536;if((o|0)>(q|0)){while(1){m=l-r|0;k=(g|0)==(i|0)&f>>>0>h>>>0|g>>>0>i>>>0;n=m-k|0;k=(p-((l>>>0>>0)+t|0)|0)-(k>>>0>m>>>0)|0;f:{if((k|0)>0|(k|0)>=0){l=h;h=h-f|0;i=i-((f>>>0>l>>>0)+g|0)|0;if(!(h|n|(i|k))){ob(j+32|0,b,c,d,e,0,0,0,0);d=J[j+40>>2];e=J[j+44>>2];h=J[j+32>>2];i=J[j+36>>2];break a}k=k<<1|n>>>31;l=n<<1|i>>>31;break f}k=p<<1|l>>>31;l=l<<1|i>>>31;}p=k;k=i<<1|h>>>31;h=h<<1;i=k;o=o-1|0;if((o|0)>(q|0)){continue}break}o=q;}m=l-r|0;k=(g|0)==(i|0)&f>>>0>h>>>0|g>>>0>i>>>0;n=m-k|0;k=(p-((l>>>0>>0)+t|0)|0)-(k>>>0>m>>>0)|0;m=k;g:{if((k|0)<0){n=l;m=p;break g}l=h;h=h-f|0;i=i-((f>>>0>l>>>0)+g|0)|0;if(h|n|(i|m)){break g}ob(j+48|0,b,c,d,e,0,0,0,0);d=J[j+56>>2];e=J[j+60>>2];h=J[j+48>>2];i=J[j+52>>2];break a}if((m|0)==65535|m>>>0<65535){while(1){b=i>>>31|0;o=o-1|0;p=i<<1|h>>>31;h=h<<1;i=p;c=b;b=m<<1|n>>>31;n=c|n<<1;m=b;if(b>>>0<65536){continue}break}}b=s&32768;if((o|0)<=0){ob(j- -64|0,h,i,n,m&65535|(b|o+120)<<16,0,0,0,1065811968);d=J[j+72>>2];e=J[j+76>>2];h=J[j+64>>2];i=J[j+68>>2];break a}d=n;e=m&65535|(b|o)<<16;}J[a>>2]=h;J[a+4>>2]=i;J[a+8>>2]=d;J[a+12>>2]=e;Ua=j+128|0;}function tn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0;h=J[b>>2];f=K[b+11|0];g=f<<24>>24;c=(g|0)<0;i=J[b+4>>2];d=c?i:f;a:{if((d|0)<9){break a}f=c?h:b;e=f+d|0;while(1){c=f;while(1){c=Zb(c,115,d-8|0);if(!c){break a}if(Eb(c,4824,9)){c=c+1|0;d=e-c|0;if((d|0)>=9){continue}break a}break}if((c|0)==(e|0)){break a}c=c-f|0;if((c|0)==-1){break a}Lc(b,c,9,5034);h=J[b>>2];c=K[b+11|0];g=c<<24>>24;e=(g|0)<0;f=e?h:b;i=J[b+4>>2];d=e?i:c;e=f+d|0;if((d|0)>8){continue}break}}c=g<<24>>24;d=(c|0)<0?i:g&255;b:{if((d|0)<10){break b}f=(c|0)<0?h:b;e=f+d|0;while(1){c=f;while(1){c=Zb(c,104,d-9|0);if(!c){break b}if(Eb(c,4813,10)){c=c+1|0;d=e-c|0;if((d|0)>=10){continue}break b}break}if((c|0)==(e|0)){break b}c=c-f|0;if((c|0)==-1){break b}Lc(b,c,10,4960);h=J[b>>2];c=K[b+11|0];g=c<<24>>24;e=(g|0)<0;f=e?h:b;i=J[b+4>>2];d=e?i:c;e=f+d|0;if((d|0)>9){continue}break}}c=g<<24>>24<0;d=c?i:g&255;c:{if((d|0)<12){break c}f=c?h:b;e=f+d|0;while(1){c=f;while(1){c=Zb(c,114,d-11|0);if(!c){break c}if(Eb(c,4845,12)){c=c+1|0;d=e-c|0;if((d|0)>=12){continue}break c}break}if((c|0)==(e|0)){break c}c=c-f|0;if((c|0)==-1){break c}Lc(b,c,12,4908);h=J[b>>2];c=K[b+11|0];g=c<<24>>24;e=(g|0)<0;f=e?h:b;i=J[b+4>>2];d=e?i:c;e=f+d|0;if((d|0)>11){continue}break}}c=g<<24>>24;d=(c|0)<0?i:g&255;d:{if((d|0)<10){break d}f=(c|0)<0?h:b;e=f+d|0;while(1){c=f;while(1){c=Zb(c,104,d-9|0);if(!c){break d}if(Eb(c,4834,10)){c=c+1|0;d=e-c|0;if((d|0)>=10){continue}break d}break}if((c|0)==(e|0)){break d}c=c-f|0;if((c|0)==-1){break d}Lc(b,c,10,4858);h=J[b>>2];c=K[b+11|0];g=c<<24>>24;e=(g|0)<0;f=e?h:b;i=J[b+4>>2];d=e?i:c;e=f+d|0;if((d|0)>9){continue}break}}c=g<<24>>24<0;d=c?i:g&255;e:{if((d|0)<=0){break e}e=c?h:b;g=e+d|0;while(1){c=e;while(1){c=Zb(c,32,d);if(!c){break e}if(K[c|0]!=32){c=c+1|0;d=g-c|0;if((d|0)>0){continue}break e}break}if((c|0)==(g|0)){break e}c=c-e|0;if((c|0)==-1){break e}Lc(b,c,1,5575);c=K[b+11|0];f=c<<24>>24<0;e=f?J[b>>2]:b;d=f?J[b+4>>2]:c;g=e+d|0;if((d|0)>0){continue}break}}c=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=c;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;} +function Sk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;k=Ua-16|0;Ua=k;l=je(J[g>>2]);o=Zd(J[g>>2]);g=o;Xa[J[J[g>>2]+20>>2]](k+4|0,g);J[f>>2]=d;a:{b:{c:{i=a;g=K[i|0];switch(g-43|0){case 0:case 2:break c;default:break b}}J[5996]=0;g=_(216,l|0,g<<24>>24)|0;i=J[5996];J[5996]=0;if((i|0)==1){break a}i=J[f>>2];J[f>>2]=i+4;J[i>>2]=g;i=a+1|0;}d:{g=i;if(!((c-g|0)<=1|K[g|0]!=48|(K[g+1|0]|32)!=120)){J[5996]=0;i=_(216,l|0,48)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+4;J[h>>2]=i;i=H[g+1|0];J[5996]=0;i=_(216,l|0,i|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+4;J[h>>2]=i;i=g+2|0;g=i;while(1){if(c>>>0<=g>>>0){break d}h=H[g|0];jb();if(!(h-48>>>0<10|(h|32)-97>>>0<6)){break d}g=g+1|0;continue}}while(1){if(c>>>0<=g>>>0){break d}h=H[g|0];jb();if(h-48>>>0>=10){break d}g=g+1|0;continue}}e:{h=K[k+15|0];if(!((h&128)>>>7|0?J[k+8>>2]:h&127)){h=J[f>>2];J[5996]=0;ga(208,l|0,i|0,g|0,h|0);h=J[5996];J[5996]=0;if((h|0)==1){break a}J[f>>2]=J[f>>2]+(g-i<<2);break e}vc(i,g);J[5996]=0;q=$(206,o|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=i;while(1){if(g>>>0<=h>>>0){md((i-a<<2)+d|0,J[f>>2]);break e}j=k+4|0;m=(K[j+11|0]&128)>>>7|0;if(!(H[(m?J[j>>2]:j)+n|0]<=0|H[(m?J[j>>2]:j)+n|0]!=(p|0))){j=J[f>>2];J[f>>2]=j+4;J[j>>2]=q;p=0;j=K[k+15|0];n=(((j&128)>>>7|0?J[k+8>>2]:j&127)-1>>>0>n>>>0)+n|0;}j=H[h|0];J[5996]=0;j=_(216,l|0,j|0)|0;m=J[5996];J[5996]=0;if((m|0)!=1){m=J[f>>2];J[f>>2]=m+4;J[m>>2]=j;h=h+1|0;p=p+1|0;continue}break}break a}f:{while(1){if(c>>>0>g>>>0){i=K[g|0];if((i|0)==46){J[5996]=0;i=$(209,o|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}j=J[f>>2];h=j+4|0;J[f>>2]=h;J[j>>2]=i;g=g+1|0;break f}J[5996]=0;i=_(216,l|0,i<<24>>24)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+4;J[h>>2]=i;g=g+1|0;continue}break}h=J[f>>2];}J[5996]=0;ga(208,l|0,g|0,c|0,h|0);i=J[5996];J[5996]=0;if((i|0)==1){break a}i=f;f=J[f>>2]+(c-g<<2)|0;J[i>>2]=f;J[e>>2]=(b|0)==(c|0)?f:(b-a<<2)+d|0;ab(k+4|0);Ua=k+16|0;return}a=Z()|0;ab(k+4|0);da(a|0);B();}function bl(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;k=Ua-16|0;Ua=k;l=le(J[g>>2]);o=de(J[g>>2]);g=o;Xa[J[J[g>>2]+20>>2]](k+4|0,g);J[f>>2]=d;a:{b:{c:{i=a;g=K[i|0];switch(g-43|0){case 0:case 2:break c;default:break b}}J[5996]=0;g=_(171,l|0,g<<24>>24)|0;i=J[5996];J[5996]=0;if((i|0)==1){break a}i=J[f>>2];J[f>>2]=i+1;H[i|0]=g;i=a+1|0;}d:{g=i;if(!((c-g|0)<=1|K[g|0]!=48|(K[g+1|0]|32)!=120)){J[5996]=0;i=_(171,l|0,48)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;i=H[g+1|0];J[5996]=0;i=_(171,l|0,i|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;i=g+2|0;g=i;while(1){if(c>>>0<=g>>>0){break d}h=H[g|0];jb();if(!(h-48>>>0<10|(h|32)-97>>>0<6)){break d}g=g+1|0;continue}}while(1){if(c>>>0<=g>>>0){break d}h=H[g|0];jb();if(h-48>>>0>=10){break d}g=g+1|0;continue}}e:{h=K[k+15|0];if(!((h&128)>>>7|0?J[k+8>>2]:h&127)){h=J[f>>2];J[5996]=0;ga(195,l|0,i|0,g|0,h|0);h=J[5996];J[5996]=0;if((h|0)==1){break a}J[f>>2]=J[f>>2]+(g-i|0);break e}vc(i,g);J[5996]=0;q=$(193,o|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=i;while(1){if(g>>>0<=h>>>0){vc((i-a|0)+d|0,J[f>>2]);break e}j=k+4|0;m=(K[j+11|0]&128)>>>7|0;if(!(H[(m?J[j>>2]:j)+n|0]<=0|H[(m?J[j>>2]:j)+n|0]!=(p|0))){j=J[f>>2];J[f>>2]=j+1;H[j|0]=q;p=0;j=K[k+15|0];n=(((j&128)>>>7|0?J[k+8>>2]:j&127)-1>>>0>n>>>0)+n|0;}j=H[h|0];J[5996]=0;j=_(171,l|0,j|0)|0;m=J[5996];J[5996]=0;if((m|0)!=1){m=J[f>>2];J[f>>2]=m+1;H[m|0]=j;h=h+1|0;p=p+1|0;continue}break}break a}while(1){f:{if(c>>>0>g>>>0){i=K[g|0];if((i|0)!=46){break f}J[5996]=0;i=$(196,o|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;g=g+1|0;}i=J[f>>2];J[5996]=0;ga(195,l|0,g|0,c|0,i|0);i=J[5996];J[5996]=0;if((i|0)==1){break a}i=f;f=J[f>>2]+(c-g|0)|0;J[i>>2]=f;J[e>>2]=(b|0)==(c|0)?f:(b-a|0)+d|0;ab(k+4|0);Ua=k+16|0;return}J[5996]=0;i=_(171,l|0,i<<24>>24)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;g=g+1|0;continue}}a=Z()|0;ab(k+4|0);da(a|0);B();}function bg(a,b,c,d){var e=0,f=0,g=0,h=0,i=0;e=J[b>>2];a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{if(!d){break l}g=J[d>>2];if(!g){break l}if(!a){d=c;break j}J[d>>2]=0;d=c;break k}m:{if(!J[J[6178]>>2]){if(!a){break m}if(!c){break a}g=c;while(1){d=H[e|0];if(d){J[a>>2]=d&57343;a=a+4|0;e=e+1|0;g=g-1|0;if(g){continue}break a}break}J[a>>2]=0;J[b>>2]=0;return c-g|0}d=c;if(!a){break i}break g}return Gb(e)}f=1;break g}f=0;break h}f=1;}while(1){if(!f){f=K[e|0]>>>3|0;if((f-16|f+(g>>26))>>>0>7){break f}f=e+1|0;n:{if(!(g&33554432)){break n}if((K[f|0]&192)!=128){e=e-1|0;break d}f=e+2|0;if(!(g&524288)){break n}if((K[f|0]&192)!=128){e=e-1|0;break d}f=e+3|0;}e=f;d=d-1|0;f=1;continue}while(1){g=K[e|0];o:{if(e&3|g-1>>>0>126){break o}g=J[e>>2];if((g|g-16843009)&-2139062144){break o}while(1){d=d-4|0;g=J[e+4>>2];e=e+4|0;if(!((g-16843009|g)&-2139062144)){continue}break}}f=g&255;if(f-1>>>0<=126){d=d-1|0;e=e+1|0;continue}break}f=f-194|0;if(f>>>0>50){break e}e=e+1|0;g=J[(f<<2)+12208>>2];f=0;continue}}while(1){if(!f){if(!d){break a}while(1){p:{f=K[e|0];h=f-1|0;q:{r:{if(h>>>0>126){g=f;break r}if(e&3|d>>>0<5){break q}s:{while(1){g=J[e>>2];if((g|g-16843009)&-2139062144){break s}J[a>>2]=g&255;J[a+4>>2]=K[e+1|0];J[a+8>>2]=K[e+2|0];J[a+12>>2]=K[e+3|0];a=a+16|0;e=e+4|0;d=d-4|0;if(d>>>0>4){continue}break}g=K[e|0];}f=g&255;h=f-1|0;}if(h>>>0>126){break p}}J[a>>2]=f;a=a+4|0;e=e+1|0;d=d-1|0;if(d){continue}break a}break}f=f-194|0;if(f>>>0>50){break e}e=e+1|0;g=J[(f<<2)+12208>>2];f=1;continue}i=K[e|0];f=i>>>3|0;if((f-16|f+(g>>26))>>>0>7){break f}t:{u:{h=e+1|0;f=i-128|g<<6;v:{if((f|0)>=0){break v}i=K[h|0]-128|0;if(i>>>0>63){break u}h=e+2|0;f=i|f<<6;if((f|0)>=0){break v}h=K[h|0]-128|0;if(h>>>0>63){break u}f=h|f<<6;h=e+3|0;}e=h;J[a>>2]=f;d=d-1|0;a=a+4|0;break t}J[5732]=25;e=e-1|0;break c}f=0;continue}}e=e-1|0;if(g){break d}g=K[e|0];}if(g&255){break d}if(a){J[a>>2]=0;J[b>>2]=0;}return c-d|0}J[5732]=25;if(!a){break b}}J[b>>2]=e;}return -1}J[b>>2]=e;return c}function ul(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;a=Ua-256|0;Ua=a;J[a+248>>2]=c;J[a+252>>2]=b;h=a+196|0;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;g=a+16|0;b=J[d+28>>2];J[g>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(170,J[a+16>>2])|0;c=J[5996];J[5996]=0;a:{b:{if((c|0)==1){break b}J[5996]=0;ga(195,b|0,12416,12442,a+208|0);b=J[5996];J[5996]=0;if((b|0)==1){break b}b=J[a+16>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}c=a+184|0;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;b=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,b|0);b=J[5996];J[5996]=0;if((b|0)!=1){c:{b=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;J[a+180>>2]=b;J[a+12>>2]=g;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+252|0,a+248|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break d}d=J[a+180>>2];e:{if(!g){g=d;d=K[c+11|0];d=(d&128)>>>7|0?J[c+4>>2]:d&127;if((g|0)==(d+b|0)){J[5996]=0;aa(172,c|0,d<<1);b=J[5996];J[5996]=0;if((b|0)==1){break c}b=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break c}b=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;J[a+180>>2]=d+b;}J[5996]=0;d=$(187,J[a+252>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(!Dc(d,16,b,a+180|0,a+8|0,0,J[h+4>>2],K[h+11|0],a+16|0,a+12|0,a+208|0)){break e}d=J[a+180>>2];}J[5996]=0;aa(172,c|0,d-b|0);b=J[5996];J[5996]=0;if((b|0)==1){break d}b=J[c>>2];d=(K[c+11|0]&128)>>>7|0;g=jb();J[a>>2]=f;if((Kf(d?b:c,g,a)|0)!=1){J[e>>2]=4;}J[5996]=0;b=_(186,a+252|0,a+248|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break d}if(b){J[e>>2]=J[e>>2]|2;}b=J[a+252>>2];ab(c);ab(h);Ua=a+256|0;return b|0}J[5996]=0;$(189,a+252|0)|0;d=J[5996];J[5996]=0;if((d|0)!=1){continue}}break}}}b=Z()|0;ab(c);break a}b=Z()|0;a=J[a+16>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}ab(h);da(b|0);B();}function jl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;a=Ua-320|0;Ua=a;J[a+312>>2]=c;J[a+316>>2]=b;h=a+196|0;J[h>>2]=0;J[h+4>>2]=0;J[h+8>>2]=0;g=a+16|0;b=J[d+28>>2];J[g>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(197,J[a+16>>2])|0;c=J[5996];J[5996]=0;a:{b:{if((c|0)==1){break b}J[5996]=0;ga(208,b|0,12416,12442,a+208|0);b=J[5996];J[5996]=0;if((b|0)==1){break b}b=J[a+16>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}c=a+184|0;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;b=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,b|0);b=J[5996];J[5996]=0;if((b|0)!=1){c:{b=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;J[a+180>>2]=b;J[a+12>>2]=g;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+316|0,a+312|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break d}d=J[a+180>>2];e:{if(!g){g=d;d=K[c+11|0];d=(d&128)>>>7|0?J[c+4>>2]:d&127;if((g|0)==(d+b|0)){J[5996]=0;aa(172,c|0,d<<1);b=J[5996];J[5996]=0;if((b|0)==1){break c}b=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break c}b=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;J[a+180>>2]=d+b;}J[5996]=0;d=$(203,J[a+316>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(!Cc(d,16,b,a+180|0,a+8|0,0,J[h+4>>2],K[h+11|0],a+16|0,a+12|0,a+208|0)){break e}d=J[a+180>>2];}J[5996]=0;aa(172,c|0,d-b|0);b=J[5996];J[5996]=0;if((b|0)==1){break d}b=J[c>>2];d=(K[c+11|0]&128)>>>7|0;g=jb();J[a>>2]=f;if((Kf(d?b:c,g,a)|0)!=1){J[e>>2]=4;}J[5996]=0;b=_(202,a+316|0,a+312|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break d}if(b){J[e>>2]=J[e>>2]|2;}b=J[a+316>>2];ab(c);ab(h);Ua=a+320|0;return b|0}J[5996]=0;$(205,a+316|0)|0;d=J[5996];J[5996]=0;if((d|0)!=1){continue}}break}}}b=Z()|0;ab(c);break a}b=Z()|0;a=J[a+16>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}ab(h);da(b|0);B();}function ek(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=Ua-480|0;Ua=a;g=J[d+28>>2];J[a+476>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;o=$(197,J[a+476>>2])|0;g=J[5996];J[5996]=0;a:{b:{c:{d:{e:{if((g|0)!=1){i=K[f+11|0];g=(i&128)>>>7|0;if(g?J[f+4>>2]:i&127){g=J[(g?J[f>>2]:f)>>2];J[5996]=0;i=_(216,o|0,45)|0;k=J[5996];J[5996]=0;if((k|0)==1){break e}p=(g|0)==(i|0);}k=a+452|0;J[k>>2]=0;J[k+4>>2]=0;J[k+8>>2]=0;g=a+440|0;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;i=a+428|0;J[i>>2]=0;J[i+4>>2]=0;J[i+8>>2]=0;J[5996]=0;sa(238,c|0,p|0,J[a+476>>2],a+472|0,a+468|0,a+464|0,k|0,g|0,i|0,a+424|0);c=J[5996];J[5996]=0;if((c|0)==1){break d}J[a+4>>2]=184;l=a+8|0;J[l>>2]=0;J[l+4>>2]=J[a+4>>2];c=a+16|0;j=K[f+11|0];j=(j&128)>>>7|0?J[f+4>>2]:j&127;m=J[a+424>>2];f:{if((j|0)>(m|0)){h=K[i+11|0];n=(j-m<<1)+((h&128)>>>7|0?J[i+4>>2]:h&127)|0;h=K[g+11|0];h=(n+((h&128)>>>7|0?J[g+4>>2]:h&127)|0)+1|0;break f}h=K[i+11|0];n=(h&128)>>>7|0?J[i+4>>2]:h&127;h=K[g+11|0];h=(n+((h&128)>>>7|0?J[g+4>>2]:h&127)|0)+2|0;}g:{h=h+m|0;if(h>>>0>=101){tb(l,sb(h<<2));c=J[l>>2];if(!c){break g}j=K[f+11|0];j=(j&128)>>>7|0?J[f+4>>2]:j&127;}h=J[d+4>>2];f=(K[f+11|0]&128)>>>7|0?J[f>>2]:f;J[5996]=0;ta(239,c|0,a+4|0,a|0,h|0,f|0,f+(j<<2)|0,o|0,p|0,a+472|0,J[a+468>>2],J[a+464>>2],k|0,g|0,i|0,m|0);f=J[5996];J[5996]=0;if((f|0)==1){break c}J[5996]=0;d=ka(219,b|0,c|0,J[a+4>>2],J[a>>2],d|0,e|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break c}db(l);ab(i);ab(g);ab(k);b=J[a+476>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Ua=a+480|0;return d|0}J[5996]=0;ca(185);b=J[5996];J[5996]=0;if((b|0)==1){break c}B();}f=Z()|0;break a}f=Z()|0;break a}f=Z()|0;break b}f=Z()|0;db(l);}ab(i);ab(g);ab(k);}a=J[a+476>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(f|0);B();}function ik(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=Ua-176|0;Ua=a;g=J[d+28>>2];J[a+172>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;o=$(170,J[a+172>>2])|0;g=J[5996];J[5996]=0;a:{b:{c:{d:{e:{if((g|0)!=1){i=K[f+11|0];g=(i&128)>>>7|0;if(g?J[f+4>>2]:i&127){g=K[(g?J[f>>2]:f)|0];J[5996]=0;i=_(171,o|0,45)|0;k=J[5996];J[5996]=0;if((k|0)==1){break e}p=(i&255)==(g|0);}k=a+152|0;J[k>>2]=0;J[k+4>>2]=0;J[k+8>>2]=0;g=a+140|0;J[g>>2]=0;J[g+4>>2]=0;J[g+8>>2]=0;i=a+128|0;J[i>>2]=0;J[i+4>>2]=0;J[i+8>>2]=0;J[5996]=0;sa(236,c|0,p|0,J[a+172>>2],a+168|0,a+167|0,a+166|0,k|0,g|0,i|0,a+124|0);c=J[5996];J[5996]=0;if((c|0)==1){break d}J[a+4>>2]=184;l=a+8|0;J[l>>2]=0;J[l+4>>2]=J[a+4>>2];c=a+16|0;j=K[f+11|0];j=(j&128)>>>7|0?J[f+4>>2]:j&127;m=J[a+124>>2];f:{if((j|0)>(m|0)){h=K[i+11|0];n=(j-m<<1)+((h&128)>>>7|0?J[i+4>>2]:h&127)|0;h=K[g+11|0];h=(n+((h&128)>>>7|0?J[g+4>>2]:h&127)|0)+1|0;break f}h=K[i+11|0];n=(h&128)>>>7|0?J[i+4>>2]:h&127;h=K[g+11|0];h=(n+((h&128)>>>7|0?J[g+4>>2]:h&127)|0)+2|0;}g:{h=h+m|0;if(h>>>0>=101){tb(l,sb(h));c=J[l>>2];if(!c){break g}j=K[f+11|0];j=(j&128)>>>7|0?J[f+4>>2]:j&127;}h=J[d+4>>2];f=(K[f+11|0]&128)>>>7|0?J[f>>2]:f;J[5996]=0;ta(237,c|0,a+4|0,a|0,h|0,f|0,f+j|0,o|0,p|0,a+168|0,H[a+167|0],H[a+166|0],k|0,g|0,i|0,m|0);f=J[5996];J[5996]=0;if((f|0)==1){break c}J[5996]=0;d=ka(213,b|0,c|0,J[a+4>>2],J[a>>2],d|0,e|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break c}db(l);ab(i);ab(g);ab(k);b=J[a+172>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Ua=a+176|0;return d|0}J[5996]=0;ca(185);b=J[5996];J[5996]=0;if((b|0)==1){break c}B();}f=Z()|0;break a}f=Z()|0;break a}f=Z()|0;break b}f=Z()|0;db(l);}ab(i);ab(g);ab(k);}a=J[a+172>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(f|0);B();}function fk(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0;l=l|0;m=m|0;n=n|0;o=o|0;var p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;J[c>>2]=a;v=d&512;w=h<<2;while(1){if((u|0)==4){e=K[n+11|0];if(((e&128)>>>7|0?J[n+4>>2]:e&127)>>>0>1){J[c>>2]=mf(Rd(Mb(n),1),qc(n),J[c>>2]);}d=d&176;if((d|0)!=16){if((d|0)==32){a=J[c>>2];}J[b>>2]=a;}}else {a:{b:{switch(H[i+u|0]){case 0:J[b>>2]=J[c>>2];break a;case 1:J[b>>2]=J[c>>2];h=Xa[J[J[g>>2]+44>>2]](g,32)|0;p=J[c>>2];J[c>>2]=p+4;J[p>>2]=h;break a;case 3:h=K[n+11|0];r=h&127;h=(h&128)>>>7|0;if(!(h?J[n+4>>2]:r)){break a}h=J[(h?J[n>>2]:n)>>2];p=J[c>>2];J[c>>2]=p+4;J[p>>2]=h;break a;case 2:if(!v){break a}h=K[m+11|0];if(!((h&128)>>>7|0?J[m+4>>2]:h&127)){break a}J[c>>2]=mf(Mb(m),qc(m),J[c>>2]);break a;case 4:break b;default:break a}}x=J[c>>2];e=e+w|0;h=e;while(1){c:{if(f>>>0<=h>>>0){break c}if(!(Xa[J[J[g>>2]+12>>2]](g,64,J[h>>2])|0)){break c}h=h+4|0;continue}break}if((o|0)>0){p=J[c>>2];q=o;while(1){if(!(!q|e>>>0>=h>>>0)){q=q-1|0;h=h-4|0;s=J[h>>2];r=p+4|0;J[c>>2]=r;J[p>>2]=s;p=r;continue}break}d:{if(!q){s=0;break d}s=Xa[J[J[g>>2]+44>>2]](g,48)|0;p=J[c>>2];}while(1){r=p+4|0;if((q|0)>0){J[p>>2]=s;q=q-1|0;p=r;continue}break}J[c>>2]=r;J[p>>2]=j;}e:{if((e|0)==(h|0)){p=Xa[J[J[g>>2]+44>>2]](g,48)|0;q=J[c>>2];h=q+4|0;J[c>>2]=h;J[q>>2]=p;break e}s=-1;p=K[l+11|0];r=(p&128)>>>7|0;if(r?J[l+4>>2]:p&127){s=H[(r?J[l>>2]:l)|0];}q=0;t=0;while(1){if((e|0)!=(h|0)){r=J[c>>2];f:{if((q|0)!=(s|0)){p=r;r=q;break f}p=r+4|0;J[c>>2]=p;J[r>>2]=k;r=0;t=t+1|0;s=K[l+11|0];if(t>>>0>=((s&128)>>>7|0?J[l+4>>2]:s&127)>>>0){s=q;break f}s=-1;q=((K[l+11|0]&128)>>>7|0?J[l>>2]:l)+t|0;if(K[q|0]==127){break f}s=H[q|0];}h=h-4|0;q=J[h>>2];J[c>>2]=p+4;J[p>>2]=q;q=r+1|0;continue}break}h=J[c>>2];}md(x,h);}u=u+1|0;continue}break}}function jk(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;k=k|0;l=l|0;m=m|0;n=n|0;o=o|0;var p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;J[c>>2]=a;w=d&512;while(1){if((u|0)==4){e=K[n+11|0];if(((e&128)>>>7|0?J[n+4>>2]:e&127)>>>0>1){J[c>>2]=nf(Td(Mb(n),1),sc(n),J[c>>2]);}d=d&176;if((d|0)!=16){if((d|0)==32){a=J[c>>2];}J[b>>2]=a;}}else {a:{b:{switch(H[i+u|0]){case 0:J[b>>2]=J[c>>2];break a;case 1:J[b>>2]=J[c>>2];p=Xa[J[J[g>>2]+28>>2]](g,32)|0;q=J[c>>2];J[c>>2]=q+1;H[q|0]=p;break a;case 3:p=K[n+11|0];q=(p&128)>>>7|0;if(!(q?J[n+4>>2]:p&127)){break a}p=K[(q?J[n>>2]:n)|0];q=J[c>>2];J[c>>2]=q+1;H[q|0]=p;break a;case 2:if(!w){break a}p=K[m+11|0];if(!((p&128)>>>7|0?J[m+4>>2]:p&127)){break a}J[c>>2]=nf(Mb(m),sc(m),J[c>>2]);break a;case 4:break b;default:break a}}q=J[g+8>>2];x=J[c>>2];e=e+h|0;r=e;while(1){c:{if(f>>>0<=r>>>0){break c}p=H[r|0];if((p|0)>=0){p=(J[q+((p&255)<<2)>>2]&64)!=0;}else {p=0;}if(!p){break c}r=r+1|0;continue}break}p=o;if((p|0)>0){while(1){if(!(!p|e>>>0>=r>>>0)){p=p-1|0;r=r-1|0;q=K[r|0];s=J[c>>2];J[c>>2]=s+1;H[s|0]=q;continue}break}if(p){q=Xa[J[J[g>>2]+28>>2]](g,48)|0;}else {q=0;}while(1){s=J[c>>2];J[c>>2]=s+1;if((p|0)>0){H[s|0]=q;p=p-1|0;continue}break}H[s|0]=j;}d:{if((e|0)==(r|0)){p=Xa[J[J[g>>2]+28>>2]](g,48)|0;q=J[c>>2];J[c>>2]=q+1;H[q|0]=p;break d}q=-1;p=K[l+11|0];s=p&127;p=(p&128)>>>7|0;if(p?J[l+4>>2]:s){q=H[(p?J[l>>2]:l)|0];}p=0;t=0;while(1){if((e|0)==(r|0)){break d}e:{if((p|0)!=(q|0)){s=p;break e}q=J[c>>2];J[c>>2]=q+1;H[q|0]=k;s=0;t=t+1|0;q=K[l+11|0];if(t>>>0>=((q&128)>>>7|0?J[l+4>>2]:q&127)>>>0){q=p;break e}q=-1;p=((K[l+11|0]&128)>>>7|0?J[l>>2]:l)+t|0;if(K[p|0]==127){break e}q=H[p|0];}r=r-1|0;p=K[r|0];v=J[c>>2];J[c>>2]=v+1;H[v|0]=p;p=s+1|0;continue}}vc(x,J[c>>2]);}u=u+1|0;continue}break}}function Fi(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0;r=Ua-16|0;Ua=r;j=c;while(1){a:{if((d|0)==(j|0)){j=d;break a}if(!K[j|0]){break a}j=j+1|0;continue}break}J[h>>2]=f;J[e>>2]=c;while(1){b:{c:{d:{if((c|0)==(d|0)|(f|0)==(g|0)){break d}i=J[b+4>>2];J[r+8>>2]=J[b>>2];J[r+12>>2]=i;s=Ua-16|0;Ua=s;v=Xb(s+12|0,J[a+8>>2]);m=j-c|0;k=0;n=0;o=Ua-1040|0;Ua=o;q=J[e>>2];J[o+12>>2]=q;p=f?f:o+16|0;l=f?g-f>>2:256;e:{f:{g:{if(!(!q|!l)){while(1){i=m>>>2|0;if(!(m>>>0>131|i>>>0>=l>>>0)){i=q;break f}t=bg(p,o+12|0,i>>>0>>0?i:l,b);i=J[o+12>>2];if((t|0)==-1){l=0;k=-1;break g}u=(o+16|0)!=(p|0)?t:0;l=l-u|0;p=(u<<2)+p|0;m=i?(m+q|0)-i|0:0;k=k+t|0;if(!i){break g}q=i;if(l){continue}break}break g}i=q;}if(!i){break e}}if(!(!l|!m)){n=i;i=k;while(1){h:{k=qd(p,n,m,b);i:{if(k+2>>>0<=2){j:{switch(k+1|0){case 1:n=0;break i;case 0:break e;default:break j}}J[b>>2]=0;break i}n=k+n|0;J[o+12>>2]=n;i=i+1|0;l=l-1|0;if(l){break h}}k=i;break e}p=p+4|0;m=m-k|0;k=i;if(m){continue}break}break e}n=i;}if(f){J[e>>2]=n;}Ua=o+1040|0;i=J[v>>2];if(i){J[6178]=(i|0)==-1?24816:i;}Ua=s+16|0;k:{l:{m:{n:{if((k|0)==-1){while(1){o:{J[h>>2]=f;if(J[e>>2]==(c|0)){break o}g=1;p:{q:{r:{b=Me(f,c,j-c|0,r+8|0,J[a+8>>2]);switch(b+2|0){case 0:break l;case 2:break p;case 1:break r;default:break q}}J[e>>2]=c;break n}g=b;}c=c+g|0;f=J[h>>2]+4|0;continue}break}J[e>>2]=c;break d}f=J[h>>2]+(k<<2)|0;J[h>>2]=f;if((f|0)==(g|0)){break k}c=J[e>>2];if((d|0)==(j|0)){j=d;continue}if(!Me(f,c,1,b,J[a+8>>2])){break m}}a=2;break c}J[h>>2]=J[h>>2]+4;c=J[e>>2]+1|0;J[e>>2]=c;j=c;while(1){if((d|0)==(j|0)){j=d;break b}if(!K[j|0]){break b}j=j+1|0;continue}}J[e>>2]=c;a=1;break c}c=J[e>>2];}a=(c|0)!=(d|0);}Ua=r+16|0;return a|0}f=J[h>>2];continue}}function nd(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;j=Ua-128|0;Ua=j;J[j+124>>2]=b;J[j+4>>2]=184;b=j+8|0;J[b>>2]=0;J[b+4>>2]=J[j+4>>2];o=b;k=j+16|0;l=(d-c|0)/12|0;a:{b:{if(l>>>0>=101){k=sb(l);if(!k){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break b}tb(o,k);}h=k;b=c;c:{d:{while(1){if((b|0)==(d|0)){e:while(1){f:{J[5996]=0;h=_(186,a|0,j+124|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break f}if((!l|h)==1){J[5996]=0;b=_(186,a|0,j+124|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break c}if(!b){break d}J[f>>2]=J[f>>2]|2;break d}b=J[a>>2];J[5996]=0;p=$(187,b|0)|0;b=J[5996];J[5996]=0;g:{if((b|0)!=1){if(g){break g}J[5996]=0;p=_(188,e|0,p|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break g}}break b}i=q+1|0;s=0;h=k;b=c;while(1){if((b|0)==(d|0)){q=i;if(!s){continue e}J[5996]=0;$(189,a|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){h=k;b=c;if(l+m>>>0<2){continue e}while(1){if((b|0)==(d|0)){continue e}h:{if(K[h|0]!=2){break h}i=K[b+11|0];if((((i&128)>>>7|0?J[b+4>>2]:i&127)|0)==(q|0)){break h}H[h|0]=0;m=m-1|0;}h=h+1|0;b=b+12|0;continue}}break b}i:{if(K[h|0]!=1){break i}r=K[((K[b+11|0]&128)>>>7|0?J[b>>2]:b)+q|0];j:{if(g){break j}J[5996]=0;r=_(188,e|0,r<<24>>24)|0;n=J[5996];J[5996]=0;if((n|0)!=1){break j}break b}k:{if((p&255)==(r&255)){s=1;n=K[b+11|0];if((i|0)!=(((n&128)>>>7|0?J[b+4>>2]:n&127)|0)){break i}H[h|0]=2;m=m+1|0;break k}H[h|0]=0;}l=l-1|0;}h=h+1|0;b=b+12|0;continue}}break}}else {i=K[b+11|0];i=!((i&128)>>>7|0?J[b+4>>2]:i&127);H[h|0]=i?2:1;m=i+m|0;l=l-i|0;h=h+1|0;b=b+12|0;continue}break}break b}l:{m:{while(1){if((c|0)==(d|0)){break m}if(K[k|0]!=2){k=k+1|0;c=c+12|0;continue}break}d=c;break l}J[f>>2]=J[f>>2]|4;}db(o);Ua=j+128|0;return d|0}}a=Z()|0;db(o);da(a|0);}B();}function ld(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;j=Ua-128|0;Ua=j;J[j+124>>2]=b;J[j+4>>2]=184;b=j+8|0;J[b>>2]=0;J[b+4>>2]=J[j+4>>2];o=b;k=j+16|0;l=(d-c|0)/12|0;a:{b:{if(l>>>0>=101){k=sb(l);if(!k){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break b}tb(o,k);}h=k;b=c;c:{d:{while(1){if((b|0)==(d|0)){e:while(1){f:{J[5996]=0;h=_(202,a|0,j+124|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break f}if((!l|h)==1){J[5996]=0;b=_(202,a|0,j+124|0)|0;a=J[5996];J[5996]=0;if((a|0)==1){break c}if(!b){break d}J[f>>2]=J[f>>2]|2;break d}b=J[a>>2];J[5996]=0;p=$(203,b|0)|0;b=J[5996];J[5996]=0;g:{if((b|0)!=1){if(g){break g}J[5996]=0;p=_(204,e|0,p|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){break g}}break b}i=q+1|0;s=0;h=k;b=c;while(1){if((b|0)==(d|0)){q=i;if(!s){continue e}J[5996]=0;$(205,a|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){h=k;b=c;if(l+m>>>0<2){continue e}while(1){if((b|0)==(d|0)){continue e}h:{if(K[h|0]!=2){break h}i=K[b+11|0];if((((i&128)>>>7|0?J[b+4>>2]:i&127)|0)==(q|0)){break h}H[h|0]=0;m=m-1|0;}h=h+1|0;b=b+12|0;continue}}break b}i:{if(K[h|0]!=1){break i}r=J[(q<<2)+((K[b+11|0]&128)>>>7|0?J[b>>2]:b)>>2];j:{if(g){break j}J[5996]=0;r=_(204,e|0,r|0)|0;n=J[5996];J[5996]=0;if((n|0)!=1){break j}break b}k:{if((p|0)==(r|0)){s=1;n=K[b+11|0];if((i|0)!=(((n&128)>>>7|0?J[b+4>>2]:n&127)|0)){break i}H[h|0]=2;m=m+1|0;break k}H[h|0]=0;}l=l-1|0;}h=h+1|0;b=b+12|0;continue}}break}}else {i=K[b+11|0];i=!((i&128)>>>7|0?J[b+4>>2]:i&127);H[h|0]=i?2:1;m=i+m|0;l=l-i|0;h=h+1|0;b=b+12|0;continue}break}break b}l:{m:{while(1){if((c|0)==(d|0)){break m}if(K[k|0]!=2){k=k+1|0;c=c+12|0;continue}break}d=c;break l}J[f>>2]=J[f>>2]|4;}db(o);Ua=j+128|0;return d|0}}a=Z()|0;db(o);da(a|0);}B();}function uk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0;h=Ua-624|0;Ua=h;J[h+616>>2]=c;J[h+620>>2]=b;J[h+16>>2]=220;i=h+200|0;J[i>>2]=h+208;a=h+16|0;J[i+4>>2]=J[a>>2];j=h+192|0;b=J[e+28>>2];J[j>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;k=$(197,J[h+192>>2])|0;b=J[5996];J[5996]=0;a:{b:{c:{d:{e:{f:{g:{if((b|0)!=1){H[h+191|0]=0;b=J[e+4>>2];J[5996]=0;b=ua(228,h+620|0,c|0,d|0,j|0,b|0,f|0,h+191|0,k|0,i|0,h+196|0,h+608|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break d}if(!b){break e}b=K[3833]|K[3834]<<8|(K[3835]<<16|K[3836]<<24);H[h+183|0]=b;H[h+184|0]=b>>>8;H[h+185|0]=b>>>16;H[h+186|0]=b>>>24;b=K[3830]|K[3831]<<8|(K[3832]<<16|K[3833]<<24);J[h+176>>2]=K[3826]|K[3827]<<8|(K[3828]<<16|K[3829]<<24);J[h+180>>2]=b;J[5996]=0;ga(208,k|0,h+176|0,h+186|0,h+128|0);b=J[5996];J[5996]=0;if((b|0)==1){break g}J[h+4>>2]=184;d=h+8|0;J[d>>2]=0;J[d+4>>2]=J[h+4>>2];e=a;b=J[h+196>>2];a=b-J[i>>2]|0;if((a|0)<393){break f}tb(d,sb((a>>2)+2|0));e=J[d>>2];if(e){break f}J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break c}break a}c=Z()|0;break b}c=Z()|0;break b}if(K[h+191|0]){H[e|0]=45;e=e+1|0;}c=J[i>>2];while(1){if(b>>>0<=c>>>0){H[e|0]=0;J[h>>2]=g;if((eg(h+16|0,h)|0)!=1){J[5996]=0;ha(222,1730);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break c}db(d);}else {a=h+128|0;H[e|0]=K[(h+176|0)+(Yd(a,a+40|0,J[c>>2])-a>>2)|0];e=e+1|0;c=c+4|0;b=J[h+196>>2];continue}break}}J[5996]=0;a=_(202,h+620|0,h+616|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break d}if(a){J[f>>2]=J[f>>2]|2;}c=J[h+620>>2];a=J[h+192>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(i);Ua=h+624|0;return c|0}c=Z()|0;break b}c=Z()|0;db(d);}a=J[h+192>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(i);da(c|0);B();}B();}function vj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;e=J[a+4>>2];c=J[a>>2];d=e-c>>2;if(d>>>0>>0){h=Ua-32|0;Ua=h;f=b-d|0;a:{if(f>>>0<=J[a+8>>2]-e>>2>>>0){ff(a,f);break a}g=a+16|0;d=h+12|0;c=Ua-16|0;Ua=c;e=f+(e-J[a>>2]>>2)|0;J[c+12>>2]=e;b:{b=_e();if(e>>>0<=b>>>0){e=J[a+8>>2]-J[a>>2]>>2;if(e>>>0>>1>>>0){J[c+8>>2]=e<<1;b=J[(M[c+8>>2]>2]?c+12|0:c+8|0)>>2];}Ua=c+16|0;break b}nb();B();}i=J[a+4>>2]-J[a>>2]>>2;e=Ua-16|0;Ua=e;J[d+12>>2]=0;J[d+16>>2]=g;c:{if(!b){c=0;b=0;break c}Ze(e+8|0,J[d+16>>2],b);c=J[e+8>>2];b=J[e+12>>2];}J[d>>2]=c;g=c+(i<<2)|0;J[d+8>>2]=g;J[d+4>>2]=g;J[d+12>>2]=c+(b<<2);Ua=e+16|0;c=Ua-16|0;Ua=c;J[c+4>>2]=J[d+8>>2];b=J[d+8>>2];J[c+12>>2]=d+8;J[c+8>>2]=b+(f<<2);b=J[c+4>>2];while(1){if(J[c+8>>2]!=(b|0)){J[b>>2]=0;b=J[c+4>>2]+4|0;J[c+4>>2]=b;continue}break}J[J[c+12>>2]>>2]=J[c+4>>2];Ua=c+16|0;e=Ua-16|0;Ua=e;J[e+12>>2]=J[a+4>>2];J[e+8>>2]=J[a>>2];J[e+4>>2]=J[d+4>>2];f=J[e+12>>2];i=J[e+4>>2];g=Ua-16|0;Ua=g;b=Ua-32|0;Ua=b;c=Ua-16|0;Ua=c;J[c+12>>2]=J[e+8>>2];J[b+24>>2]=f;J[b+28>>2]=J[c+12>>2];Ua=c+16|0;f=J[b+24>>2];j=J[b+28>>2];c=Ua-16|0;Ua=c;J[c+8>>2]=i;J[c+12>>2]=f;while(1){if((f|0)!=(j|0)){J[J[c+8>>2]-4>>2]=J[f-4>>2];J[c+12>>2]=J[c+12>>2]-4;J[c+8>>2]=J[c+8>>2]-4;f=J[c+12>>2];continue}break}J[b+16>>2]=f;J[b+20>>2]=J[c+8>>2];Ua=c+16|0;c=J[b+16>>2];J[b+12>>2]=J[b+20>>2];J[g+8>>2]=c;J[g+12>>2]=J[b+12>>2];Ua=b+32|0;Ua=g+16|0;J[d+4>>2]=J[g+12>>2];b=J[a>>2];J[a>>2]=J[d+4>>2];J[d+4>>2]=b;b=J[a+4>>2];J[a+4>>2]=J[d+8>>2];J[d+8>>2]=b;b=J[a+8>>2];J[a+8>>2]=J[d+12>>2];J[d+12>>2]=b;J[d>>2]=J[d+4>>2];Ua=e+16|0;b=J[d+4>>2];a=J[d+8>>2];while(1){if((a|0)!=(b|0)){a=a-4|0;J[d+8>>2]=a;continue}break}a=J[d>>2];if(a){bf(J[d+16>>2],a);}}Ua=h+32|0;return}if(b>>>0>>0){af(a,c+(b<<2)|0);}}function Bk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0;h=Ua-272|0;Ua=h;J[h+264>>2]=c;J[h+268>>2]=b;J[h+16>>2]=220;i=h+152|0;J[i>>2]=h+160;a=h+16|0;J[i+4>>2]=J[a>>2];j=h+144|0;b=J[e+28>>2];J[j>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;k=$(170,J[h+144>>2])|0;b=J[5996];J[5996]=0;a:{b:{c:{d:{e:{f:{g:{if((b|0)!=1){H[h+143|0]=0;b=J[e+4>>2];J[5996]=0;b=ua(221,h+268|0,c|0,d|0,j|0,b|0,f|0,h+143|0,k|0,i|0,h+148|0,h+260|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break d}if(!b){break e}b=K[3833]|K[3834]<<8|(K[3835]<<16|K[3836]<<24);H[h+135|0]=b;H[h+136|0]=b>>>8;H[h+137|0]=b>>>16;H[h+138|0]=b>>>24;b=K[3830]|K[3831]<<8|(K[3832]<<16|K[3833]<<24);J[h+128>>2]=K[3826]|K[3827]<<8|(K[3828]<<16|K[3829]<<24);J[h+132>>2]=b;J[5996]=0;ga(195,k|0,h+128|0,h+138|0,h+118|0);b=J[5996];J[5996]=0;if((b|0)==1){break g}J[h+4>>2]=184;d=h+8|0;J[d>>2]=0;J[d+4>>2]=J[h+4>>2];e=a;b=J[h+148>>2];a=b-J[i>>2]|0;if((a|0)<99){break f}tb(d,sb(a+2|0));e=J[d>>2];if(e){break f}J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break c}break a}c=Z()|0;break b}c=Z()|0;break b}if(K[h+143|0]){H[e|0]=45;e=e+1|0;}c=J[i>>2];while(1){if(b>>>0<=c>>>0){H[e|0]=0;J[h>>2]=g;if((eg(h+16|0,h)|0)!=1){J[5996]=0;ha(222,1730);a=J[5996];J[5996]=0;if((a|0)!=1){break a}break c}db(d);}else {a=h+118|0;H[e|0]=K[((be(a,a+10|0,K[c|0])-h|0)+h|0)+10|0];e=e+1|0;c=c+1|0;b=J[h+148>>2];continue}break}}J[5996]=0;a=_(186,h+268|0,h+264|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break d}if(a){J[f>>2]=J[f>>2]|2;}c=J[h+268>>2];a=J[h+144>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(i);Ua=h+272|0;return c|0}c=Z()|0;break b}c=Z()|0;db(d);}a=J[h+144>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(i);da(c|0);B();}B();}function vl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-272|0;Ua=a;J[a+264>>2]=c;J[a+268>>2]=b;$d(a+208|0,d,a+224|0,a+223|0,a+222|0);d=a+196|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+192>>2]=c;J[a+28>>2]=a+32;J[a+24>>2]=0;H[a+23|0]=1;H[a+22|0]=69;g=K[a+222|0]<<24>>24;i=K[a+223|0]<<24>>24;while(1){d:{J[5996]=0;b=_(186,a+268|0,a+264|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+192>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+192>>2]=b+c;}J[5996]=0;b=$(187,J[a+268>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(_d(b,a+23|0,a+22|0,c,a+192|0,i,g,a+208|0,a+32|0,a+28|0,a+24|0,a+224|0)){break c}J[5996]=0;$(189,a+268|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+219|0];e:{if(!((b&128)>>>7|0?J[a+212>>2]:b&127)|!K[a+23|0]){break e}b=J[a+28>>2];if((b-(a+32|0)|0)>159){break e}J[a+28>>2]=b+4;J[b>>2]=J[a+24>>2];}Lf(a,c,J[a+192>>2],e);b=J[a>>2];c=J[a+4>>2];g=J[a+12>>2];J[f+8>>2]=J[a+8>>2];J[f+12>>2]=g;J[f>>2]=b;J[f+4>>2]=c;zb(a+208|0,a+32|0,J[a+28>>2],e);J[5996]=0;b=_(186,a+268|0,a+264|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+268>>2];ab(d);ab(a+208|0);Ua=a+272|0;break a}}b=Z()|0;ab(d);ab(a+208|0);da(b|0);B();}return b|0}function kl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-384|0;Ua=a;J[a+376>>2]=c;J[a+380>>2]=b;Xd(a+220|0,d,a+240|0,a+236|0,a+232|0);d=a+208|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+204>>2]=c;J[a+28>>2]=a+32;J[a+24>>2]=0;H[a+23|0]=1;H[a+22|0]=69;g=J[a+232>>2];i=J[a+236>>2];while(1){d:{J[5996]=0;b=_(202,a+380|0,a+376|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+204>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+204>>2]=b+c;}J[5996]=0;b=$(203,J[a+380>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Wd(b,a+23|0,a+22|0,c,a+204|0,i,g,a+220|0,a+32|0,a+28|0,a+24|0,a+240|0)){break c}J[5996]=0;$(205,a+380|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+231|0];e:{if(!((b&128)>>>7|0?J[a+224>>2]:b&127)|!K[a+23|0]){break e}b=J[a+28>>2];if((b-(a+32|0)|0)>159){break e}J[a+28>>2]=b+4;J[b>>2]=J[a+24>>2];}Lf(a,c,J[a+204>>2],e);b=J[a>>2];c=J[a+4>>2];g=J[a+12>>2];J[f+8>>2]=J[a+8>>2];J[f+12>>2]=g;J[f>>2]=b;J[f+4>>2]=c;zb(a+220|0,a+32|0,J[a+28>>2],e);J[5996]=0;b=_(202,a+380|0,a+376|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+380>>2];ab(d);ab(a+220|0);Ua=a+384|0;break a}}b=Z()|0;ab(d);ab(a+220|0);da(b|0);B();}return b|0}function al(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0,l=0,m=0,n=0;n=b;i=Ua-256|0;Ua=i;J[i+248>>2]=37;J[i+252>>2]=0;b=i+248|0;l=kd(b|1,3264,J[c+4>>2]);j=i+208|0;J[i+204>>2]=j;a=jb();a:{if(l){k=J[c+8>>2];m=i- -64|0;J[m>>2]=g;J[m+4>>2]=h;J[i+56>>2]=e;J[i+60>>2]=f;J[i+48>>2]=k;j=yb(j,30,a,b,i+48|0);break a}J[i+80>>2]=e;J[i+84>>2]=f;J[i+88>>2]=g;J[i+92>>2]=h;j=yb(i+208|0,30,a,i+248|0,i+80|0);}J[i+128>>2]=184;k=i+196|0;J[k>>2]=0;J[k+4>>2]=J[i+128>>2];b=i+208|0;a=b;b:{c:{d:{e:{if((j|0)>=30){a=jb();f:{if(l){j=J[c+8>>2];J[i+16>>2]=g;J[i+20>>2]=h;J[i+8>>2]=e;J[i+12>>2]=f;J[i>>2]=j;j=dc(i+204|0,a,i+248|0,i);break f}J[i+32>>2]=e;J[i+36>>2]=f;J[i+40>>2]=g;J[i+44>>2]=h;j=dc(i+204|0,a,i+248|0,i+32|0);}if((j|0)==-1){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break d}break e}a=J[i+204>>2];tb(k,a);}g=a+j|0;h=Lb(a,g,J[c+4>>2]);J[i+116>>2]=184;e=i+120|0;J[e>>2]=0;J[e+4>>2]=J[i+116>>2];g:{h:{if((i+208|0)==(a|0)){j=i+128|0;break h}j=sb(j<<1);if(!j){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break e}a=Z()|0;break g}tb(e,j);b=a;}a=i+108|0;f=J[c+28>>2];J[a>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;ma(212,b|0,h|0,g|0,j|0,i+116|0,i+112|0,a|0);b=J[5996];J[5996]=0;i:{if((b|0)!=1){a=J[a>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;a=ka(213,n|0,j|0,J[i+116>>2],J[i+112>>2],c|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break i}db(e);db(k);Ua=i+256|0;break b}a=Z()|0;b=J[i+108>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}break g}a=Z()|0;}db(e);break c}B();}a=Z()|0;}db(k);da(a|0);B();}return a|0}function Rk(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0,l=0,m=0,n=0;n=b;i=Ua-416|0;Ua=i;J[i+408>>2]=37;J[i+412>>2]=0;b=i+408|0;l=kd(b|1,3264,J[c+4>>2]);j=i+368|0;J[i+364>>2]=j;a=jb();a:{if(l){k=J[c+8>>2];m=i- -64|0;J[m>>2]=g;J[m+4>>2]=h;J[i+56>>2]=e;J[i+60>>2]=f;J[i+48>>2]=k;j=yb(j,30,a,b,i+48|0);break a}J[i+80>>2]=e;J[i+84>>2]=f;J[i+88>>2]=g;J[i+92>>2]=h;j=yb(i+368|0,30,a,i+408|0,i+80|0);}J[i+128>>2]=184;k=i+356|0;J[k>>2]=0;J[k+4>>2]=J[i+128>>2];b=i+368|0;a=b;b:{c:{d:{e:{if((j|0)>=30){a=jb();f:{if(l){j=J[c+8>>2];J[i+16>>2]=g;J[i+20>>2]=h;J[i+8>>2]=e;J[i+12>>2]=f;J[i>>2]=j;j=dc(i+364|0,a,i+408|0,i);break f}J[i+32>>2]=e;J[i+36>>2]=f;J[i+40>>2]=g;J[i+44>>2]=h;j=dc(i+364|0,a,i+408|0,i+32|0);}if((j|0)==-1){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break d}break e}a=J[i+364>>2];tb(k,a);}g=a+j|0;h=Lb(a,g,J[c+4>>2]);J[i+116>>2]=184;e=i+120|0;J[e>>2]=0;J[e+4>>2]=J[i+116>>2];g:{h:{if((i+368|0)==(a|0)){j=i+128|0;break h}j=sb(j<<3);if(!j){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break e}a=Z()|0;break g}tb(e,j);b=a;}a=i+108|0;f=J[c+28>>2];J[a>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;ma(218,b|0,h|0,g|0,j|0,i+116|0,i+112|0,a|0);b=J[5996];J[5996]=0;i:{if((b|0)!=1){a=J[a>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;a=ka(219,n|0,j|0,J[i+116>>2],J[i+112>>2],c|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break i}db(e);db(k);Ua=i+416|0;break b}a=Z()|0;b=J[i+108>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}break g}a=Z()|0;}db(e);break c}B();}a=Z()|0;}db(k);da(a|0);B();}return a|0}function te(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;j=K[b+8|0]|K[b+9|0]<<8|(K[b+10|0]<<16|K[b+11|0]<<24);e=-29;f=K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24);h=f>>>0<29;a:{f=h?f:f-29|0;if(f>>>0>=29){J[5996]=0;aa(124,a|0,f+(f>>>1|0)|0);e=J[5996];J[5996]=0;if((e|0)==1){break a}d=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);g=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=g-29|0;}i=g>>>0<29;d=i?a+4|0:d;eb(f+d|0,d,i?g:e);e=f+(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))|0;H[a|0]=e;H[a+1|0]=e>>>8;H[a+2|0]=e>>>16;H[a+3|0]=e>>>24;b:{if(!f){break b}e=h?b+4|0:j;h=f&7;c:{if(!h){b=e;break c}g=0;b=e;while(1){H[d|0]=K[b|0];b=b+1|0;d=d+1|0;g=g+1|0;if((h|0)!=(g|0)){continue}break}}if(f>>>0<8){break b}e=e+f|0;while(1){H[d|0]=K[b|0];H[d+1|0]=K[b+1|0];H[d+2|0]=K[b+2|0];H[d+3|0]=K[b+3|0];H[d+4|0]=K[b+4|0];H[d+5|0]=K[b+5|0];H[d+6|0]=K[b+6|0];H[d+7|0]=K[b+7|0];d=d+8|0;b=b+8|0;if((e|0)!=(b|0)){continue}break}}b=J[c>>2];J[5996]=0;_(127,a|0,b|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}return}b=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}da(b|0);B();}function zl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-256|0;Ua=a;J[a+248>>2]=c;J[a+252>>2]=b;$d(a+192|0,d,a+208|0,a+207|0,a+206|0);d=a+180|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+176>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;H[a+7|0]=1;H[a+6|0]=69;h=K[a+206|0]<<24>>24;i=K[a+207|0]<<24>>24;while(1){d:{J[5996]=0;b=_(186,a+252|0,a+248|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+176>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+176>>2]=b+c;}J[5996]=0;b=$(187,J[a+252>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(_d(b,a+7|0,a+6|0,c,a+176|0,i,h,a+192|0,a+16|0,a+12|0,a+8|0,a+208|0)){break c}J[5996]=0;$(189,a+252|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+203|0];e:{if(!((b&128)>>>7|0?J[a+196>>2]:b&127)|!K[a+7|0]){break e}b=J[a+12>>2];if((b-(a+16|0)|0)>159){break e}J[a+12>>2]=b+4;J[b>>2]=J[a+8>>2];}N[f>>2]=Of(c,J[a+176>>2],e);zb(a+192|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+252|0,a+248|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+252>>2];ab(d);ab(a+192|0);Ua=a+256|0;break a}}b=Z()|0;ab(d);ab(a+192|0);da(b|0);B();}return b|0}function xl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-256|0;Ua=a;J[a+248>>2]=c;J[a+252>>2]=b;$d(a+192|0,d,a+208|0,a+207|0,a+206|0);d=a+180|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+176>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;H[a+7|0]=1;H[a+6|0]=69;h=K[a+206|0]<<24>>24;i=K[a+207|0]<<24>>24;while(1){d:{J[5996]=0;b=_(186,a+252|0,a+248|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+176>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+176>>2]=b+c;}J[5996]=0;b=$(187,J[a+252>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(_d(b,a+7|0,a+6|0,c,a+176|0,i,h,a+192|0,a+16|0,a+12|0,a+8|0,a+208|0)){break c}J[5996]=0;$(189,a+252|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+203|0];e:{if(!((b&128)>>>7|0?J[a+196>>2]:b&127)|!K[a+7|0]){break e}b=J[a+12>>2];if((b-(a+16|0)|0)>159){break e}J[a+12>>2]=b+4;J[b>>2]=J[a+8>>2];}O[f>>3]=Mf(c,J[a+176>>2],e);zb(a+192|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+252|0,a+248|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+252>>2];ab(d);ab(a+192|0);Ua=a+256|0;break a}}b=Z()|0;ab(d);ab(a+192|0);da(b|0);B();}return b|0}function kc(a,b,c,d,e,f,g,h){var i=0,j=0,k=0;i=Ua-16|0;Ua=i;J[i+8>>2]=c;J[i+12>>2]=b;b=J[d+28>>2];J[i+4>>2]=b;J[b+4>>2]=J[b+4>>2]+1;c=0;J[5996]=0;j=$(170,J[i+4>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[i+4>>2];k=J[b+4>>2]-1|0;J[b+4>>2]=k;if((k|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}J[e>>2]=0;a:{while(1){if(c|(g|0)==(h|0)){break a}b:{if(Ub(i+12|0,i+8|0)){break b}c:{if((Xa[J[J[j>>2]+36>>2]](j,H[g|0],0)|0)==37){if((g+1|0)==(h|0)){break b}c=Xa[J[J[j>>2]+36>>2]](j,H[g+1|0],0)|0;d:{if(!((c|0)==69|(c&255)==48)){b=0;k=1;break d}if((g+2|0)==(h|0)){break b}b=c;c=Xa[J[J[j>>2]+36>>2]](j,H[g+2|0],0)|0;k=2;}J[i+12>>2]=Xa[J[J[a>>2]+36>>2]](a,J[i+12>>2],J[i+8>>2],d,e,f,c,b);g=(g+k|0)+1|0;break c}b=J[j+8>>2];c=H[g|0];if((c|0)>=0){c=J[b+((c&255)<<2)>>2]&1;}else {c=0;}if(c){while(1){e:{g=g+1|0;if((h|0)==(g|0)){g=h;break e}c=H[g|0];if((c|0)>=0){c=J[b+((c&255)<<2)>>2]&1;}else {c=0;}if(c){continue}}break}while(1){k=i+12|0;if(Ub(k,i+8|0)){break c}b=J[i+12>>2];c=J[b+12>>2];f:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break f}b=K[c|0];}c=J[j+8>>2];b=b<<24>>24;if((b|0)>=0){b=J[c+((b&255)<<2)>>2]&1;}else {b=0;}if(!b){break c}Ic(k);continue}}b=J[i+12>>2];c=J[b+12>>2];g:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break g}b=K[c|0];}if((Xa[J[J[j>>2]+12>>2]](j,b<<24>>24)|0)==(Xa[J[J[j>>2]+12>>2]](j,H[g|0])|0)){g=g+1|0;Ic(i+12|0);break c}J[e>>2]=4;}c=J[e>>2];continue}break}J[e>>2]=4;}if(Ub(i+12|0,i+8|0)){J[e>>2]=J[e>>2]|2;}Ua=i+16|0;return J[i+12>>2]}c=Z()|0;a=J[i+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function ml(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-368|0;Ua=a;J[a+360>>2]=c;J[a+364>>2]=b;Xd(a+204|0,d,a+224|0,a+220|0,a+216|0);d=a+192|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+188>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;H[a+7|0]=1;H[a+6|0]=69;h=J[a+216>>2];i=J[a+220>>2];while(1){d:{J[5996]=0;b=_(202,a+364|0,a+360|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+188>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+188>>2]=b+c;}J[5996]=0;b=$(203,J[a+364>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(Wd(b,a+7|0,a+6|0,c,a+188|0,i,h,a+204|0,a+16|0,a+12|0,a+8|0,a+224|0)){break c}J[5996]=0;$(205,a+364|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+215|0];e:{if(!((b&128)>>>7|0?J[a+208>>2]:b&127)|!K[a+7|0]){break e}b=J[a+12>>2];if((b-(a+16|0)|0)>159){break e}J[a+12>>2]=b+4;J[b>>2]=J[a+8>>2];}N[f>>2]=Of(c,J[a+188>>2],e);zb(a+204|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+364|0,a+360|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+364>>2];ab(d);ab(a+204|0);Ua=a+368|0;break a}}b=Z()|0;ab(d);ab(a+204|0);da(b|0);B();}return b|0}function ll(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;d=J[d+28>>2];a=Ua-368|0;Ua=a;J[a+360>>2]=c;J[a+364>>2]=b;Xd(a+204|0,d,a+224|0,a+220|0,a+216|0);d=a+192|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;b=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,b|0);b=J[5996];J[5996]=0;a:{b:{c:{if((b|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+188>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;H[a+7|0]=1;H[a+6|0]=69;h=J[a+216>>2];i=J[a+220>>2];while(1){d:{J[5996]=0;b=_(202,a+364|0,a+360|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(b){break c}b=K[d+11|0];b=(b&128)>>>7|0?J[d+4>>2]:b&127;if(J[a+188>>2]==(b+c|0)){J[5996]=0;aa(172,d|0,b<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+188>>2]=b+c;}J[5996]=0;b=$(203,J[a+364>>2])|0;g=J[5996];J[5996]=0;if((g|0)==1){break d}if(Wd(b,a+7|0,a+6|0,c,a+188|0,i,h,a+204|0,a+16|0,a+12|0,a+8|0,a+224|0)){break c}J[5996]=0;$(205,a+364|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){continue}}break}break b}break b}b=K[a+215|0];e:{if(!((b&128)>>>7|0?J[a+208>>2]:b&127)|!K[a+7|0]){break e}b=J[a+12>>2];if((b-(a+16|0)|0)>159){break e}J[a+12>>2]=b+4;J[b>>2]=J[a+8>>2];}O[f>>3]=Mf(c,J[a+188>>2],e);zb(a+204|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+364|0,a+360|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+364>>2];ab(d);ab(a+204|0);Ua=a+368|0;break a}}b=Z()|0;ab(d);ab(a+204|0);da(b|0);B();}return b|0}function _c(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;a:{b:{if(a-1&a|b>>>0>4294967239){break b}while(1){a=a>>>0<=8?8:a;e=J[5995];f=J[5994];b=b>>>0<=8?8:b+3&-4;c:{if(b>>>0<=127){g=(b>>>3|0)-1|0;break c}d=S(b);g=((b>>>29-d^4)-(d<<2)|0)+110|0;if(b>>>0<=4095){break c}d=((b>>>30-d^2)-(d<<1)|0)+71|0;g=d>>>0>=63?63:d;}c=g&31;if((g&63)>>>0>=32){d=0;c=e>>>c|0;}else {d=e>>>c|0;c=((1<>>c;}if(c|d){while(1){e=c;d:{if(d|e){f=d-1|0;h=f+1|0;c=f;f=e-1|0;h=(f|0)!=-1?h:c;c=S(d^h);c=(c|0)==32?S(e^f)+32|0:c;f=63-c|0;Wa=0-(c>>>0>63)|0;break d}Wa=0;f=64;}h=f;f=h&31;if((h&63)>>>0>=32){c=0;f=d>>>f|0;}else {c=d>>>f|0;f=((1<>>f;}d=c;g=g+h|0;h=g<<4;e=J[h+22952>>2];i=h+22944|0;e:{if((e|0)!=(i|0)){c=ye(e,a,b);if(c){break b}c=J[e+4>>2];J[c+8>>2]=J[e+8>>2];J[J[e+8>>2]+4>>2]=c;J[e+8>>2]=i;c=h+22948|0;J[e+4>>2]=J[c>>2];J[c>>2]=e;J[J[e+4>>2]+8>>2]=e;g=g+1|0;c=(d&1)<<31|f>>>1;d=d>>>1|0;break e}c=J[5995];J[5994]=J[5994]&go(-2,-1,g);J[5995]=Wa&c;c=f^1;}if(d|c){continue}break}f=J[5994];e=J[5995];}f:{if(e|f){d=S(e);h=63-((d|0)==32?S(f)+32|0:d)|0;c=h<<4;d=J[c+22952>>2];g:{if(!e&f>>>0<1073741824){break g}g=99;e=c+22944|0;if((e|0)==(d|0)){break g}while(1){if(!g){break g}c=ye(d,a,b);if(c){break b}g=g-1|0;d=J[d+8>>2];if((e|0)!=(d|0)){continue}break}d=e;}if(Cd(b+48|0)){break f}if(!d){break a}e=(h<<4)+22944|0;if((e|0)==(d|0)){break a}while(1){c=ye(d,a,b);if(c){break b}d=J[d+8>>2];if((e|0)!=(d|0)){continue}break}break a}if(!Cd(b+48|0)){break a}}c=0;if(a-1&a){break b}if(b>>>0<=4294967239){continue}break}}return c}return 0}function ql(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;a=Ua-336|0;Ua=a;J[a+328>>2]=c;J[a+332>>2]=b;b=ec(J[d+4>>2]);i=Sc(J[d+28>>2],a+208|0);Rc(a+196|0,J[d+28>>2],a+324|0);d=a+184|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+332|0,a+328|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+180>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=g+c;}J[5996]=0;g=$(203,J[a+332>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Cc(g,b,c,a+180|0,a+8|0,J[a+324>>2],J[a+200>>2],K[a+207|0],a+16|0,a+12|0,i)){break c}J[5996]=0;$(205,a+332|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+207|0];e:{if(!((g&128)>>>7|0?J[a+200>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Tf(c,J[a+180>>2],e,b);J[f+4>>2]=Wa;zb(a+196|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+332|0,a+328|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+332>>2];ab(d);ab(a+196|0);Ua=a+336|0;break a}}b=Z()|0;ab(d);ab(a+196|0);da(b|0);B();}return b|0}function ol(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;a=Ua-336|0;Ua=a;J[a+328>>2]=c;J[a+332>>2]=b;b=ec(J[d+4>>2]);i=Sc(J[d+28>>2],a+208|0);Rc(a+196|0,J[d+28>>2],a+324|0);d=a+184|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+332|0,a+328|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+180>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=g+c;}J[5996]=0;g=$(203,J[a+332>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Cc(g,b,c,a+180|0,a+8|0,J[a+324>>2],J[a+200>>2],K[a+207|0],a+16|0,a+12|0,i)){break c}J[5996]=0;$(205,a+332|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+207|0];e:{if(!((g&128)>>>7|0?J[a+200>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Pf(c,J[a+180>>2],e,b);J[f+4>>2]=Wa;zb(a+196|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+332|0,a+328|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+332>>2];ab(d);ab(a+196|0);Ua=a+336|0;break a}}b=Z()|0;ab(d);ab(a+196|0);da(b|0);B();}return b|0}function sl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;a=Ua-336|0;Ua=a;J[a+328>>2]=c;J[a+332>>2]=b;b=ec(J[d+4>>2]);i=Sc(J[d+28>>2],a+208|0);Rc(a+196|0,J[d+28>>2],a+324|0);d=a+184|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+332|0,a+328|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+180>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=g+c;}J[5996]=0;g=$(203,J[a+332>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Cc(g,b,c,a+180|0,a+8|0,J[a+324>>2],J[a+200>>2],K[a+207|0],a+16|0,a+12|0,i)){break c}J[5996]=0;$(205,a+332|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+207|0];e:{if(!((g&128)>>>7|0?J[a+200>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Yf(c,J[a+180>>2],e,b);zb(a+196|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+332|0,a+328|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+332>>2];ab(d);ab(a+196|0);Ua=a+336|0;break a}}b=Z()|0;ab(d);ab(a+196|0);da(b|0);B();}return b|0}function pl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;a=Ua-336|0;Ua=a;J[a+328>>2]=c;J[a+332>>2]=b;b=ec(J[d+4>>2]);i=Sc(J[d+28>>2],a+208|0);Rc(a+196|0,J[d+28>>2],a+324|0);d=a+184|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+332|0,a+328|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+180>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=g+c;}J[5996]=0;g=$(203,J[a+332>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Cc(g,b,c,a+180|0,a+8|0,J[a+324>>2],J[a+200>>2],K[a+207|0],a+16|0,a+12|0,i)){break c}J[5996]=0;$(205,a+332|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+207|0];e:{if(!((g&128)>>>7|0?J[a+200>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}I[f>>1]=Sf(c,J[a+180>>2],e,b);zb(a+196|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+332|0,a+328|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+332>>2];ab(d);ab(a+196|0);Ua=a+336|0;break a}}b=Z()|0;ab(d);ab(a+196|0);da(b|0);B();}return b|0}function Jf(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;a=Ua-336|0;Ua=a;J[a+328>>2]=c;J[a+332>>2]=b;b=ec(J[d+4>>2]);i=Sc(J[d+28>>2],a+208|0);Rc(a+196|0,J[d+28>>2],a+324|0);d=a+184|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(202,a+332|0,a+328|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+180>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+180>>2]=g+c;}J[5996]=0;g=$(203,J[a+332>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Cc(g,b,c,a+180|0,a+8|0,J[a+324>>2],J[a+200>>2],K[a+207|0],a+16|0,a+12|0,i)){break c}J[5996]=0;$(205,a+332|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+207|0];e:{if(!((g&128)>>>7|0?J[a+200>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Qf(c,J[a+180>>2],e,b);zb(a+196|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(202,a+332|0,a+328|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+332>>2];ab(d);ab(a+196|0);Ua=a+336|0;break a}}b=Z()|0;ab(d);ab(a+196|0);da(b|0);B();}return b|0}function Cl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=J[d+4>>2];d=J[d+28>>2];a=Ua-224|0;Ua=a;J[a+216>>2]=c;J[a+220>>2]=b;b=ec(g);Tc(a+200|0,d,a+215|0);d=a+188|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+220|0,a+216|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+184>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=g+c;}J[5996]=0;g=$(187,J[a+220>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Dc(g,b,c,a+184|0,a+8|0,H[a+215|0],J[a+204>>2],K[a+211|0],a+16|0,a+12|0,12416)){break c}J[5996]=0;$(189,a+220|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+211|0];e:{if(!((g&128)>>>7|0?J[a+204>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Tf(c,J[a+184>>2],e,b);J[f+4>>2]=Wa;zb(a+200|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+220|0,a+216|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+220>>2];ab(d);ab(a+200|0);Ua=a+224|0;break a}}b=Z()|0;ab(d);ab(a+200|0);da(b|0);B();}return b|0}function Al(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=J[d+4>>2];d=J[d+28>>2];a=Ua-224|0;Ua=a;J[a+216>>2]=c;J[a+220>>2]=b;b=ec(g);Tc(a+200|0,d,a+215|0);d=a+188|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+220|0,a+216|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+184>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=g+c;}J[5996]=0;g=$(187,J[a+220>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Dc(g,b,c,a+184|0,a+8|0,H[a+215|0],J[a+204>>2],K[a+211|0],a+16|0,a+12|0,12416)){break c}J[5996]=0;$(189,a+220|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+211|0];e:{if(!((g&128)>>>7|0?J[a+204>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Pf(c,J[a+184>>2],e,b);J[f+4>>2]=Wa;zb(a+200|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+220|0,a+216|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+220>>2];ab(d);ab(a+200|0);Ua=a+224|0;break a}}b=Z()|0;ab(d);ab(a+200|0);da(b|0);B();}return b|0}function Vc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;a:{if(!a){a=_c(8,b);break a}if(!b){$a(a);a=0;break a}b:{if(b>>>0>4294967239){break b}h=b>>>0<=8?8:b+3&-4;b=h+8|0;c:{d:{k=a-4|0;f=k;e=J[f>>2];c=e+f|0;j=J[c>>2];g=j+c|0;e:{f:{if(J[g-4>>2]!=(j|0)){d=b+f|0;if(d+16>>>0<=g>>>0){e=J[c+4>>2];J[e+8>>2]=J[c+8>>2];J[J[c+8>>2]+4>>2]=e;c=g-d|0;J[d>>2]=c;J[(d+(c&-4)|0)-4>>2]=c|1;e=J[d>>2]-8|0;g:{if(e>>>0<=127){c=(e>>>3|0)-1|0;break g}g=S(e);c=((e>>>29-g^4)-(g<<2)|0)+110|0;if(e>>>0<=4095){break g}c=((e>>>30-g^2)-(g<<1)|0)+71|0;c=c>>>0>=63?63:c;}e=c<<4;J[d+4>>2]=e+22944;e=e+22952|0;J[d+8>>2]=J[e>>2];J[e>>2]=d;J[J[d+8>>2]+4>>2]=d;e=J[5995];d=c&31;if((c&63)>>>0>=32){c=1<>>32-d;}J[5994]=g|J[5994];J[5995]=c|e;J[f>>2]=b;break d}if(d>>>0>g>>>0){break f}b=J[c+4>>2];J[b+8>>2]=J[c+8>>2];J[J[c+8>>2]+4>>2]=b;b=e+j|0;J[f>>2]=b;break d}if(e>>>0>=b+16>>>0){J[f>>2]=b;J[(f+(b&-4)|0)-4>>2]=b;d=b+f|0;b=e-b|0;J[d>>2]=b;J[(d+(b&-4)|0)-4>>2]=b|1;c=J[d>>2]-8|0;h:{if(c>>>0<=127){b=(c>>>3|0)-1|0;break h}f=S(c);b=((c>>>29-f^4)-(f<<2)|0)+110|0;if(c>>>0<=4095){break h}b=((c>>>30-f^2)-(f<<1)|0)+71|0;b=b>>>0>=63?63:b;}c=b<<4;J[d+4>>2]=c+22944;c=c+22952|0;J[d+8>>2]=J[c>>2];J[c>>2]=d;J[J[d+8>>2]+4>>2]=d;c=J[5995];d=b&31;if((b&63)>>>0>=32){b=1<>>32-d;}J[5994]=e|J[5994];J[5995]=b|c;d=1;break c}d=1;if(b>>>0<=e>>>0){break e}}d=0;}break c}J[(f+(b&-4)|0)-4>>2]=b;d=1;}if(d){break a}b=_c(8,h);if(!b){break b}i=J[k>>2]-8|0;fb(b,a,h>>>0>>0?h:i);$a(a);i=b;}a=i;}return a}function an(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0;d=Ua-160|0;Ua=d;J[d+72>>2]=8356;J[d+16>>2]=8336;h=d+72|0;c=h;J[c+20>>2]=0;e=d+20|0;J[c+24>>2]=e;J[c+12>>2]=0;J[c+4>>2]=4098;J[c+8>>2]=6;J[c+16>>2]=!e;Sb(c+32|0,0,40);yg(c+28|0);J[d+72>>2]=8316;J[d+16>>2]=8296;J[d+144>>2]=0;J[d+148>>2]=-1;J[e>>2]=7896;yg(e+4|0);J[e+24>>2]=0;J[e+28>>2]=0;J[e+16>>2]=0;J[e+20>>2]=0;J[e+8>>2]=0;J[e+12>>2]=0;J[e>>2]=7960;J[d+60>>2]=0;J[d+64>>2]=0;J[d+52>>2]=0;J[d+56>>2]=0;J[d+68>>2]=16;c=J[J[d+16>>2]-12>>2];J[5996]=0;g=Ca(129)|0;f=J[5996];J[5996]=0;a:{b:{if((f|0)==1){break b}f=c+(d+16|0)|0;c=J[f+28>>2];J[d+12>>2]=c;J[c+4>>2]=J[c+4>>2]+1;J[5996]=0;ea(130,d+156|0,f|0,g|0);c=J[5996];J[5996]=0;c:{if((c|0)==1){break c}c=J[d+156>>2];i=J[c+4>>2]-1|0;J[c+4>>2]=i;if((i|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}c=J[f+24>>2];if(c){f=J[J[c>>2]+8>>2];J[5996]=0;aa(f|0,c|0,g|0);f=J[5996];J[5996]=0;if((f|0)==1){break c}f=J[c+4>>2];J[d+152>>2]=f;J[f+4>>2]=J[f+4>>2]+1;Og(c+4|0,g);c=J[d+152>>2];g=J[c+4>>2]-1|0;J[c+4>>2]=g;if((g|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}}c=J[d+12>>2];g=J[c+4>>2]-1|0;J[c+4>>2]=g;if((g|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}b=J[b>>2];J[5996]=0;b=_(131,d+16|0,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break b}J[5996]=0;aa(132,a|0,e|0);a=J[5996];J[5996]=0;if((a|0)==1){break b}J[b>>2]=8296;J[d+72>>2]=8316;J[e>>2]=7960;if(H[b+47|0]<0){$a(J[d+52>>2]);}Qc(e);Od(h);Ua=d+160|0;return}a=Z()|0;b=J[d+12>>2];e=J[b+4>>2]-1|0;J[b+4>>2]=e;if((e|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}break a}a=Z()|0;}gd(d+16|0);da(a|0);B();} +function Rf(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=J[d+4>>2];d=J[d+28>>2];a=Ua-224|0;Ua=a;J[a+216>>2]=c;J[a+220>>2]=b;b=ec(g);Tc(a+200|0,d,a+215|0);d=a+188|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+220|0,a+216|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+184>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=g+c;}J[5996]=0;g=$(187,J[a+220>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Dc(g,b,c,a+184|0,a+8|0,H[a+215|0],J[a+204>>2],K[a+211|0],a+16|0,a+12|0,12416)){break c}J[5996]=0;$(189,a+220|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+211|0];e:{if(!((g&128)>>>7|0?J[a+204>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Qf(c,J[a+184>>2],e,b);zb(a+200|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+220|0,a+216|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+220>>2];ab(d);ab(a+200|0);Ua=a+224|0;break a}}b=Z()|0;ab(d);ab(a+200|0);da(b|0);B();}return b|0}function Dl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=J[d+4>>2];d=J[d+28>>2];a=Ua-224|0;Ua=a;J[a+216>>2]=c;J[a+220>>2]=b;b=ec(g);Tc(a+200|0,d,a+215|0);d=a+188|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+220|0,a+216|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+184>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=g+c;}J[5996]=0;g=$(187,J[a+220>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Dc(g,b,c,a+184|0,a+8|0,H[a+215|0],J[a+204>>2],K[a+211|0],a+16|0,a+12|0,12416)){break c}J[5996]=0;$(189,a+220|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+211|0];e:{if(!((g&128)>>>7|0?J[a+204>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}J[f>>2]=Yf(c,J[a+184>>2],e,b);zb(a+200|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+220|0,a+216|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+220>>2];ab(d);ab(a+200|0);Ua=a+224|0;break a}}b=Z()|0;ab(d);ab(a+200|0);da(b|0);B();}return b|0}function Bl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=J[d+4>>2];d=J[d+28>>2];a=Ua-224|0;Ua=a;J[a+216>>2]=c;J[a+220>>2]=b;b=ec(g);Tc(a+200|0,d,a+215|0);d=a+188|0;J[d>>2]=0;J[d+4>>2]=0;J[d+8>>2]=0;c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=c;J[a+12>>2]=a+16;J[a+8>>2]=0;while(1){d:{J[5996]=0;g=_(186,a+220|0,a+216|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(g){break c}g=K[d+11|0];g=(g&128)>>>7|0?J[d+4>>2]:g&127;if(J[a+184>>2]==(g+c|0)){J[5996]=0;aa(172,d|0,g<<1);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?(J[d+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,d|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break b}c=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+184>>2]=g+c;}J[5996]=0;g=$(187,J[a+220>>2])|0;h=J[5996];J[5996]=0;if((h|0)==1){break d}if(Dc(g,b,c,a+184|0,a+8|0,H[a+215|0],J[a+204>>2],K[a+211|0],a+16|0,a+12|0,12416)){break c}J[5996]=0;$(189,a+220|0)|0;g=J[5996];J[5996]=0;if((g|0)!=1){continue}}break}break b}break b}g=K[a+211|0];e:{if(!((g&128)>>>7|0?J[a+204>>2]:g&127)){break e}g=J[a+12>>2];if((g-(a+16|0)|0)>159){break e}J[a+12>>2]=g+4;J[g>>2]=J[a+8>>2];}I[f>>1]=Sf(c,J[a+184>>2],e,b);zb(a+200|0,a+16|0,J[a+12>>2],e);J[5996]=0;b=_(186,a+220|0,a+216|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if(b){J[e>>2]=J[e>>2]|2;}b=J[a+220>>2];ab(d);ab(a+200|0);Ua=a+224|0;break a}}b=Z()|0;ab(d);ab(a+200|0);da(b|0);B();}return b|0}function jc(a,b,c,d,e,f,g,h){var i=0,j=0,k=0;i=Ua-16|0;Ua=i;J[i+8>>2]=c;J[i+12>>2]=b;b=J[d+28>>2];J[i+4>>2]=b;J[b+4>>2]=J[b+4>>2]+1;b=0;J[5996]=0;j=$(197,J[i+4>>2])|0;c=J[5996];J[5996]=0;if((c|0)!=1){c=J[i+4>>2];k=J[c+4>>2]-1|0;J[c+4>>2]=k;if((k|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}J[e>>2]=0;a:{while(1){if(b|(g|0)==(h|0)){break a}b:{if(Tb(i+12|0,i+8|0)){break b}c:{if((Xa[J[J[j>>2]+52>>2]](j,J[g>>2],0)|0)==37){if((g+4|0)==(h|0)){break b}b=Xa[J[J[j>>2]+52>>2]](j,J[g+4>>2],0)|0;d:{if(!((b|0)==69|(b&255)==48)){c=0;k=1;break d}if((g+8|0)==(h|0)){break b}c=b;b=Xa[J[J[j>>2]+52>>2]](j,J[g+8>>2],0)|0;k=2;}J[i+12>>2]=Xa[J[J[a>>2]+36>>2]](a,J[i+12>>2],J[i+8>>2],d,e,f,b,c);g=((k<<2)+g|0)+4|0;break c}if(Xa[J[J[j>>2]+12>>2]](j,1,J[g>>2])|0){while(1){e:{g=g+4|0;if((h|0)==(g|0)){g=h;break e}if(Xa[J[J[j>>2]+12>>2]](j,1,J[g>>2])|0){continue}}break}while(1){k=i+12|0;if(Tb(k,i+8|0)){break c}b=J[i+12>>2];c=J[b+12>>2];f:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break f}b=J[c>>2];}if(!(Xa[J[J[j>>2]+12>>2]](j,1,b)|0)){break c}Hc(k);continue}}b=J[i+12>>2];c=J[b+12>>2];g:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break g}b=J[c>>2];}if((Xa[J[J[j>>2]+28>>2]](j,b)|0)==(Xa[J[J[j>>2]+28>>2]](j,J[g>>2])|0)){g=g+4|0;Hc(i+12|0);break c}J[e>>2]=4;}b=J[e>>2];continue}break}J[e>>2]=4;}if(Tb(i+12|0,i+8|0)){J[e>>2]=J[e>>2]|2;}Ua=i+16|0;return J[i+12>>2]}c=Z()|0;a=J[i+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function cl(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=+e;var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;l=b;f=Ua-208|0;Ua=f;J[f+200>>2]=37;J[f+204>>2]=0;b=f+200|0;h=kd(b|1,5575,J[c+4>>2]);g=f+160|0;J[f+156>>2]=g;a=jb();a:{if(h){i=J[c+8>>2];O[f+40>>3]=e;J[f+32>>2]=i;g=yb(g,30,a,b,f+32|0);break a}O[f+48>>3]=e;g=yb(f+160|0,30,a,f+200|0,f+48|0);}J[f+80>>2]=184;i=f+148|0;J[i>>2]=0;J[i+4>>2]=J[f+80>>2];b=f+160|0;a=b;b:{c:{d:{e:{if((g|0)>=30){a=jb();f:{if(h){g=J[c+8>>2];O[f+8>>3]=e;J[f>>2]=g;g=dc(f+156|0,a,f+200|0,f);break f}O[f+16>>3]=e;g=dc(f+156|0,a,f+200|0,f+16|0);}if((g|0)==-1){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break d}break e}a=J[f+156>>2];tb(i,a);}k=a+g|0;m=Lb(a,k,J[c+4>>2]);J[f+68>>2]=184;h=f+72|0;J[h>>2]=0;J[h+4>>2]=J[f+68>>2];g:{h:{if((f+160|0)==(a|0)){g=f+80|0;break h}g=sb(g<<1);if(!g){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break e}a=Z()|0;break g}tb(h,g);b=a;}a=f+60|0;j=J[c+28>>2];J[a>>2]=j;J[j+4>>2]=J[j+4>>2]+1;J[5996]=0;ma(212,b|0,m|0,k|0,g|0,f+68|0,f- -64|0,a|0);b=J[5996];J[5996]=0;i:{if((b|0)!=1){a=J[a>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;a=ka(213,l|0,g|0,J[f+68>>2],J[f+64>>2],c|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break i}db(h);db(i);Ua=f+208|0;break b}a=Z()|0;b=J[f+60>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}break g}a=Z()|0;}db(h);break c}B();}a=Z()|0;}db(i);da(a|0);B();}return a|0}function Tk(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=+e;var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;l=b;f=Ua-368|0;Ua=f;J[f+360>>2]=37;J[f+364>>2]=0;b=f+360|0;h=kd(b|1,5575,J[c+4>>2]);g=f+320|0;J[f+316>>2]=g;a=jb();a:{if(h){i=J[c+8>>2];O[f+40>>3]=e;J[f+32>>2]=i;g=yb(g,30,a,b,f+32|0);break a}O[f+48>>3]=e;g=yb(f+320|0,30,a,f+360|0,f+48|0);}J[f+80>>2]=184;i=f+308|0;J[i>>2]=0;J[i+4>>2]=J[f+80>>2];b=f+320|0;a=b;b:{c:{d:{e:{if((g|0)>=30){a=jb();f:{if(h){g=J[c+8>>2];O[f+8>>3]=e;J[f>>2]=g;g=dc(f+316|0,a,f+360|0,f);break f}O[f+16>>3]=e;g=dc(f+316|0,a,f+360|0,f+16|0);}if((g|0)==-1){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)==1){break d}break e}a=J[f+316>>2];tb(i,a);}k=a+g|0;m=Lb(a,k,J[c+4>>2]);J[f+68>>2]=184;h=f+72|0;J[h>>2]=0;J[h+4>>2]=J[f+68>>2];g:{h:{if((f+320|0)==(a|0)){g=f+80|0;break h}g=sb(g<<3);if(!g){J[5996]=0;ca(185);a=J[5996];J[5996]=0;if((a|0)!=1){break e}a=Z()|0;break g}tb(h,g);b=a;}a=f+60|0;j=J[c+28>>2];J[a>>2]=j;J[j+4>>2]=J[j+4>>2]+1;J[5996]=0;ma(218,b|0,m|0,k|0,g|0,f+68|0,f- -64|0,a|0);b=J[5996];J[5996]=0;i:{if((b|0)!=1){a=J[a>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;a=ka(219,l|0,g|0,J[f+68>>2],J[f+64>>2],c|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break i}db(h);db(i);Ua=f+368|0;break b}a=Z()|0;b=J[f+60>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}break g}a=Z()|0;}db(h);break c}B();}a=Z()|0;}db(i);da(a|0);B();}return a|0}function Gi(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;n=Ua-16|0;Ua=n;b=c;while(1){a:{if((b|0)==(d|0)){b=d;break a}if(!J[b>>2]){break a}b=b+4|0;continue}break}J[h>>2]=f;J[e>>2]=c;while(1){b:{c:{if(!((c|0)==(d|0)|(f|0)==(g|0))){q=1;r=Ua-16|0;Ua=r;s=Xb(r+12|0,J[a+8>>2]);i=f;j=g-i|0;m=0;o=Ua-16|0;Ua=o;k=J[e>>2];p=b-c>>2;d:{if(!k|!p){break d}j=i?j:0;while(1){l=pe(j>>>0<4?o+12|0:i,J[k>>2]);if((l|0)==-1){m=-1;break d}if(i){if(j>>>0<=3){if(j>>>0>>0){break d}fb(i,o+12|0,l);}j=j-l|0;i=i+l|0;}else {i=0;}if(!J[k>>2]){k=0;break d}m=m+l|0;k=k+4|0;p=p-1|0;if(p){continue}break}}if(i){J[e>>2]=k;}Ua=o+16|0;i=J[s>>2];if(i){J[6178]=(i|0)==-1?24816:i;}Ua=r+16|0;e:{f:{g:{h:{switch(m+1|0){case 0:J[h>>2]=f;while(1){i:{if(J[e>>2]==(c|0)){break i}b=Md(f,J[c>>2],J[a+8>>2]);if((b|0)==-1){break i}f=b+J[h>>2]|0;J[h>>2]=f;c=c+4|0;continue}break}J[e>>2]=c;break g;case 1:break c;default:break h}}f=m+J[h>>2]|0;J[h>>2]=f;if((f|0)==(g|0)){break e}if((b|0)==(d|0)){c=J[e>>2];b=d;continue}b=Md(n+12|0,0,J[a+8>>2]);if((b|0)!=-1){break f}}q=2;break c}c=n+12|0;if(g-J[h>>2]>>>0>>0){break c}while(1){if(b){f=K[c|0];i=J[h>>2];J[h>>2]=i+1;H[i|0]=f;b=b-1|0;c=c+1|0;continue}break}c=J[e>>2]+4|0;J[e>>2]=c;b=c;while(1){if((b|0)==(d|0)){b=d;break b}if(!J[b>>2]){break b}b=b+4|0;continue}}c=J[e>>2];}q=(c|0)!=(d|0);}Ua=n+16|0;return q|0}f=J[h>>2];continue}}function Yk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;k=Ua-16|0;Ua=k;m=je(J[g>>2]);g=Zd(J[g>>2]);Xa[J[J[g>>2]+20>>2]](k+4|0,g);a:{j=K[k+15|0];b:{if(!((j&128)>>>7|0?J[k+8>>2]:j&127)){J[5996]=0;ga(208,m|0,a|0,c|0,d|0);g=J[5996];J[5996]=0;if((g|0)==1){break b}g=(c-a<<2)+d|0;J[f>>2]=g;break a}J[f>>2]=d;c:{d:{j=a;i=K[j|0];switch(i-43|0){case 0:case 2:break d;default:break c}}J[5996]=0;j=_(216,m|0,i<<24>>24)|0;i=J[5996];J[5996]=0;if((i|0)==1){break b}i=J[f>>2];J[f>>2]=i+4;J[i>>2]=j;j=a+1|0;}if(!(K[j|0]!=48|(c-j|0)<2|(K[j+1|0]|32)!=120)){J[5996]=0;i=_(216,m|0,48)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}h=J[f>>2];J[f>>2]=h+4;J[h>>2]=i;i=H[j+1|0];J[5996]=0;i=_(216,m|0,i|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}h=J[f>>2];J[f>>2]=h+4;J[h>>2]=i;j=j+2|0;}vc(j,c);J[5996]=0;o=$(206,g|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break b}i=0;g=j;while(1){if(c>>>0<=g>>>0){md((j-a<<2)+d|0,J[f>>2]);g=J[f>>2];break a}h=k+4|0;l=(K[h+11|0]&128)>>>7|0;if(!(!K[(l?J[h>>2]:h)+i|0]|H[(l?J[h>>2]:h)+i|0]!=(n|0))){h=J[f>>2];J[f>>2]=h+4;J[h>>2]=o;n=0;l=i;i=K[k+15|0];i=l+(l>>>0<((i&128)>>>7|0?J[k+8>>2]:i&127)-1>>>0)|0;}h=H[g|0];J[5996]=0;h=_(216,m|0,h|0)|0;l=J[5996];J[5996]=0;if((l|0)!=1){l=J[f>>2];J[f>>2]=l+4;J[l>>2]=h;g=g+1|0;n=n+1|0;continue}break}}a=Z()|0;ab(k+4|0);da(a|0);B();}J[e>>2]=(b|0)==(c|0)?g:(b-a<<2)+d|0;ab(k+4|0);Ua=k+16|0;}function gl(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;k=Ua-16|0;Ua=k;m=le(J[g>>2]);g=de(J[g>>2]);Xa[J[J[g>>2]+20>>2]](k+4|0,g);a:{j=K[k+15|0];b:{if(!((j&128)>>>7|0?J[k+8>>2]:j&127)){J[5996]=0;ga(195,m|0,a|0,c|0,d|0);g=J[5996];J[5996]=0;if((g|0)==1){break b}g=(c-a|0)+d|0;J[f>>2]=g;break a}J[f>>2]=d;c:{d:{j=a;i=K[j|0];switch(i-43|0){case 0:case 2:break d;default:break c}}J[5996]=0;j=_(171,m|0,i<<24>>24)|0;i=J[5996];J[5996]=0;if((i|0)==1){break b}i=J[f>>2];J[f>>2]=i+1;H[i|0]=j;j=a+1|0;}if(!(K[j|0]!=48|(c-j|0)<2|(K[j+1|0]|32)!=120)){J[5996]=0;i=_(171,m|0,48)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;i=H[j+1|0];J[5996]=0;i=_(171,m|0,i|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}h=J[f>>2];J[f>>2]=h+1;H[h|0]=i;j=j+2|0;}vc(j,c);J[5996]=0;o=$(193,g|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break b}i=0;g=j;while(1){if(c>>>0<=g>>>0){vc((j-a|0)+d|0,J[f>>2]);g=J[f>>2];break a}h=k+4|0;l=(K[h+11|0]&128)>>>7|0;if(!(!K[(l?J[h>>2]:h)+i|0]|H[(l?J[h>>2]:h)+i|0]!=(n|0))){h=J[f>>2];J[f>>2]=h+1;H[h|0]=o;n=0;l=i;i=K[k+15|0];i=l+(l>>>0<((i&128)>>>7|0?J[k+8>>2]:i&127)-1>>>0)|0;}h=H[g|0];J[5996]=0;h=_(171,m|0,h|0)|0;l=J[5996];J[5996]=0;if((l|0)!=1){l=J[f>>2];J[f>>2]=l+1;H[l|0]=h;g=g+1|0;n=n+1|0;continue}break}}a=Z()|0;ab(k+4|0);da(a|0);B();}J[e>>2]=(b|0)==(c|0)?g:(b-a|0)+d|0;ab(k+4|0);Ua=k+16|0;}function Pe(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0;a=Ua-16|0;Ua=a;J[a+12>>2]=c;J[a+8>>2]=f;J[a+12>>2]=c;J[a+8>>2]=f;a:{b:{c:{while(1){c=J[a+12>>2];if(!(c>>>0>=d>>>0|f>>>0>=g>>>0)){i=H[c|0];j=i&255;d:{if((i|0)>=0){I[f>>1]=j;b=c+1|0;break d}b=2;if(i>>>0<4294967234){break b}if(i>>>0<=4294967263){if((d-c|0)<2){break c}i=K[c+1|0];if((i&192)!=128){break a}I[f>>1]=i&63|j<<6&1984;b=c+2|0;break d}if(i>>>0<=4294967279){if((d-c|0)<3){break c}k=K[c+2|0];i=K[c+1|0];e:{f:{if((j|0)!=237){if((j|0)!=224){break f}if((i&224)==160){break e}break a}if((i&224)==128){break e}break a}if((i&192)!=128){break a}}if((k&192)!=128){break a}I[f>>1]=k&63|((i&63)<<6|j<<12);b=c+3|0;break d}if(i>>>0>4294967284){break b}b=1;if((d-c|0)<4){break a}k=K[c+3|0];i=K[c+2|0];c=K[c+1|0];g:{h:{switch(j-240|0){case 0:if((c+112&255)>>>0>=48){break b}break g;case 4:if((c&240)!=128){break b}break g;default:break h}}if((c&192)!=128){break b}}if((i&192)!=128|(k&192)!=128){break b}if((g-f|0)<4){break a}b=2;j=j&7;if((c<<12&196608|j<<18)>>>0>1114111){break a}b=c<<2;I[f>>1]=(i>>>4&3|(b&192|j<<8|b&60))+16320|55296;J[a+8>>2]=f+2;I[f+2>>1]=i<<6&960|k&63|56320;b=J[a+12>>2]+4|0;}J[a+12>>2]=b;f=J[a+8>>2]+2|0;J[a+8>>2]=f;continue}break}b=c>>>0>>0;break a}b=1;break a}b=2;}J[e>>2]=J[a+12>>2];J[h>>2]=J[a+8>>2];Ua=a+16|0;return b|0}function tl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-32|0;Ua=g;J[g+28>>2]=b;a:{b:{if(!(H[d+4|0]&1)){J[g>>2]=-1;b=Xa[J[J[a>>2]+16>>2]](a,b,c,d,e,g)|0;c:{switch(J[g>>2]){case 1:H[f|0]=1;break a;case 0:break b;default:break c}}H[f|0]=1;J[e>>2]=4;break a}a=J[d+28>>2];J[g>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;h=$(197,J[g>>2])|0;a=J[5996];J[5996]=0;d:{e:{f:{g:{if((a|0)!=1){a=J[g>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=J[d+28>>2];J[g>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;b=$(198,J[g>>2])|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}a=J[g>>2];d=J[a+4>>2]-1|0;J[a+4>>2]=d;if((d|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;aa(199,g|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){b=Z()|0;break d}J[5996]=0;aa(200,g|12,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break f}J[5996]=0;d=g+24|0;a=Ba(201,g+28|0,c|0,g|0,d|0,h|0,e|0,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break e}H[f|0]=(a|0)==(g|0);b=J[g+28>>2];while(1){d=ab(d-12|0);if((g|0)!=(d|0)){continue}break}break a}b=Z()|0;a=J[g>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}break d}b=Z()|0;a=J[g>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}break d}b=Z()|0;ab(g);break d}b=Z()|0;while(1){d=ab(d-12|0);if((g|0)!=(d|0)){continue}break}}da(b|0);B();}H[f|0]=0;}Ua=g+32|0;return b|0}function Hl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-32|0;Ua=g;J[g+28>>2]=b;a:{b:{if(!(H[d+4|0]&1)){J[g>>2]=-1;b=Xa[J[J[a>>2]+16>>2]](a,b,c,d,e,g)|0;c:{switch(J[g>>2]){case 1:H[f|0]=1;break a;case 0:break b;default:break c}}H[f|0]=1;J[e>>2]=4;break a}a=J[d+28>>2];J[g>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;h=$(170,J[g>>2])|0;a=J[5996];J[5996]=0;d:{e:{f:{g:{if((a|0)!=1){a=J[g>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=J[d+28>>2];J[g>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;b=$(180,J[g>>2])|0;a=J[5996];J[5996]=0;if((a|0)==1){break g}a=J[g>>2];d=J[a+4>>2]-1|0;J[a+4>>2]=d;if((d|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}J[5996]=0;aa(181,g|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){b=Z()|0;break d}J[5996]=0;aa(182,g|12,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break f}J[5996]=0;d=g+24|0;a=Ba(183,g+28|0,c|0,g|0,d|0,h|0,e|0,1)|0;b=J[5996];J[5996]=0;if((b|0)==1){break e}H[f|0]=(a|0)==(g|0);b=J[g+28>>2];while(1){d=ab(d-12|0);if((g|0)!=(d|0)){continue}break}break a}b=Z()|0;a=J[g>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}break d}b=Z()|0;a=J[g>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}break d}b=Z()|0;ab(g);break d}b=Z()|0;while(1){d=ab(d-12|0);if((g|0)!=(d|0)){continue}break}}da(b|0);B();}H[f|0]=0;}Ua=g+32|0;return b|0}function Lm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0;e=Ua-32|0;Ua=e;a:{b:{c:{if((c|0)<=0){break c}while(1){h=b+g|0;if(K[h|0]!=41){g=g+1|0;if((c|0)!=(g|0)){continue}break c}break}if(g){break b}}H[a+16|0]=0;H[a|0]=0;break a}if(g>>>0<2147483632){d:{if(g>>>0<=10){H[e+31|0]=g;c=e+20|0;break d}f=(g|15)+1|0;c=cb(f);J[e+28>>2]=f|-2147483648;J[e+20>>2]=c;J[e+24>>2]=g;}i=g&7;if(i){f=0;while(1){H[c|0]=K[b|0];c=c+1|0;b=b+1|0;f=f+1|0;if((i|0)!=(f|0)){continue}break}}if(g>>>0>=8){while(1){H[c|0]=K[b|0];H[c+1|0]=K[b+1|0];H[c+2|0]=K[b+2|0];H[c+3|0]=K[b+3|0];H[c+4|0]=K[b+4|0];H[c+5|0]=K[b+5|0];H[c+6|0]=K[b+6|0];H[c+7|0]=K[b+7|0];c=c+8|0;b=b+8|0;if((h|0)!=(b|0)){continue}break}}H[c|0]=0;f=K[e+31|0];c=f<<24>>24;b=(c|0)<0;e:{f:{g:{f=b?J[e+24>>2]:f;h:{if(!f){break h}b=b?J[e+20>>2]:e+20|0;h=f+b|0;while(1){if(H[K[b|0]+5584|0]<0){break h}b=b+1|0;if((h|0)!=(b|0)){continue}break}if(!(f&1)){break g}}H[a+16|0]=0;H[a|0]=0;break f}J[5996]=0;aa(31,e+8|0,e+20|0);b=J[5996];J[5996]=0;if((b|0)==1){break e}c=J[e+12>>2];b=J[e+8>>2];i:{if((c-b|0)==(d|0)){d=J[e+16>>2];H[a+16|0]=1;J[a+12>>2]=g;J[a+8>>2]=d;J[a+4>>2]=c;J[a>>2]=b;break i}H[a+16|0]=0;H[a|0]=0;if(!b){break i}$a(b);}c=K[e+31|0];}if(c<<24>>24>=0){break a}$a(J[e+20>>2]);break a}a=Z()|0;if(H[e+31|0]<0){$a(J[e+20>>2]);}da(a|0);B();}ub();B();}Ua=e+32|0;}function wk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0;a=Ua-144|0;Ua=a;J[a+136>>2]=c;J[a+140>>2]=b;J[a+20>>2]=220;b=a+24|0;J[b>>2]=a+32;i=a+20|0;J[b+4>>2]=J[i>>2];j=a+16|0;h=J[e+28>>2];J[j>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=$(170,J[a+16>>2])|0;k=J[5996];J[5996]=0;if((k|0)!=1){a:{H[a+15|0]=0;e=J[e+4>>2];J[5996]=0;c=ua(221,a+140|0,c|0,d|0,j|0,e|0,f|0,a+15|0,h|0,b|0,i|0,a+132|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}b:{c:{if(!c){break c}d:{if((K[g+11|0]&128)>>>7|0){H[J[g>>2]]=0;J[g+4>>2]=0;break d}H[g|0]=0;H[g+11|0]=0;}if(K[a+15|0]){J[5996]=0;c=_(171,h|0,45)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}J[5996]=0;aa(98,g|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}}J[5996]=0;d=_(171,h|0,48)|0;c=J[5996];J[5996]=0;if((c|0)==1){break b}e=J[a+20>>2];h=e-1|0;c=J[b>>2];d=d&255;while(1){if(!((d|0)!=K[c|0]|c>>>0>=h>>>0)){c=c+1|0;continue}break}J[5996]=0;ba(227,g|0,c|0,e|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break c}break a}J[5996]=0;c=_(186,a+140|0,a+136|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}if(c){J[f>>2]=J[f>>2]|2;}e=J[a+140>>2];c=J[a+16>>2];d=J[c+4>>2]-1|0;J[c+4>>2]=d;if((d|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}db(b);Ua=a+144|0;return e|0}}}d=Z()|0;a=J[a+16>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(b);da(d|0);B();}function ok(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0,j=0,k=0;a=Ua-448|0;Ua=a;J[a+440>>2]=c;J[a+444>>2]=b;J[a+20>>2]=220;b=a+24|0;J[b>>2]=a+32;i=a+20|0;J[b+4>>2]=J[i>>2];j=a+16|0;h=J[e+28>>2];J[j>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=$(197,J[a+16>>2])|0;k=J[5996];J[5996]=0;if((k|0)!=1){a:{H[a+15|0]=0;e=J[e+4>>2];J[5996]=0;c=ua(228,a+444|0,c|0,d|0,j|0,e|0,f|0,a+15|0,h|0,b|0,i|0,a+432|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}b:{c:{if(!c){break c}d:{if((K[g+11|0]&128)>>>7|0){J[J[g>>2]>>2]=0;J[g+4>>2]=0;break d}J[g>>2]=0;H[g+11|0]=0;}if(K[a+15|0]){J[5996]=0;c=_(216,h|0,45)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}J[5996]=0;aa(232,g|0,c|0);c=J[5996];J[5996]=0;if((c|0)==1){break a}}J[5996]=0;d=_(216,h|0,48)|0;c=J[5996];J[5996]=0;if((c|0)==1){break b}e=J[a+20>>2];h=e-4|0;c=J[b>>2];while(1){if(!((d|0)!=J[c>>2]|c>>>0>=h>>>0)){c=c+4|0;continue}break}J[5996]=0;ba(234,g|0,c|0,e|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break c}break a}J[5996]=0;c=_(202,a+444|0,a+440|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}if(c){J[f>>2]=J[f>>2]|2;}e=J[a+444>>2];c=J[a+16>>2];d=J[c+4>>2]-1|0;J[c+4>>2]=d;if((d|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}db(b);Ua=a+448|0;return e|0}}}d=Z()|0;a=J[a+16>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}db(b);da(d|0);B();} +function Hh(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0;if(Jb(a,J[b+8>>2],e)){if(!(J[b+28>>2]==1|J[b+4>>2]!=(c|0))){J[b+28>>2]=d;}return}a:{if(Jb(a,J[b>>2],e)){if(!(J[b+16>>2]!=(c|0)&J[b+20>>2]!=(c|0))){if((d|0)!=1){break a}J[b+32>>2]=1;return}J[b+32>>2]=d;b:{if(J[b+44>>2]==4){break b}f=a+16|0;h=f+(J[a+12>>2]<<3)|0;d=0;c:{d:{while(1){e:{if(f>>>0>=h>>>0){break e}I[b+52>>1]=0;Fd(J[f>>2],J[f+4>>2],b,c,c,1,e);if(K[b+54|0]){break e}f:{if(!K[b+53|0]){break f}if(K[b+52|0]){if(J[b+24>>2]!=1){d=1;g=1;if(K[a+8|0]&2){break f}}J[b+44>>2]=3;return}d=1;if(!(H[a+8|0]&1)){break d}}f=f+8|0;continue}break}if(!d){break c}}J[b+44>>2]=3;if(!g){break b}break a}J[b+44>>2]=4;if(g){break a}}J[b+20>>2]=c;J[b+40>>2]=J[b+40>>2]+1;if(J[b+36>>2]!=1|J[b+24>>2]!=2){break a}H[b+54|0]=1;return}g=J[a+12>>2];cd(J[a+16>>2],J[a+20>>2],b,c,d,e);f=a+24|0;g=(a+16|0)+(g<<3)|0;if(f>>>0>=g>>>0){break a}a=J[a+8>>2];if(!(!(a&2)&J[b+36>>2]!=1)){while(1){if(K[b+54|0]){break a}cd(J[f>>2],J[f+4>>2],b,c,d,e);f=f+8|0;if(g>>>0>f>>>0){continue}break}break a}if(!(a&1)){while(1){if(K[b+54|0]|J[b+36>>2]==1){break a}cd(J[f>>2],J[f+4>>2],b,c,d,e);f=f+8|0;if(g>>>0>f>>>0){continue}break a}}while(1){if(K[b+54|0]|J[b+36>>2]==1&J[b+24>>2]==1){break a}cd(J[f>>2],J[f+4>>2],b,c,d,e);f=f+8|0;if(g>>>0>f>>>0){continue}break}}}function Qe(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0;a=Ua-16|0;Ua=a;J[a+12>>2]=c;J[a+8>>2]=f;J[a+12>>2]=c;J[a+8>>2]=f;c=J[a+12>>2];a:{while(1){if(c>>>0>=d>>>0){f=0;break a}b:{b=L[c>>1];c:{if(b>>>0<=127){f=1;c=J[a+8>>2];if((g-c|0)<=0){break a}J[a+8>>2]=c+1;H[c|0]=b;break c}if(b>>>0<=2047){c=J[a+8>>2];if((g-c|0)<2){break b}J[a+8>>2]=c+1;H[c|0]=b>>>6|192;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;break c}if(b>>>0<=55295){c=J[a+8>>2];if((g-c|0)<3){break b}J[a+8>>2]=c+1;H[c|0]=b>>>12|224;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b>>>6&63|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;break c}d:{e:{if(b>>>0<=56319){f=1;if((d-c|0)<4){break a}i=L[c+2>>1];if((i&64512)!=56320){break e}if((g-J[a+8>>2]|0)<4){break a}J[a+12>>2]=c+2;c=J[a+8>>2];J[a+8>>2]=c+1;f=c;c=(b>>>6&15)+1|0;H[f|0]=c>>>2|240;f=J[a+8>>2];J[a+8>>2]=f+1;H[f|0]=c<<4&48|b>>>2&15|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=i>>>6&15|b<<4&48|128;b=J[a+8>>2];J[a+8>>2]=b+1;H[b|0]=i&63|128;break c}if(b>>>0>=57344){break d}}f=2;break a}c=J[a+8>>2];if((g-c|0)<3){break b}J[a+8>>2]=c+1;H[c|0]=b>>>12|224;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b>>>6&63|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;}c=J[a+12>>2]+2|0;J[a+12>>2]=c;continue}break}f=1;}J[e>>2]=J[a+12>>2];J[h>>2]=J[a+8>>2];Ua=a+16|0;return f|0}function Yn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=J[a+4>>2];d=J[a+8>>2];if(c>>>0>>0){J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;e=J[b+28>>2];J[c+24>>2]=J[b+24>>2];J[c+28>>2]=e;e=J[b+20>>2];J[c+16>>2]=J[b+16>>2];J[c+20>>2]=e;e=J[b+12>>2];J[c+8>>2]=J[b+8>>2];J[c+12>>2]=e;J[a+4>>2]=c+32;return}a:{h=J[a>>2];f=c-h>>5;e=f+1|0;if(e>>>0<134217728){d=d-h|0;g=d>>4;g=d>>>0>=2147483616?134217727:e>>>0>>0?g:e;if(g){if(g>>>0>=134217728){break a}e=cb(g<<5);}else {e=0;}d=e+(f<<5)|0;J[d>>2]=J[b>>2];J[d+4>>2]=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;f=J[b+28>>2];J[d+24>>2]=J[b+24>>2];J[d+28>>2]=f;f=J[b+20>>2];J[d+16>>2]=J[b+16>>2];J[d+20>>2]=f;f=J[b+12>>2];J[d+8>>2]=J[b+8>>2];J[d+12>>2]=f;f=d+32|0;if((c|0)!=(h|0)){while(1){d=d-32|0;c=c-32|0;J[d>>2]=J[c>>2];J[d+4>>2]=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;b=J[c+28>>2];J[d+24>>2]=J[c+24>>2];J[d+28>>2]=b;b=J[c+20>>2];J[d+16>>2]=J[c+16>>2];J[d+20>>2]=b;b=J[c+12>>2];J[d+8>>2]=J[c+8>>2];J[d+12>>2]=b;if((c|0)!=(h|0)){continue}break}}J[a+8>>2]=e+(g<<5);b=J[a>>2];J[a>>2]=d;c=J[a+4>>2];J[a+4>>2]=f;if((b|0)!=(c|0)){while(1){c=c-32|0;a=J[c+4>>2];b:{if(!a){break b}e=J[a+4>>2];J[a+4>>2]=e-1;if(e){break b}Xa[J[J[a>>2]+8>>2]](a);bb(a);}if((b|0)!=(c|0)){continue}break}}if(b){$a(b);}return}nb();B();}Pb();B();}function hg(a,b){var c=0,d=0,e=0,f=0,g=0;a:{b:{c:{d:{e:{f:{c=J[a+4>>2];g:{if((c|0)!=J[a+104>>2]){J[a+4>>2]=c+1;c=K[c|0];break g}c=gb(a);}switch(c-43|0){case 0:case 2:break f;default:break e}}g=(c|0)==45;b=!b;c=J[a+4>>2];h:{if((c|0)!=J[a+104>>2]){J[a+4>>2]=c+1;c=K[c|0];break h}c=gb(a);}d=c-58|0;if(b|d>>>0>4294967285){break d}b=J[a+116>>2];if((b|0)>0|(b|0)>=0){break c}break a}d=c-58|0;}if(d>>>0<=4294967285){if(J[a+116>>2]<0){break a}break b}i:{if(c-48>>>0>=10){break i}while(1){e=(P(e,10)+c|0)-48|0;f=(e|0)<214748364;c=J[a+4>>2];j:{if((c|0)!=J[a+104>>2]){J[a+4>>2]=c+1;c=K[c|0];break j}c=gb(a);}b=c-48|0;if(f&b>>>0<=9){continue}break}f=e>>31;if(b>>>0>=10){break i}while(1){b=c;c=co(e,f,10,0);d=b+c|0;b=Wa;e=d-48|0;d=(c>>>0>d>>>0?b+1|0:b)-(d>>>0<48)|0;f=d;d=e>>>0<2061584302&(d|0)<=21474836|(d|0)<21474836;c=J[a+4>>2];k:{if((c|0)!=J[a+104>>2]){J[a+4>>2]=c+1;c=K[c|0];break k}c=gb(a);}b=c-48|0;if(d&b>>>0<=9){continue}break}if(b>>>0>=10){break i}while(1){b=J[a+4>>2];l:{if((b|0)!=J[a+104>>2]){J[a+4>>2]=b+1;b=K[b|0];break l}b=gb(a);}if(b-48>>>0<10){continue}break}}b=J[a+116>>2];if((b|0)>0|(b|0)>=0){J[a+4>>2]=J[a+4>>2]-1;}Wa=g?0-(((e|0)!=0)+f|0)|0:f;return g?0-e|0:e}J[a+4>>2]=J[a+4>>2]-1;}J[a+4>>2]=J[a+4>>2]-1;}Wa=-2147483648;return 0}function Se(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;var i=0,j=0,k=0,l=0,m=0;a=Ua-16|0;Ua=a;J[a+12>>2]=c;J[a+8>>2]=f;J[a+12>>2]=c;J[a+8>>2]=f;a:{b:{while(1){b=J[a+12>>2];if(!(d>>>0<=b>>>0|f>>>0>=g>>>0)){i=H[b|0];c=i&255;c:{if((i|0)>=0){i=1;break c}k=2;if(i>>>0<4294967234){break a}if(i>>>0<=4294967263){if((d-b|0)<2){break b}i=K[b+1|0];if((i&192)!=128){break a}c=i&63|c<<6&1984;i=2;break c}if(i>>>0<=4294967279){if((d-b|0)<3){break b}j=K[b+2|0];i=K[b+1|0];d:{e:{if((c|0)!=237){if((c|0)!=224){break e}if((i&224)==160){break d}break a}if((i&224)==128){break d}break a}if((i&192)!=128){break a}}if((j&192)!=128){break a}c=j&63|(c<<12&61440|(i&63)<<6);i=3;break c}if(i>>>0>4294967284){break a}if((d-b|0)<4){break b}l=K[b+3|0];m=K[b+2|0];j=K[b+1|0];f:{g:{switch(c-240|0){case 0:if((j+112&255)>>>0<48){break f}break a;case 4:if((j&240)==128){break f}break a;default:break g}}if((j&192)!=128){break a}}if((m&192)!=128|(l&192)!=128){break a}i=4;c=l&63|(m<<6&4032|(c<<18&1835008|(j&63)<<12));if(c>>>0>1114111){break a}}J[f>>2]=c;J[a+12>>2]=b+i;f=J[a+8>>2]+4|0;J[a+8>>2]=f;continue}break}k=b>>>0>>0;break a}k=1;}J[e>>2]=J[a+12>>2];J[h>>2]=J[a+8>>2];Ua=a+16|0;return k|0}function Wn(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0;f=Ua-32|0;Ua=f;J[a+8>>2]=0;J[a+12>>2]=0;J[a+4>>2]=e;J[a>>2]=b;J[a+16>>2]=0;J[a+8>>2]=J[d>>2];J[a+12>>2]=J[d+4>>2];J[a+16>>2]=J[d+8>>2];J[d+8>>2]=0;J[d>>2]=0;J[d+4>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+32>>2]=J[c>>2];J[a+36>>2]=J[c+4>>2];J[a+40>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[5996]=0;aa(86,a+44|0,a|0);b=J[5996];J[5996]=0;a:{if((b|0)==1){break a}J[5996]=0;aa(87,a- -64|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}c=0;J[5996]=0;b=$(88,a|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}J[a+80>>2]=b;b=J[a+32>>2];e=J[a+36>>2];if((b|0)==(e|0)){d=0;}else {d=b;while(1){c=J[J[d>>2]+84>>2]+c|0;d=d+8|0;if((e|0)!=(d|0)){continue}break}d=J[J[b>>2]+80>>2];}g=J[a+4>>2];h=J[a>>2];i=J[a+8>>2];j=J[a+12>>2];J[5996]=0;b=ka(89,h|0,d|0,c|0,g|0,e-b>>3,(j-i|0)/12|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+84>>2]=b;J[5996]=0;J[f+28>>2]=a;ea(90,f+12|0,a|0,f+28|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[f+24|0];if(b){Db(J[f+16>>2]);}H[a+88|0]=b^1;Ua=f+32|0;return a|0}c=Z()|0;lb(a+32|0);b=J[a+20>>2];if(b){J[a+24>>2]=b;$a(b);}rb(a+8|0);da(c|0);B();}function Km(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;g=Ua-32|0;Ua=g;d=cb(104);J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;e=J[c+8>>2];J[c+8>>2]=0;f=J[c>>2];h=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;J[d+16>>2]=0;J[d+20>>2]=0;J[d+12>>2]=b;J[d+24>>2]=0;J[d+28>>2]=0;J[d+52>>2]=0;i=d+44|0;b=i;J[b>>2]=0;J[b+4>>2]=0;J[d+40>>2]=e;J[d+32>>2]=f;J[d+36>>2]=h;J[5996]=0;f=d+12|0;aa(86,d+56|0,f|0);b=J[5996];J[5996]=0;a:{if((b|0)==1){break a}J[5996]=0;aa(87,d+76|0,f|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=0;J[5996]=0;c=$(88,f|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break a}J[d+92>>2]=c;h=J[d+48>>2];e=J[d+44>>2];if((h|0)==(e|0)){c=0;}else {c=e;while(1){b=J[J[c>>2]+84>>2]+b|0;c=c+8|0;if((h|0)!=(c|0)){continue}break}c=J[J[e>>2]+80>>2];}j=J[d+16>>2];k=J[d+12>>2];l=J[d+20>>2];m=J[d+24>>2];J[5996]=0;b=ka(89,k|0,c|0,b|0,j|0,h-e>>3,(m-l|0)/12|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[d+96>>2]=b;J[5996]=0;J[g+28>>2]=f;ea(90,g+12|0,f|0,g+28|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[g+24|0];if(b){Db(J[g+16>>2]);}H[d+100|0]=b^1;J[a+4>>2]=d;J[a>>2]=f;Ua=g+32|0;return}b=Z()|0;lb(i);a=J[d+32>>2];if(a){J[d+36>>2]=a;$a(a);}rb(d+20|0);$a(d);da(b|0);B();}function sh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-32|0;Ua=g;h=1;a:{b:{c:{d:{switch(a|0){case 3:h=24;break c;case 4:case 5:J[g+24>>2]=0;J[g+28>>2]=0;J[g+16>>2]=0;J[g+20>>2]=0;J[g+8>>2]=0;J[g+12>>2]=0;J[g>>2]=0;J[g+4>>2]=0;J[5996]=0;a=nc(g,d,0);b=J[5996];J[5996]=0;if((b|0)==1){h=Z()|0;if(M[g>>2]<29){break a}break b}a=J[a>>2];b=a>>>0<29;h=(b?a:a-29|0)+1|0;if(b){break c}$a(J[g+8>>2]);break c;case 6:case 7:h=39;break c;case 8:case 9:h=27;break c;case 25:h=(P(f,34)|d>>>0>16)+(f>>>0>16?4:3)|0;break c;case 17:h=c;break c;case 14:h=!(Wb(1239,1)&(b^-1))+c|0;break c;case 11:case 12:case 16:case 18:case 19:h=c+1|0;break c;case 10:case 20:h=c+2|0;break c;case 13:case 21:case 22:case 23:h=c+3|0;break c;case 15:h=c+4|0;break c;case 24:J[g+24>>2]=0;J[g+28>>2]=0;J[g+16>>2]=0;J[g+20>>2]=0;J[g+8>>2]=0;J[g+12>>2]=0;J[g>>2]=0;J[g+4>>2]=0;J[5996]=0;a=nc(g,d,0);b=J[5996];J[5996]=0;if((b|0)==1){h=Z()|0;if(M[g>>2]>=29){break b}break a}a=J[a>>2];b=a>>>0<29;h=(c+e|0)+(b?a:a-29|0)|0;if(b){break c}$a(J[g+8>>2]);break c;default:la(2350,1859,280,2003);B();case 0:case 1:break c;case 2:break d}}h=34;}Ua=g+32|0;return h|0}$a(J[g+8>>2]);}da(h|0);B();}function cn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;g=J[a+8>>2];e=J[a+4>>2];if(g-e>>>0>=b>>>0){d=e;h=b&7;if(h){while(1){H[d|0]=K[c|0];d=d+1|0;f=f+1|0;if((h|0)!=(f|0)){continue}break}}b=b+e|0;while(1){H[d|0]=K[c|0];H[d+1|0]=K[c|0];H[d+2|0]=K[c|0];H[d+3|0]=K[c|0];H[d+4|0]=K[c|0];H[d+5|0]=K[c|0];H[d+6|0]=K[c|0];H[d+7|0]=K[c|0];d=d+8|0;if((b|0)!=(d|0)){continue}break}J[a+4>>2]=b;return}d=J[a>>2];f=e-d|0;i=f+b|0;if((i|0)>=0){g=g-d|0;d=g<<1;i=g>>>0>=1073741823?2147483647:d>>>0>i>>>0?d:i;if(i){j=cb(i);}f=f+j|0;d=f;g=b&7;if(g){while(1){H[d|0]=K[c|0];d=d+1|0;h=h+1|0;if((g|0)!=(h|0)){continue}break}}h=b+f|0;while(1){H[d|0]=K[c|0];H[d+1|0]=K[c|0];H[d+2|0]=K[c|0];H[d+3|0]=K[c|0];H[d+4|0]=K[c|0];H[d+5|0]=K[c|0];H[d+6|0]=K[c|0];H[d+7|0]=K[c|0];d=d+8|0;if((h|0)!=(d|0)){continue}break}g=J[a>>2];if((g|0)!=(e|0)){d=(g^-1)+e|0;b=e-g&3;if(b){c=0;while(1){f=f-1|0;e=e-1|0;H[f|0]=K[e|0];c=c+1|0;if((b|0)!=(c|0)){continue}break}}if(d>>>0>=3){while(1){H[f-1|0]=K[e-1|0];H[f-2|0]=K[e-2|0];H[f-3|0]=K[e-3|0];f=f-4|0;e=e-4|0;H[f|0]=K[e|0];if((e|0)!=(g|0)){continue}break}}e=J[a>>2];}J[a+8>>2]=i+j;J[a+4>>2]=h;J[a>>2]=f;if(e){$a(e);}return}nb();B();}function qe(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;m=Ua-16|0;Ua=m;g=K[a|0];a:{if(!g){f=a;break a}f=a;b:{while(1){i=g<<24>>24;if(!((i|0)==32|i-9>>>0<5)){break b}g=K[f+1|0];f=f+1|0;if(g){continue}break}break a}c:{g=g&255;switch(g-43|0){case 0:case 2:break c;default:break a}}j=(g|0)==45?-1:0;f=f+1|0;}d:{if(!((c|16)!=16|K[f|0]!=48)){o=1;if((K[f+1|0]&223)==88){f=f+2|0;i=16;break d}f=f+1|0;i=c?c:8;break d}i=c?c:10;}c=0;while(1){e:{g=-48;k=H[f|0];f:{if((k-48&255)>>>0<10){break f}g=-87;if((k-97&255)>>>0<26){break f}g=-55;if((k-65&255)>>>0>25){break e}}n=g+k|0;if((n|0)>=(i|0)){break e}xb(m,i,0,0,0,l,h,0,0);g=1;g:{if(J[m+8>>2]|J[m+12>>2]){break g}p=co(l,h,i,0);k=Wa;if((k|0)==-1&(n^-1)>>>0

>>0){break g}h=k;l=n+p|0;h=l>>>0>>0?h+1|0:h;o=1;g=c;}f=f+1|0;c=g;continue}break}if(b){J[b>>2]=o?f:a;}h:{i:{j:{if(c){J[5732]=68;a=d&1;j=a?0:j;l=d;h=e;break j}if((e|0)==(h|0)&d>>>0>l>>>0|e>>>0>h>>>0){break i}a=d&1;}if(!(a|j)){J[5732]=68;a=d;d=a-1|0;e=e-!a|0;break h}if((e|0)==(h|0)&d>>>0>=l>>>0|e>>>0>h>>>0){break i}J[5732]=68;break h}a=j^l;d=a-j|0;b=j>>31;e=(b^h)-((a>>>0>>0)+b|0)|0;}Ua=m+16|0;Wa=e;return d}function gk(a,b,c,d,e,f,g,h,i,j){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;var k=0;k=Ua-16|0;Ua=k;a:{if(a){a=qf(c);b:{if(b){b=k+4|0;Xa[J[J[a>>2]+44>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+32>>2]](b,a);break b}b=k+4|0;Xa[J[J[a>>2]+40>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+28>>2]](b,a);}ac(i,b);ab(b);J[e>>2]=Xa[J[J[a>>2]+12>>2]](a);J[f>>2]=Xa[J[J[a>>2]+16>>2]](a);b=k+4|0;Xa[J[J[a>>2]+20>>2]](b,a);Ab(g,b);ab(b);Xa[J[J[a>>2]+24>>2]](b,a);ac(h,b);ab(b);a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}a=pf(c);c:{if(b){b=k+4|0;Xa[J[J[a>>2]+44>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+32>>2]](b,a);break c}b=k+4|0;Xa[J[J[a>>2]+40>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+28>>2]](b,a);}ac(i,b);ab(b);J[e>>2]=Xa[J[J[a>>2]+12>>2]](a);J[f>>2]=Xa[J[J[a>>2]+16>>2]](a);b=k+4|0;Xa[J[J[a>>2]+20>>2]](b,a);Ab(g,b);ab(b);Xa[J[J[a>>2]+24>>2]](b,a);ac(h,b);ab(b);a=Xa[J[J[a>>2]+36>>2]](a)|0;}J[j>>2]=a;Ua=k+16|0;}function fb(a,b,c){var d=0,e=0,f=0;if(c>>>0>=512){Ia(a|0,b|0,c|0);return a}e=a+c|0;a:{if(!((a^b)&3)){b:{if(!(a&3)){c=a;break b}if(!c){c=a;break b}c=a;while(1){H[c|0]=K[b|0];b=b+1|0;c=c+1|0;if(!(c&3)){break b}if(c>>>0>>0){continue}break}}d=e&-4;c:{if(d>>>0<64){break c}f=d+-64|0;if(f>>>0>>0){break c}while(1){J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[c+8>>2]=J[b+8>>2];J[c+12>>2]=J[b+12>>2];J[c+16>>2]=J[b+16>>2];J[c+20>>2]=J[b+20>>2];J[c+24>>2]=J[b+24>>2];J[c+28>>2]=J[b+28>>2];J[c+32>>2]=J[b+32>>2];J[c+36>>2]=J[b+36>>2];J[c+40>>2]=J[b+40>>2];J[c+44>>2]=J[b+44>>2];J[c+48>>2]=J[b+48>>2];J[c+52>>2]=J[b+52>>2];J[c+56>>2]=J[b+56>>2];J[c+60>>2]=J[b+60>>2];b=b- -64|0;c=c- -64|0;if(f>>>0>=c>>>0){continue}break}}if(c>>>0>=d>>>0){break a}while(1){J[c>>2]=J[b>>2];b=b+4|0;c=c+4|0;if(d>>>0>c>>>0){continue}break}break a}if(e>>>0<4){c=a;break a}d=e-4|0;if(d>>>0>>0){c=a;break a}c=a;while(1){H[c|0]=K[b|0];H[c+1|0]=K[b+1|0];H[c+2|0]=K[b+2|0];H[c+3|0]=K[b+3|0];b=b+4|0;c=c+4|0;if(d>>>0>=c>>>0){continue}break}}if(c>>>0>>0){while(1){H[c|0]=K[b|0];b=b+1|0;c=c+1|0;if((e|0)!=(c|0)){continue}break}}return a}function kk(a,b,c,d,e,f,g,h,i,j){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;var k=0;k=Ua-16|0;Ua=k;a:{if(a){a=tf(c);b:{if(b){b=k+4|0;Xa[J[J[a>>2]+44>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+32>>2]](b,a);break b}b=k+4|0;Xa[J[J[a>>2]+40>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+28>>2]](b,a);}Ab(i,b);ab(b);H[e|0]=Xa[J[J[a>>2]+12>>2]](a);H[f|0]=Xa[J[J[a>>2]+16>>2]](a);b=k+4|0;Xa[J[J[a>>2]+20>>2]](b,a);Ab(g,b);ab(b);Xa[J[J[a>>2]+24>>2]](b,a);Ab(h,b);ab(b);a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}a=sf(c);c:{if(b){b=k+4|0;Xa[J[J[a>>2]+44>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+32>>2]](b,a);break c}b=k+4|0;Xa[J[J[a>>2]+40>>2]](b,a);c=J[k+4>>2];H[d|0]=c;H[d+1|0]=c>>>8;H[d+2|0]=c>>>16;H[d+3|0]=c>>>24;Xa[J[J[a>>2]+28>>2]](b,a);}Ab(i,b);ab(b);H[e|0]=Xa[J[J[a>>2]+12>>2]](a);H[f|0]=Xa[J[J[a>>2]+16>>2]](a);b=k+4|0;Xa[J[J[a>>2]+20>>2]](b,a);Ab(g,b);ab(b);Xa[J[J[a>>2]+24>>2]](b,a);Ab(h,b);ab(b);a=Xa[J[J[a>>2]+36>>2]](a)|0;}J[j>>2]=a;Ua=k+16|0;}function Un(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0;e=Ua-32|0;Ua=e;J[a+8>>2]=0;J[a+12>>2]=0;J[a+4>>2]=d;J[a>>2]=b;J[a+16>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;g=a+32|0;b=g;J[b>>2]=0;J[b+4>>2]=0;J[a+40>>2]=0;J[b>>2]=J[c>>2];J[a+36>>2]=J[c+4>>2];J[a+40>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[5996]=0;aa(86,a+44|0,a|0);b=J[5996];J[5996]=0;a:{if((b|0)==1){break a}J[5996]=0;aa(87,a- -64|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}d=0;J[5996]=0;b=$(88,a|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+80>>2]=b;f=J[a+36>>2];b=J[a+32>>2];if((f|0)==(b|0)){c=0;}else {c=b;while(1){d=J[J[c>>2]+84>>2]+d|0;c=c+8|0;if((f|0)!=(c|0)){continue}break}c=J[J[b>>2]+80>>2];}h=J[a+4>>2];i=J[a>>2];j=J[a+8>>2];k=J[a+12>>2];J[5996]=0;b=ka(89,i|0,c|0,d|0,h|0,f-b>>3,(k-j|0)/12|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+84>>2]=b;J[5996]=0;J[e+28>>2]=a;ea(90,e+12|0,a|0,e+28|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[e+24|0];if(b){Db(J[e+16>>2]);}H[a+88|0]=b^1;Ua=e+32|0;return a|0}c=Z()|0;lb(g);b=J[a+20>>2];if(b){J[a+24>>2]=b;$a(b);}rb(a+8|0);da(c|0);B();}function Dm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;e=Ua-32|0;Ua=e;J[a+8>>2]=0;J[a+12>>2]=0;J[a+4>>2]=d;J[a>>2]=b;J[a+16>>2]=0;J[a+8>>2]=J[c>>2];J[a+12>>2]=J[c+4>>2];J[a+16>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[a+36>>2]=0;J[a+40>>2]=0;J[a+28>>2]=0;J[a+32>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[5996]=0;aa(86,a+44|0,a|0);b=J[5996];J[5996]=0;a:{if((b|0)==1){break a}J[5996]=0;aa(87,a- -64|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}d=0;J[5996]=0;b=$(88,a|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+80>>2]=b;f=J[a+36>>2];b=J[a+32>>2];if((f|0)==(b|0)){c=0;}else {c=b;while(1){d=J[J[c>>2]+84>>2]+d|0;c=c+8|0;if((f|0)!=(c|0)){continue}break}c=J[J[b>>2]+80>>2];}g=J[a+4>>2];h=J[a>>2];i=J[a+8>>2];j=J[a+12>>2];J[5996]=0;b=ka(89,h|0,c|0,d|0,g|0,f-b>>3,(j-i|0)/12|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+84>>2]=b;J[5996]=0;J[e+28>>2]=a;ea(90,e+12|0,a|0,e+28|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[e+24|0];if(b){Db(J[e+16>>2]);}H[a+88|0]=b^1;Ua=e+32|0;return a|0}c=Z()|0;lb(a+32|0);b=J[a+20>>2];if(b){J[a+24>>2]=b;$a(b);}rb(a+8|0);da(c|0);B();}function Zm(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;d=Ua-16|0;Ua=d;J[5996]=0;f=_(134,d+8|0,a|0)|0;c=J[5996];J[5996]=0;a:{b:{c:{if((c|0)!=1){d:{if(!K[f|0]){break d}c=J[(J[J[a>>2]-12>>2]+a|0)+28>>2];J[d+4>>2]=c;J[c+4>>2]=J[c+4>>2]+1;J[5996]=0;h=$(135,J[d+4>>2])|0;c=J[5996];J[5996]=0;e:{f:{if((c|0)!=1){c=J[d+4>>2];e=J[c+4>>2]-1|0;J[c+4>>2]=e;if((e|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}J[d+4>>2]=J[(J[J[a>>2]-12>>2]+a|0)+24>>2];c=J[J[a>>2]-12>>2];J[5996]=0;c=a+c|0;e=$(136,c|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break f}g=J[d+4>>2];J[5996]=0;b=xa(137,h|0,g|0,c|0,e|0,b|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break f}if(b){break d}b=J[J[a>>2]-12>>2];J[5996]=0;aa(138,a+b|0,5);b=J[5996];J[5996]=0;if((b|0)!=1){break d}b=fa(0)|0;break e}b=fa(0)|0;c=J[d+4>>2];e=J[c+4>>2]-1|0;J[c+4>>2]=e;if((e|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}break e}b=fa(0)|0;}ud(f);break c}ud(f);break b}b=fa(0)|0;}pa(b|0)|0;b=J[J[a>>2]-12>>2];J[5996]=0;ha(139,a+b|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}ra();}Ua=d+16|0;return a|0}a=Z()|0;J[5996]=0;ca(110);b=J[5996];J[5996]=0;if((b|0)!=1){da(a|0);B();}fa(0)|0;Vb();B();}function Sn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;e=Ua-32|0;Ua=e;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;H[e+4|0]=0;J[e>>2]=a;a:{b:{c:{d:{e:{if(c){if(c>>>0>=357913942){J[5996]=0;ca(47);a=J[5996];J[5996]=0;if((a|0)==1){break c}break a}J[5996]=0;c=P(c,12);g=$(3,c|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break c}J[a+4>>2]=g;J[a>>2]=g;J[a+8>>2]=c+g;J[e+24>>2]=g;H[e+20|0]=0;J[e+8>>2]=a+8;j=b+c|0;J[e+16>>2]=e+28;J[e+12>>2]=e+24;d=g;while(1){J[d+8>>2]=0;J[d>>2]=0;J[d+4>>2]=0;f=J[b>>2];c=J[b+4>>2];if((f|0)!=(c|0)){h=c-f|0;if((h|0)<0){J[5996]=0;J[e+28>>2]=d;ca(84);b=J[5996];J[5996]=0;if((b|0)!=1){break a}c=Z()|0;b=J[d>>2];if(!b){break d}J[d+4>>2]=b;$a(b);break d}J[5996]=0;c=$(3,h|0)|0;i=J[5996];J[5996]=0;if((i|0)==1){break e}J[d+4>>2]=c;J[d>>2]=c;J[d+8>>2]=(h&-8)+c;h=J[b+4>>2];if((h|0)!=(f|0)){while(1){i=J[f+4>>2];J[c>>2]=J[f>>2];J[c+4>>2]=i;c=c+8|0;f=f+8|0;if((h|0)!=(f|0)){continue}break}}J[d+4>>2]=c;}d=d+12|0;b=b+12|0;if((j|0)!=(b|0)){continue}break}J[a+4>>2]=d;}Ua=e+32|0;return a|0}c=Z()|0;J[e+28>>2]=d;}Ed(e+8|0);J[a+4>>2]=g;break b}c=Z()|0;}Nc(e);da(c|0);B();}B();}function pk(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;h=J[b>>2];c=H[b+11|0];J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;b=(c|0)<0?h:b;c=0;h=0;a:{b:{c:{while(1){e=d;g=c;f=h;while(1){c=K[b|0];if(!(c-9>>>0>=5&(c|0)!=32)){b=b+1|0;continue}d=K[c+5584|0];if((d|0)==255){break a}c=K[K[b+1|0]+5584|0];if((c|0)==255){break a}b=b+2|0;h=c|d<<4;if((e|0)!=(f|0)){H[f|0]=h;f=f+1|0;J[a+4>>2]=f;continue}break}i=f-g|0;d=i+1|0;if((d|0)<0){J[5996]=0;ca(8);b=J[5996];J[5996]=0;if((b|0)==1){break c}B();}d:{c=i<<1;d=i>>>0>=1073741823?2147483647:c>>>0>d>>>0?c:d;e:{if(!d){j=0;break e}J[5996]=0;j=$(3,d|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break d}}c=i+j|0;H[c|0]=h;d=d+j|0;h=c+1|0;if((e|0)!=(g|0)){k=(g^-1)+f|0;f=0;i=i&3;if(i){while(1){c=c-1|0;e=e-1|0;H[c|0]=K[e|0];f=f+1|0;if((i|0)!=(f|0)){continue}break}}if(k>>>0>=3){while(1){H[c-1|0]=K[e-1|0];H[c-2|0]=K[e-2|0];H[c-3|0]=K[e-3|0];c=c-4|0;e=e-4|0;H[c|0]=K[e|0];if((e|0)!=(g|0)){continue}break}}c=j;}J[a+8>>2]=d;J[a+4>>2]=h;J[a>>2]=c;if(!g){continue}$a(g);continue}break}b=Z()|0;break b}b=Z()|0;g=J[a>>2];}if(g){J[a+4>>2]=g;$a(g);}da(b|0);B();}}function vd(a,b,c,d,e,f){var g=0,h=0;H[a|0]=0;H[a+1|0]=0;H[a+2|0]=0;H[a+3|0]=0;H[a+4|0]=0;H[a+5|0]=0;H[a+6|0]=0;H[a+7|0]=0;H[a+24|0]=0;H[a+25|0]=0;H[a+26|0]=0;H[a+27|0]=0;H[a+28|0]=0;H[a+29|0]=0;H[a+30|0]=0;H[a+31|0]=0;H[a+16|0]=0;H[a+17|0]=0;H[a+18|0]=0;H[a+19|0]=0;H[a+20|0]=0;H[a+21|0]=0;H[a+22|0]=0;H[a+23|0]=0;H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;H[a+12|0]=0;H[a+13|0]=0;H[a+14|0]=0;H[a+15|0]=0;J[5996]=0;g=_(127,a|0,130)|0;h=J[5996];J[5996]=0;if((h|0)!=1){a:{b=J[b>>2];J[5996]=0;b=nc(g,b,b>>31);g=J[5996];J[5996]=0;if((g|0)==1){break a}c=J[c>>2];J[5996]=0;b=_(127,b|0,c|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[d>>2];J[5996]=0;b=_(127,b|0,c|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[5996]=0;b=_(19,b|0,e|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}c=J[f>>2];J[5996]=0;_(127,b|0,c|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}return}}b=Z()|0;if((K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))>>>0>=29){$a(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24));H[a+8|0]=0;H[a+9|0]=0;H[a+10|0]=0;H[a+11|0]=0;}da(b|0);B();}function _d(a,b,c,d,e,f,g,h,i,j,k,l){a:{b:{if((a|0)==(f|0)){if(!K[b|0]){break a}f=0;H[b|0]=0;a=J[e>>2];J[e>>2]=a+1;H[a|0]=46;a=K[h+11|0];if(!((a&128)>>>7|0?J[h+4>>2]:a&127)){break b}a=J[j>>2];if((a-i|0)>159){break b}b=J[k>>2];J[j>>2]=a+4;J[a>>2]=b;return 0}c:{if((a|0)!=(g|0)){break c}f=K[h+11|0];if(!((f&128)>>>7|0?J[h+4>>2]:f&127)){break c}if(!K[b|0]){break a}f=0;a=J[j>>2];if((a-i|0)>159){break b}b=J[k>>2];J[j>>2]=a+4;J[a>>2]=b;J[k>>2]=0;return 0}f=-1;g=be(l,l+32|0,a)-l|0;if((g|0)>31){break b}a=H[g+12416|0];d:{e:{switch((g&-2)-22|0){case 2:b=J[e>>2];if((b|0)!=(d|0)){d=H[b-1|0];c=H[c|0];if(((d-97>>>0<26?d&95:d)|0)!=((c-97>>>0<26?c&95:c)|0)){break b}}J[e>>2]=b+1;H[b|0]=a;return 0;case 0:H[c|0]=80;break d;default:break e}}d=a-97>>>0<26?a&95:a;if((d|0)!=H[c|0]){break d}H[c|0]=d-65>>>0<26?d|32:d;if(!K[b|0]){break d}H[b|0]=0;b=K[h+11|0];if(!((b&128)>>>7|0?J[h+4>>2]:b&127)){break d}b=J[j>>2];if((b-i|0)>159){break d}c=J[k>>2];J[j>>2]=b+4;J[b>>2]=c;}b=J[e>>2];J[e>>2]=b+1;H[b|0]=a;f=0;if((g|0)>21){break b}J[k>>2]=J[k>>2]+1;}return f}return -1}function Wd(a,b,c,d,e,f,g,h,i,j,k,l){a:{b:{if((a|0)==(f|0)){if(!K[b|0]){break a}f=0;H[b|0]=0;a=J[e>>2];J[e>>2]=a+1;H[a|0]=46;a=K[h+11|0];if(!((a&128)>>>7|0?J[h+4>>2]:a&127)){break b}a=J[j>>2];if((a-i|0)>159){break b}b=J[k>>2];J[j>>2]=a+4;J[a>>2]=b;return 0}c:{if((a|0)!=(g|0)){break c}f=K[h+11|0];if(!((f&128)>>>7|0?J[h+4>>2]:f&127)){break c}if(!K[b|0]){break a}f=0;a=J[j>>2];if((a-i|0)>159){break b}b=J[k>>2];J[j>>2]=a+4;J[a>>2]=b;J[k>>2]=0;return 0}f=-1;g=Yd(l,l+128|0,a)-l|0;if((g|0)>124){break b}a=H[(g>>2)+12416|0];d:{e:{l=g&-5;if((l|0)!=88){if((l|0)!=96){break e}b=J[e>>2];if((b|0)!=(d|0)){d=H[b-1|0];c=H[c|0];if(((d-97>>>0<26?d&95:d)|0)!=((c-97>>>0<26?c&95:c)|0)){break b}}J[e>>2]=b+1;H[b|0]=a;return 0}H[c|0]=80;break d}d=a-97>>>0<26?a&95:a;if((d|0)!=H[c|0]){break d}H[c|0]=d-65>>>0<26?d|32:d;if(!K[b|0]){break d}H[b|0]=0;b=K[h+11|0];if(!((b&128)>>>7|0?J[h+4>>2]:b&127)){break d}b=J[j>>2];if((b-i|0)>159){break d}c=J[k>>2];J[j>>2]=b+4;J[b>>2]=c;}b=J[e>>2];J[e>>2]=b+1;H[b|0]=a;f=0;if((g|0)>84){break b}J[k>>2]=J[k>>2]+1;}return f}return -1}function Tl(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;if((c|0)!=1){l=Ua-1040|0;Ua=l;q=J[5732];a:{b:{g=l+16|0;n=L[((c>>>0<=153?c:0)<<1)+21296>>1]+19372|0;b=J[J[6178]+20>>2];if(b){h=J[b+4>>2];d=J[b>>2];f=J[d>>2]+1794895138|0;i=wc(J[d+8>>2],f);j=wc(J[d+12>>2],f);e=wc(J[d+16>>2],f);c:{if(h>>>2>>>0<=i>>>0){break c}b=h-(i<<2)|0;if((e|j)&3|(b>>>0<=j>>>0|b>>>0<=e>>>0)){break c}r=e>>>2|0;s=j>>>2|0;while(1){m=i>>>1|0;j=m+o|0;e=j<<1;b=d+(e+s<<2)|0;p=wc(J[b>>2],f);b=wc(J[b+4>>2],f);if(b>>>0>=h>>>0|h-b>>>0<=p>>>0|K[d+(b+p|0)|0]){break c}b=Uc(n,b+d|0);if(!b){b=d+(e+r<<2)|0;e=wc(J[b>>2],f);b=wc(J[b+4>>2],f);if(b>>>0>=h>>>0|e>>>0>=h-b>>>0){break c}k=K[d+(b+e|0)|0]?0:b+d|0;break c}if((i|0)==1){break c}b=(b|0)<0;i=b?m:i-m|0;o=b?o:j;continue}}}k=k?k:n;b=Gb(k);d:{if(b>>>0>=1024){fb(g,k,1023);H[g+1023|0]=0;b=68;break d}fb(g,k,b+1|0);b=0;}if(b){if((b|0)!=28){break b}b=5575;}else {b=g;}break a}za();B();}if(!K[b|0]){J[l>>2]=c;od(g,1024,2507,l);b=g;}J[5732]=q;Kb(a,b);Ua=l+1040|0;return}Kb(a,1694);}function li(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;f=Ua-32|0;Ua=f;J[f+28>>2]=d;J[f+24>>2]=d;H[f+20|0]=0;J[f+8>>2]=a;J[f+16>>2]=f+28;J[f+12>>2]=f+24;a:{b:{c:{if((b|0)!=(c|0)){while(1){J[d+8>>2]=0;J[d>>2]=0;J[d+4>>2]=0;a=J[b+4>>2];e=J[b>>2];if((a|0)!=(e|0)){e=a-e|0;if((e|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)==1){break c}B();}J[5996]=0;a=$(3,e|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break b}J[d+4>>2]=a;J[d>>2]=a;J[d+8>>2]=a+e;e=J[b>>2];g=J[b+4>>2];d:{if((e|0)==(g|0)){break d}j=(e^-1)+g|0;h=0;i=g-e&7;if(i){while(1){H[a|0]=K[e|0];a=a+1|0;e=e+1|0;h=h+1|0;if((i|0)!=(h|0)){continue}break}}if(j>>>0<7){break d}while(1){H[a|0]=K[e|0];H[a+1|0]=K[e+1|0];H[a+2|0]=K[e+2|0];H[a+3|0]=K[e+3|0];H[a+4|0]=K[e+4|0];H[a+5|0]=K[e+5|0];H[a+6|0]=K[e+6|0];H[a+7|0]=K[e+7|0];a=a+8|0;e=e+8|0;if((g|0)!=(e|0)){continue}break}}J[d+4>>2]=a;}d=d+12|0;J[f+28>>2]=d;b=b+12|0;if((c|0)!=(b|0)){continue}break}}Ua=f+32|0;return d|0}a=Z()|0;b=J[d>>2];if(!b){break a}J[d+4>>2]=b;$a(b);break a}a=Z()|0;}Ed(f+8|0);da(a|0);B();}function zd(a,b){var c=0,d=0,e=0;c=(a|0)==(b|0);H[b+12|0]=c;a:{if(c){break a}while(1){d=J[b+8>>2];if(K[d+12|0]){break a}b:{c=J[d+8>>2];e=J[c>>2];if((e|0)==(d|0)){e=J[c+4>>2];if(!(!e|K[e+12|0])){break b}c:{if(J[d>>2]==(b|0)){b=d;break c}b=J[d+4>>2];a=J[b>>2];J[d+4>>2]=a;if(a){J[a+8>>2]=d;c=J[d+8>>2];}J[b+8>>2]=c;a=J[d+8>>2];J[((J[a>>2]!=(d|0))<<2)+a>>2]=b;J[b>>2]=d;J[d+8>>2]=b;c=J[b+8>>2];d=J[c>>2];}H[b+12|0]=1;H[c+12|0]=0;a=J[d+4>>2];J[c>>2]=a;if(a){J[a+8>>2]=c;}J[d+8>>2]=J[c+8>>2];a=J[c+8>>2];J[((J[a>>2]!=(c|0))<<2)+a>>2]=d;J[d+4>>2]=c;J[c+8>>2]=d;return}if(!(K[e+12|0]|!e)){break b}d:{if(J[d>>2]!=(b|0)){b=d;break d}a=J[b+4>>2];J[d>>2]=a;if(a){J[a+8>>2]=d;c=J[d+8>>2];}J[b+8>>2]=c;a=J[d+8>>2];J[((J[a>>2]!=(d|0))<<2)+a>>2]=b;J[b+4>>2]=d;J[d+8>>2]=b;c=J[b+8>>2];}H[b+12|0]=1;H[c+12|0]=0;a=J[c+4>>2];b=J[a>>2];J[c+4>>2]=b;if(b){J[b+8>>2]=c;}J[a+8>>2]=J[c+8>>2];b=J[c+8>>2];J[((J[b>>2]!=(c|0))<<2)+b>>2]=a;J[a>>2]=c;J[c+8>>2]=a;break a}H[d+12|0]=1;H[c+12|0]=(a|0)==(c|0);H[e+12|0]=1;b=c;if((a|0)!=(c|0)){continue}break}}}function Tn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;a:{b:{c:{d:{e:{f:{e=J[b+4>>2];d=J[b>>2];if((e|0)!=(d|0)){d=e-d|0;if((d|0)<0){J[5996]=0;ca(85);b=J[5996];J[5996]=0;if((b|0)==1){break f}break a}J[5996]=0;e=$(3,d|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break f}J[a+4>>2]=e;J[a>>2]=e;J[a+8>>2]=(d&-8)+e;d=J[b>>2];b=J[b+4>>2];if((d|0)!=(b|0)){while(1){O[e>>3]=O[d>>3];e=e+8|0;d=d+8|0;if((b|0)!=(d|0)){continue}break}}J[a+4>>2]=e;}J[a+12>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;b=J[c+4>>2];e=J[c>>2];if((b|0)==(e|0)){break d}b=b-e|0;if((b|0)>=0){break e}J[5996]=0;ca(85);b=J[5996];J[5996]=0;if((b|0)!=1){break a}break c}d=Z()|0;break b}J[5996]=0;e=$(3,b|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break c}J[a+16>>2]=e;J[a+12>>2]=e;J[a+20>>2]=(b&-8)+e;d=J[c>>2];b=J[c+4>>2];if((d|0)!=(b|0)){while(1){O[e>>3]=O[d>>3];e=e+8|0;d=d+8|0;if((b|0)!=(d|0)){continue}break}}J[a+16>>2]=e;}return a|0}d=Z()|0;b=J[a+12>>2];if(!b){break b}J[a+16>>2]=b;$a(b);}b=J[a>>2];if(b){J[a+4>>2]=b;$a(b);}da(d|0);B();}B();}function Tm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=Ua-32|0;Ua=d;J[a+8>>2]=0;J[a+12>>2]=0;J[a+4>>2]=c;J[a>>2]=b;J[a+16>>2]=0;J[a+20>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;f=a+32|0;J[f>>2]=0;J[f+4>>2]=0;J[a+40>>2]=0;J[5996]=0;aa(86,a+44|0,a|0);b=J[5996];J[5996]=0;a:{if((b|0)==1){break a}J[5996]=0;aa(87,a- -64|0,a|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=0;J[5996]=0;c=$(88,a|0)|0;e=J[5996];J[5996]=0;if((e|0)==1){break a}J[a+80>>2]=c;e=J[a+32>>2];g=J[a+36>>2];if((e|0)==(g|0)){c=0;}else {c=e;while(1){b=J[J[c>>2]+84>>2]+b|0;c=c+8|0;if((g|0)!=(c|0)){continue}break}c=J[J[e>>2]+80>>2];}h=J[a+4>>2];i=J[a>>2];j=J[a+8>>2];k=J[a+12>>2];J[5996]=0;b=ka(89,i|0,c|0,b|0,h|0,g-e>>3,(k-j|0)/12|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[a+84>>2]=b;J[5996]=0;J[d+28>>2]=a;ea(90,d+12|0,a|0,d+28|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}b=K[d+24|0];if(b){Db(J[d+16>>2]);}H[a+88|0]=b^1;Ua=d+32|0;return a|0}c=Z()|0;lb(f);b=J[a+20>>2];if(b){J[a+24>>2]=b;$a(b);}rb(a+8|0);da(c|0);B();} +function Pn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;a:{if(c){if(c>>>0>=536870912){J[5996]=0;ca(84);b=J[5996];J[5996]=0;if((b|0)==1){break a}B();}J[5996]=0;e=c<<3;d=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break a}J[a+4>>2]=d;J[a>>2]=d;J[a+8>>2]=d+e;f=c-1&536870911;g=c&7;b:{if(!g){c=b;break b}c=b;while(1){i=J[c+4>>2];J[d>>2]=J[c>>2];J[d+4>>2]=i;d=d+8|0;c=c+8|0;h=h+1|0;if((h|0)!=(g|0)){continue}break}}if(f>>>0>=7){b=b+e|0;while(1){e=J[c+4>>2];J[d>>2]=J[c>>2];J[d+4>>2]=e;e=J[c+12>>2];J[d+8>>2]=J[c+8>>2];J[d+12>>2]=e;e=J[c+20>>2];J[d+16>>2]=J[c+16>>2];J[d+20>>2]=e;e=J[c+28>>2];J[d+24>>2]=J[c+24>>2];J[d+28>>2]=e;e=J[c+36>>2];J[d+32>>2]=J[c+32>>2];J[d+36>>2]=e;e=J[c+44>>2];J[d+40>>2]=J[c+40>>2];J[d+44>>2]=e;e=J[c+52>>2];J[d+48>>2]=J[c+48>>2];J[d+52>>2]=e;e=J[c+60>>2];J[d+56>>2]=J[c+56>>2];J[d+60>>2]=e;d=d- -64|0;c=c- -64|0;if((b|0)!=(c|0)){continue}break}}J[a+4>>2]=d;}return a|0}c=Z()|0;b=J[a>>2];if(b){J[a+4>>2]=b;$a(b);}da(c|0);B();}function ge(a,b,c,d){var e=0,f=0,g=0,h=0;g=Ua-32|0;Ua=g;e=d&2147483647;h=e;f=e-1006698496|0;e=e-1140785152|0;a:{if((f|0)==(e|0)&0|e>>>0>f>>>0){e=c<<4|b>>>28;c=d<<4|c>>>28;b=b&268435455;if((b|0)==134217728&(a|0)!=0|b>>>0>134217728){f=c+1073741824|0;e=e+1|0;f=e?f:f+1|0;break a}f=c+1073741824|0;if(a|(b|0)!=134217728){break a}a=e&1;e=a+e|0;f=a>>>0>e>>>0?f+1|0:f;break a}if(!(!c&(h|0)==2147418112?!(a|b):h>>>0<2147418112)){a=d<<4|c>>>28;e=c<<4|b>>>28;f=a&524287|2146959360;break a}e=0;f=2146435072;if(h>>>0>1140785151){break a}f=0;h=h>>>16|0;if(h>>>0<15249){break a}e=d&65535|65536;Cb(g+16|0,a,b,c,e,h-15233|0);xc(g,a,b,c,e,15361-h|0);b=J[g+8>>2];e=b<<4;b=J[g+12>>2]<<4|b>>>28;c=J[g>>2];f=J[g+4>>2];h=f;e=f>>>28|e;f=b;a=h&268435455;b=c|(J[g+16>>2]|J[g+24>>2]|(J[g+20>>2]|J[g+28>>2]))!=0;if((a|0)==134217728&(b|0)!=0|a>>>0>134217728){e=e+1|0;f=e?f:f+1|0;break a}if(b|(a|0)!=134217728){break a}a=e;e=e+(e&1)|0;f=a>>>0>e>>>0?f+1|0:f;}Ua=g+32|0;x(0,e|0);x(1,d&-2147483648|f);return +z()}function pn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;d=Ua-16|0;Ua=d;J[d+12>>2]=b;if(b>>>0<2147483632){a:{if(((K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:10)>>>0>=b>>>0){break a}b=K[a+11|0];J[d+8>>2]=(b&128)>>>7|0?J[a+4>>2]:b&127;c=J[(M[d+12>>2]>2]?d+8|0:d+12|0)>>2];if(c>>>0>=11){c=c+16&-16;e=c-1|0;c=(e|0)==11?c:e;}else {c=10;}if((c|0)==(((K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:10)|0)){break a}f=Ua-16|0;Ua=f;b=K[a+11|0];e=(b&128)>>>7|0?J[a+4>>2]:b&127;b:{c:{i=c>>>0<11;d:{if(i){j=1;g=c+1|0;h=J[a>>2];c=e;b=a;break d}g=c+1|0;e:{if(c>>>0>((K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:10)>>>0){Gc(f+8|0,g);break e}J[5996]=0;aa(289,f+8|0,g|0);b=J[5996];J[5996]=0;if((b|0)==1){break c}}g=J[f+12>>2];c=K[a+11|0];b=(c&128)>>>7|0;j=b;h=b?J[a>>2]:a;c=b?J[a+4>>2]:c&127;b=J[f+8>>2];}b=gc(b,h,c+1|0);if(j){$a(h);}if(!i){J[a+8>>2]=g|-2147483648;J[a+4>>2]=e;J[a>>2]=b;break b}H[a+11|0]=e;break b}pa(fa(0)|0)|0;ra();}Ua=f+16|0;}Ua=d+16|0;return}ub();B();}function Cd(a){var b=0,c=0,d=0,e=0,f=0;d=J[5726];c=a+7&-8;b=d+c|0;a:{b:{if(b>>>0<=d>>>0?c:0){break b}if(b>>>0>Ya()<<16>>>0){if(!(Qa(b|0)|0)){break b}}J[5726]=b;break a}J[5732]=48;d=-1;}if((d|0)!=-1){a=a+d|0;J[a-4>>2]=16;c=a-16|0;J[c>>2]=16;b=J[5992];if(b){f=J[b+8>>2];}else {f=0;}c:{d:{if((f|0)==(d|0)){e=d-(J[d-4>>2]&-2)|0;f=J[e-4>>2];J[b+8>>2]=a;a=e-(f&-2)|0;b=-16;if(!(H[(a+J[a>>2]|0)-4|0]&1)){break d}b=J[a+4>>2];J[b+8>>2]=J[a+8>>2];J[J[a+8>>2]+4>>2]=b;b=c-a|0;J[a>>2]=b;break c}J[d+12>>2]=16;J[d>>2]=16;J[d+8>>2]=a;J[d+4>>2]=b;J[5992]=d;b=16;}a=b+d|0;b=c-a|0;J[a>>2]=b;}J[((b&-4)+a|0)-4>>2]=b|1;c=J[a>>2]-8|0;e:{if(c>>>0<=127){b=(c>>>3|0)-1|0;break e}e=S(c);b=((c>>>29-e^4)-(e<<2)|0)+110|0;if(c>>>0<=4095){break e}b=((c>>>30-e^2)-(e<<1)|0)+71|0;b=b>>>0>=63?63:b;}c=b<<4;J[a+4>>2]=c+22944;c=c+22952|0;J[a+8>>2]=J[c>>2];J[c>>2]=a;J[J[a+8>>2]+4>>2]=a;c=J[5994];e=J[5995];a=b&31;if((b&63)>>>0>=32){b=1<>>32-a;}J[5994]=f|c;J[5995]=b|e;}return (d|0)!=-1}function Te(a,b,c,d,e,f,g,h){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;a=Ua-16|0;Ua=a;J[a+12>>2]=c;J[a+8>>2]=f;J[a+12>>2]=c;J[a+8>>2]=f;b=J[a+12>>2];a:{while(1){if(b>>>0>=d>>>0){c=0;break a}c=2;b=J[b>>2];if(b>>>0>1114111|(b&-2048)==55296){break a}b:{c:{if(b>>>0<=127){c=1;f=J[a+8>>2];if((g-f|0)<=0){break a}J[a+8>>2]=f+1;H[f|0]=b;break c}if(b>>>0<=2047){c=J[a+8>>2];if((g-c|0)<2){break b}J[a+8>>2]=c+1;H[c|0]=b>>>6|192;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;break c}c=J[a+8>>2];f=g-c|0;if(b>>>0<=65535){if((f|0)<3){break b}J[a+8>>2]=c+1;H[c|0]=b>>>12|224;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b>>>6&63|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;break c}if((f|0)<4){break b}J[a+8>>2]=c+1;H[c|0]=b>>>18|240;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b>>>12&63|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b>>>6&63|128;c=J[a+8>>2];J[a+8>>2]=c+1;H[c|0]=b&63|128;}b=J[a+12>>2]+4|0;J[a+12>>2]=b;continue}break}c=1;}J[e>>2]=J[a+12>>2];J[h>>2]=J[a+8>>2];Ua=a+16|0;return c|0}function Yg(a){var b=0,c=0,d=0,e=0,f=0;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;a:{b:{c:{d:{e:{f:{c=J[6141];d=J[6142];if((c|0)!=(d|0)){e=d-c|0;if((e|0)<0){J[5996]=0;ca(85);b=J[5996];J[5996]=0;if((b|0)==1){break f}break a}J[5996]=0;b=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break f}J[a+4>>2]=b;J[a>>2]=b;J[a+8>>2]=(e&-8)+b;while(1){O[b>>3]=O[c>>3];b=b+8|0;c=c+8|0;if((d|0)!=(c|0)){continue}break}J[a+4>>2]=b;}J[a+12>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;c=J[6144];d=J[6145];if((c|0)==(d|0)){break d}e=d-c|0;if((e|0)>=0){break e}J[5996]=0;ca(85);b=J[5996];J[5996]=0;if((b|0)!=1){break a}break c}c=Z()|0;break b}J[5996]=0;b=$(3,e|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break c}J[a+16>>2]=b;J[a+12>>2]=b;J[a+20>>2]=(e&-8)+b;while(1){O[b>>3]=O[c>>3];b=b+8|0;c=c+8|0;if((d|0)!=(c|0)){continue}break}J[a+16>>2]=b;}return a}c=Z()|0;b=J[a+12>>2];if(!b){break b}J[a+16>>2]=b;$a(b);}b=J[a>>2];if(b){J[a+4>>2]=b;$a(b);}da(c|0);B();}B();}function Oe(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;b=0;a=c;while(1){a:{if(a>>>0>=d>>>0|b>>>0>=e>>>0){break a}g=1;f=H[a|0];b:{if((f|0)>=0){break b}if(f>>>0<4294967234){break a}if(f>>>0<=4294967263){if((d-a|0)<2){break a}g=2;if((K[a+1|0]&192)!=128){break a}break b}g=f&255;if(f>>>0<=4294967279){if((d-a|0)<3){break a}h=K[a+2|0];f=K[a+1|0];c:{d:{if((g|0)!=237){if((g|0)!=224){break d}if((f&224)==160){break c}break a}if((f&224)!=128){break a}break c}if((f&192)!=128){break a}}g=3;if((h&192)!=128){break a}break b}if((d-a|0)<4|f>>>0>4294967284|e-b>>>0<2){break a}h=K[a+3|0];i=K[a+2|0];f=K[a+1|0];e:{f:{switch(g-240|0){case 0:if((f+112&255)>>>0>=48){break a}break e;case 4:if((f&240)!=128){break a}break e;default:break f}}if((f&192)!=128){break a}}if((i&192)!=128|(h&192)!=128|(g<<18&1835008|(f&48)<<12)>>>0>1114111){break a}b=b+1|0;g=4;}b=b+1|0;a=a+g|0;continue}break}return a-c|0}function gh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=Ua-32|0;Ua=c;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;H[c+4|0]=0;J[c>>2]=a;e=J[b+4>>2];f=J[b>>2];g=e-f|0;d=(g|0)/12|0;a:{b:{c:{if((e|0)!=(f|0)){if(d>>>0>=357913942){J[5996]=0;ca(41);a=J[5996];J[5996]=0;if((a|0)==1){break c}B();}J[5996]=0;e=$(3,g|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break c}J[a+4>>2]=e;J[a>>2]=e;J[a+8>>2]=e+P(d,12);f=J[b+4>>2];b=J[b>>2];J[c+28>>2]=e;J[c+24>>2]=e;H[c+20|0]=0;J[c+8>>2]=a+8;J[c+16>>2]=c+28;J[c+12>>2]=c+24;d:{if((b|0)==(f|0)){d=e;break d}d=e;while(1){e:{if(H[b+11|0]>=0){g=J[b+4>>2];J[d>>2]=J[b>>2];J[d+4>>2]=g;J[d+8>>2]=J[b+8>>2];break e}g=J[b+4>>2];h=J[b>>2];J[5996]=0;ea(40,d|0,h|0,g|0);d=J[5996];J[5996]=0;if((d|0)==1){break b}d=J[c+28>>2];}d=d+12|0;J[c+28>>2]=d;b=b+12|0;if((f|0)!=(b|0)){continue}break}}J[a+4>>2]=d;}Ua=c+32|0;return a|0}b=Z()|0;break a}b=Z()|0;Wg(c+8|0);J[a+4>>2]=e;}Vg(c);da(b|0);B();}function Re(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;a=c;while(1){a:{if(e>>>0<=i>>>0|a>>>0>=d>>>0){break a}f=1;b=H[a|0];b:{if((b|0)>=0){break b}if(b>>>0<4294967234){break a}if(b>>>0<=4294967263){if((d-a|0)<2){break a}f=2;if((K[a+1|0]&192)!=128){break a}break b}g=b&255;if(b>>>0<=4294967279){if((d-a|0)<3){break a}h=K[a+2|0];b=K[a+1|0];c:{d:{if((g|0)!=237){if((g|0)!=224){break d}if((b&224)==160){break c}break a}if((b&224)!=128){break a}break c}if((b&192)!=128){break a}}f=3;if((h&192)!=128){break a}break b}if((d-a|0)<4|b>>>0>4294967284){break a}f=K[a+3|0];h=K[a+2|0];b=K[a+1|0];e:{f:{switch(g-240|0){case 0:if((b+112&255)>>>0>=48){break a}break e;case 4:if((b&240)!=128){break a}break e;default:break f}}if((b&192)!=128){break a}}if((h&192)!=128|(f&192)!=128){break a}f=4;if((g<<18&1835008|(b&48)<<12)>>>0>1114111){break a}}i=i+1|0;a=a+f|0;continue}break}return a-c|0}function zk(a,b,c,d,e,f,g,h,i,j){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;var k=0,l=0;k=Ua-16|0;Ua=k;l=j;a:{if(a){j=k+4|0;a=tf(b);Xa[J[J[a>>2]+44>>2]](j,a);b=J[k+4>>2];H[c|0]=b;H[c+1|0]=b>>>8;H[c+2|0]=b>>>16;H[c+3|0]=b>>>24;Xa[J[J[a>>2]+32>>2]](j,a);Ab(i,j);ab(j);Xa[J[J[a>>2]+28>>2]](j,a);Ab(h,j);ab(j);H[d|0]=Xa[J[J[a>>2]+12>>2]](a);H[e|0]=Xa[J[J[a>>2]+16>>2]](a);Xa[J[J[a>>2]+20>>2]](j,a);Ab(f,j);ab(j);Xa[J[J[a>>2]+24>>2]](j,a);Ab(g,j);ab(k+4|0);a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}j=k+4|0;a=sf(b);Xa[J[J[a>>2]+44>>2]](j,a);b=J[k+4>>2];H[c|0]=b;H[c+1|0]=b>>>8;H[c+2|0]=b>>>16;H[c+3|0]=b>>>24;Xa[J[J[a>>2]+32>>2]](j,a);Ab(i,j);ab(j);Xa[J[J[a>>2]+28>>2]](j,a);Ab(h,j);ab(j);H[d|0]=Xa[J[J[a>>2]+12>>2]](a);H[e|0]=Xa[J[J[a>>2]+16>>2]](a);Xa[J[J[a>>2]+20>>2]](j,a);Ab(f,j);ab(j);Xa[J[J[a>>2]+24>>2]](j,a);Ab(g,j);ab(k+4|0);a=Xa[J[J[a>>2]+36>>2]](a)|0;}J[l>>2]=a;Ua=k+16|0;}function sk(a,b,c,d,e,f,g,h,i,j){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;h=h|0;i=i|0;j=j|0;var k=0,l=0;k=Ua-16|0;Ua=k;l=j;a:{if(a){j=k+4|0;a=qf(b);Xa[J[J[a>>2]+44>>2]](j,a);b=J[k+4>>2];H[c|0]=b;H[c+1|0]=b>>>8;H[c+2|0]=b>>>16;H[c+3|0]=b>>>24;Xa[J[J[a>>2]+32>>2]](j,a);ac(i,j);ab(j);Xa[J[J[a>>2]+28>>2]](j,a);ac(h,j);ab(j);J[d>>2]=Xa[J[J[a>>2]+12>>2]](a);J[e>>2]=Xa[J[J[a>>2]+16>>2]](a);Xa[J[J[a>>2]+20>>2]](j,a);Ab(f,j);ab(j);Xa[J[J[a>>2]+24>>2]](j,a);ac(g,j);ab(j);a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}j=k+4|0;a=pf(b);Xa[J[J[a>>2]+44>>2]](j,a);b=J[k+4>>2];H[c|0]=b;H[c+1|0]=b>>>8;H[c+2|0]=b>>>16;H[c+3|0]=b>>>24;Xa[J[J[a>>2]+32>>2]](j,a);ac(i,j);ab(j);Xa[J[J[a>>2]+28>>2]](j,a);ac(h,j);ab(j);J[d>>2]=Xa[J[J[a>>2]+12>>2]](a);J[e>>2]=Xa[J[J[a>>2]+16>>2]](a);Xa[J[J[a>>2]+20>>2]](j,a);Ab(f,j);ab(j);Xa[J[J[a>>2]+24>>2]](j,a);ac(g,j);ab(j);a=Xa[J[J[a>>2]+36>>2]](a)|0;}J[l>>2]=a;Ua=k+16|0;}function gb(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;b=J[a+112>>2];d=J[a+116>>2];g=(b|d)!=0;h=b;c=J[a+4>>2];f=J[a+44>>2];b=c-f|0;i=b;e=b+J[a+120>>2]|0;b=J[a+124>>2]+(b>>31)|0;a:{b=e>>>0>>0?b+1|0:b;if(!(((b|0)>=(d|0)&e>>>0>=h>>>0|(b|0)>(d|0))&g)){d=Ua-16|0;Ua=d;c=-1;b:{if(Dg(a)){break b}if((Xa[J[a+32>>2]](a,d+15|0,1)|0)!=1){break b}c=K[d+15|0];}Ua=d+16|0;d=c;if((c|0)>=0){break a}f=J[a+44>>2];c=J[a+4>>2];}J[a+112>>2]=-1;J[a+116>>2]=-1;J[a+104>>2]=c;d=f-c|0;c=d+e|0;b=(d>>31)+b|0;J[a+120>>2]=c;J[a+124>>2]=c>>>0>>0?b+1|0:b;return -1}c=e+1|0;b=c?b:b+1|0;h=J[a+4>>2];f=J[a+8>>2];e=J[a+116>>2];i=e;g=J[a+112>>2];c:{if(!(e|g)){break c}e=g-c|0;g=i-(b+(c>>>0>g>>>0)|0)|0;j=f-h|0;i=j>>31;if((g|0)>=(i|0)&e>>>0>=j>>>0|(g|0)>(i|0)){break c}f=e+h|0;}J[a+104>>2]=f;e=J[a+44>>2];f=e-h|0;c=f+c|0;b=(f>>31)+b|0;J[a+120>>2]=c;J[a+124>>2]=c>>>0>>0?b+1|0:b;if(e>>>0>=h>>>0){H[h-1|0]=d;}return d}function $l(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;g=Ua-16|0;Ua=g;a:{b:{if((b|0)!=-1){i=J[a+8>>2];j=J[a+12>>2];d=J[a+24>>2];if((d|0)==J[a+28>>2]){e=-1;if(!(K[a+48|0]&16)){break a}k=J[a+44>>2];h=J[a+20>>2];J[5996]=0;c=a+32|0;aa(98,c|0,0);f=J[5996];J[5996]=0;if((f|0)==1){break b}f=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,f|0);f=J[5996];J[5996]=0;if((f|0)==1){break b}c=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;e=K[a+43|0];J[a+28>>2]=c+((e&128)>>>7|0?J[a+36>>2]:e&127);J[a+20>>2]=c;J[a+24>>2]=c;J[a+24>>2]=J[a+24>>2]+(d-h|0);J[a+44>>2]=J[a+20>>2]+(k-h|0);d=J[a+24>>2];}J[g+12>>2]=d+1;d=a+44|0;c=g+12|0;c=J[(M[c>>2]>2]?d:c)>>2];J[a+44>>2]=c;if(K[a+48|0]&8){d=a+32|0;d=(K[d+11|0]&128)>>>7|0?J[d>>2]:d;J[a+16>>2]=c;J[a+12>>2]=d+(j-i|0);J[a+8>>2]=d;}e=vg(a,b<<24>>24);break a}e=(b|0)!=-1?b:0;break a}pa(fa(0)|0)|0;ra();}Ua=g+16|0;return e|0}function Vf(a,b,c,d){var e=0,f=0,g=0,h=0;g=Ua-32|0;Ua=g;f=d&2147483647;e=f-1065418752|0;h=f-1082064896|0;a:{if((e|0)==(h|0)&0|e>>>0>>0){f=(d&33554431)<<7|c>>>25;e=0;h=e;c=c&33554431;if(!(!e&(c|0)==16777216?!(a|b):!e&c>>>0<16777216)){e=f+1073741825|0;break a}e=f+1073741824|0;if(c^16777216|a|(b|h)){break a}e=(f&1)+e|0;break a}if(!(!c&(f|0)==2147418112?!(a|b):f>>>0<2147418112)){e=((d&33554431)<<7|c>>>25)&4194303|2143289344;break a}e=2139095040;if(f>>>0>1082064895){break a}e=0;f=f>>>16|0;if(f>>>0<16145){break a}e=d&65535|65536;Cb(g+16|0,a,b,c,e,f-16129|0);xc(g,a,b,c,e,16257-f|0);a=J[g+8>>2];e=(J[g+12>>2]&33554431)<<7|a>>>25;c=J[g>>2]|(J[g+16>>2]|J[g+24>>2]|(J[g+20>>2]|J[g+28>>2]))!=0;f=J[g+4>>2];b=0;a=a&33554431;if(!(!b&(a|0)==16777216?!(c|f):!b&a>>>0<16777216)){e=e+1|0;break a}if(a^16777216|c|(b|f)){break a}e=(e&1)+e|0;}Ua=g+32|0;return x(2,d&-2147483648|e),C()}function eo(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{if(b){if(!c){break j}break i}Wa=0;a=(a>>>0)/(c>>>0)|0;break a}if(!a){break h}break g}if(!(c-1&c)){break f}f=(S(c)+33|0)-S(b)|0;g=0-f|0;break d}Wa=0;a=(b>>>0)/0|0;break a}d=32-S(b)|0;if(d>>>0<31){break e}break c}if((c|0)==1){break b}f=c?31-S(c-1^c)|0:32;c=f&31;if((f&63)>>>0>=32){a=b>>>c|0;}else {d=b>>>c|0;a=((1<>>c;}Wa=d;break a}f=d+1|0;g=63-d|0;}d=f&63;e=d&31;if(d>>>0>=32){d=0;h=b>>>e|0;}else {d=b>>>e|0;h=((1<>>e;}g=g&63;e=g&31;if(g>>>0>=32){b=a<>>32-e|b<>>31;d=h<<1|b>>>31;e=l-(i+(d>>>0>g>>>0)|0)>>31;j=c&e;h=d-j|0;d=i-(d>>>0>>0)|0;b=b<<1|a>>>31;a=k|a<<1;k=e&1;f=f-1|0;if(f){continue}break}}Wa=b<<1|a>>>31;a=k|a<<1;break a}a=0;b=0;}Wa=b;}return a}function _l(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;i=J[b+44>>2];j=J[b+24>>2];if(i>>>0>>0){J[b+44>>2]=j;i=j;}m=-1;n=-1;o=f&24;a:{if(!o|(e|0)==1&(o|0)==24){break a}if(i){g=b+32|0;g=i-((K[g+11|0]&128)>>>7|0?J[g>>2]:g)|0;k=g>>31;}b:{c:{switch(e|0){case 1:if(f&8){h=J[b+12>>2]-J[b+8>>2]|0;l=h>>31;break b}h=j-J[b+20>>2]|0;l=h>>31;break b;case 0:break b;case 2:break c;default:break a}}h=g;l=k;}d=d+l|0;c=c+h|0;d=h>>>0>c>>>0?d+1|0:d;if((d|0)<0|(c>>>0>g>>>0&(d|0)>=(k|0)|(d|0)>(k|0))){break a}e=f&8;d:{if(!(c|d)){break d}if(J[b+12>>2]?0:e){break a}if(!(f&16)){break d}if(!j){break a}}if(e){e=J[b+8>>2];J[b+16>>2]=i;J[b+12>>2]=c+e;J[b+8>>2]=e;}if(f&16){e=J[b+20>>2];J[b+28>>2]=J[b+28>>2];J[b+20>>2]=e;J[b+24>>2]=e;J[b+24>>2]=c+J[b+24>>2];}m=c;n=d;}J[a+8>>2]=m;J[a+12>>2]=n;J[a>>2]=0;J[a+4>>2]=0;}function fe(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;b=a;a:{if(b&3){while(1){c=K[b|0];if(!c|(c|0)==61){break a}b=b+1|0;if(b&3){continue}break}}c=J[b>>2];b:{if((c^-1)&c-16843009&-2139062144){break b}while(1){if((c^1027423549)-16843009&(c^-1)&-2139062144){break b}c=J[b+4>>2];b=b+4|0;if(!(c-16843009&(c^-1)&-2139062144)){continue}break}}while(1){c=b;d=K[b|0];if((d|0)!=61){b=b+1|0;if(d){continue}}break}b=c;}if((a|0)==(b|0)){return 0}f=b-a|0;c:{if(K[f+a|0]){break c}e=J[6181];if(!e){break c}b=J[e>>2];if(!b){break c}while(1){d:{g=a;c=b;h=f;d=0;e:{if(!f){break e}d=K[a|0];if(d){f:{while(1){i=K[c|0];if((i|0)!=(d|0)|!i){break f}h=h-1|0;if(!h){break f}c=c+1|0;d=K[g+1|0];g=g+1|0;if(d){continue}break}d=0;}}else {d=0;}d=d-K[c|0]|0;}if(!d){b=b+f|0;if(K[b|0]==61){break d}}b=J[e+4>>2];e=e+4|0;if(b){continue}break c}break}j=b+1|0;}return j}function Ob(a,b){a=a|0;b=b|0;var c=0,d=0;d=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);a:{b:{c:{if(b>>>0<=28){if(d>>>0<29){break c}b=K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24);fb(a+4|0,b,d-29|0);$a(b);b=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))-29|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;return}if(d>>>0>=29){c=Vc(K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24),b);H[a+8|0]=c;H[a+9|0]=c>>>8;H[a+10|0]=c>>>16;H[a+11|0]=c>>>24;if(!c){break b}H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;return}c=sb(b);if(!c){break a}c=fb(c,a+4|0,d);H[a+4|0]=b;H[a+5|0]=b>>>8;H[a+6|0]=b>>>16;H[a+7|0]=b>>>24;H[a+8|0]=c;H[a+9|0]=c>>>8;H[a+10|0]=c>>>16;H[a+11|0]=c>>>24;b=d+29|0;H[a|0]=b;H[a+1|0]=b>>>8;H[a+2|0]=b>>>16;H[a+3|0]=b>>>24;}return}la(1370,2249,181,1040);B();}la(1357,2249,185,1040);B();}function pd(a,b,c,d){var e=0,f=0,g=0;e=Ua-160|0;Ua=e;f=b?a:e+158|0;J[e+148>>2]=f;a=-1;g=b-1|0;J[e+152>>2]=b>>>0>=g>>>0?g:0;e=Sb(e,0,144);J[e+76>>2]=-1;J[e+36>>2]=179;J[e+80>>2]=-1;J[e+44>>2]=e+159;J[e+84>>2]=e+148;a:{if((b|0)<0){J[5732]=61;break a}H[f|0]=0;f=0;b=Ua-208|0;Ua=b;J[b+204>>2]=d;a=b+160|0;Sb(a,0,40);J[b+200>>2]=J[b+204>>2];b:{if((Kg(0,c,b+200|0,b+80|0,a)|0)<0){a=-1;break b}d=J[e+76>>2]>=0;g=J[e>>2];J[e>>2]=g&-33;c:{d:{e:{if(!J[e+48>>2]){J[e+48>>2]=80;J[e+28>>2]=0;J[e+16>>2]=0;J[e+20>>2]=0;f=J[e+44>>2];J[e+44>>2]=b;break e}if(J[e+16>>2]){break d}}a=-1;if(Be(e)){break c}}a=Kg(e,c,b+200|0,b+80|0,b+160|0);}c=a;if(f){Xa[J[e+36>>2]](e,0,0)|0;J[e+48>>2]=0;J[e+44>>2]=f;J[e+28>>2]=0;a=J[e+20>>2];J[e+16>>2]=0;J[e+20>>2]=0;c=a?c:-1;}a=J[e>>2];J[e>>2]=a|g&32;a=a&32?-1:c;if(!d){break b}}Ua=b+208|0;}Ua=e+160|0;return a}function Ck(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,i=0;h=Ua-416|0;Ua=h;d=h+416|0;J[h+12>>2]=d;c=Ua-144|0;Ua=c;J[c+28>>2]=c+132;i=c+32|0;yf(J[a+8>>2],i,c+28|0,e,f,g);J[c+16>>2]=0;J[c+20>>2]=0;J[c+12>>2]=i;e=h+16|0;g=J[h+12>>2]-e>>2;f=Ua-16|0;Ua=f;a=Xb(f+12|0,J[a+8>>2]);g=bg(e,c+12|0,g,c+16|0);a=J[a>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=f+16|0;if((g|0)==-1){xf(2472);B();}J[h+12>>2]=e+(g<<2);Ua=c+144|0;c=Ua-16|0;Ua=c;a=Ua-32|0;Ua=a;f=Ua-16|0;Ua=f;J[f+12>>2]=J[h+12>>2];J[a+24>>2]=e;J[a+28>>2]=J[f+12>>2];Ua=f+16|0;f=J[a+24>>2];g=J[a+28>>2];e=Ua-16|0;Ua=e;J[e+12>>2]=b;while(1){if((f|0)!=(g|0)){pg(e+12|0,J[f>>2]);f=f+4|0;continue}break}J[a+16>>2]=g;J[a+20>>2]=J[e+12>>2];Ua=e+16|0;b=J[a+16>>2];J[a+12>>2]=J[a+20>>2];J[c+8>>2]=b;J[c+12>>2]=J[a+12>>2];Ua=a+32|0;Ua=c+16|0;Ua=d;return J[c+12>>2]}function Kc(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=Ua-32|0;Ua=e;h=e+32|0;c=h;d=e+21|0;f=c-d|0;a:{if((f|0)<=9){i=f;f=P(32-S(b|1)|0,1233)>>>12|0;g=61;if((i|0)<((M[(f<<2)+21616>>2]<=b>>>0)+f|0)){break a}}b:{if(b>>>0<=999999){if(b>>>0<=9999){if(b>>>0<=99){if(b>>>0<=9){H[d|0]=b+48;c=d+1|0;break b}c=uc(d,b);break b}if(b>>>0<=999){c=(b>>>0)/100|0;H[d|0]=c+48;c=uc(d+1|0,P(c,-100)+b|0);break b}c=Kd(d,b);break b}if(b>>>0<=99999){c=(b>>>0)/1e4|0;H[d|0]=c+48;c=Kd(d+1|0,P(c,-1e4)+b|0);break b}c=Jd(d,b);break b}if(b>>>0<=99999999){if(b>>>0<=9999999){c=(b>>>0)/1e6|0;H[d|0]=c+48;c=Jd(d+1|0,P(c,-1e6)+b|0);break b}c=Id(d,b);break b}if(b>>>0<=999999999){c=(b>>>0)/1e8|0;H[d|0]=c+48;c=Id(d+1|0,P(c,-1e8)+b|0);break b}c=(b>>>0)/1e8|0;c=Id(uc(d,c),P(c,-1e8)+b|0);}g=0;}J[e+16>>2]=g;J[e+12>>2]=c;td(a,d,J[e+12>>2]);Ua=h;}function ye(a,b,c){var d=0,e=0,f=0,g=0;d=a+4|0;e=(d+b|0)-1&0-b;b=J[a>>2];if(e+c>>>0<=(b+a|0)-4>>>0){f=J[a+4>>2];J[f+8>>2]=J[a+8>>2];J[J[a+8>>2]+4>>2]=f;if((d|0)!=(e|0)){e=e-d|0;f=a-(J[a-4>>2]&-2)|0;d=e+J[f>>2]|0;J[f>>2]=d;J[(f+(d&-4)|0)-4>>2]=d;a=a+e|0;b=b-e|0;J[a>>2]=b;}a:{if(c+24>>>0<=b>>>0){d=(a+c|0)+8|0;b=(b-c|0)-8|0;J[d>>2]=b;J[(d+(b&-4)|0)-4>>2]=b|1;e=J[d>>2]-8|0;b:{if(e>>>0<=127){b=(e>>>3|0)-1|0;break b}f=S(e);b=((e>>>29-f^4)-(f<<2)|0)+110|0;if(e>>>0<=4095){break b}b=((e>>>30-f^2)-(f<<1)|0)+71|0;b=b>>>0>=63?63:b;}e=b<<4;J[d+4>>2]=e+22944;e=e+22952|0;J[d+8>>2]=J[e>>2];J[e>>2]=d;J[J[d+8>>2]+4>>2]=d;e=J[5994];f=J[5995];d=b&31;if((b&63)>>>0>=32){b=1<>>32-d;d=g;}J[5994]=d|e;J[5995]=b|f;b=c+8|0;J[a>>2]=b;J[((b&-4)+a|0)-4>>2]=b;break a}J[(a+b|0)-4>>2]=b;}a=a+4|0;}else {a=0;}return a}function $m(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;a:{b:{c:{d=J[a>>2];f=(J[a+4>>2]-d|0)/12|0;c=f+1|0;if(c>>>0<357913942){d=(J[a+8>>2]-d|0)/12|0;g=d<<1;d=d>>>0>=178956970?357913941:c>>>0>>0?g:c;if(d){if(d>>>0>=357913942){break c}e=cb(P(d,12));}c=P(f,12)+e|0;f=J[b+4>>2];J[c>>2]=J[b>>2];J[c+4>>2]=f;J[c+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;e=P(d,12)+e|0;d=c+12|0;b=J[a+4>>2];f=J[a>>2];if((b|0)==(f|0)){break b}while(1){b=b-12|0;g=J[b+4>>2];c=c-12|0;J[c>>2]=J[b>>2];J[c+4>>2]=g;J[c+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;if((b|0)!=(f|0)){continue}break}J[a+8>>2]=e;e=J[a+4>>2];J[a+4>>2]=d;b=J[a>>2];J[a>>2]=c;if((b|0)==(e|0)){break a}while(1){a=e-12|0;if(H[e-1|0]<0){$a(J[a>>2]);}e=a;if((a|0)!=(b|0)){continue}break}break a}nb();B();}Pb();B();}J[a+8>>2]=e;J[a+4>>2]=d;J[a>>2]=c;}if(b){$a(b);}}function Lf(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;i=Ua-32|0;Ua=i;a:{b:{c:{if((b|0)!=(c|0)){k=J[5732];J[5732]=0;g=Ua-16|0;Ua=g;jb();f=Ua-16|0;Ua=f;e=Ua-16|0;Ua=e;ee(e,b,i+28|0,2);h=J[e>>2];j=J[e+4>>2];b=f;f=J[e+12>>2];J[b+8>>2]=J[e+8>>2];J[b+12>>2]=f;J[b>>2]=h;J[b+4>>2]=j;Ua=e+16|0;f=J[b>>2];h=J[b+4>>2];e=g;g=J[b+12>>2];J[e+8>>2]=J[b+8>>2];J[e+12>>2]=g;J[e>>2]=f;J[e+4>>2]=h;Ua=b+16|0;g=J[e>>2];f=J[e+4>>2];h=J[e+12>>2];b=i;J[b+16>>2]=J[e+8>>2];J[b+20>>2]=h;J[b+8>>2]=g;J[b+12>>2]=f;Ua=e+16|0;e=J[b+16>>2];f=J[b+20>>2];g=J[b+8>>2];h=J[b+12>>2];j=J[5732];if(!j){break c}if(J[b+28>>2]!=(c|0)){break b}l=g;m=h;n=e;o=f;if((j|0)!=68){break a}break b}J[d>>2]=4;break a}J[5732]=k;if(J[i+28>>2]==(c|0)){break a}}J[d>>2]=4;g=l;h=m;e=n;f=o;}J[a>>2]=g;J[a+4>>2]=h;J[a+8>>2]=e;J[a+12>>2]=f;Ua=i+32|0;}function Gm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;f=J[a+4>>2];e=J[a+8>>2];if(f>>>0>>0){J[f>>2]=b;J[f+8>>2]=c;J[f+12>>2]=c>>31;b=J[d+4>>2];J[f+16>>2]=J[d>>2];J[f+20>>2]=b;J[a+4>>2]=f+24;return}a:{i=J[a>>2];g=(f-i|0)/24|0;h=g+1|0;if(h>>>0<178956971){j=P(g,24);e=(e-i|0)/24|0;g=e<<1;g=e>>>0>=89478485?178956970:g>>>0>h>>>0?g:h;if(g){if(g>>>0>=178956971){break a}h=cb(P(g,24));}else {h=0;}e=j+h|0;J[e+8>>2]=c;J[e+12>>2]=c>>31;J[e>>2]=b;b=J[d+4>>2];J[e+16>>2]=J[d>>2];J[e+20>>2]=b;b=e+24|0;if((f|0)!=(i|0)){while(1){f=f-24|0;d=J[f+4>>2];e=e-24|0;J[e>>2]=J[f>>2];J[e+4>>2]=d;c=J[f+20>>2];J[e+16>>2]=J[f+16>>2];J[e+20>>2]=c;c=J[f+12>>2];J[e+8>>2]=J[f+8>>2];J[e+12>>2]=c;if((f|0)!=(i|0)){continue}break}f=J[a>>2];}J[a+8>>2]=h+P(g,24);J[a+4>>2]=b;J[a>>2]=e;if(f){$a(f);}return}nb();B();}Pb();B();}function _k(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0;f=Ua-32|0;Ua=f;J[f+28>>2]=b;a:{if(!(H[c+4|0]&1)){c=Xa[J[J[a>>2]+24>>2]](a,b,c,d,e)|0;break a}d=f+16|0;a=J[c+28>>2];J[d>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;a=$(198,J[f+16>>2])|0;b=J[5996];J[5996]=0;b:{if((b|0)!=1){b=J[d>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}c:{if(e){Xa[J[J[a>>2]+24>>2]](d,a);break c}Xa[J[J[a>>2]+28>>2]](f+16|0,a);}J[f+12>>2]=Mb(f+16|0);while(1){a=f+16|0;c=qc(a);b=J[f+12>>2];if((c|0)==(b|0)){c=J[f+28>>2];ab(a);break a}a=J[b>>2];J[5996]=0;_(214,f+28|0,a|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){J[f+12>>2]=J[f+12>>2]+4;continue}break}c=Z()|0;ab(f+16|0);break b}c=Z()|0;a=J[f+16>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}da(c|0);B();}Ua=f+32|0;return c|0}function il(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0;f=Ua-32|0;Ua=f;J[f+28>>2]=b;a:{if(!(H[c+4|0]&1)){c=Xa[J[J[a>>2]+24>>2]](a,b,c,d,e)|0;break a}d=f+16|0;a=J[c+28>>2];J[d>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;a=$(180,J[f+16>>2])|0;b=J[5996];J[5996]=0;b:{if((b|0)!=1){b=J[d>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}c:{if(e){Xa[J[J[a>>2]+24>>2]](d,a);break c}Xa[J[J[a>>2]+28>>2]](f+16|0,a);}J[f+12>>2]=Mb(f+16|0);while(1){a=f+16|0;c=sc(a);b=J[f+12>>2];if((c|0)==(b|0)){c=J[f+28>>2];ab(a);break a}a=H[b|0];J[5996]=0;_(210,f+28|0,a|0)|0;a=J[5996];J[5996]=0;if((a|0)!=1){J[f+12>>2]=J[f+12>>2]+1;continue}break}c=Z()|0;ab(f+16|0);break b}c=Z()|0;a=J[f+16>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}}da(c|0);B();}Ua=f+32|0;return c|0}function $n(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0;f=Ua-32|0;Ua=f;J[f+24>>2]=d;H[f+20|0]=0;J[f+8>>2]=a;J[f+16>>2]=f+28;J[f+12>>2]=f+24;a:{b:{c:{if((b|0)!=(c|0)){while(1){J[d+8>>2]=0;J[d>>2]=0;J[d+4>>2]=0;a=J[b+4>>2];e=J[b>>2];if((a|0)!=(e|0)){e=a-e|0;if((e|0)<0){J[5996]=0;J[f+28>>2]=d;ca(84);a=J[5996];J[5996]=0;if((a|0)==1){break c}B();}J[5996]=0;a=$(3,e|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break b}J[d+4>>2]=a;J[d>>2]=a;J[d+8>>2]=(e&-8)+a;e=J[b>>2];g=J[b+4>>2];if((e|0)!=(g|0)){while(1){h=J[e+4>>2];J[a>>2]=J[e>>2];J[a+4>>2]=h;a=a+8|0;e=e+8|0;if((g|0)!=(e|0)){continue}break}}J[d+4>>2]=a;}d=d+12|0;b=b+12|0;if((c|0)!=(b|0)){continue}break}}Ua=f+32|0;return d|0}a=Z()|0;b=J[d>>2];if(!b){break a}J[d+4>>2]=b;$a(b);break a}a=Z()|0;J[f+28>>2]=d;}Ed(f+8|0);da(a|0);B();}function Fm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;f=J[a+4>>2];e=J[a+8>>2];if(f>>>0>>0){J[f>>2]=b;J[f+16>>2]=d;J[f+20>>2]=d>>31;J[f+8>>2]=c;J[f+12>>2]=c>>31;J[a+4>>2]=f+24;return}a:{i=J[a>>2];g=(f-i|0)/24|0;h=g+1|0;if(h>>>0<178956971){j=P(g,24);e=(e-i|0)/24|0;g=e<<1;g=e>>>0>=89478485?178956970:g>>>0>h>>>0?g:h;if(g){if(g>>>0>=178956971){break a}h=cb(P(g,24));}else {h=0;}e=j+h|0;J[e+16>>2]=d;J[e+20>>2]=d>>31;J[e+8>>2]=c;J[e+12>>2]=c>>31;J[e>>2]=b;b=e+24|0;if((f|0)!=(i|0)){while(1){f=f-24|0;d=J[f+4>>2];e=e-24|0;J[e>>2]=J[f>>2];J[e+4>>2]=d;c=J[f+20>>2];J[e+16>>2]=J[f+16>>2];J[e+20>>2]=c;c=J[f+12>>2];J[e+8>>2]=J[f+8>>2];J[e+12>>2]=c;if((f|0)!=(i|0)){continue}break}f=J[a>>2];}J[a+8>>2]=h+P(g,24);J[a+4>>2]=b;J[a>>2]=e;if(f){$a(f);}return}nb();B();}Pb();B();}function Lc(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;g=d;d=Gb(d);i=Ua-16|0;Ua=i;J[i+12>>2]=c;c=a;a:{b:{e=J[a+4>>2];a=K[a+11|0];h=(a&128)>>>7|0?e:a&127;if(h>>>0>=b>>>0){e=h-b|0;J[i+8>>2]=e;a=i+8|0;f=i+12|0;a=J[(M[a>>2]>2]?a:f)>>2];f=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;if(a+(f-h|0)>>>0>=d>>>0){f=(K[c+11|0]&128)>>>7|0?J[c>>2]:c;c:{if((a|0)==(d|0)){a=d;break c}if((a|0)==(e|0)){a=e;break c}j=e-a|0;e=b+f|0;if(a>>>0>d>>>0){break b}d:{if(f+h>>>0<=g>>>0|e>>>0>=g>>>0){break d}if(a+e>>>0<=g>>>0){g=(d-a|0)+g|0;break d}oc(e,g,a);e=d-a|0;g=d+g|0;b=a+b|0;a=0;d=e;}e=b+f|0;oc(e+d|0,a+e|0,j);}oc(b+f|0,g,d);sd(c,f,(d+h|0)-a|0);break a}dd(c,f,d+h-(a+f)|0,h,b,a,d,g);break a}ue();B();}b=oc(e,g,d);oc(b+d|0,a+b|0,j);sd(c,f,(d+h|0)-a|0);}Ua=i+16|0;}function nk(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;h=Ua-16|0;Ua=h;d=K[a+11|0];e=d&127;d=(d&128)>>>7|0;e=d?J[a+4>>2]:e;d=d?(J[a+8>>2]&2147483647)-1|0:1;f=c-b>>2;a:{if(!f){break a}b:{g=K[a+11|0];i=(g&128)>>>7|0?J[a>>2]:a;if(i>>>0<=b>>>0){g=(((g&128)>>>7|0?J[a+4>>2]:g&127)<<2)+i>>>0>=b>>>0;}else {g=0;}if(!g){if(d-e>>>0>>0){of(a,d,(e-d|0)+f|0,e,e);}d=(e<<2)+((K[a+11|0]&128)>>>7|0?J[a>>2]:a)|0;while(1){if((b|0)==(c|0)){break b}J[d>>2]=J[b>>2];b=b+4|0;d=d+4|0;continue}}b=ag(h+4|0,b,c);c=K[b+11|0];f=(c&128)>>>7|0;d=f?J[b>>2]:b;e=J[b+4>>2];J[5996]=0;ba(235,a|0,d|0,(f?e:c&127)|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){ab(b);break a}a=Z()|0;ab(b);da(a|0);B();}J[d>>2]=0;b=e+f|0;c:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break c}H[a+11|0]=b;}}Ua=h+16|0;return a|0}function rm(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;J[a+4>>2]=b;H[a|0]=0;b=J[J[b>>2]-12>>2]+b|0;if(!J[b+16>>2]){b=J[b+72>>2];if(b){a:{e=Ua-16|0;Ua=e;b:{c:{if(!J[(b+J[J[b>>2]-12>>2]|0)+24>>2]){break c}J[5996]=0;d=_(134,e+8|0,b|0)|0;c=J[5996];J[5996]=0;d:{if((c|0)!=1){e:{if(!K[d|0]){break e}c=J[(b+J[J[b>>2]-12>>2]|0)+24>>2];J[5996]=0;c=$(169,c|0)|0;f=J[5996];J[5996]=0;if((f|0)!=1){if((c|0)!=-1){break e}c=J[J[b>>2]-12>>2];J[5996]=0;aa(138,b+c|0,1);c=J[5996];J[5996]=0;if((c|0)!=1){break e}}c=fa(0)|0;ud(d);break d}ud(d);break c}c=fa(0)|0;}pa(c|0)|0;d=J[J[b>>2]-12>>2];J[5996]=0;ha(139,b+d|0);b=J[5996];J[5996]=0;if((b|0)==1){break b}ra();}Ua=e+16|0;break a}a=Z()|0;J[5996]=0;ca(110);b=J[5996];J[5996]=0;if((b|0)!=1){da(a|0);B();}fa(0)|0;Vb();B();}}H[a|0]=1;}return a|0}function Pm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;d=Ua-32|0;Ua=d;a:{b:{c:{if((c|0)<=0){break c}while(1){if(K[b+e|0]!=41){e=e+1|0;if((c|0)!=(e|0)){continue}break c}break}if(e){break b}}H[a+16|0]=0;H[a|0]=0;break a}d:{e:{if(e>>>0<=17){if(e>>>0>10){break e}H[d+31|0]=e;c=d+20|0;break d}H[a+16|0]=0;H[a|0]=0;break a}f=(e|15)+1|0;c=cb(f);J[d+28>>2]=f|-2147483648;J[d+20>>2]=c;J[d+24>>2]=e;}H[fb(c,b,e)+e|0]=0;c=J[d+20>>2];b=K[d+27|0]|K[d+28|0]<<8|(K[d+29|0]<<16|K[d+30|0]<<24);H[d+15|0]=b;H[d+16|0]=b>>>8;H[d+17|0]=b>>>16;H[d+18|0]=b>>>24;J[d+12>>2]=J[d+24>>2];f=K[d+31|0];J[a>>2]=c;J[a+4>>2]=J[d+12>>2];b=K[d+15|0]|K[d+16|0]<<8|(K[d+17|0]<<16|K[d+18|0]<<24);H[a+7|0]=b;H[a+8|0]=b>>>8;H[a+9|0]=b>>>16;H[a+10|0]=b>>>24;H[a+16|0]=1;J[a+12>>2]=e;H[a+11|0]=f;}Ua=d+32|0;}function Ac(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0;g=Ua-16|0;Ua=g;a:{b:{c:{if(!a){break c}i=J[e+12>>2];j=c-b|0;if((j|0)>0){if((Xa[J[J[a>>2]+48>>2]](a,b,j)|0)!=(j|0)){break c}}b=d-b|0;b=(b|0)<(i|0)?i-b|0:0;if((b|0)>0){if(b>>>0>=2147483632){break a}d:{if(b>>>0>=11){i=(b|15)+1|0;h=cb(i);J[g+12>>2]=i|-2147483648;J[g+4>>2]=h;J[g+8>>2]=b;break d}H[g+15|0]=b;h=g+4|0;}H[Sb(h,f,b)+b|0]=0;f=J[J[a>>2]+48>>2];J[5996]=0;f=ba(f|0,a|0,(H[g+15|0]<0?J[g+4>>2]:g+4|0)|0,b|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break b}if(H[g+15|0]<0){$a(J[g+4>>2]);}h=0;if((b|0)!=(f|0)){break c}}b=d-c|0;if((b|0)>0){if((Xa[J[J[a>>2]+48>>2]](a,c,b)|0)!=(b|0)){break c}}J[e+12>>2]=0;h=a;}Ua=g+16|0;return h|0}a=Z()|0;if(H[g+15|0]<0){$a(J[g+4>>2]);}da(a|0);B();}ub();B();}function vk(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;h=Ua-16|0;Ua=h;d=K[a+11|0];e=d&127;d=(d&128)>>>7|0;e=d?J[a+4>>2]:e;d=d?(J[a+8>>2]&2147483647)-1|0:10;f=c-b|0;a:{if(!f){break a}b:{g=K[a+11|0];i=(g&128)>>>7|0?J[a>>2]:a;if(i>>>0<=b>>>0){g=((g&128)>>>7|0?J[a+4>>2]:g&127)+i>>>0>=b>>>0;}else {g=0;}if(!g){if(d-e>>>0>>0){Sd(a,d,(e-d|0)+f|0,e,e);}d=e+((K[a+11|0]&128)>>>7|0?J[a>>2]:a)|0;while(1){if((b|0)==(c|0)){break b}H[d|0]=K[b|0];b=b+1|0;d=d+1|0;continue}}b=td(h+4|0,b,c);c=K[b+11|0];f=(c&128)>>>7|0;d=f?J[b>>2]:b;e=J[b+4>>2];J[5996]=0;ba(100,a|0,d|0,(f?e:c&127)|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){ab(b);break a}a=Z()|0;ab(b);da(a|0);B();}H[d|0]=0;b=e+f|0;c:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break c}H[a+11|0]=b;}}Ua=h+16|0;return a|0}function eb(a,b,c){var d=0,e=0;a:{if((a|0)==(b|0)){break a}e=a+c|0;if(b-e>>>0<=0-(c<<1)>>>0){return fb(a,b,c)}d=(a^b)&3;b:{c:{if(a>>>0>>0){if(d){d=a;break b}if(!(a&3)){d=a;break c}d=a;while(1){if(!c){break a}H[d|0]=K[b|0];b=b+1|0;c=c-1|0;d=d+1|0;if(d&3){continue}break}break c}d:{if(d){break d}if(e&3){while(1){if(!c){break a}c=c-1|0;d=c+a|0;H[d|0]=K[b+c|0];if(d&3){continue}break}}if(c>>>0<=3){break d}while(1){c=c-4|0;J[c+a>>2]=J[b+c>>2];if(c>>>0>3){continue}break}}if(!c){break a}while(1){c=c-1|0;H[c+a|0]=K[b+c|0];if(c){continue}break}break a}if(c>>>0<=3){break b}while(1){J[d>>2]=J[b>>2];b=b+4|0;d=d+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}while(1){H[d|0]=K[b|0];d=d+1|0;b=b+1|0;c=c-1|0;if(c){continue}break}}return a}function Ig(a,b,c){a:{switch(b-9|0){case 0:b=J[c>>2];J[c>>2]=b+4;J[a>>2]=J[b>>2];return;case 6:b=J[c>>2];J[c>>2]=b+4;b=I[b>>1];J[a>>2]=b;J[a+4>>2]=b>>31;return;case 7:b=J[c>>2];J[c>>2]=b+4;J[a>>2]=L[b>>1];J[a+4>>2]=0;return;case 8:b=J[c>>2];J[c>>2]=b+4;b=H[b|0];J[a>>2]=b;J[a+4>>2]=b>>31;return;case 9:b=J[c>>2];J[c>>2]=b+4;J[a>>2]=K[b|0];J[a+4>>2]=0;return;case 16:b=J[c>>2]+7&-8;J[c>>2]=b+8;O[a>>3]=O[b>>3];return;case 17:Fg(a,c);default:return;case 1:case 4:case 14:b=J[c>>2];J[c>>2]=b+4;b=J[b>>2];J[a>>2]=b;J[a+4>>2]=b>>31;return;case 2:case 5:case 11:case 15:b=J[c>>2];J[c>>2]=b+4;J[a>>2]=J[b>>2];J[a+4>>2]=0;return;case 3:case 10:case 12:case 13:break a}}b=J[c>>2]+7&-8;J[c>>2]=b+8;c=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=c;}function Xd(a,b,c,d,e){var f=0,g=0;f=Ua-16|0;Ua=f;J[f+12>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(197,J[f+12>>2])|0;g=J[5996];J[5996]=0;a:{if((g|0)==1){break a}J[5996]=0;ga(208,b|0,12416,12448,c|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}J[5996]=0;b=$(198,J[f+12>>2])|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[5996]=0;c=$(209,b|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break a}J[d>>2]=c;J[5996]=0;c=$(206,b|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}J[e>>2]=c;J[5996]=0;aa(207,a|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[f+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}Ua=f+16|0;return}c=Z()|0;a=J[f+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function $d(a,b,c,d,e){var f=0,g=0;f=Ua-16|0;Ua=f;J[f+12>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(170,J[f+12>>2])|0;g=J[5996];J[5996]=0;a:{if((g|0)==1){break a}J[5996]=0;ga(195,b|0,12416,12448,c|0);b=J[5996];J[5996]=0;if((b|0)==1){break a}J[5996]=0;b=$(180,J[f+12>>2])|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}J[5996]=0;c=$(196,b|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break a}H[d|0]=c;J[5996]=0;c=$(193,b|0)|0;d=J[5996];J[5996]=0;if((d|0)==1){break a}H[e|0]=c;J[5996]=0;aa(194,a|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[f+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}Ua=f+16|0;return}c=Z()|0;a=J[f+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function jg(a,b,c,d,e,f){var g=0;g=Ua-80|0;Ua=g;a:{if((f|0)>=16384){ob(g+32|0,b,c,d,e,0,0,0,2147352576);d=J[g+40>>2];e=J[g+44>>2];b=J[g+32>>2];c=J[g+36>>2];if(f>>>0<32767){f=f-16383|0;break a}ob(g+16|0,b,c,d,e,0,0,0,2147352576);f=((f|0)>=49149?49149:f)-32766|0;d=J[g+24>>2];e=J[g+28>>2];b=J[g+16>>2];c=J[g+20>>2];break a}if((f|0)>-16383){break a}ob(g- -64|0,b,c,d,e,0,0,0,7471104);d=J[g+72>>2];e=J[g+76>>2];b=J[g+64>>2];c=J[g+68>>2];if(f>>>0>4294934644){f=f+16269|0;break a}ob(g+48|0,b,c,d,e,0,0,0,7471104);f=((f|0)<=-48920?-48920:f)+32538|0;d=J[g+56>>2];e=J[g+60>>2];b=J[g+48>>2];c=J[g+52>>2];}ob(g,b,c,d,e,0,0,0,f+16383<<16);b=J[g+12>>2];J[a+8>>2]=J[g+8>>2];J[a+12>>2]=b;b=J[g+4>>2];J[a>>2]=J[g>>2];J[a+4>>2]=b;Ua=g+80|0;}function cc(a,b,c,d,e){var f=0,g=0,h=0,i=0;h=Ua-16|0;Ua=h;J[h+12>>2]=b;b=0;g=6;a:{b:{if(Ub(a,h+12|0)){break b}g=J[a>>2];f=J[g+12>>2];c:{if((f|0)==J[g+16>>2]){f=Xa[J[J[g>>2]+36>>2]](g)|0;break c}f=K[f|0];}g=4;i=J[d+8>>2];f=f<<24>>24;if((f|0)>=0){i=(J[((f&255)<<2)+i>>2]&64)!=0;}else {i=0;}if(!i){break b}b=Xa[J[J[d>>2]+36>>2]](d,f,0)|0;while(1){d:{b=b-48|0;f=Ic(a);if(Ub(f,h+12|0)|(e|0)<2){break d}g=J[f>>2];f=J[g+12>>2];e:{if((f|0)==J[g+16>>2]){g=Xa[J[J[g>>2]+36>>2]](g)|0;break e}g=K[f|0];}f=J[d+8>>2];g=g<<24>>24;if((g|0)>=0){f=(J[f+((g&255)<<2)>>2]&64)!=0;}else {f=0;}if(!f){break a}e=e-1|0;b=(Xa[J[J[d>>2]+36>>2]](d,g,0)|0)+P(b,10)|0;continue}break}g=2;if(!Ub(f,h+12|0)){break a}}J[c>>2]=J[c>>2]|g;}Ua=h+16|0;return b}function Wb(a,b){a=a|0;b=b|0;var c=0,d=0;a:{if((b|0)>0){d=a+b|0;while(1){b=1;b:{c:{switch(K[a|0]-66|0){default:a=Rb(8);J[5996]=0;b=_(17,a|0,2064)|0;c=J[5996];J[5996]=0;if((c|0)==1){break a}na(b|0,22528,7);B();case 20:b=2;break b;case 9:b=4;break b;case 21:b=8;break b;case 56:b=16;break b;case 45:b=32;break b;case 44:b=64;break b;case 34:b=128;break b;case 51:b=256;break b;case 35:b=512;break b;case 36:b=1024;break b;case 49:b=2048;break b;case 43:b=4096;break b;case 54:b=8192;break b;case 37:b=16384;break b;case 38:b=32768;break b;case 39:b=65536;break b;case 40:b=131072;break b;case 0:break b;case 41:break c}}b=262144;}c=b|c;a=a+1|0;if(d>>>0>a>>>0){continue}break}}return c|0}b=Z()|0;ic(a);da(b|0);B();}function Sb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(!c){break a}H[a|0]=b;d=a+c|0;H[d-1|0]=b;if(c>>>0<3){break a}H[a+2|0]=b;H[a+1|0]=b;H[d-3|0]=b;H[d-2|0]=b;if(c>>>0<7){break a}H[a+3|0]=b;H[d-4|0]=b;if(c>>>0<9){break a}d=0-a&3;e=d+a|0;b=P(b&255,16843009);J[e>>2]=b;d=c-d&-4;c=d+e|0;J[c-4>>2]=b;if(d>>>0<9){break a}J[e+8>>2]=b;J[e+4>>2]=b;J[c-8>>2]=b;J[c-12>>2]=b;if(d>>>0<25){break a}J[e+24>>2]=b;J[e+20>>2]=b;J[e+16>>2]=b;J[e+12>>2]=b;J[c-16>>2]=b;J[c-20>>2]=b;J[c-24>>2]=b;J[c-28>>2]=b;g=e&4|24;c=d-g|0;if(c>>>0<32){break a}d=co(b,0,1,1);f=Wa;b=e+g|0;while(1){J[b+24>>2]=d;J[b+28>>2]=f;J[b+16>>2]=d;J[b+20>>2]=f;J[b+8>>2]=d;J[b+12>>2]=f;J[b>>2]=d;J[b+4>>2]=f;b=b+32|0;c=c-32|0;if(c>>>0>31){continue}break}}return a}function re(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;a:{d=J[a+4>>2];h=J[a>>2];f=d-h>>3;c=f+1|0;if(c>>>0<536870912){g=J[a+8>>2]-h|0;e=g>>2;c=g>>>0>=2147483640?536870911:c>>>0>>0?e:c;if(c>>>0>=536870912){break a}e=f<<3;f=c<<3;g=cb(f);c=e+g|0;J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;e=c+8|0;if((d|0)!=(h|0)){while(1){c=c-8|0;d=d-8|0;J[c>>2]=J[d>>2];J[c+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;if((d|0)!=(h|0)){continue}break}}J[a+8>>2]=f+g;b=J[a>>2];J[a>>2]=c;d=J[a+4>>2];J[a+4>>2]=e;if((b|0)!=(d|0)){while(1){d=d-8|0;a=J[d+4>>2];b:{if(!a){break b}c=J[a+4>>2];J[a+4>>2]=c-1;if(c){break b}Xa[J[J[a>>2]+8>>2]](a);bb(a);}if((b|0)!=(d|0)){continue}break}}if(b){$a(b);}return}nb();B();}Pb();B();}function jb(){var a=0,b=0,c=0,d=0;if(K[25008]){return J[6251]}c=Ua-32|0;Ua=c;a:{b:{while(1){b=c+8|0;d=dg(a,1<>2]=d;if((d|0)==-1){break b}a=a+1|0;if((a|0)!=6){continue}break}a=19324;if(!Eb(b,19324,24)){break a}a=19348;if(!Eb(b,19348,24)){break a}a=0;if(!K[24780]){while(1){J[(a<<2)+24732>>2]=dg(a,5575);a=a+1|0;if((a|0)!=6){continue}break}H[24780]=1;J[6189]=J[6183];}a=24732;b=c+8|0;if(!Eb(b,24732,24)){break a}a=24756;if(!Eb(b,24756,24)){break a}a=sb(24);if(!a){break b}b=J[c+12>>2];J[a>>2]=J[c+8>>2];J[a+4>>2]=b;b=J[c+28>>2];J[a+16>>2]=J[c+24>>2];J[a+20>>2]=b;b=J[c+20>>2];J[a+8>>2]=J[c+16>>2];J[a+12>>2]=b;break a}a=0;}Ua=c+32|0;H[25008]=1;J[6251]=a;return a}function Fe(a,b){var c=0,d=0,e=0,f=0;c=Ua+-64|0;Ua=c;d=J[a>>2];e=J[d-4>>2];f=J[d-8>>2];J[c+28>>2]=0;J[c+32>>2]=0;J[c+36>>2]=0;J[c+40>>2]=0;J[c+44>>2]=0;J[c+48>>2]=0;J[c+52>>2]=0;J[c+56>>2]=0;d=0;H[c+59|0]=0;H[c+60|0]=0;H[c+61|0]=0;H[c+62|0]=0;J[c+20>>2]=0;J[c+24>>2]=0;J[c+16>>2]=22056;J[c+12>>2]=a;J[c+8>>2]=b;a=a+f|0;a:{if(Jb(e,b,0)){J[c+56>>2]=1;Xa[J[J[e>>2]+20>>2]](e,c+8|0,a,a,1,0);d=J[c+32>>2]==1?a:0;break a}Xa[J[J[e>>2]+24>>2]](e,c+8|0,a,1,0);b:{switch(J[c+44>>2]){case 0:d=J[c+48>>2]==1?J[c+36>>2]==1?J[c+40>>2]==1?J[c+28>>2]:0:0:0;break a;case 1:break b;default:break a}}if(J[c+32>>2]!=1){if(J[c+48>>2]|J[c+36>>2]!=1|J[c+40>>2]!=1){break a}}d=J[c+24>>2];}Ua=c- -64|0;return d}function dg(a,b){var c=0,d=0,e=0;a:{if(K[b|0]){break a}b=fe(3169);if(K[b|0]?b:0){break a}b=fe(P(a,12)+9024|0);if(K[b|0]?b:0){break a}b=fe(3321);if(K[b|0]?b:0){break a}b=3845;}b:{while(1){d=K[b+c|0];if(!(!d|(d|0)==47)){d=23;c=c+1|0;if((c|0)!=23){continue}break b}break}d=c;}e=3845;c:{d:{c=K[b|0];e:{f:{if(!(K[b+d|0]|(c|0)==46)){e=b;if((c|0)!=67){break f}}if(!K[e+1|0]){break e}}if(!Uc(e,3845)){break e}if(Uc(e,2764)){break d}}if(!a){c=9096;if(K[e+1|0]==46){break c}}return 0}c=J[6182];if(c){while(1){if(!Uc(e,c+8|0)){break c}c=J[c+32>>2];if(c){continue}break}}c=sb(36);if(c){J[c+4>>2]=20;J[c>>2]=8992;b=c+8|0;fb(b,e,d);H[b+d|0]=0;J[c+32>>2]=J[6182];J[6182]=c;}c=a|c?c:9096;}return c}function $a(a){var b=0,c=0,d=0,e=0,f=0;if(a){b=a-4|0;e=J[b>>2];d=e;c=b;f=J[a-8>>2];a=f&-2;if((a|0)!=(f|0)){c=b-a|0;f=J[c+4>>2];J[f+8>>2]=J[c+8>>2];J[J[c+8>>2]+4>>2]=f;d=a+d|0;}a=b+e|0;b=J[a>>2];if((b|0)!=J[(a+b|0)-4>>2]){e=J[a+4>>2];J[e+8>>2]=J[a+8>>2];J[J[a+8>>2]+4>>2]=e;d=b+d|0;}J[c>>2]=d;J[((d&-4)+c|0)-4>>2]=d|1;b=J[c>>2]-8|0;a:{if(b>>>0<=127){a=(b>>>3|0)-1|0;break a}d=S(b);a=((b>>>29-d^4)-(d<<2)|0)+110|0;if(b>>>0<=4095){break a}a=((b>>>30-d^2)-(d<<1)|0)+71|0;a=a>>>0>=63?63:a;}b=a<<4;J[c+4>>2]=b+22944;b=b+22952|0;J[c+8>>2]=J[b>>2];J[b>>2]=c;J[J[c+8>>2]+4>>2]=c;b=J[5994];d=J[5995];c=a&31;if((a&63)>>>0>=32){a=1<>>32-c;}J[5994]=e|b;J[5995]=a|d;}}function Dc(a,b,c,d,e,f,g,h,i,j,k){var l=0,m=0,n=0;a:{b:{l=J[d>>2];if((l|0)!=(c|0)){break b}m=43;n=a&255;if((n|0)!=K[k+24|0]){m=45;if(K[k+25|0]!=(n|0)){break b}}J[d>>2]=c+1;H[c|0]=m;break a}c:{if(!(!((h&128)>>>7|0?g:h&127)|(a|0)!=(f|0))){h=0;a=J[j>>2];if((a-i|0)>159){break c}b=J[e>>2];J[j>>2]=a+4;J[a>>2]=b;break a}h=-1;a=be(k,k+26|0,a)-k|0;if((a|0)>23){break c}d:{e:{switch(b-8|0){case 0:case 2:if((a|0)<(b|0)){break d}break c;case 1:break d;default:break e}}if((b|0)!=16|(a|0)<22){break d}if((c|0)==(l|0)|(l-c|0)>2|K[l-1|0]!=48){break c}J[e>>2]=0;J[d>>2]=l+1;H[l|0]=K[a+12416|0];return 0}J[d>>2]=l+1;H[l|0]=K[a+12416|0];J[e>>2]=J[e>>2]+1;h=0;}return h}J[e>>2]=0;return 0}function Cc(a,b,c,d,e,f,g,h,i,j,k){var l=0,m=0;a:{b:{l=J[d>>2];if((l|0)!=(c|0)){break b}m=43;if(J[k+96>>2]!=(a|0)){m=45;if(J[k+100>>2]!=(a|0)){break b}}J[d>>2]=c+1;H[c|0]=m;break a}c:{if(!(!((h&128)>>>7|0?g:h&127)|(a|0)!=(f|0))){h=0;a=J[j>>2];if((a-i|0)>159){break c}b=J[e>>2];J[j>>2]=a+4;J[a>>2]=b;break a}h=-1;f=Yd(k,k+104|0,a)-k|0;if((f|0)>92){break c}a=f>>2;d:{e:{switch(b-8|0){case 0:case 2:if((a|0)<(b|0)){break d}break c;case 1:break d;default:break e}}if((b|0)!=16|(f|0)<88){break d}if((c|0)==(l|0)|(l-c|0)>2|K[l-1|0]!=48){break c}J[e>>2]=0;J[d>>2]=l+1;H[l|0]=K[a+12416|0];return 0}J[d>>2]=l+1;H[l|0]=K[a+12416|0];J[e>>2]=J[e>>2]+1;h=0;}return h}J[e>>2]=0;return 0}function mc(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=J[a+4>>2];d=J[a+8>>2];if(c>>>0>>0){J[c>>2]=b;J[a+4>>2]=c+4;return}a:{b:{c:{g=J[a>>2];e=c-g>>2;f=e+1|0;if(f>>>0<1073741824){h=e<<2;d=d-g|0;e=d>>1;d=d>>>0>=2147483644?1073741823:f>>>0>>0?e:f;if(d){if(d>>>0>=1073741824){break c}e=cb(d<<2);}else {e=0;}f=h+e|0;J[f>>2]=b;b=e+(d<<2)|0;d=f+4|0;if((c|0)==(g|0)){break b}while(1){c=c-4|0;e=J[c>>2];J[c>>2]=0;f=f-4|0;J[f>>2]=e;if((c|0)!=(g|0)){continue}break}J[a+8>>2]=b;b=J[a+4>>2];J[a+4>>2]=d;c=J[a>>2];J[a>>2]=f;if((b|0)==(c|0)){break a}while(1){b=b-4|0;ad(b);if((b|0)!=(c|0)){continue}break}break a}nb();B();}Pb();B();}J[a+8>>2]=b;J[a+4>>2]=d;J[a>>2]=f;}if(c){$a(c);}}function bn(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;a:{if(b>>>0>=256){a=Rb(8);J[5996]=0;b=_(91,a|0,2394)|0;c=J[5996];J[5996]=0;if((c|0)!=1){break a}b=Z()|0;ic(a);da(b|0);B();}c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=c-29|0;f=c>>>0<29?c:e;d=f+1|0;if(d>>>0>(c>>>0<=28?28:K[a+4|0]|K[a+5|0]<<8|(K[a+6|0]<<16|K[a+7|0]<<24))>>>0){Ob(a,d+(d>>>1|0)|0);c=K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24);e=c-29|0;}g=c>>>0<29;d=(g?a+4|0:K[a+8|0]|K[a+9|0]<<8|(K[a+10|0]<<16|K[a+11|0]<<24))+f|0;eb(d+1|0,d,(g?c:e)-f|0);c=(K[a|0]|K[a+1|0]<<8|(K[a+2|0]<<16|K[a+3|0]<<24))+1|0;H[a|0]=c;H[a+1|0]=c>>>8;H[a+2|0]=c>>>16;H[a+3|0]=c>>>24;H[d|0]=b;return a|0}na(b|0,22664,92);B();}function Wk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;g=Ua-256|0;Ua=g;J[g+248>>2]=37;J[g+252>>2]=0;h=g+248|0;rc(h|1,2055,1,J[c+4>>2]);i=jb();J[g>>2]=e;J[g+4>>2]=f;a=g+224|0;e=yb(a,24,i,h,g)+a|0;i=Lb(a,e,J[c+4>>2]);f=g+20|0;h=J[c+28>>2];J[f>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=g+32|0;ma(215,a|0,i|0,e|0,h|0,g+28|0,g+24|0,f|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[f>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Bc(b,h,J[g+28>>2],J[g+24>>2],c,d);Ua=g+256|0;break a}c=Z()|0;a=J[g+20>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function Uk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;g=Ua-256|0;Ua=g;J[g+248>>2]=37;J[g+252>>2]=0;h=g+248|0;rc(h|1,2055,0,J[c+4>>2]);i=jb();J[g>>2]=e;J[g+4>>2]=f;a=g+224|0;e=yb(a,24,i,h,g)+a|0;i=Lb(a,e,J[c+4>>2]);f=g+20|0;h=J[c+28>>2];J[f>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=g+32|0;ma(215,a|0,i|0,e|0,h|0,g+28|0,g+24|0,f|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[f>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Bc(b,h,J[g+28>>2],J[g+24>>2],c,d);Ua=g+256|0;break a}c=Z()|0;a=J[g+20>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function fl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;g=Ua-112|0;Ua=g;J[g+104>>2]=37;J[g+108>>2]=0;h=g+104|0;rc(h|1,2055,1,J[c+4>>2]);i=jb();J[g>>2]=e;J[g+4>>2]=f;a=g+80|0;e=yb(a,24,i,h,g)+a|0;i=Lb(a,e,J[c+4>>2]);f=g+20|0;h=J[c+28>>2];J[f>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=g+32|0;ma(211,a|0,i|0,e|0,h|0,g+28|0,g+24|0,f|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[f>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Ac(b,h,J[g+28>>2],J[g+24>>2],c,d);Ua=g+112|0;break a}c=Z()|0;a=J[g+20>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function dl(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0;g=Ua-112|0;Ua=g;J[g+104>>2]=37;J[g+108>>2]=0;h=g+104|0;rc(h|1,2055,0,J[c+4>>2]);i=jb();J[g>>2]=e;J[g+4>>2]=f;a=g+80|0;e=yb(a,24,i,h,g)+a|0;i=Lb(a,e,J[c+4>>2]);f=g+20|0;h=J[c+28>>2];J[f>>2]=h;J[h+4>>2]=J[h+4>>2]+1;J[5996]=0;h=g+32|0;ma(211,a|0,i|0,e|0,h|0,g+28|0,g+24|0,f|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[f>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Ac(b,h,J[g+28>>2],J[g+24>>2],c,d);Ua=g+112|0;break a}c=Z()|0;a=J[g+20>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function Fh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0;if(Jb(a,J[b+8>>2],f)){Hd(b,c,d,e);return}g=K[b+53|0];i=J[a+12>>2];H[b+53|0]=0;h=K[b+52|0];H[b+52|0]=0;Fd(J[a+16>>2],J[a+20>>2],b,c,d,e,f);j=K[b+52|0];h=(h|j)!=0;k=K[b+53|0];l=(g|k)!=0;g=a+24|0;i=(a+16|0)+(i<<3)|0;a:{if(g>>>0>=i>>>0){break a}while(1){if(K[b+54|0]){break a}b:{if(j){if(J[b+24>>2]==1){break a}if(K[a+8|0]&2){break b}break a}if(!k){break b}if(!(H[a+8|0]&1)){break a}}I[b+52>>1]=0;Fd(J[g>>2],J[g+4>>2],b,c,d,e,f);k=K[b+53|0];l=(k|l)!=0;j=K[b+52|0];h=(j|h)!=0;g=g+8|0;if(i>>>0>g>>>0){continue}break}}H[b+53|0]=l;H[b+52|0]=h;}function bc(a,b,c,d,e){var f=0,g=0,h=0,i=0;h=Ua-16|0;Ua=h;J[h+12>>2]=b;b=0;g=6;a:{b:{if(Tb(a,h+12|0)){break b}g=4;f=J[a>>2];i=J[f+12>>2];c:{if((i|0)==J[f+16>>2]){f=Xa[J[J[f>>2]+36>>2]](f)|0;break c}f=J[i>>2];}if(!(Xa[J[J[d>>2]+12>>2]](d,64,f)|0)){break b}b=Xa[J[J[d>>2]+52>>2]](d,f,0)|0;while(1){d:{b=b-48|0;f=Hc(a);if(Tb(f,h+12|0)|(e|0)<2){break d}g=J[f>>2];f=J[g+12>>2];e:{if((f|0)==J[g+16>>2]){g=Xa[J[J[g>>2]+36>>2]](g)|0;break e}g=J[f>>2];}if(!(Xa[J[J[d>>2]+12>>2]](d,64,g)|0)){break a}e=e-1|0;b=(Xa[J[J[d>>2]+52>>2]](d,g,0)|0)+P(b,10)|0;continue}break}g=2;if(!Tb(f,h+12|0)){break a}}J[c>>2]=J[c>>2]|g;}Ua=h+16|0;return b}function qd(a,b,c,d){var e=0,f=0,g=0,h=0;g=d?d:24720;d=J[g>>2];a:{b:{c:{if(!b){if(d){break c}return 0}e=-2;if(!c){break b}d:{if(d){e=c;break d}d=K[b|0];f=d<<24>>24;if((f|0)>=0){if(a){J[a>>2]=d;}return (f|0)!=0}if(!J[J[6178]>>2]){e=1;if(!a){break b}J[a>>2]=f&57343;return 1}d=d-194|0;if(d>>>0>50){break c}d=J[(d<<2)+12208>>2];e=c-1|0;if(!e){break a}b=b+1|0;}f=K[b|0];h=f>>>3|0;if((h-16|(d>>26)+h)>>>0>7){break c}while(1){e=e-1|0;d=f-128|d<<6;if((d|0)>=0){J[g>>2]=0;if(a){J[a>>2]=d;}return c-e|0}if(!e){break a}b=b+1|0;f=K[b|0];if((f&192)==128){continue}break}}J[g>>2]=0;J[5732]=25;e=-1;}return e}J[g>>2]=d;return -2}function Zk(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=Ua-144|0;Ua=f;J[f+136>>2]=37;J[f+140>>2]=0;h=f+136|0;rc(h|1,2096,1,J[c+4>>2]);g=jb();J[f>>2]=e;a=f+123|0;e=yb(a,13,g,h,f)+a|0;i=Lb(a,e,J[c+4>>2]);h=f+4|0;g=J[c+28>>2];J[h>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;g=f+16|0;ma(215,a|0,i|0,e|0,g|0,f+12|0,f+8|0,h|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[h>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Bc(b,g,J[f+12>>2],J[f+8>>2],c,d);Ua=f+144|0;break a}c=Z()|0;a=J[f+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function Vk(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=Ua-144|0;Ua=f;J[f+136>>2]=37;J[f+140>>2]=0;h=f+136|0;rc(h|1,2096,0,J[c+4>>2]);g=jb();J[f>>2]=e;a=f+123|0;e=yb(a,13,g,h,f)+a|0;i=Lb(a,e,J[c+4>>2]);h=f+4|0;g=J[c+28>>2];J[h>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;g=f+16|0;ma(215,a|0,i|0,e|0,g|0,f+12|0,f+8|0,h|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[h>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Bc(b,g,J[f+12>>2],J[f+8>>2],c,d);Ua=f+144|0;break a}c=Z()|0;a=J[f+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function hl(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=Ua+-64|0;Ua=f;J[f+56>>2]=37;J[f+60>>2]=0;h=f+56|0;rc(h|1,2096,1,J[c+4>>2]);g=jb();J[f>>2]=e;a=f+43|0;e=yb(a,13,g,h,f)+a|0;i=Lb(a,e,J[c+4>>2]);h=f+4|0;g=J[c+28>>2];J[h>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;g=f+16|0;ma(211,a|0,i|0,e|0,g|0,f+12|0,f+8|0,h|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[h>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Ac(b,g,J[f+12>>2],J[f+8>>2],c,d);Ua=f- -64|0;break a}c=Z()|0;a=J[f+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function el(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=Ua+-64|0;Ua=f;J[f+56>>2]=37;J[f+60>>2]=0;h=f+56|0;rc(h|1,2096,0,J[c+4>>2]);g=jb();J[f>>2]=e;a=f+43|0;e=yb(a,13,g,h,f)+a|0;i=Lb(a,e,J[c+4>>2]);h=f+4|0;g=J[c+28>>2];J[h>>2]=g;J[g+4>>2]=J[g+4>>2]+1;J[5996]=0;g=f+16|0;ma(211,a|0,i|0,e|0,g|0,f+12|0,f+8|0,h|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){a=J[h>>2];e=J[a+4>>2]-1|0;J[a+4>>2]=e;if((e|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}a=Ac(b,g,J[f+12>>2],J[f+8>>2],c,d);Ua=f- -64|0;break a}c=Z()|0;a=J[f+4>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}return a|0}function jh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;J[c>>2]=0;a:{e=J[b+4>>2];if(!e){break a}f=J[b>>2];b:{c:{d:{while(1){d=H[f|0];g=J[c>>2];if((d|0)<((g?48:49)|0)|(d|0)>57){break d}d=(d+P(g,10)|0)-48|0;J[c>>2]=d>>>0>=65535?65535:d;e=e-1|0;J[b+4>>2]=e;f=f+1|0;J[b>>2]=f;if(e){continue}break}if(J[c>>2]){break c}break a}if(!g){break a}if((d|0)==64){break b}}J[a>>2]=0;J[a+4>>2]=0;J[a+48>>2]=0;J[a+52>>2]=0;J[a+40>>2]=0;J[a+44>>2]=0;J[a+32>>2]=0;J[a+36>>2]=0;J[a+24>>2]=0;J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;J[a+8>>2]=0;J[a+12>>2]=0;return}J[b+4>>2]=e-1;J[b>>2]=f+1;Bd(a,b);return}J[c>>2]=1;Bd(a,b);}function yc(a,b,c,d,e,f,g,h){var i=0,j=0,k=0,l=0;j=1;i=d&2147483647;l=i;k=(i|0)==2147418112;a:{if(k&!c?a|b:k&(c|0)!=0|i>>>0>2147418112){break a}i=h&2147483647;if(!g&(i|0)==2147418112?e|f:(i|0)==2147418112&(g|0)!=0|i>>>0>2147418112){break a}if(!(a|e|(c|g)|(b|f|(i|l)))){return 0}j=d&h;if((j|0)>0|(j|0)>=0){j=-1;if((c|0)==(g|0)&(d|0)==(h|0)?(b|0)==(f|0)&a>>>0>>0|b>>>0>>0:c>>>0>>0&(d|0)<=(h|0)|(d|0)<(h|0)){break a}return (a^e|c^g|(b^f|d^h))!=0}j=-1;if((c|0)==(g|0)&(d|0)==(h|0)?(b|0)==(f|0)&a>>>0>e>>>0|b>>>0>f>>>0:c>>>0>g>>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break a}j=(a^e|c^g|(b^f|d^h))!=0;}return j}function _n(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;a:{b:{e=J[a+4>>2];f=J[a>>2];d=e-f>>2;c:{if(d>>>0>>0){g=b-d|0;c=J[a+8>>2];if(g>>>0<=c-e>>2>>>0){b=a;a=g<<2;J[b+4>>2]=Sb(e,0,a)+a;return}if(b>>>0>=1073741824){break b}c=c-f|0;h=c>>1;b=c>>>0>=2147483644?1073741823:b>>>0>>0?h:b;if(b>>>0>=1073741824){break a}c=b<<2;b=cb(c);c=b+c|0;b=b+(d<<2)|0;d=g<<2;d=Sb(b,0,d)+d|0;if((e|0)!=(f|0)){while(1){b=b-4|0;e=e-4|0;J[b>>2]=J[e>>2];if((e|0)!=(f|0)){continue}break}}J[a+8>>2]=c;J[a+4>>2]=d;J[a>>2]=b;if(!f){break c}$a(f);return}if(b>>>0>=d>>>0){break c}J[a+4>>2]=(b<<2)+f;}return}nb();B();}Pb();B();}function Qk(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0;a=Ua-208|0;Ua=a;g=jb();J[a>>2]=e;e=a+176|0;h=yb(e,20,g,1937,a);g=h+e|0;i=Lb(e,g,J[c+4>>2]);f=J[c+28>>2];J[a+12>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;j=$(197,J[a+12>>2])|0;f=J[5996];J[5996]=0;if((f|0)!=1){f=J[a+12>>2];k=J[f+4>>2]-1|0;J[f+4>>2]=k;if((k|0)==-1){Xa[J[J[f>>2]+8>>2]](f);}f=e;e=a+16|0;Xa[J[J[j>>2]+48>>2]](j,f,g,e)|0;f=b;b=e+(h<<2)|0;b=Bc(f,e,(g|0)==(i|0)?b:(a+(i-a<<2)|0)-688|0,b,c,d);Ua=a+208|0;return b|0}c=Z()|0;a=J[a+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Rb(a){var b=0,c=0,d=0,e=0,f=0;f=a+27&-4;a=f;b=a>>>0<=1?1:a;a=b;c=a+15&-16;a=a>>>0>>0?c:a;if(a&15){a=0;}else {a=_c(16,a);}if(!a){a:{c=0;a=J[6705];if(!a){J[6705]=26844;I[13423]=125;I[13422]=128;a=J[6705];}d=(b+3>>>2|0)+1|0;while(1){b=0;b:{if(!a|(a|0)==27344){a=b;}else {b=L[a+2>>1];e=d+(b>>>0>d>>>0?b-d&3:0)|0;if(e>>>0>>0){c=b-e|0;I[a+2>>1]=c;a=((c&65535)<<2)+a|0;I[a+2>>1]=e;I[a>>1]=0;a=a+4|0;break a}if(b>>>0>>0){break b}b=L[a>>1];c:{if(!c){J[6705]=(b<<2)+26832;break c}I[c>>1]=b;}I[a>>1]=0;a=a+4|0;}break a}c=a;a=(L[a>>1]<<2)+26832|0;continue}}}if(!a){Vb();B();}return Sb(a,0,f)+24|0}function $k(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0;a=Ua-96|0;Ua=a;g=jb();J[a>>2]=e;e=a- -64|0;h=yb(e,20,g,1937,a);g=h+e|0;i=Lb(e,g,J[c+4>>2]);f=J[c+28>>2];J[a+12>>2]=f;J[f+4>>2]=J[f+4>>2]+1;J[5996]=0;j=$(170,J[a+12>>2])|0;f=J[5996];J[5996]=0;if((f|0)!=1){f=J[a+12>>2];k=J[f+4>>2]-1|0;J[f+4>>2]=k;if((k|0)==-1){Xa[J[J[f>>2]+8>>2]](f);}f=e;e=a+16|0;Xa[J[J[j>>2]+32>>2]](j,f,g,e)|0;f=b;b=e+h|0;b=Ac(f,e,(g|0)==(i|0)?b:(a+(i-a|0)|0)-48|0,b,c,d);Ua=a+96|0;return b|0}c=Z()|0;a=J[a+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function He(a,b,c,d,e,f,g,h){var i=0,j=0,k=0,l=0;i=Ua-16|0;Ua=i;if(1073741806-b>>>0>=c>>>0){k=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;j=i+4|0;l=j;if(b>>>0<=536870886){J[i+12>>2]=b<<1;J[i+4>>2]=b+c;c=J[(M[j>>2]>2]?i+12|0:j)>>2];if(c>>>0>=2){j=c+4&-4;c=j-1|0;c=(c|0)==2?j:c;}else {c=1;}c=c+1|0;}else {c=1073741807;}Fc(l,c);c=J[i+4>>2];if(e){tc(c,k,e);}if(g){tc(c+(e<<2)|0,h,g);}j=e+f|0;h=d-j|0;if((d|0)!=(j|0)){d=e<<2;tc((d+c|0)+(g<<2)|0,(d+k|0)+(f<<2)|0,h);}if((b|0)!=1){$a(k);}J[a>>2]=c;J[a+8>>2]=J[i+8>>2]|-2147483648;b=a;a=h+(e+g|0)|0;J[b+4>>2]=a;J[c+(a<<2)>>2]=0;Ua=i+16|0;return}ub();B();}function Ad(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;e=c-b|0;if(e>>>0<2147483632){a:{if(e>>>0<=10){H[a+11|0]=e;d=a;break a}f=(e|15)+1|0;d=cb(f);J[a+8>>2]=f|-2147483648;J[a>>2]=d;J[a+4>>2]=e;}b:{if((b|0)==(c|0)){break b}f=(b^-1)+c|0;g=e&7;if(g){e=0;while(1){H[d|0]=K[b|0];d=d+1|0;b=b+1|0;e=e+1|0;if((g|0)!=(e|0)){continue}break}}if(f>>>0<7){break b}while(1){H[d|0]=K[b|0];H[d+1|0]=K[b+1|0];H[d+2|0]=K[b+2|0];H[d+3|0]=K[b+3|0];H[d+4|0]=K[b+4|0];H[d+5|0]=K[b+5|0];H[d+6|0]=K[b+6|0];H[d+7|0]=K[b+7|0];d=d+8|0;b=b+8|0;if((c|0)!=(b|0)){continue}break}}H[d|0]=0;return a|0}ub();B();}function $c(a,b,c,d){var e=0,f=0,g=0;e=Ua-32|0;Ua=e;if(c>>>0<2147483632){a:{b:{if(c>>>0>=11){g=(c|15)+1|0;f=cb(g);J[e+16>>2]=g|-2147483648;J[e+8>>2]=f;J[e+12>>2]=c;break b}H[e+19|0]=c;f=e+8|0;if(!c){break a}}f=fb(f,b,c)+c|0;}H[f|0]=0;J[5996]=0;aa(31,e+20|0,e+8|0);b=J[5996];J[5996]=0;c:{d:{if((b|0)!=1){if(H[e+19|0]<0){$a(J[e+8>>2]);}c=J[e+24>>2];b=J[e+20>>2];if((c-b|0)!=(d|0)){break d}J[a+4>>2]=c;J[a>>2]=b;J[a+8>>2]=J[e+28>>2];break c}a=Z()|0;if(H[e+19|0]<0){$a(J[e+8>>2]);}da(a|0);B();}J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;if(!b){break c}$a(b);}Ua=e+32|0;return}ub();B();}function dd(a,b,c,d,e,f,g,h){var i=0,j=0,k=0,l=0;i=Ua-16|0;Ua=i;if(2147483630-b>>>0>=c>>>0){k=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;j=i+4|0;l=j;if(b>>>0<=1073741798){J[i+12>>2]=b<<1;J[i+4>>2]=b+c;c=J[(M[j>>2]>2]?i+12|0:j)>>2];if(c>>>0>=11){j=c+16&-16;c=j-1|0;c=(c|0)==11?j:c;}else {c=10;}c=c+1|0;}else {c=2147483631;}Gc(l,c);c=J[i+4>>2];if(e){gc(c,k,e);}if(g){gc(c+e|0,h,g);}j=e+f|0;h=d-j|0;if((d|0)!=(j|0)){gc((c+e|0)+g|0,(e+k|0)+f|0,h);}if((b|0)!=10){$a(k);}J[a>>2]=c;J[a+8>>2]=J[i+8>>2]|-2147483648;b=a;a=h+(e+g|0)|0;J[b+4>>2]=a;H[a+c|0]=0;Ua=i+16|0;return}ub();B();}function Bc(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0;i=Ua-16|0;Ua=i;a:{b:{if(!a){break b}g=J[e+12>>2];h=c-b|0;if((h|0)>0){h=h>>>2|0;if((Xa[J[J[a>>2]+48>>2]](a,b,h)|0)!=(h|0)){break b}}b=d-b>>2;g=(b|0)<(g|0)?g-b|0:0;if((g|0)>0){b=Hf(i+4|0,g,f);f=(K[b+11|0]&128)>>>7|0?J[b>>2]:b;J[5996]=0;f=ba(217,a|0,f|0,g|0)|0;h=J[5996];J[5996]=0;if((h|0)==1){break a}ab(b);if((f|0)!=(g|0)){break b}}b=d-c|0;if((b|0)>0){b=b>>>2|0;if((Xa[J[J[a>>2]+48>>2]](a,c,b)|0)!=(b|0)){break b}}J[e+12>>2]=0;j=a;}Ua=i+16|0;return j|0}a=Z()|0;ab(b);da(a|0);B();}function Mh(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(Jb(a,J[b+8>>2],e)){if(!(J[b+28>>2]==1|J[b+4>>2]!=(c|0))){J[b+28>>2]=d;}return}a:{if(Jb(a,J[b>>2],e)){if(!(J[b+16>>2]!=(c|0)&J[b+20>>2]!=(c|0))){if((d|0)!=1){break a}J[b+32>>2]=1;return}J[b+32>>2]=d;b:{if(J[b+44>>2]==4){break b}I[b+52>>1]=0;a=J[a+8>>2];Xa[J[J[a>>2]+20>>2]](a,b,c,c,1,e);if(K[b+53|0]){J[b+44>>2]=3;if(!K[b+52|0]){break b}break a}J[b+44>>2]=4;}J[b+20>>2]=c;J[b+40>>2]=J[b+40>>2]+1;if(J[b+36>>2]!=1|J[b+24>>2]!=2){break a}H[b+54|0]=1;return}a=J[a+8>>2];Xa[J[J[a>>2]+24>>2]](a,b,c,d,e);}}function pb(a){var b=0,c=0,d=0,e=0;e=Ua-16|0;Ua=e;b=e+4|0;J[b+4>>2]=190;J[b>>2]=a;J[b+8>>2]=0;d=Ua-16|0;Ua=d;if(J[a>>2]!=-1){a:{c=d+12|0;J[c>>2]=b;b=d+8|0;J[b>>2]=c;while(1){c=J[a>>2];if((c|0)==1){continue}break}b:{if(!c){J[a>>2]=1;b=J[J[b>>2]>>2];J[5996]=0;ha(191,b|0);b=J[5996];J[5996]=0;if((b|0)==1){break b}J[a>>2]=-1;}break a}pa(fa(0)|0)|0;J[a>>2]=0;J[5996]=0;ca(192);a=J[5996];J[5996]=0;c:{if((a|0)==1){a=Z()|0;J[5996]=0;ca(110);b=J[5996];J[5996]=0;if((b|0)!=1){break c}fa(0)|0;Vb();}B();}da(a|0);B();}}Ua=d+16|0;Ua=e+16|0;return J[a+4>>2]-1|0}function Dk(a,b,c,d,e,f,g){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;c=Ua-128|0;Ua=c;J[c+12>>2]=c+116;d=J[a+8>>2];a=c+16|0;yf(d,a,c+12|0,e,f,g);e=Ua-16|0;Ua=e;g=Ua-32|0;Ua=g;d=Ua-16|0;Ua=d;J[d+12>>2]=J[c+12>>2];J[g+24>>2]=a;J[g+28>>2]=J[d+12>>2];Ua=d+16|0;f=J[g+24>>2];a=J[g+28>>2];d=Ua-16|0;Ua=d;J[d+12>>2]=b;while(1){if((a|0)!=(f|0)){sg(d+12|0,H[f|0]);f=f+1|0;continue}break}J[g+16>>2]=a;J[g+20>>2]=J[d+12>>2];Ua=d+16|0;a=J[g+16>>2];J[g+12>>2]=J[g+20>>2];J[e+8>>2]=a;J[e+12>>2]=J[g+12>>2];Ua=g+32|0;Ua=e+16|0;Ua=c+128|0;return J[e+12>>2]}function Sm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;J[5996]=0;e=$(3,24)|0;f=J[5996];J[5996]=0;a:{if((f|0)!=1){J[a+4>>2]=e;J[a>>2]=e;f=e+24|0;J[a+8>>2]=f;J[e>>2]=J[b>>2];J[e+4>>2]=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;J[a+4>>2]=e+8;J[e+8>>2]=J[c>>2];J[e+12>>2]=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;b=e+16|0;J[a+4>>2]=b;if(b>>>0>>0){J[b>>2]=J[d>>2];J[b+4>>2]=J[d+4>>2];J[d>>2]=0;J[d+4>>2]=0;J[a+4>>2]=b+8;break a}J[5996]=0;aa(162,a|0,d|0);b=J[5996];J[5996]=0;if((b|0)!=1){break a}}b=Z()|0;lb(a);da(b|0);B();}}function Rm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;d=Ua-16|0;Ua=d;J[a>>2]=7e3;J[a+4>>2]=0;J[a+8>>2]=0;J[d+4>>2]=J[c>>2];J[d+8>>2]=J[c+4>>2];J[d+12>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[5996]=0;ia(64,a+12|0,b|0,d+4|0,0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[d+4>>2];if(b){c=J[d+8>>2];if((b|0)!=(c|0)){while(1){c=c-8|0;e=J[c+4>>2];a:{if(!e){break a}f=J[e+4>>2];J[e+4>>2]=f-1;if(f){break a}Xa[J[J[e>>2]+8>>2]](e);bb(e);}if((b|0)!=(c|0)){continue}break}b=J[d+4>>2];}$a(b);}Ua=d+16|0;return a|0}a=Z()|0;lb(d+4|0);da(a|0);B();}function fc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=Ua-16|0;Ua=e;A(+b);g=v(1)|0;c=v(0)|0;d=g&2147483647;f=d+-1048576|0;a:{if((f|0)==2145386495|f>>>0<2145386495){h=c<<28;c=(d&15)<<28|c>>>4;d=(d>>>4|0)+1006632960|0;break a}if((d|0)==2146435072|d>>>0>2146435072){h=c<<28;c=(g&15)<<28|c>>>4;d=g>>>4|2147418112;break a}if(!(c|d)){c=0;d=0;break a}f=c;c=d?S(d):S(c)+32|0;Cb(e,f,d,0,0,c+49|0);i=J[e>>2];h=J[e+4>>2];f=15372-c<<16;c=J[e+8>>2];d=f|J[e+12>>2]^65536;}J[a>>2]=i;J[a+4>>2]=h;J[a+8>>2]=c;J[a+12>>2]=g&-2147483648|d;Ua=e+16|0;}function hm(a){a=a|0;var b=0,c=0,d=0,e=0;c=J[a+76>>2];if((c|0)==-1){c=a;d=Ua-16|0;Ua=d;a=J[a+28>>2];J[d+12>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;a=$(170,J[d+12>>2])|0;b=J[5996];J[5996]=0;a:{b:{if((b|0)==1){break b}J[5996]=0;a=_(171,a|0,32)|0;b=J[5996];J[5996]=0;if((b|0)==1){break b}b=J[d+12>>2];e=J[b+4>>2]-1|0;J[b+4>>2]=e;if((e|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Ua=d+16|0;break a}b=Z()|0;a=J[d+12>>2];c=J[a+4>>2]-1|0;J[a+4>>2]=c;if((c|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(b|0);B();}b=c;c=a;J[b+76>>2]=a;}return c<<24>>24}function ch(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=J[a+4>>2];d=J[a+8>>2];if(c>>>0>>0){J[c>>2]=b;J[a+4>>2]=c+4;return}a:{g=J[a>>2];e=c-g>>2;f=e+1|0;if(f>>>0<1073741824){h=e<<2;d=d-g|0;e=d>>1;e=d>>>0>=2147483644?1073741823:e>>>0>f>>>0?e:f;if(e){if(e>>>0>=1073741824){break a}f=cb(e<<2);}else {f=0;}d=h+f|0;J[d>>2]=b;b=d+4|0;if((c|0)!=(g|0)){while(1){d=d-4|0;c=c-4|0;J[d>>2]=J[c>>2];if((c|0)!=(g|0)){continue}break}c=J[a>>2];}J[a+8>>2]=f+(e<<2);J[a+4>>2]=b;J[a>>2]=d;if(c){$a(c);}return}nb();B();}Pb();B();}function Hm(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0;e=Ua-16|0;Ua=e;f=cb(104);J[f>>2]=7e3;J[f+4>>2]=0;J[f+8>>2]=0;J[e+4>>2]=J[c>>2];J[e+8>>2]=J[c+4>>2];J[e+12>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[5996]=0;g=ia(163,f+12|0,b|0,e+4|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){d=J[e+4>>2];if(d){b=J[e+8>>2];if((d|0)!=(b|0)){while(1){c=b-12|0;if(H[b-1|0]<0){$a(J[c>>2]);}b=c;if((c|0)!=(d|0)){continue}break}}$a(d);}J[a+4>>2]=f;J[a>>2]=g;Ua=e+16|0;return}a=Z()|0;rb(e+4|0);$a(f);da(a|0);B();}function Yf(a,b,c,d){var e=0,f=0,g=0;e=Ua-16|0;Ua=e;a:{b:{if((a|0)!=(b|0)){c:{g=J[5732];J[5732]=0;jb();a=Uf(a,e+12|0,d);d=Wa;d:{f=J[5732];if(f){if(J[e+12>>2]!=(b|0)){break c}if((f|0)!=68){break d}J[c>>2]=4;b=2147483647;if(!!a&(d|0)>=0|(d|0)>0){break a}break b}J[5732]=g;if(J[e+12>>2]==(b|0)){break d}break c}if((d|0)<0&a>>>0<=2147483647|(d|0)<-1){J[c>>2]=4;break b}if((d|0)>=0&a>>>0>=2147483648|(d|0)>0){J[c>>2]=4;b=2147483647;break a}b=a;break a}}J[c>>2]=4;b=0;break a}b=-2147483648;}Ua=e+16|0;return b}function xc(a,b,c,d,e,f){var g=0,h=0,i=0,j=0;a:{if(f&64){c=f+-64|0;b=c&31;if((c&63)>>>0>=32){c=0;b=e>>>b|0;}else {c=e>>>b|0;b=((1<>>b;}d=0;e=0;break a}if(!f){break a}i=d;h=64-f|0;g=h&31;if((h&63)>>>0>=32){h=d<>>32-g|e<>>0>=32){g=0;b=c>>>b|0;}else {g=c>>>b|0;b=((1<>>b;}b=j|b;c=g|h;g=d;d=f&31;if((f&63)>>>0>=32){h=0;d=e>>>d|0;}else {h=e>>>d|0;d=((1<>>d;}e=h;}J[a>>2]=b;J[a+4>>2]=c;J[a+8>>2]=d;J[a+12>>2]=e;}function Rc(a,b,c){var d=0,e=0,f=0;d=Ua-16|0;Ua=d;J[d+12>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(198,J[d+12>>2])|0;e=J[5996];J[5996]=0;a:{if((e|0)==1){break a}J[5996]=0;e=$(206,b|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break a}J[c>>2]=e;J[5996]=0;aa(207,a|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[d+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}Ua=d+16|0;return}c=Z()|0;a=J[d+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Tc(a,b,c){var d=0,e=0,f=0;d=Ua-16|0;Ua=d;J[d+12>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;b=$(180,J[d+12>>2])|0;e=J[5996];J[5996]=0;a:{if((e|0)==1){break a}J[5996]=0;e=$(193,b|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break a}H[c|0]=e;J[5996]=0;aa(194,a|0,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[d+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}Ua=d+16|0;return}c=Z()|0;a=J[d+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function sj(a){if(K[25148]){return J[6286]}if(!K[26240]){H[26240]=1;}ib(25952,18680);ib(25964,18712);ib(25976,18748);ib(25988,18772);ib(26e3,18796);ib(26012,18812);ib(26024,18832);ib(26036,18852);ib(26048,18880);ib(26060,18920);ib(26072,18952);ib(26084,18988);ib(26096,19024);ib(26108,19040);ib(26120,19056);ib(26132,19072);ib(26144,18796);ib(26156,19088);ib(26168,19104);ib(26180,19120);ib(26192,19136);ib(26204,19152);ib(26216,19168);ib(26228,19184);H[25148]=1;J[6286]=25952;return 25952}function qn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0;f=Gb(c);a:{d=K[a+11|0];e=d&127;d=(d&128)>>>7|0;e=d?J[a+4>>2]:e;if(e>>>0>=b>>>0){d=d?(J[a+8>>2]&2147483647)-1|0:10;if(d-e>>>0>=f>>>0){if(!f){break a}d=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;h=d+b|0;if((b|0)!=(e|0)){g=b+d|0;oc(g+f|0,g,e-b|0);c=(c>>>0>=g>>>0?d+e>>>0>c>>>0?f:0:0)+c|0;}oc(h,c,f);b=f+e|0;b:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break b}H[a+11|0]=b;}H[b+d|0]=0;break a}dd(a,d,(f+e|0)-d|0,e,b,0,f,c);break a}ue();B();}return a|0}function hh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;e=J[a+4>>2];if((e|0)!=J[a+8>>2]){J[e>>2]=b;J[a+4>>2]=e+4;return}a:{g=J[a>>2];f=e-g|0;c=f>>2;d=c+1|0;if(d>>>0<1073741824){h=c<<2;c=f>>1;c=f>>>0>=2147483644?1073741823:c>>>0>d>>>0?c:d;if(c){if(c>>>0>=1073741824){break a}f=cb(c<<2);}else {f=0;}d=h+f|0;J[d>>2]=b;b=d+4|0;if((e|0)!=(g|0)){while(1){d=d-4|0;e=e-4|0;J[d>>2]=J[e>>2];if((e|0)!=(g|0)){continue}break}}J[a+8>>2]=f+(c<<2);J[a+4>>2]=b;J[a>>2]=d;if(g){$a(g);}return}nb();B();}Pb();B();}function Cb(a,b,c,d,e,f){var g=0,h=0,i=0;a:{if(f&64){e=f+-64|0;f=b;d=e&31;if((e&63)>>>0>=32){e=f<>>32-d|c<>>0>=32){i=d<>>32-g|e<>>0>=32){e=0;d=c>>>d|0;}else {e=c>>>d|0;d=((1<>>d;}d=h|d;e=e|i;h=b;g=f&31;if((f&63)>>>0>=32){i=b<>>32-g|c<>2]=b;J[a+4>>2]=c;J[a+8>>2]=d;J[a+12>>2]=e;}function vn(a){a=a|0;var b=0,c=0,d=0,e=0;e=J[a+44>>2];if(e){b=e;d=J[a+48>>2];if((b|0)!=(d|0)){while(1){d=d-8|0;c=J[d+4>>2];a:{if(!c){break a}b=J[c+4>>2];J[c+4>>2]=b-1;if(b){break a}Xa[J[J[c>>2]+8>>2]](c);bb(c);}if((d|0)!=(e|0)){continue}break}b=J[a+44>>2];}J[a+48>>2]=e;$a(b);}b=J[a+32>>2];if(b){J[a+36>>2]=b;$a(b);}c=J[a+20>>2];if(c){d=c;b=J[a+24>>2];if((c|0)!=(b|0)){while(1){e=b-12|0;if(H[b-1|0]<0){$a(J[e>>2]);}b=e;if((c|0)!=(b|0)){continue}break}d=J[a+20>>2];}J[a+24>>2]=c;$a(d);}}function Sl(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0;e=Ua-16|0;Ua=e;J[e>>2]=c;J[e+4>>2]=d;J[e+8>>2]=c;J[e+12>>2]=d;c=Ua-32|0;Ua=c;b=Kb(c+8|0,b);J[5996]=0;d=c+20|0;ea(174,d|0,e|0,b|0);f=J[5996];J[5996]=0;a:{b:{c:{if((f|0)!=1){J[5996]=0;a=_(175,a|0,d|0)|0;f=J[5996];J[5996]=0;if((f|0)==1){break c}ab(d);ab(b);J[a>>2]=21872;b=J[e+4>>2];J[a+8>>2]=J[e>>2];J[a+12>>2]=b;Ua=c+32|0;break a}a=Z()|0;break b}a=Z()|0;ab(c+20|0);}ab(b);da(a|0);B();}J[a>>2]=8492;Ua=e+16|0;return a|0}function ej(a){if(K[25140]){return J[6284]}if(!K[25936]){H[25936]=1;}hb(25648,1065);hb(25660,1056);hb(25672,2204);hb(25684,2058);hb(25696,1135);hb(25708,2381);hb(25720,1073);hb(25732,1297);hb(25744,1802);hb(25756,1785);hb(25768,1793);hb(25780,1812);hb(25792,2024);hb(25804,2543);hb(25816,1837);hb(25828,1683);hb(25840,1135);hb(25852,1965);hb(25864,2051);hb(25876,2280);hb(25888,1924);hb(25900,1386);hb(25912,1263);hb(25924,2539);H[25140]=1;J[6284]=25648;return 25648}function of(a,b,c,d,e){var f=0,g=0,h=0,i=0;f=Ua-16|0;Ua=f;if(1073741807-b>>>0>=c>>>0){h=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;g=f+4|0;i=g;if(b>>>0<=536870886){J[f+12>>2]=b<<1;J[f+4>>2]=b+c;c=J[(M[g>>2]>2]?f+12|0:g)>>2];if(c>>>0>=2){g=c+4&-4;c=g-1|0;c=(c|0)==2?g:c;}else {c=1;}c=c+1|0;}else {c=1073741807;}Fc(i,c);c=J[f+4>>2];if(e){tc(c,h,e);}if((d|0)!=(e|0)){g=e<<2;tc(g+c|0,g+h|0,d-e|0);}if((b|0)!=1){$a(h);}J[a>>2]=c;J[a+8>>2]=J[f+8>>2]|-2147483648;Ua=f+16|0;return}ub();B();}function Sd(a,b,c,d,e){var f=0,g=0,h=0,i=0;f=Ua-16|0;Ua=f;if(2147483631-b>>>0>=c>>>0){h=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;g=f+4|0;i=g;if(b>>>0<=1073741798){J[f+12>>2]=b<<1;J[f+4>>2]=b+c;c=J[(M[g>>2]>2]?f+12|0:g)>>2];if(c>>>0>=11){g=c+16&-16;c=g-1|0;c=(c|0)==11?g:c;}else {c=10;}c=c+1|0;}else {c=2147483631;}Gc(i,c);c=J[f+4>>2];if(e){gc(c,h,e);}if((d|0)!=(e|0)){gc(c+e|0,e+h|0,d-e|0);}if((b|0)!=10){$a(h);}J[a>>2]=c;J[a+8>>2]=J[f+8>>2]|-2147483648;Ua=f+16|0;return}ub();B();}function wm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;while(1){a:{if((c|0)<=(f|0)){break a}g=J[a+16>>2];d=J[a+12>>2];b:{if(g>>>0>d>>>0){J[e+12>>2]=2147483647;J[e+8>>2]=g-d;J[e+4>>2]=c-f;h=b;g=d;b=e+4|0;d=e+8|0;b=J[b>>2]>2]?b:d;d=e+12|0;d=J[(J[b>>2]>2]?b:d)>>2];b=gc(h,g,d);J[a+12>>2]=J[a+12>>2]+d;b=b+d|0;break b}d=Xa[J[J[a>>2]+40>>2]](a)|0;if((d|0)==-1){break a}H[b|0]=d<<24>>24;d=1;b=b+1|0;}f=d+f|0;continue}break}Ua=e+16|0;return f|0}function fh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=cb(56);a:{b:{if((c|0)==(d|0)){d=0;c=0;break b}f=d-c|0;if((f|0)<0){J[5996]=0;ca(8);a=J[5996];J[5996]=0;if((a|0)==1){break a}B();}J[5996]=0;d=$(3,f|0)|0;g=J[5996];J[5996]=0;if((g|0)==1){break a}c=fb(d,c,f)+f|0;}J[e+4>>2]=0;J[e+8>>2]=0;J[e>>2]=b;J[e+40>>2]=0;J[e+44>>2]=0;J[e+28>>2]=d;J[e+12>>2]=0;J[e+16>>2]=0;J[e+20>>2]=0;J[e+24>>2]=0;J[e+36>>2]=c;J[e+32>>2]=c;mc(a,e);return e|0}a=Z()|0;$a(e);da(a|0);B();}function Zb(a,b,c){var d=0,e=0;d=(c|0)!=0;a:{b:{c:{if(!(a&3)|!c){break c}e=b&255;while(1){if((e|0)==K[a|0]){break b}c=c-1|0;d=(c|0)!=0;a=a+1|0;if(!(a&3)){break c}if(c){continue}break}}if(!d){break a}d=b&255;if(!((d|0)==K[a|0]|c>>>0<4)){d=P(d,16843009);while(1){e=d^J[a>>2];if((e^-1)&e-16843009&-2139062144){break b}a=a+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}}b=b&255;while(1){if((b|0)==K[a|0]){return a}a=a+1|0;c=c-1|0;if(c){continue}break}}return 0}function ck(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0;a:{if(!((K[f+11|0]&128)>>>7|0)){b=J[f+4>>2];J[a>>2]=J[f>>2];J[a+4>>2]=b;J[a+8>>2]=J[f+8>>2];break a}e=J[f>>2];d=Ua-16|0;Ua=d;b:{c:{c=J[f+4>>2];d:{if(c>>>0<2){H[a+11|0]=c;break d}if(c>>>0>=1073741808){break c}g=d+8|0;if(c>>>0>=2){f=c+4&-4;b=f-1|0;b=(b|0)==2?f:b;}else {b=1;}Fc(g,b+1|0);b=J[d+8>>2];J[a>>2]=b;J[a+8>>2]=J[d+12>>2]|-2147483648;J[a+4>>2]=c;a=b;}tc(a,e,c+1|0);Ua=d+16|0;break b}ub();B();}}}function ud(a){var b=0,c=0;a:{b=J[a+4>>2];b=J[J[b>>2]-12>>2]+b|0;b:{if(!J[b+24>>2]|J[b+16>>2]|!(K[b+5|0]&32)){break b}if((Ha()|0)>0){break b}b=J[a+4>>2];b=J[(J[J[b>>2]-12>>2]+b|0)+24>>2];J[5996]=0;b=$(169,b|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){if((b|0)!=-1){break b}a=J[a+4>>2];b=J[J[a>>2]-12>>2];J[5996]=0;aa(138,a+b|0,1);a=J[5996];J[5996]=0;if((a|0)!=1){break b}}pa(fa(0)|0)|0;J[5996]=0;ca(110);a=J[5996];J[5996]=0;if((a|0)==1){break a}}return}fa(0)|0;Vb();B();}function Sf(a,b,c,d){var e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;a:{b:{if((a|0)!=(b|0)){c:{d:{f=K[a|0];if((f|0)!=45){break d}a=a+1|0;if((b|0)!=(a|0)){break d}break c}h=J[5732];J[5732]=0;jb();a=ae(a,e+12|0,d);d=Wa;g=J[5732];e:{if(g){if(J[e+12>>2]!=(b|0)){break c}if(!d&a>>>0>65535|d|(g|0)==68){break e}break b}J[5732]=h;if(J[e+12>>2]!=(b|0)){break c}if(!d&a>>>0<65536){break b}}J[c>>2]=4;a=65535;break a}}J[c>>2]=4;a=0;break a}a=(f|0)==45?0-a|0:a;}Ua=e+16|0;return a&65535}function jf(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;d=K[a+11|0];c=d<<24>>24;c=(c|0)<0;d=c?J[a+4>>2]:d;a:{if(!d){break a}c=c?J[a>>2]:a;g=K[c|0];f=g-9&255;if(f>>>0<24&(8388639>>>f&1)){break a}f=K[(c+d|0)-1|0]-9|0;if((f&255)>>>0<24&(8388639>>>f&1)){break a}if((g|0)==45|(Gb(c)|0)!=(d|0)){break a}J[e+12>>2]=0;J[5732]=0;a=hf(H[a+11|0]<0?J[a>>2]:a,e+12|0,10);c=Wa;if(b){J[b>>2]=a;J[b+4>>2]=c;}a=J[e+12>>2];if(!a|K[a|0]){break a}h=!J[5732];}Ua=e+16|0;return h}function Pf(a,b,c,d){var e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;a:{if((a|0)!=(b|0)){b:{c:{f=K[a|0];if((f|0)!=45){break c}a=a+1|0;if((b|0)!=(a|0)){break c}break b}h=J[5732];J[5732]=0;jb();a=ae(a,e+12|0,d);d=Wa;d:{g=J[5732];if(g){if(J[e+12>>2]!=(b|0)){break b}if((g|0)!=68){break d}J[c>>2]=4;a=-1;b=-1;break a}J[5732]=h;if(J[e+12>>2]==(b|0)){break d}break b}b=a;c=(f|0)==45;a=c?0-b|0:b;b=c?0-(d+((b|0)!=0)|0)|0:d;break a}}J[c>>2]=4;a=0;b=0;}Ua=e+16|0;Wa=b;return a}function Qm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=Ua-16|0;Ua=d;J[a>>2]=7e3;J[a+4>>2]=0;J[a+8>>2]=0;J[d+4>>2]=J[c>>2];J[d+8>>2]=J[c+4>>2];J[d+12>>2]=J[c+8>>2];J[c+8>>2]=0;J[c>>2]=0;J[c+4>>2]=0;J[5996]=0;ia(163,a+12|0,b|0,d+4|0,0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){e=J[d+4>>2];if(e){b=J[d+8>>2];if((e|0)!=(b|0)){while(1){c=b-12|0;if(H[b-1|0]<0){$a(J[c>>2]);}b=c;if((c|0)!=(e|0)){continue}break}}$a(e);}Ua=d+16|0;return a|0}a=Z()|0;rb(d+4|0);da(a|0);B();}function hd(a,b){var c=0,d=0,e=0,f=0,g=0;e=Ua-16|0;Ua=e;d=K[a+11|0];c=d<<24>>24;c=(c|0)<0;d=c?J[a+4>>2]:d;a:{if(!d){break a}c=c?J[a>>2]:a;f=K[c|0]-9&255;if(f>>>0<24&(8388639>>>f&1)){break a}f=K[(c+d|0)-1|0]-9|0;if((f&255)>>>0<24&(8388639>>>f&1)){break a}if((Gb(c)|0)!=(d|0)){break a}J[e+12>>2]=0;J[5732]=0;a=kf(H[a+11|0]<0?J[a>>2]:a,e+12|0,10);c=Wa;if(b){J[b>>2]=a;J[b+4>>2]=c;}a=J[e+12>>2];if(!a|K[a|0]){break a}g=!J[5732];}Ua=e+16|0;return g}function Sc(a,b){var c=0,d=0;c=Ua-16|0;Ua=c;J[c+12>>2]=a;J[a+4>>2]=J[a+4>>2]+1;J[5996]=0;a=$(197,J[c+12>>2])|0;d=J[5996];J[5996]=0;a:{b:{if((d|0)==1){break b}J[5996]=0;ga(208,a|0,12416,12442,b|0);a=J[5996];J[5996]=0;if((a|0)==1){break b}a=J[c+12>>2];d=J[a+4>>2]-1|0;J[a+4>>2]=d;if((d|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}Ua=c+16|0;break a}d=Z()|0;a=J[c+12>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(d|0);B();}return b}function Nk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-16|0;Ua=g;J[g+12>>2]=b;b=J[d+28>>2];J[g+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;h=$(170,J[g+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[g+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Ef(a,f+24|0,g+12|0,c,e,h);Ua=g+16|0;return J[g+12>>2]}c=Z()|0;a=J[g+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Mk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-16|0;Ua=g;J[g+12>>2]=b;b=J[d+28>>2];J[g+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;h=$(170,J[g+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[g+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Df(a,f+16|0,g+12|0,c,e,h);Ua=g+16|0;return J[g+12>>2]}c=Z()|0;a=J[g+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Hk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-16|0;Ua=g;J[g+12>>2]=b;b=J[d+28>>2];J[g+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;h=$(197,J[g+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[g+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Bf(a,f+24|0,g+12|0,c,e,h);Ua=g+16|0;return J[g+12>>2]}c=Z()|0;a=J[g+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Gk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-16|0;Ua=g;J[g+12>>2]=b;b=J[d+28>>2];J[g+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;h=$(197,J[g+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[g+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Af(a,f+16|0,g+12|0,c,e,h);Ua=g+16|0;return J[g+12>>2]}c=Z()|0;a=J[g+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function pe(a,b){a:{if(a){if(b>>>0<=127){break a}b:{if(!J[J[6178]>>2]){if((b&-128)==57216){break a}break b}if(b>>>0<=2047){H[a+1|0]=b&63|128;H[a|0]=b>>>6|192;return 2}if(!((b&-8192)!=57344&b>>>0>=55296)){H[a+2|0]=b&63|128;H[a|0]=b>>>12|224;H[a+1|0]=b>>>6&63|128;return 3}if(b-65536>>>0<=1048575){H[a+3|0]=b&63|128;H[a|0]=b>>>18|240;H[a+2|0]=b>>>6&63|128;H[a+1|0]=b>>>12&63|128;return 4}}J[5732]=25;a=-1;}else {a=1;}return a}H[a|0]=b;return 1}function ic(a){var b=0,c=0,d=0,e=0,f=0;a:{d=a-24|0;a=d;if(a>>>0<27344&a>>>0>=26832){b=a-4|0;e=J[6705];c=e;while(1){a=c;if(!(!a|(a|0)==27344)){c=L[a+2>>1];if((a+(c<<2)|0)==(b|0)){I[a+2>>1]=c+L[d-2>>1];break a}if((a|0)==((L[b+2>>1]<<2)+b|0)){c=d-2|0;I[c>>1]=L[a+2>>1]+L[c>>1];if(!f){J[6705]=b;I[b>>1]=L[a>>1];break a}I[f>>1]=b-26832>>>2;break a}else {c=(L[a>>1]<<2)+26832|0;f=a;continue}}break}I[b>>1]=e-26832>>>2;J[6705]=b;break a}$a(d);}}function Rg(a,b,c,d,e){var f=0,g=0,h=0;h=-1;g=d&2147483647;f=(g|0)==2147418112;a:{if(f&!c?a|b:f&(c|0)!=0|g>>>0>2147418112){break a}f=e&2147483647;if(((f|0)==2147418112&0|f>>>0>2147418112)&(f|0)!=2147418112){break a}if(!(a|c|(f|g|b))){return 0}f=d&e;if((f|0)>0|(f|0)>=0){if(((c|0)!=0|(d|0)!=(e|0))&(d|0)<(e|0)){break a}return (a|c|(d^e|b))!=0}if(!c&(d|0)==(e|0)?a|b:(c|0)!=0&(d|0)>=(e|0)|(d|0)>(e|0)){break a}h=(a|c|(d^e|b))!=0;}return h}function Lk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0;a=Ua-16|0;Ua=a;J[a+12>>2]=b;b=J[d+28>>2];J[a+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;g=$(170,J[a+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[a+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}Cf(f+20|0,a+12|0,c,e,g);Ua=a+16|0;return J[a+12>>2]}c=Z()|0;a=J[a+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Fk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0;a=Ua-16|0;Ua=a;J[a+12>>2]=b;b=J[d+28>>2];J[a+8>>2]=b;J[b+4>>2]=J[b+4>>2]+1;J[5996]=0;g=$(197,J[a+8>>2])|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=J[a+8>>2];d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}zf(f+20|0,a+12|0,c,e,g);Ua=a+16|0;return J[a+12>>2]}c=Z()|0;a=J[a+8>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}function Hf(a,b,c){var d=0,e=0,f=0,g=0,h=0;e=a;g=Ua-16|0;Ua=g;a:{if(b>>>0<1073741808){b:{if(b>>>0<2){H[e+11|0]=b;break b}h=g+8|0;if(b>>>0>=2){f=b+4&-4;d=f-1|0;d=(d|0)==2?f:d;}else {d=1;}Fc(h,d+1|0);d=J[g+8>>2];J[e>>2]=d;J[e+8>>2]=J[g+12>>2]|-2147483648;J[e+4>>2]=b;e=d;}f=Ua-16|0;Ua=f;J[f+12>>2]=c;c=e;d=b;while(1){if(d){J[c>>2]=J[f+12>>2];d=d-1|0;c=c+4|0;continue}break}Ua=f+16|0;J[(b<<2)+e>>2]=0;Ua=g+16|0;break a}ub();B();}return a}function xb(a,b,c,d,e,f,g,h,i){var j=0,k=0,l=0,m=0;i=co(b,c,h,i);h=Wa;e=co(d,e,f,g);i=e+i|0;d=Wa+h|0;h=e>>>0>i>>>0?d+1|0:d;j=g;e=0;k=c;d=0;c=co(g,e,c,d);g=c+i|0;i=Wa+h|0;l=g;c=c>>>0>g>>>0?i+1|0:i;g=co(f,0,b,0);h=Wa;i=0;d=co(f,i,k,d);h=h+d|0;f=Wa+i|0;f=d>>>0>h>>>0?f+1|0:f;i=f+l|0;d=c;f=f>>>0>i>>>0?d+1|0:d;b=co(b,m,j,e)+h|0;e=Wa;e=b>>>0>>0?e+1|0:e;h=e+i|0;i=f;J[a+8>>2]=h;J[a+12>>2]=e>>>0>h>>>0?i+1|0:i;J[a>>2]=g;J[a+4>>2]=b;}function Qf(a,b,c,d){var e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;a:{b:{if((a|0)!=(b|0)){c:{d:{f=K[a|0];if((f|0)!=45){break d}a=a+1|0;if((b|0)!=(a|0)){break d}break c}h=J[5732];J[5732]=0;jb();a=ae(a,e+12|0,d);d=Wa;g=J[5732];e:{if(g){if(J[e+12>>2]!=(b|0)){break c}if((g|0)==68|d){break e}break b}J[5732]=h;if(J[e+12>>2]!=(b|0)){break c}if(!d){break b}}J[c>>2]=4;a=-1;break a}}J[c>>2]=4;a=0;break a}a=(f|0)==45?0-a|0:a;}Ua=e+16|0;return a}function ie(a,b){a=a|0;b=b|0;var c=0,d=0;a:{d=K[a+11|0];c=d&127;d=(d&128)>>>7|0;c=d?J[a+4>>2]:c;if(c>>>0>>0){b=b-c|0;if(b){d=d?(J[a+8>>2]&2147483647)-1|0:10;c=K[a+11|0];c=(c&128)>>>7|0?J[a+4>>2]:c&127;if(d-c>>>0>>0){Sd(a,d,c+(b-d|0)|0,c,c);}d=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;og(d+c|0,b,0);b=b+c|0;b:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break b}H[a+11|0]=b;}H[b+d|0]=0;}break a}sd(a,(K[a+11|0]&128)>>>7|0?J[a>>2]:a,b);}}function qb(a,b,c){var d=0,e=0,f=0;e=Ua-16|0;Ua=e;J[b+4>>2]=J[b+4>>2]+1;f=a+8|0;d=e+12|0;J[d>>2]=b;a:{b=J[a+12>>2];a=J[a+8>>2];if(b-a>>2>>>0<=c>>>0){J[5996]=0;aa(274,f|0,c+1|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}a=J[f>>2];}a=(c<<2)+a|0;b=J[a>>2];if(b){a=J[b+4>>2]-1|0;J[b+4>>2]=a;if((a|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}a=J[f>>2]+(c<<2)|0;}b=J[d>>2];J[d>>2]=0;J[a>>2]=b;$e(d);Ua=e+16|0;return}a=Z()|0;$e(d);da(a|0);B();}function Im(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;d=Ua-16|0;Ua=d;a:{b:{c:{if((b|0)!=(c|0)){c=c-b|0;if((c|0)<18){break c}}H[a+12|0]=0;H[a|0]=0;break b}if(c>>>0>=2147483632){break a}d:{if(c>>>0<=10){H[d+15|0]=c;e=d+4|0;break d}f=(c|15)+1|0;e=cb(f);J[d+12>>2]=f|-2147483648;J[d+4>>2]=e;J[d+8>>2]=c;}H[fb(e,b,c)+c|0]=0;J[a+8>>2]=J[d+12>>2];b=J[d+8>>2];J[a>>2]=J[d+4>>2];J[a+4>>2]=b;H[a+12|0]=1;}Ua=d+16|0;return}ub();B();}function Uh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;e=Ua-16|0;Ua=e;a:{f=J[b>>2];if(f){d=K[c+11|0];if((d&128)>>>7|0?J[c+4>>2]:d&127){Sg(c,5570);f=J[b>>2];}d=e+4|0;b=J[b+4>>2];Xa[J[J[b>>2]+24>>2]](d,b,f);J[5996]=0;_(290,c|0,d|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}ab(d);}b=J[c+4>>2];J[a>>2]=J[c>>2];J[a+4>>2]=b;J[a+8>>2]=J[c+8>>2];J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;Ua=e+16|0;return}a=Z()|0;ab(e+4|0);da(a|0);B();}function Fb(a){var b=0,c=0,d=0;b=J[a+40>>2];if(b){J[a+44>>2]=b;$a(b);}c=J[a+28>>2];if(c){d=c;b=J[a+32>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;if(H[b-1|0]<0){$a(J[d>>2]);}b=d;if((c|0)!=(b|0)){continue}break}d=J[a+28>>2];}J[a+32>>2]=c;$a(d);}b=J[a+16>>2];if(b){J[a+20>>2]=b;$a(b);}c=J[a+4>>2];if(c){b=c;d=J[a+8>>2];if((b|0)!=(d|0)){while(1){d=Fb(d-56|0);if((c|0)!=(d|0)){continue}break}b=J[a+4>>2];}J[a+8>>2]=c;$a(b);}return a}function zb(a,b,c,d){var e=0,f=0,g=0;a:{e=K[a+11|0];if(!((e&128)>>>7|0?J[a+4>>2]:e&127)|(c-b|0)<5){break a}md(b,c);e=c-4|0;c=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;f=J[a+4>>2];a=K[a+11|0];g=c+((a&128)>>>7|0?f:a&127)|0;b:{while(1){c:{a=H[c|0];f=a-127|0;if(b>>>0>=e>>>0){break c}if((a|0)!=J[b>>2]&(f&255)>>>0>=130){break b}b=b+4|0;c=((g-c|0)>1)+c|0;continue}break}if((f&255)>>>0<130|a>>>0>J[e>>2]-1>>>0){break a}}J[d>>2]=4;}}function Xc(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0;d=J[a>>2];if(d){b=d;c=J[a+4>>2];if((b|0)!=(c|0)){while(1){f=c-12|0;e=J[f>>2];if(e){b=e;g=c-8|0;c=J[g>>2];if((b|0)!=(c|0)){while(1){c=c-32|0;b=J[c+4>>2];a:{if(!b){break a}h=J[b+4>>2];J[b+4>>2]=h-1;if(h){break a}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((c|0)!=(e|0)){continue}break}b=J[f>>2];}J[g>>2]=e;$a(b);}c=f;if((d|0)!=(c|0)){continue}break}b=J[a>>2];}J[a+4>>2]=d;$a(b);}}function td(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;d=a;g=Ua-16|0;Ua=g;a:{f=c-b|0;if(f>>>0<2147483632){b:{if(f>>>0<11){H[d+11|0]=f;break b}i=g+8|0;if(f>>>0>=11){h=f+16&-16;e=h-1|0;e=(e|0)==11?h:e;}else {e=10;}Gc(i,e+1|0);e=J[g+8>>2];J[d>>2]=e;J[d+8>>2]=J[g+12>>2]|-2147483648;J[d+4>>2]=f;d=e;}while(1){if((b|0)!=(c|0)){H[d|0]=K[b|0];d=d+1|0;b=b+1|0;continue}break}H[d|0]=0;Ua=g+16|0;break a}ub();B();}return a}function ag(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;d=a;g=Ua-16|0;Ua=g;a:{f=c-b>>2;if(f>>>0<1073741808){b:{if(f>>>0<2){H[d+11|0]=f;break b}i=g+8|0;if(f>>>0>=2){h=f+4&-4;e=h-1|0;e=(e|0)==2?h:e;}else {e=1;}Fc(i,e+1|0);e=J[g+8>>2];J[d>>2]=e;J[d+8>>2]=J[g+12>>2]|-2147483648;J[d+4>>2]=f;d=e;}while(1){if((b|0)!=(c|0)){J[d>>2]=J[b>>2];d=d+4|0;b=b+4|0;continue}break}J[d>>2]=0;Ua=g+16|0;break a}ub();B();}return a} +function pm(a,b){a=a|0;b=b|0;var c=0,d=0;b=!J[a+24>>2]|(J[a+16>>2]|b);J[a+16>>2]=b;if(b&J[a+20>>2]){a=Ua-16|0;Ua=a;c=Rb(16);a=a+8|0;b=Ua-16|0;Ua=b;if(!K[24716]){H[24716]=1;}J[b+12>>2]=22908;J[b+8>>2]=1;d=J[b+12>>2];J[a>>2]=J[b+8>>2];J[a+4>>2]=d;Ua=b+16|0;b=J[a+4>>2];a=J[a>>2];J[5996]=0;a=Ja(176,c|0,1821,a|0,b|0)|0;b=J[5996];J[5996]=0;if((b|0)!=1){na(a|0,8576,177);B();}a=Z()|0;ic(c);da(a|0);B();}}function tm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;while(1){a:{if((c|0)<=(f|0)){break a}d=J[a+24>>2];g=J[a+28>>2];if(d>>>0>=g>>>0){if((Xa[J[J[a>>2]+52>>2]](a,K[b|0])|0)==-1){break a}f=f+1|0;b=b+1|0;}else {J[e+12>>2]=g-d;J[e+8>>2]=c-f;h=d;d=e+8|0;g=e+12|0;d=J[(J[d>>2]>2]?d:g)>>2];gc(h,b,d);J[a+24>>2]=d+J[a+24>>2];f=d+f|0;b=b+d|0;}continue}break}Ua=e+16|0;return f|0}function go(a,b,c){var d=0,e=0,f=0,g=0;g=c&63;f=g;e=f&31;if(f>>>0>=32){f=-1>>>e|0;}else {d=-1>>>e|0;f=d|(1<>>0>=32){d=f<>>32-e|d<>>0>=32){d=-1<>>32-d;}a=c&a;b=b&d;d=e&31;if(e>>>0>=32){c=0;a=b>>>d|0;}else {c=b>>>d|0;a=((1<>>d;}a=a|g;Wa=c|f;return a} +function wb(a,b,c){var d=0,e=0,f=0;if(!(K[a|0]&32)){a:{d=b;b=a;a=J[b+16>>2];b:{if(!a){if(Be(b)){break b}a=J[b+16>>2];}f=J[b+20>>2];if(a-f>>>0>>0){Xa[J[b+36>>2]](b,d,c)|0;break a}c:{if(J[b+80>>2]<0){break c}a=c;while(1){e=a;if(!a){break c}a=a-1|0;if(K[d+a|0]!=10){continue}break}if(Xa[J[b+36>>2]](b,d,e)>>>0>>0){break b}d=d+e|0;c=c-e|0;f=J[b+20>>2];}fb(f,d,c);J[b+20>>2]=J[b+20>>2]+c;}}}}function am(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;e=J[a+44>>2];c=J[a+24>>2];if(e>>>0>>0){J[a+44>>2]=c;e=c;}c=J[a+12>>2];f=J[a+8>>2];d=-1;a:{if(c>>>0<=f>>>0){break a}if((b|0)==-1){J[a+16>>2]=e;J[a+12>>2]=c-1;J[a+8>>2]=f;return ((b|0)!=-1?b:0)|0}g=b<<24>>24;if(!(J[a+48>>2]&16)){d=-1;if((g|0)!=H[c-1|0]){break a}}J[a+16>>2]=e;J[a+12>>2]=c-1;J[a+8>>2]=f;H[J[a+12>>2]]=g;d=b;}return d|0}function Yh(a,b,c){a=a|0;b=b|0;c=+c;var d=0,e=0,f=0;f=Ua-16|0;Ua=f;d=K[b+11|0];d=(d&128)>>>7|0?J[b+4>>2]:d&127;while(1){a:{e=(K[b+11|0]&128)>>>7|0?J[b>>2]:b;O[f>>3]=c;e=od(e,d+1|0,2314,f);b:{if((e|0)>=0){if(d>>>0>=e>>>0){break a}d=e;break b}d=d<<1|1;}ie(b,d);continue}break}ie(b,e);d=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=d;J[a+8>>2]=J[b+8>>2];J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;Ua=f+16|0;}function Of(a,b,c){var d=0,e=0,f=Q(0),g=0,h=Q(0);e=Ua-16|0;Ua=e;a:{b:{c:{if((a|0)!=(b|0)){g=J[5732];J[5732]=0;jb();d=Ua-16|0;Ua=d;ee(d,a,e+12|0,0);f=Vf(J[d>>2],J[d+4>>2],J[d+8>>2],J[d+12>>2]);Ua=d+16|0;a=J[5732];if(!a){break c}if(J[e+12>>2]!=(b|0)){break b}h=f;if((a|0)!=68){break a}break b}J[c>>2]=4;break a}J[5732]=g;if(J[e+12>>2]==(b|0)){break a}}J[c>>2]=4;f=h;}Ua=e+16|0;return f}function Mf(a,b,c){var d=0,e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;a:{b:{c:{if((a|0)!=(b|0)){g=J[5732];J[5732]=0;jb();d=Ua-16|0;Ua=d;ee(d,a,e+12|0,1);f=ge(J[d>>2],J[d+4>>2],J[d+8>>2],J[d+12>>2]);Ua=d+16|0;a=J[5732];if(!a){break c}if(J[e+12>>2]!=(b|0)){break b}h=f;if((a|0)!=68){break a}break b}J[c>>2]=4;break a}J[5732]=g;if(J[e+12>>2]==(b|0)){break a}}J[c>>2]=4;f=h;}Ua=e+16|0;return f}function mk(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;e=(K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:1;f=K[a+11|0];d=f;d=(d&128)>>>7|0?J[a+4>>2]:d&127;a:{if(e-d>>>0>=c>>>0){if(!c){break a}e=(f&128)>>>7|0?J[a>>2]:a;tc(e+(d<<2)|0,b,c);b=c+d|0;b:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break b}H[a+11|0]=b;}J[e+(b<<2)>>2]=0;return a|0}He(a,e,d+(c-e|0)|0,d,d,0,c,b);}return a|0}function Bi(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0;while(1){a:{if((c|0)==(d|0)|e>>>0<=i>>>0){break a}g=1;h=Ua-16|0;Ua=h;f=Xb(h+12|0,J[a+8>>2]);j=qd(0,c,d-c|0,b?b:24840);f=J[f>>2];if(f){J[6178]=(f|0)==-1?24816:f;}Ua=h+16|0;b:{switch(j+2|0){default:g=j;break;case 0:case 1:break a;case 2:break b}}i=i+1|0;k=g+k|0;c=c+g|0;continue}break}return k|0}function kd(a,b,c){var d=0,e=0;if(c&2048){H[a|0]=43;a=a+1|0;}if(c&1024){H[a|0]=35;a=a+1|0;}d=c&260;if((d|0)!=260){H[a|0]=46;H[a+1|0]=42;a=a+2|0;}c=c&16384;while(1){e=K[b|0];if(e){H[a|0]=e;a=a+1|0;b=b+1|0;continue}break}a:{b:{if((d|0)!=256){if((d|0)!=4){break b}b=c?70:102;break a}b=c?69:101;break a}b=c?65:97;if((d|0)==260){break a}b=c?71:103;}H[a|0]=b;return (d|0)!=260}function ve(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;e=(K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:10;f=K[a+11|0];d=f;d=(d&128)>>>7|0?J[a+4>>2]:d&127;a:{if(e-d>>>0>=c>>>0){if(!c){break a}e=(f&128)>>>7|0?J[a>>2]:a;gc(e+d|0,b,c);b=c+d|0;b:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=b;break b}H[a+11|0]=b;}H[b+e|0]=0;return a|0}dd(a,e,d+(c-e|0)|0,d,d,0,c,b);}return a|0}function Gh(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(Jb(a,J[b+8>>2],e)){if(!(J[b+28>>2]==1|J[b+4>>2]!=(c|0))){J[b+28>>2]=d;}return}a:{if(!Jb(a,J[b>>2],e)){break a}if(!(J[b+16>>2]!=(c|0)&J[b+20>>2]!=(c|0))){if((d|0)!=1){break a}J[b+32>>2]=1;return}J[b+20>>2]=c;J[b+32>>2]=d;J[b+40>>2]=J[b+40>>2]+1;if(!(J[b+36>>2]!=1|J[b+24>>2]!=2)){H[b+54|0]=1;}J[b+44>>2]=4;}}function uf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=Ua-16|0;Ua=e;i=J[b>>2];d=J[c>>2];g=J[a>>2];f=d-g|0;f=f>>>0>=2147483647?-1:(d|0)==(g|0)?4:f<<1;d=J[a+4>>2]==220;h=Vc(d?0:g,f);if(h){if(!d){J[a>>2]=0;}J[e+4>>2]=184;d=e+8|0;J[d>>2]=h;J[d+4>>2]=J[e+4>>2];a=rf(a,d);db(d);J[b>>2]=J[a>>2]+(i-g|0);J[c>>2]=J[a>>2]+(f&-4);Ua=e+16|0;return}ce();B();}function gn(a,b){a=a|0;b=+b;var c=0,d=0,e=0;d=Ua-16|0;Ua=d;c=d+4|0;J[c>>2]=0;J[c+4>>2]=0;J[c+8>>2]=0;e=(K[c+11|0]&128)>>>7|0?(J[c+8>>2]&2147483647)-1|0:10;J[5996]=0;aa(172,c|0,e|0);e=J[5996];J[5996]=0;if((e|0)==1){a=Z()|0;ab(c);da(a|0);B();}J[5996]=0;Pa(120,a|0,c|0,+b);a=J[5996];J[5996]=0;if((a|0)!=1){ab(c);Ua=d+16|0;return}a=Z()|0;ab(d+4|0);da(a|0);B();}function fd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;c=K[a+11|0];d=c<<24>>24;f=J[b+4>>2];d=(d|0)<0;c=d?J[a+4>>2]:c;a:{if(f>>>0>>0){break a}e=J[b>>2];g=c+e|0;if(K[g|0]!=40|K[(e+f|0)-1|0]!=41){break a}if(c){a=d?J[a>>2]:a;d=c+a|0;while(1){if(K[a|0]!=K[e|0]){return 0}e=e+1|0;a=a+1|0;if((d|0)!=(a|0)){continue}break}}J[b+4>>2]=(f-c|0)-2;h=1;J[b>>2]=g+1;}return h}function Tf(a,b,c,d){var e=0,f=0,g=0;e=Ua-16|0;Ua=e;a:{if((a|0)!=(b|0)){g=J[5732];J[5732]=0;jb();a=Uf(a,e+12|0,d);d=Wa;f=J[5732];b:{if(f){if(J[e+12>>2]!=(b|0)){break b}if((f|0)!=68){break a}J[c>>2]=4;b=!!a&(d|0)>=0|(d|0)>0;a=b?-1:0;d=b?2147483647:-2147483648;break a}J[5732]=g;if(J[e+12>>2]==(b|0)){break a}}}J[c>>2]=4;a=0;d=0;}Ua=e+16|0;Wa=d;return a}function Ol(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0;e=J[a+84>>2];f=J[e>>2];d=J[e+4>>2];h=J[a+28>>2];g=J[a+20>>2]-h|0;g=d>>>0>>0?d:g;if(g){fb(f,h,g);f=g+J[e>>2]|0;J[e>>2]=f;d=J[e+4>>2]-g|0;J[e+4>>2]=d;}d=c>>>0>d>>>0?d:c;if(d){fb(f,b,d);f=d+J[e>>2]|0;J[e>>2]=f;J[e+4>>2]=J[e+4>>2]-d;}H[f|0]=0;b=J[a+44>>2];J[a+28>>2]=b;J[a+20>>2]=b;return c|0}function xk(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=Ua-16|0;Ua=e;i=J[b>>2];g=J[a>>2];d=J[c>>2]-g|0;f=d<<1;f=d>>>0>=2147483647?-1:f>>>0<=1?1:f;d=J[a+4>>2]==220;h=Vc(d?0:g,f);if(h){if(!d){J[a>>2]=0;}J[e+4>>2]=184;d=e+8|0;J[d>>2]=h;J[d+4>>2]=J[e+4>>2];a=rf(a,d);db(d);J[b>>2]=J[a>>2]+(i-g|0);J[c>>2]=f+J[a>>2];Ua=e+16|0;return}ce();B();}function Hd(a,b,c,d){H[a+53|0]=1;a:{if(J[a+4>>2]!=(c|0)){break a}H[a+52|0]=1;c=J[a+16>>2];b:{if(!c){J[a+36>>2]=1;J[a+24>>2]=d;J[a+16>>2]=b;if((d|0)!=1){break a}if(J[a+48>>2]==1){break b}break a}if((b|0)==(c|0)){c=J[a+24>>2];if((c|0)==2){J[a+24>>2]=d;c=d;}if(J[a+48>>2]!=1){break a}if((c|0)==1){break b}break a}J[a+36>>2]=J[a+36>>2]+1;}H[a+54|0]=1;}}function Oh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=Ua+-64|0;Ua=d;e=1;a:{if(Jb(a,b,0)){break a}e=0;if(!b){break a}b=Fe(b,22104);e=0;if(!b){break a}Sb(d+12|0,0,52);J[d+56>>2]=1;J[d+20>>2]=-1;J[d+16>>2]=a;J[d+8>>2]=b;Xa[J[J[b>>2]+28>>2]](b,d+8|0,J[c>>2],1);a=J[d+32>>2];if((a|0)==1){J[c>>2]=J[d+24>>2];}e=(a|0)==1;}a=e;Ua=d- -64|0;return a|0}function tj(a){if(K[25132]){return J[6282]}if(!K[25640]){H[25640]=1;}ib(25472,18340);ib(25484,18368);ib(25496,18396);ib(25508,18428);ib(25520,18468);ib(25532,18504);ib(25544,18532);ib(25556,18568);ib(25568,18584);ib(25580,18600);ib(25592,18616);ib(25604,18632);ib(25616,18648);ib(25628,18664);H[25132]=1;J[6282]=25472;return 25472}function en(a){a=a|0;var b=0,c=0;b=J[a+80>>2];a:{if(!b|M[a+84>>2]>3600){break a}if(Wb(3557,1)&(b^-1)){break a}b=J[a+80>>2];if(!b|M[a+84>>2]>3600|(J[a+52>>2]+J[a+44>>2]>>>0>201|M[a+68>>2]>100)){break a}if(Wb(2049,1)&(b^-1)){break a}b=J[a+80>>2];if(Wb(2165,1)&(b^-1)|K[a+88|0]){break a}a=J[a+80>>2];c=!(Wb(1681,1)&(a^-1));}return c|0}function Zc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;e=Ua-16|0;Ua=e;a:{b:{if(c>>>0<11){H[a+11|0]=c;break b}if(c>>>0>=2147483632){break a}g=e+8|0;if(c>>>0>=11){f=c+16&-16;d=f-1|0;d=(d|0)==11?f:d;}else {d=10;}Gc(g,d+1|0);d=J[e+8>>2];J[a>>2]=d;J[a+8>>2]=J[e+12>>2]|-2147483648;J[a+4>>2]=c;a=d;}gc(a,b,c+1|0);Ua=e+16|0;return}ub();B();}function ib(a,b){var c=0,d=0,e=0,f=0;a:{c=We(b);d=(K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:1;if(c>>>0<=d>>>0){b=eb((K[a+11|0]&128)>>>7|0?J[a>>2]:a,b,c<<2);b:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=c;break b}H[a+11|0]=c;}J[(c<<2)+b>>2]=0;break a}e=a;f=J[a+4>>2];a=K[a+11|0];a=(a&128)>>>7|0?f:a&127;He(e,d,c-d|0,a,0,a,c,b);}}function Qg(a){var b=0,c=0,d=0;d=J[a>>2];if(d){b=J[a+4>>2];c=d;if((b|0)!=(c|0)){while(1){c=b-32|0;if((K[c|0]|K[c+1|0]<<8|(K[c+2|0]<<16|K[c+3|0]<<24))>>>0>=29){b=b-24|0;$a(K[b|0]|K[b+1|0]<<8|(K[b+2|0]<<16|K[b+3|0]<<24));H[b|0]=0;H[b+1|0]=0;H[b+2|0]=0;H[b+3|0]=0;}b=c;if((d|0)!=(b|0)){continue}break}c=J[a>>2];}J[a+4>>2]=d;$a(c);}}function Ei(a,b){a=a|0;b=b|0;var c=0,d=0;H[a+6|0]=0;I[a+4>>1]=0;J[a>>2]=1;c=J[b>>2];d=J[b+4>>2];J[a+20>>2]=0;J[a+12>>2]=0;J[a+16>>2]=0;J[a+8>>2]=(d-c|0)+1;c=cb(12);J[a+16>>2]=c;J[a+12>>2]=c;d=c+12|0;J[a+20>>2]=d;J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[c+8>>2]=J[b+8>>2];J[b+8>>2]=0;J[b>>2]=0;J[b+4>>2]=0;J[a+16>>2]=d;return a|0}function dh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=+d;var e=0,f=0,g=0,h=0;e=cb(56);f=J[c+8>>2];J[c+8>>2]=0;g=J[c>>2];h=J[c+4>>2];J[c>>2]=0;J[c+4>>2]=0;J[e+16>>2]=0;J[e+20>>2]=0;J[e+12>>2]=f;J[e+4>>2]=g;J[e+8>>2]=h;J[e>>2]=b;J[e+24>>2]=0;J[e+28>>2]=0;J[e+32>>2]=0;J[e+36>>2]=0;J[e+40>>2]=0;J[e+44>>2]=0;O[e+48>>3]=d;mc(a,e);return e|0}function fj(a){if(K[25124]){return J[6280]}if(!K[25464]){H[25464]=1;}hb(25296,1114);hb(25308,1121);hb(25320,1087);hb(25332,1095);hb(25344,1078);hb(25356,1128);hb(25368,1105);hb(25380,1961);hb(25392,1999);hb(25404,2336);hb(25416,2493);hb(25428,1273);hb(25440,2172);hb(25452,1390);H[25124]=1;J[6280]=25296;return 25296}function zc(a,b){var c=0,d=0,e=0,f=0,g=0;a:{c=We(b);e=Ua-16|0;Ua=e;if(c>>>0<1073741808){b:{if(c>>>0<2){H[a+11|0]=c;break b}g=e+8|0;if(c>>>0>=2){f=c+4&-4;d=f-1|0;d=(d|0)==2?f:d;}else {d=1;}Fc(g,d+1|0);d=J[e+8>>2];J[a>>2]=d;J[a+8>>2]=J[e+12>>2]|-2147483648;J[a+4>>2]=c;a=d;}J[tc(a,b,c)+(c<<2)>>2]=0;Ua=e+16|0;break a}ub();B();}}function dc(a,b,c,d){var e=0,f=0,g=0,h=0;e=Ua-16|0;Ua=e;J[e+12>>2]=d;g=Xb(e+8|0,b);b=Ua-16|0;Ua=b;d=J[e+12>>2];J[b+12>>2]=d;J[b+8>>2]=d;f=-1;d=pd(0,0,c,d);a:{if((d|0)<0){break a}h=a;d=d+1|0;a=sb(d);J[h>>2]=a;if(!a){break a}f=pd(a,d,c,J[b+12>>2]);}Ua=b+16|0;a=J[g>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=e+16|0;return f}function bh(a,b,c){a=a|0;b=b|0;c=+c;var d=0,e=0,f=0,g=0;d=cb(56);e=J[b+8>>2];J[b+8>>2]=0;f=J[b>>2];g=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;J[d+16>>2]=0;J[d+20>>2]=0;J[d+12>>2]=e;J[d+4>>2]=f;J[d+8>>2]=g;J[d>>2]=12;J[d+24>>2]=0;J[d+28>>2]=0;J[d+32>>2]=0;J[d+36>>2]=0;J[d+40>>2]=0;J[d+44>>2]=0;O[d+48>>3]=c;mc(a,d);return d|0}function xe(a){var b=0;b=1;a:{if((a|0)>=1024){b=898846567431158e293;if(a>>>0<2047){a=a-1023|0;break a}b=Infinity;a=((a|0)>=3069?3069:a)-2046|0;break a}if((a|0)>-1023){break a}b=2004168360008973e-307;if(a>>>0>4294965304){a=a+969|0;break a}b=0;a=((a|0)<=-2960?-2960:a)+1938|0;}x(0,0);x(1,a+1023<<20);return b*+z()}function xd(a){var b=0,c=0,d=0,e=0;if(a){xd(J[a>>2]);xd(J[a+4>>2]);d=J[a+40>>2];if(d){b=d;c=J[a+44>>2];if((b|0)!=(c|0)){while(1){c=c-32|0;b=J[c+4>>2];a:{if(!b){break a}e=J[b+4>>2];J[b+4>>2]=e-1;if(e){break a}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((d|0)!=(c|0)){continue}break}b=J[a+40>>2];}J[a+44>>2]=d;$a(b);}$a(a);}}function Di(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0;g=Ua-16|0;Ua=g;J[e>>2]=c;b=g+12|0;a=Md(b,0,J[a+8>>2]);f=2;a:{if(a+1>>>0<2){break a}c=a-1|0;f=1;if(c>>>0>d-J[e>>2]>>>0){break a}while(1){if(c){a=K[b|0];d=J[e>>2];J[e>>2]=d+1;H[d|0]=a;c=c-1|0;b=b+1|0;continue}break}f=0;}a=f;Ua=g+16|0;return a|0}function rc(a,b,c,d){var e=0;a:{if(!(d&2048)){break a}e=d&74;if(!c|((e|0)==8|(e|0)==64)){break a}H[a|0]=43;a=a+1|0;}if(d&512){H[a|0]=35;a=a+1|0;}while(1){e=K[b|0];if(e){H[a|0]=e;a=a+1|0;b=b+1|0;continue}break}e=d&74;b=111;b:{if((e|0)==64){break b}b=d&16384?88:120;if((e|0)==8){break b}b=c?100:117;}H[a|0]=b;}function ad(a){var b=0,c=0,d=0;b=J[a>>2];J[a>>2]=0;if(b){a=J[b+28>>2];if(a){J[b+32>>2]=a;$a(a);}c=J[b+16>>2];if(c){a=c;d=J[b+20>>2];if((a|0)!=(d|0)){while(1){a=d-12|0;if(H[d-1|0]<0){$a(J[a>>2]);}d=a;if((a|0)!=(c|0)){continue}break}a=J[b+16>>2];}J[b+20>>2]=c;$a(a);}a=J[b+4>>2];if(a){J[b+8>>2]=a;$a(a);}$a(b);}}function Om(a,b){a=a|0;b=b|0;var c=0,d=0,e=0;J[a+8>>2]=0;J[a>>2]=0;J[a+4>>2]=0;J[5996]=0;c=$(3,12)|0;d=J[5996];J[5996]=0;if((d|0)!=1){J[a>>2]=c;d=c+12|0;J[a+8>>2]=d;J[c+8>>2]=J[b+8>>2];e=J[b+4>>2];J[c>>2]=J[b>>2];J[c+4>>2]=e;J[b>>2]=0;J[b+4>>2]=0;J[b+8>>2]=0;J[a+4>>2]=d;return}b=Z()|0;rb(a);da(b|0);B();}function Jk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-32|0;Ua=g;h=J[3163];J[g+24>>2]=J[3162];J[g+28>>2]=h;h=J[3161];J[g+16>>2]=J[3160];J[g+20>>2]=h;h=J[3159];J[g+8>>2]=J[3158];J[g+12>>2]=h;h=J[3157];J[g>>2]=J[3156];J[g+4>>2]=h;h=a;a=g+32|0;b=jc(h,b,c,d,e,f,g,a);Ua=a;return b|0}function bm(a){a=a|0;var b=0,c=0,d=0,e=0;c=J[a+44>>2];b=J[a+24>>2];if(c>>>0>>0){J[a+44>>2]=b;c=b;}d=-1;a:{if(!(K[a+48|0]&8)){break a}b=J[a+16>>2];if(b>>>0>>0){e=J[a+8>>2];b=J[a+12>>2];J[a+16>>2]=c;J[a+12>>2]=b;J[a+8>>2]=e;b=J[a+16>>2];}a=J[a+12>>2];if(a>>>0>=b>>>0){break a}d=K[a|0];}return d|0}function Ih(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0;if(Jb(a,J[b+8>>2],0)){Gd(b,c,d);return}f=J[a+12>>2];Ee(J[a+16>>2],J[a+20>>2],b,c,d);e=a+24|0;a=(a+16|0)+(f<<3)|0;a:{if(e>>>0>=a>>>0){break a}while(1){Ee(J[e>>2],J[e+4>>2],b,c,d);if(K[b+54|0]){break a}e=e+8|0;if(a>>>0>e>>>0){continue}break}}}function vb(a,b){var c=0,d=0,e=0,f=0,g=0;d=K[a+11|0];c=d<<24>>24;c=(c|0)<0;e=c?J[a+4>>2]:d;f=J[b+4>>2];if(e>>>0<=f>>>0){d=J[b>>2];if(e){a=c?J[a>>2]:a;g=e+a|0;c=d;while(1){if(K[a|0]!=K[c|0]){return 0}c=c+1|0;a=a+1|0;if((g|0)!=(a|0)){continue}break}}J[b+4>>2]=f-e;J[b>>2]=d+e;a=1;}else {a=0;}return a}function Gb(a){var b=0,c=0,d=0;a:{b:{b=a;if(!(b&3)){break b}if(!K[b|0]){return 0}while(1){b=b+1|0;if(!(b&3)){break b}if(K[b|0]){continue}break}break a}while(1){c=b;b=b+4|0;d=J[c>>2];if(!((d^-1)&d-16843009&-2139062144)){continue}break}while(1){b=c;c=b+1|0;if(K[b|0]){continue}break}}return b-a|0}function Eb(a,b,c){var d=0,e=0;a:{b:{if(c>>>0>=4){if((a|b)&3){break b}while(1){if(J[a>>2]!=J[b>>2]){break b}b=b+4|0;a=a+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}}while(1){d=K[a|0];e=K[b|0];if((d|0)==(e|0)){b=b+1|0;a=a+1|0;c=c-1|0;if(c){continue}break a}break}return d-e|0}return 0}function qk(a,b){a=a|0;b=b|0;var c=0,d=0;a:{b:{c=K[a+11|0];c:{d:{if((c&128)>>>7|0){d=(J[a+8>>2]&2147483647)-1|0;c=J[a+4>>2];if((d|0)==(c|0)){break d}break c}d=1;c=c&127;if((c|0)!=1){break b}}of(a,d,1,d,d);c=d;}d=J[a>>2];J[a+4>>2]=c+1;break a}H[a+11|0]=c+1;d=a;}a=(c<<2)+d|0;J[a>>2]=b;J[a+4>>2]=0;}function Nb(a,b){var c=0,d=0,e=0,f=0;d=Ua-16|0;Ua=d;a:{if(!b){b=0;break a}c=b>>31;e=(c^b)-c|0;c=S(e);Cb(d,e,0,0,0,c+81|0);e=0+J[d+8>>2]|0;c=(J[d+12>>2]^65536)+(16414-c<<16)|0;c=e>>>0>>0?c+1|0:c;f=b&-2147483648|c;c=J[d+4>>2];b=J[d>>2];}J[a>>2]=b;J[a+4>>2]=c;J[a+8>>2]=e;J[a+12>>2]=f;Ua=d+16|0;}function mf(a,b,c){var d=0,e=0,f=0;e=Ua-16|0;Ua=e;d=Ua-32|0;Ua=d;f=Ua-16|0;Ua=f;J[f+12>>2]=b;J[d+24>>2]=a;J[d+28>>2]=J[f+12>>2];Ua=f+16|0;me(d+16|0,J[d+24>>2],J[d+28>>2],c);a=Rd(a,J[d+16>>2]-a>>2);J[d+12>>2]=J[d+20>>2];J[e+8>>2]=a;J[e+12>>2]=J[d+12>>2];Ua=d+32|0;Ua=e+16|0;return J[e+12>>2]}function ee(a,b,c,d){var e=0,f=0,g=0,h=0;e=Ua-160|0;Ua=e;J[e+60>>2]=b;J[e+20>>2]=b;J[e+24>>2]=-1;f=e+16|0;Yb(f,0,0);ig(e,f,d,1);d=J[e+8>>2];g=J[e+12>>2];f=J[e>>2];h=J[e+4>>2];if(c){J[c>>2]=((J[e+20>>2]+J[e+136>>2]|0)-J[e+60>>2]|0)+b;}J[a+8>>2]=d;J[a+12>>2]=g;J[a>>2]=f;J[a+4>>2]=h;Ua=e+160|0;}function nf(a,b,c){var d=0,e=0,f=0;e=Ua-16|0;Ua=e;d=Ua-32|0;Ua=d;f=Ua-16|0;Ua=f;J[f+12>>2]=b;J[d+24>>2]=a;J[d+28>>2]=J[f+12>>2];Ua=f+16|0;me(d+16|0,J[d+24>>2],J[d+28>>2],c);a=Td(a,J[d+16>>2]-a|0);J[d+12>>2]=J[d+20>>2];J[e+8>>2]=a;J[e+12>>2]=J[d+12>>2];Ua=d+32|0;Ua=e+16|0;return J[e+12>>2]}function rn(a,b){a=a|0;b=b|0;var c=0,d=0;a:{b:{c=K[a+11|0];c:{d:{if((c&128)>>>7|0){d=(J[a+8>>2]&2147483647)-1|0;c=J[a+4>>2];if((d|0)==(c|0)){break d}break c}d=10;c=c&127;if((c|0)!=10){break b}}Sd(a,d,1,d,d);c=d;}d=J[a>>2];J[a+4>>2]=c+1;break a}H[a+11|0]=c+1;d=a;}a=d+c|0;H[a|0]=b;H[a+1|0]=0;}function Nl(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0,h=0;h=(e-d|0)+b|0;a:{while(1){if((d|0)!=(e|0)){a=-1;if((b|0)==(c|0)){break a}f=H[b|0];g=H[d|0];if((f|0)<(g|0)){break a}if((f|0)>(g|0)){return 1}else {d=d+1|0;b=b+1|0;continue}}break}a=(c|0)!=(h|0);}return a|0}function oe(a){a=a|0;var b=0,c=0;J[a>>2]=8512;J[5996]=0;aa(133,a|0,0);b=J[5996];J[5996]=0;if((b|0)!=1){b=J[a+28>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}$a(J[a+32>>2]);$a(J[a+36>>2]);$a(J[a+48>>2]);$a(J[a+60>>2]);return a|0}fa(0)|0;Vb();B();}function Jc(a,b,c){var d=0,e=0,f=0;a:{if(!b){d=a;break a}while(1){d=eo(a,b,10);e=Wa;a=co(d,e,246,0)+a|0;c=c-1|0;H[c|0]=a|48;f=b>>>0>9;a=d;b=e;if(f){continue}break}}if(d){while(1){c=c-1|0;a=(d>>>0)/10|0;H[c|0]=P(a,246)+d|48;b=d>>>0>9;d=a;if(b){continue}break}}return c}function _b(a){var b=0,c=0,d=0,e=0;d=J[a>>2];if(d){b=d;c=J[a+4>>2];if((b|0)!=(c|0)){while(1){c=c-32|0;b=J[c+4>>2];a:{if(!b){break a}e=J[b+4>>2];J[b+4>>2]=e-1;if(e){break a}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((d|0)!=(c|0)){continue}break}b=J[a>>2];}J[a+4>>2]=d;$a(b);}}function lb(a){var b=0,c=0,d=0,e=0;d=J[a>>2];if(d){b=d;c=J[a+4>>2];if((b|0)!=(c|0)){while(1){c=c-8|0;b=J[c+4>>2];a:{if(!b){break a}e=J[b+4>>2];J[b+4>>2]=e-1;if(e){break a}Xa[J[J[b>>2]+8>>2]](b);bb(b);}if((d|0)!=(c|0)){continue}break}b=J[a>>2];}J[a+4>>2]=d;$a(b);}}function Ec(a,b){var c=0,d=0,e=0,f=0;c=Ua-16|0;Ua=c;a:{if(!b){b=0;break a}d=b;b=S(b);Cb(c,d,0,0,0,b+81|0);d=0+J[c+8>>2]|0;b=(J[c+12>>2]^65536)+(16414-b<<16)|0;f=e>>>0>d>>>0?b+1|0:b;e=J[c+4>>2];b=J[c>>2];}J[a>>2]=b;J[a+4>>2]=e;J[a+8>>2]=d;J[a+12>>2]=f;Ua=c+16|0;}function _m(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;d=J[b+28>>2];J[a>>2]=d;J[d+4>>2]=J[d+4>>2]+1;Og(b+28|0,c);J[5996]=0;aa(133,b|0,1);b=J[5996];J[5996]=0;if((b|0)==1){c=Z()|0;a=J[a>>2];b=J[a+4>>2]-1|0;J[a+4>>2]=b;if((b|0)==-1){Xa[J[J[a>>2]+8>>2]](a);}da(c|0);B();}}function Kl(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;var f=0,g=0;a:{while(1){if((d|0)!=(e|0)){a=-1;if((b|0)==(c|0)){break a}f=J[b>>2];g=J[d>>2];if((f|0)<(g|0)){break a}if((f|0)>(g|0)){return 1}else {d=d+4|0;b=b+4|0;continue}}break}a=(b|0)!=(c|0);}return a|0}function Ie(a){a=a|0;var b=0,c=0,d=0,e=0;J[a>>2]=12664;e=a+8|0;while(1){b=J[a+8>>2];if(J[a+12>>2]-b>>2>>>0>c>>>0){b=J[b+(c<<2)>>2];if(b){d=J[b+4>>2]-1|0;J[b+4>>2]=d;if((d|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}}c=c+1|0;continue}break}ab(a+152|0);gf(e);return a|0}function Nc(a){var b=0,c=0,d=0,e=0,f=0;a:{if(K[a+4|0]){break a}e=J[a>>2];b=J[e>>2];if(!b){break a}c=b;d=J[e+4>>2];if((d|0)!=(b|0)){while(1){c=d-12|0;f=J[c>>2];if(f){J[d-8>>2]=f;$a(f);}d=c;if((d|0)!=(b|0)){continue}break}c=J[J[a>>2]>>2];}J[e+4>>2]=b;$a(c);}}function Dg(a){var b=0,c=0;b=J[a+72>>2];J[a+72>>2]=b-1|b;if(J[a+20>>2]!=J[a+28>>2]){Xa[J[a+36>>2]](a,0,0)|0;}J[a+28>>2]=0;J[a+16>>2]=0;J[a+20>>2]=0;b=J[a>>2];if(b&4){J[a>>2]=b|32;return -1}c=J[a+44>>2]+J[a+48>>2]|0;J[a+8>>2]=c;J[a+4>>2]=c;return b<<27>>31}function hb(a,b){var c=0,d=0,e=0,f=0;a:{c=Gb(b);d=(K[a+11|0]&128)>>>7|0?(J[a+8>>2]&2147483647)-1|0:10;if(c>>>0<=d>>>0){sd(a,oc((K[a+11|0]&128)>>>7|0?J[a>>2]:a,b,c),c);break a}e=a;f=J[a+4>>2];a=K[a+11|0];a=(a&128)>>>7|0?f:a&127;dd(e,d,c-d|0,a,0,a,c,b);}}function Yb(a,b,c){var d=0,e=0,f=0,g=0;J[a+112>>2]=b;J[a+116>>2]=c;e=J[a+4>>2];d=J[a+44>>2]-e|0;J[a+120>>2]=d;J[a+124>>2]=d>>31;d=J[a+8>>2];a:{if(!(b|c)){break a}f=d-e|0;g=f>>31;if((c|0)>=(g|0)&b>>>0>=f>>>0|(c|0)>(g|0)){break a}d=b+e|0;}J[a+104>>2]=d;}function Lg(a,b){var c=0,d=0,e=0;A(+a);d=v(1)|0;e=v(0)|0;c=d>>>20&2047;if((c|0)!=2047){if(!c){if(a==0){c=0;}else {a=Lg(a*0x10000000000000000,b);c=J[b>>2]+-64|0;}J[b>>2]=c;return a}J[b>>2]=c-1022;x(0,e|0);x(1,d&-2146435073|1071644672);a=+z();}return a}function Vg(a){var b=0,c=0,d=0,e=0;a:{if(K[a+4|0]){break a}e=J[a>>2];b=J[e>>2];if(!b){break a}c=b;d=J[e+4>>2];if((b|0)!=(d|0)){while(1){c=d-12|0;if(H[d-1|0]<0){$a(J[c>>2]);}d=c;if((d|0)!=(b|0)){continue}break}c=J[J[a>>2]>>2];}J[e+4>>2]=b;$a(c);}}function ff(a,b){var c=0,d=0;d=Ua-16|0;Ua=d;c=d+4|0;J[c>>2]=a;a=J[a+4>>2];J[c+4>>2]=a;J[c+8>>2]=a+(b<<2);b=J[c+4>>2];a=J[c+8>>2];while(1){if((a|0)==(b|0)){J[J[c>>2]+4>>2]=J[c+4>>2];Ua=d+16|0;}else {J[b>>2]=0;b=b+4|0;J[c+4>>2]=b;continue}break}}function Vb(){var a=0;a=J[5728];J[5996]=0;ca(a|0);a=J[5996];J[5996]=0;a:{if((a|0)!=1){J[5996]=0;ca(291);a=J[5996];J[5996]=0;if((a|0)!=1){break a}}pa(fa(0)|0)|0;J[5996]=0;ca(291);a=J[5996];J[5996]=0;if((a|0)!=1){break a}fa(0)|0;Vb();}B();}function Ag(a,b,c,d){var e=0,f=0;e=Ua-32|0;Ua=e;f=Ua-16|0;Ua=f;J[f+12>>2]=c;J[e+24>>2]=b;J[e+28>>2]=J[f+12>>2];Ua=f+16|0;me(e+16|0,J[e+24>>2],J[e+28>>2],d);b=J[e+16>>2];J[e+12>>2]=J[e+20>>2];J[a>>2]=b;J[a+4>>2]=J[e+12>>2];Ua=e+32|0;}function Lb(a,b,c){c=c&176;if((c|0)==32){return b}a:{if((c|0)!=16){break a}b:{c:{c=K[a|0];switch(c-43|0){case 0:case 2:break c;default:break b}}return a+1|0}if((c|0)!=48|(b-a|0)<2|(K[a+1|0]|32)!=120){break a}a=a+2|0;}return a}function Ym(a,b){a=a|0;b=b|0;var c=0,d=0;c=J[b+48>>2];if(c&16){d=J[b+44>>2];c=J[b+24>>2];if(d>>>0>>0){J[b+44>>2]=c;d=c;}td(a,J[b+20>>2],d);return}if(c&8){td(a,J[b+8>>2],J[b+16>>2]);return}J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;}function Rh(a){a=a|0;var b=0,c=0;a:{b:{if(!a){break b}b=a-24|0;c=J[b>>2]-1|0;J[b>>2]=c;if(K[b+13|0]|c){break b}b=J[b+8>>2];if(b){J[5996]=0;$(b|0,a|0)|0;b=J[5996];J[5996]=0;if((b|0)==1){break a}}ic(a);}return}fa(0)|0;Vb();B();}function Eg(a,b,c){var d=0,e=0,f=0,g=0;d=Ua-16|0;Ua=d;b=b-a>>2;while(1){if(b){J[d+12>>2]=a;e=b>>>1|0;J[d+12>>2]=J[d+12>>2]+(e<<2);f=J[d+12>>2];g=M[f>>2]>>0;a=g?f+4|0:a;b=g?(e^-1)+b|0:e;continue}break}Ua=d+16|0;return a}function Kb(a,b){a=a|0;b=b|0;var c=0,d=0,e=0;c=Gb(b);if(c>>>0<2147483632){a:{if(c>>>0<=10){H[a+11|0]=c;d=a;break a}e=(c|15)+1|0;d=cb(e);J[a+8>>2]=e|-2147483648;J[a>>2]=d;J[a+4>>2]=c;}H[eb(d,b,c)+c|0]=0;return a|0}ub();B();}function Ik(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0;g=Xa[J[J[a+8>>2]+20>>2]](a+8|0)|0;h=K[g+11|0];i=a;j=b;b=(h&128)>>>7|0;a=b?J[g>>2]:g;return jc(i,j,c,d,e,f,a,a+((b?J[g+4>>2]:h&127)<<2)|0)|0}function Qn(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;a:{if(K[b|0]!=47){while(1){if((c|0)==(d|0)){e=Wb(b,c);b=0;break a}d=d+1|0;if(K[d+b|0]!=47){continue}break}}e=Wb(b,d);b=Wb((b+d|0)+1|0,(d^-1)+c|0);}J[a+4>>2]=b;J[a>>2]=e;}function co(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;e=c>>>16|0;f=a>>>16|0;j=P(e,f);g=c&65535;h=a&65535;i=P(g,h);f=(i>>>16|0)+P(f,g)|0;e=(f&65535)+P(e,h)|0;Wa=(P(b,c)+j|0)+P(a,d)+(f>>>16)+(e>>>16)|0;return i&65535|e<<16}function Ok(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0;g=Xa[J[J[a+8>>2]+20>>2]](a+8|0)|0;h=K[g+11|0];i=a;j=b;b=(h&128)>>>7|0;a=b?J[g>>2]:g;return kc(i,j,c,d,e,f,a,a+(b?J[g+4>>2]:h&127)|0)|0}function pg(a,b){a=a|0;b=b|0;var c=0,d=0;c=J[a>>2];a:{if(!c){break a}d=J[c+24>>2];b:{if((d|0)==J[c+28>>2]){b=Xa[J[J[c>>2]+52>>2]](c,b)|0;break b}J[c+24>>2]=d+4;J[d>>2]=b;}if((b|0)!=-1){break a}J[a>>2]=0;}return a|0}function Jm(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;d=cb(104);J[d>>2]=7e3;J[d+4>>2]=0;J[d+8>>2]=0;J[5996]=0;b=ba(143,d+12|0,b|0,c|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){a=Z()|0;$a(d);da(a|0);B();}J[a+4>>2]=d;J[a>>2]=b;}function Gd(a,b,c){var d=0;d=J[a+16>>2];if(!d){J[a+36>>2]=1;J[a+24>>2]=c;J[a+16>>2]=b;return}a:{if((b|0)==(d|0)){if(J[a+24>>2]!=2){break a}J[a+24>>2]=c;return}H[a+54|0]=1;J[a+24>>2]=2;J[a+36>>2]=J[a+36>>2]+1;}}function Ed(a){var b=0,c=0,d=0;a:{if(K[a+12|0]){break a}b=J[J[a+8>>2]>>2];d=J[J[a+4>>2]>>2];if((b|0)==(d|0)){break a}while(1){a=b-12|0;c=J[a>>2];if(c){J[b-8>>2]=c;$a(c);}b=a;if((a|0)!=(d|0)){continue}break}}}function yf(a,b,c,d,e,f){var g=0;g=Ua-16|0;Ua=g;H[g+15|0]=0;H[g+14|0]=f;H[g+13|0]=e;H[g+12|0]=37;if(f){e=K[g+13|0];H[g+13|0]=K[g+14|0];H[g+14|0]=e;}J[c>>2]=(Ta(b|0,J[c>>2]-b|0,g+12|0,d|0,a|0)|0)+b;Ua=g+16|0;}function Bb(a,b,c,d,e){var f=0;f=Ua-256|0;Ua=f;if(!(e&73728|(c|0)<=(d|0))){d=c-d|0;c=d>>>0<256;Sb(f,b&255,c?d:256);if(!c){while(1){wb(a,f,256);d=d-256|0;if(d>>>0>255){continue}break}}wb(a,f,d);}Ua=f+256|0;}function Wc(a){var b=0,c=0,d=0,e=0;b=J[a>>2];if(b){c=b;d=J[a+4>>2];if((d|0)!=(b|0)){while(1){c=d-12|0;e=J[c>>2];if(e){J[d-8>>2]=e;$a(e);}d=c;if((d|0)!=(b|0)){continue}break}c=J[a>>2];}J[a+4>>2]=b;$a(c);}}function wi(a){a=a|0;var b=0,c=0,d=0;a=J[6019];if(a){b=a;c=J[6020];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6019];}J[6020]=a;$a(b);}}function ph(a){a=a|0;var b=0,c=0,d=0;a=J[6049];if(a){b=a;c=J[6050];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6049];}J[6050]=a;$a(b);}}function on(a){a=a|0;var b=0,c=0,d=0;a=J[6151];if(a){b=a;c=J[6152];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6151];}J[6152]=a;$a(b);}}function oh(a){a=a|0;var b=0,c=0,d=0;a=J[6055];if(a){b=a;c=J[6056];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6055];}J[6056]=a;$a(b);}}function nn(a){a=a|0;var b=0,c=0,d=0;a=J[6157];if(a){b=a;c=J[6158];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6157];}J[6158]=a;$a(b);}}function nh(a){a=a|0;var b=0,c=0,d=0;a=J[6061];if(a){b=a;c=J[6062];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6061];}J[6062]=a;$a(b);}}function mn(a){a=a|0;var b=0,c=0,d=0;a=J[6163];if(a){b=a;c=J[6164];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6163];}J[6164]=a;$a(b);}}function mh(a){a=a|0;var b=0,c=0,d=0;a=J[6067];if(a){b=a;c=J[6068];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6067];}J[6068]=a;$a(b);}}function ln(a){a=a|0;var b=0,c=0,d=0;a=J[6169];if(a){b=a;c=J[6170];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6169];}J[6170]=a;$a(b);}}function lh(a){a=a|0;var b=0,c=0,d=0;a=J[6073];if(a){b=a;c=J[6074];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6073];}J[6074]=a;$a(b);}}function kn(a){a=a|0;var b=0,c=0,d=0;a=J[6175];if(a){b=a;c=J[6176];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6175];}J[6176]=a;$a(b);}}function ci(a){a=a|0;var b=0,c=0,d=0;a=J[6025];if(a){b=a;c=J[6026];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6025];}J[6026]=a;$a(b);}}function Zh(a){a=a|0;var b=0,c=0,d=0;a=J[6031];if(a){b=a;c=J[6032];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6031];}J[6032]=a;$a(b);}}function Rn(a){a=a|0;var b=0,c=0,d=0;a=J[6081];if(a){b=a;c=J[6082];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6081];}J[6082]=a;$a(b);}}function Qh(a){a=a|0;var b=0,c=0,d=0;a=J[6037];if(a){b=a;c=J[6038];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6037];}J[6038]=a;$a(b);}}function On(a){a=a|0;var b=0,c=0,d=0;a=J[6085];if(a){b=a;c=J[6086];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6085];}J[6086]=a;$a(b);}}function Nn(a){a=a|0;var b=0,c=0,d=0;a=J[6089];if(a){b=a;c=J[6090];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6089];}J[6090]=a;$a(b);}}function Mn(a){a=a|0;var b=0,c=0,d=0;a=J[6093];if(a){b=a;c=J[6094];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6093];}J[6094]=a;$a(b);}}function Ln(a){a=a|0;var b=0,c=0,d=0;a=J[6097];if(a){b=a;c=J[6098];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6097];}J[6098]=a;$a(b);}}function Kn(a){a=a|0;var b=0,c=0,d=0;a=J[6101];if(a){b=a;c=J[6102];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6101];}J[6102]=a;$a(b);}}function Jn(a){a=a|0;var b=0,c=0,d=0;a=J[6105];if(a){b=a;c=J[6106];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6105];}J[6106]=a;$a(b);}}function Jh(a){a=a|0;var b=0,c=0,d=0;a=J[6043];if(a){b=a;c=J[6044];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6043];}J[6044]=a;$a(b);}}function Jg(a){var b=0,c=0,d=0;d=J[a>>2];while(1){c=H[d|0];if(c-48>>>0<10){d=d+1|0;J[a>>2]=d;if(b>>>0<=214748364){c=c-48|0;b=P(b,10);b=(c|0)>(b^2147483647)?-1:c+b|0;}else {b=-1;}continue}break}return b}function In(a){a=a|0;var b=0,c=0,d=0;a=J[6109];if(a){b=a;c=J[6110];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6109];}J[6110]=a;$a(b);}}function Hn(a){a=a|0;var b=0,c=0,d=0;a=J[6113];if(a){b=a;c=J[6114];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6113];}J[6114]=a;$a(b);}}function Gn(a){a=a|0;var b=0,c=0,d=0;a=J[6117];if(a){b=a;c=J[6118];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6117];}J[6118]=a;$a(b);}}function Fn(a){a=a|0;var b=0,c=0,d=0;a=J[6121];if(a){b=a;c=J[6122];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6121];}J[6122]=a;$a(b);}}function En(a){a=a|0;var b=0,c=0,d=0;a=J[6125];if(a){b=a;c=J[6126];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6125];}J[6126]=a;$a(b);}}function Dn(a){a=a|0;var b=0,c=0,d=0;a=J[6129];if(a){b=a;c=J[6130];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6129];}J[6130]=a;$a(b);}}function Cn(a){a=a|0;var b=0,c=0,d=0;a=J[6133];if(a){b=a;c=J[6134];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6133];}J[6134]=a;$a(b);}}function Bn(a){a=a|0;var b=0,c=0,d=0;a=J[6137];if(a){b=a;c=J[6138];if((c|0)!=(a|0)){while(1){b=c-12|0;d=J[b>>2];if(d){J[c-8>>2]=d;$a(d);}c=b;if((c|0)!=(a|0)){continue}break}b=J[6137];}J[6138]=a;$a(b);}}function Wg(a){var b=0,c=0;a:{if(K[a+12|0]){break a}b=J[J[a+8>>2]>>2];c=J[J[a+4>>2]>>2];if((b|0)==(c|0)){break a}while(1){a=b-12|0;if(H[b-1|0]<0){$a(J[a>>2]);}b=a;if((a|0)!=(c|0)){continue}break}}}function lc(a,b){var c=0;b=pb(b);c=J[a+12>>2];a=J[a+8>>2];if(b>>>0>2>>>0){c=J[a+(b<<2)>>2]!=0;}else {c=0;}if(!c){a=Rb(4);J[a>>2]=22892;J[a>>2]=22736;na(a|0,22872,173);B();}return J[a+(b<<2)>>2]}function rb(a){var b=0,c=0,d=0;b=J[a>>2];if(b){c=b;d=J[a+4>>2];if((b|0)!=(d|0)){while(1){c=d-12|0;if(H[d-1|0]<0){$a(J[c>>2]);}d=c;if((d|0)!=(b|0)){continue}break}c=J[a>>2];}J[a+4>>2]=b;$a(c);}}function gg(a,b,c,d){a:{if(!a){break a}b:{switch(b+2|0){case 0:H[a|0]=c;return;case 1:I[a>>1]=c;return;case 2:case 3:J[a>>2]=c;return;case 5:break b;default:break a}}J[a>>2]=c;J[a+4>>2]=d;}}function Be(a){var b=0;b=J[a+72>>2];J[a+72>>2]=b-1|b;b=J[a>>2];if(b&8){J[a>>2]=b|32;return -1}J[a+4>>2]=0;J[a+8>>2]=0;b=J[a+44>>2];J[a+28>>2]=b;J[a+20>>2]=b;J[a+16>>2]=b+J[a+48>>2];return 0}function he(a,b,c,d,e,f,g,h,i){var j=0;j=Ua-16|0;Ua=j;Hb(j,b,c,d,e,f,g,h,i^-2147483648);d=J[j>>2];c=J[j+4>>2];b=J[j+12>>2];J[a+8>>2]=J[j+8>>2];J[a+12>>2]=b;J[a>>2]=d;J[a+4>>2]=c;Ua=j+16|0;}function cb(a){a=a|0;var b=0;a=a>>>0<=1?1:a;a:{while(1){b=sb(a);if(b){break a}b=J[6704];if(b){Xa[b|0]();continue}break}a=Rb(4);J[a>>2]=22892;J[a>>2]=22364;na(a|0,22448,5);B();}return b|0}function Uc(a,b){var c=0,d=0;c=K[a|0];d=K[b|0];a:{if(!c|(c|0)!=(d|0)){break a}while(1){d=K[b+1|0];c=K[a+1|0];if(!c){break a}b=b+1|0;a=a+1|0;if((c|0)==(d|0)){continue}break}}return c-d|0}function Pl(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;e=J[a+84>>2];d=c+256|0;f=Zb(e,0,d);d=f?f-e|0:d;c=c>>>0>d>>>0?d:c;fb(b,e,c);b=e+d|0;J[a+84>>2]=b;J[a+8>>2]=b;J[a+4>>2]=c+e;return c|0}function Pk(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0;g=Ua-16|0;Ua=g;J[g+8>>2]=624576549;J[g+12>>2]=1394948685;h=a;a=g+16|0;b=kc(h,b,c,d,e,f,g+8|0,a);Ua=a;return b|0}function xi(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;while(1){if((b|0)!=(c|0)){a=J[b>>2];if(a>>>0<=127){a=J[(a<<2)+12736>>2];}else {a=0;}J[d>>2]=a;d=d+4|0;b=b+4|0;continue}break}return c|0}function rg(a){var b=0,c=0;b=J[a>>2];if(b){c=J[b+12>>2];a:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break a}b=J[c>>2];}if((b|0)!=-1){return !J[a>>2]}J[a>>2]=0;}return 1}function xg(a){var b=0,c=0;b=J[a>>2];if(b){c=J[b+12>>2];a:{if((c|0)==J[b+16>>2]){b=Xa[J[J[b>>2]+36>>2]](b)|0;break a}b=K[c|0];}if((b|0)!=-1){return !J[a>>2]}J[a>>2]=0;}return 1}function Ug(a){var b=0,c=0,d=0;b=J[a>>2];if(b){d=b;c=J[a+4>>2];if((c|0)!=(b|0)){while(1){c=c-12|0;Db(J[c+4>>2]);if((b|0)!=(c|0)){continue}break}d=J[a>>2];}J[a+4>>2]=b;$a(d);}}function Nm(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;d=cb(104);J[5996]=0;b=ba(147,d|0,b|0,c|0)|0;c=J[5996];J[5996]=0;if((c|0)==1){a=Z()|0;$a(d);da(a|0);B();}J[a+4>>2]=b;J[a>>2]=b+12;}function ui(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;a:{while(1){if((c|0)==(d|0)){break a}a=J[c>>2];if(!(a>>>0>127|!(J[(a<<2)+12736>>2]&b))){c=c+4|0;continue}break}d=c;}return d|0}function vi(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;while(1){a:{if((c|0)!=(d|0)){a=J[c>>2];if(a>>>0>127|!(J[(a<<2)+12736>>2]&b)){break a}}else {c=d;}return c|0}c=c+4|0;continue}}function Ci(a){a=a|0;var b=0,c=0;b=Ua-16|0;Ua=b;c=J[Xb(b+12|0,J[a+8>>2])>>2];if(c){J[6178]=(c|0)==-1?24816:c;}Ua=b+16|0;a=J[a+8>>2];if(!a){return 1}return (Le(a)|0)==1|0}function yd(a){var b=0,c=0;if(a){yd(J[a>>2]);yd(J[a+4>>2]);b=J[a+28>>2];a:{if(!b){break a}c=J[b+4>>2];J[b+4>>2]=c-1;if(c){break a}Xa[J[J[b>>2]+8>>2]](b);bb(b);}$a(a);}}function wj(a){a=a|0;var b=0,c=0;b=Ua-16|0;Ua=b;if(_e()>>>0<=29){nb();B();}Ze(b+8|0,a+16|0,30);c=J[b+8>>2];J[a+4>>2]=c;J[a>>2]=c;J[a+8>>2]=(J[b+12>>2]<<2)+c;Ua=b+16|0;}function Oc(a){var b=0,c=0,d=0;b=J[a>>2];if(b){d=b;c=J[a+4>>2];if((c|0)!=(b|0)){while(1){c=Fb(c-56|0);if((c|0)!=(b|0)){continue}break}d=J[a>>2];}J[a+4>>2]=b;$a(d);}}function kh(a){a=a|0;var b=0,c=0;a=J[6076];if(a){c=a;b=J[6077];if((b|0)!=(a|0)){while(1){b=b-4|0;ad(b);if((a|0)!=(b|0)){continue}break}c=J[6076];}J[6077]=a;$a(c);}}function Dh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;d=Ua-16|0;Ua=d;J[d+12>>2]=J[c>>2];a=Xa[J[J[a>>2]+16>>2]](a,b,d+12|0)|0;if(a){J[c>>2]=J[d+12>>2];}Ua=d+16|0;return a|0}function Il(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;a=0;while(1){if((b|0)!=(c|0)){a=J[b>>2]+(a<<4)|0;d=a&-268435456;a=(d|d>>>24)^a;b=b+4|0;continue}break}return a|0}function zi(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;a=Ua-16|0;Ua=a;J[a+12>>2]=e;J[a+8>>2]=d-c;Ua=a+16|0;b=a+8|0;a=a+12|0;return J[(M[b>>2]>2]?b:a)>>2]}function yb(a,b,c,d,e){var f=0;f=Ua-16|0;Ua=f;J[f+12>>2]=e;c=Xb(f+8|0,c);b=pd(a,b,d,J[f+12>>2]);a=J[c>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=f+16|0;return b}function Ll(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;a=0;while(1){if((b|0)!=(c|0)){a=H[b|0]+(a<<4)|0;d=a&-268435456;a=(d|d>>>24)^a;b=b+1|0;continue}break}return a|0}function Mm(a,b){a=a|0;b=b|0;var c=0;c=J[a+4>>2];if(c>>>0>2]){J[c>>2]=J[b>>2];J[c+4>>2]=J[b+4>>2];J[b>>2]=0;J[b+4>>2]=0;J[a+4>>2]=c+8;return}re(a,b);}function tb(a,b){var c=0;c=J[a>>2];J[a>>2]=b;a:{if(c){a=J[a+4>>2];J[5996]=0;ha(a|0,c|0);a=J[5996];J[5996]=0;if((a|0)==1){break a}}return}fa(0)|0;Vb();B();}function Kf(a,b,c){var d=0;d=Ua-16|0;Ua=d;J[d+12>>2]=c;b=Xb(d+8|0,b);c=fg(a,1937,J[d+12>>2]);a=J[b>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=d+16|0;return c}function si(a,b,c){a=a|0;b=b|0;c=c|0;while(1){if((b|0)!=(c|0)){a=J[b>>2];if(a>>>0<=127){a=J[(a<<2)+11184>>2];}J[b>>2]=a;b=b+4|0;continue}break}return c|0}function yg(a){var b=0,c=0;J[5996]=0;c=Ca(168)|0;b=J[5996];J[5996]=0;if((b|0)!=1){b=a;a=J[c>>2];J[b>>2]=a;J[a+4>>2]=J[a+4>>2]+1;return}fa(0)|0;Vb();B();}function qi(a,b,c){a=a|0;b=b|0;c=c|0;while(1){if((b|0)!=(c|0)){a=J[b>>2];if(a>>>0<=127){a=J[(a<<2)+9648>>2];}J[b>>2]=a;b=b+4|0;continue}break}return c|0}function qc(a){var b=0,c=0,d=0;b=Ua-16|0;Ua=b;c=K[a+11|0];d=(c&128)>>>7|0;J[b+12>>2]=(d?J[a>>2]:a)+((d?J[a+4>>2]:c&127)<<2);Ua=b+16|0;return J[b+12>>2]}function ni(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;while(1){if((b|0)!=(c|0)){a=J[b>>2];H[e|0]=a>>>0<128?a:d;e=e+1|0;b=b+4|0;continue}break}return c|0}function Og(a,b){var c=0,d=0;c=J[b>>2];J[c+4>>2]=J[c+4>>2]+1;c=J[a>>2];d=J[c+4>>2]-1|0;J[c+4>>2]=d;if((d|0)==-1){Xa[J[J[c>>2]+8>>2]](c);}J[a>>2]=J[b>>2];}function md(a,b){var c=0;a:{if((a|0)==(b|0)){break a}while(1){b=b-4|0;if(b>>>0<=a>>>0){break a}c=J[a>>2];J[a>>2]=J[b>>2];J[b>>2]=c;a=a+4|0;continue}}}function Wh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;d=Ua-16|0;Ua=d;Xa[J[J[a>>2]+12>>2]](d+8|0,a,b);Ua=d+16|0;return J[d+12>>2]==J[c+4>>2]&J[d+8>>2]==J[c>>2]}function xf(a){a=a|0;var b=0,c=0;b=Rb(8);J[5996]=0;a=_(91,b|0,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){na(a|0,22664,92);B();}a=Z()|0;ic(b);da(a|0);B();}function ji(a,b,c){a=a|0;b=b|0;c=c|0;while(1){if((b|0)!=(c|0)){a=H[b|0];if((a|0)>=0){a=J[(a<<2)+11184>>2];}H[b|0]=a;b=b+1|0;continue}break}return c|0}function ei(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;while(1){if((b|0)!=(c|0)){a=H[b|0];H[e|0]=(a|0)<0?d:a;e=e+1|0;b=b+1|0;continue}break}return c|0}function hi(a,b,c){a=a|0;b=b|0;c=c|0;while(1){if((b|0)!=(c|0)){a=H[b|0];if((a|0)>=0){a=J[(a<<2)+9648>>2];}H[b|0]=a;b=b+1|0;continue}break}return c|0}function Nh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(Jb(a,J[b+8>>2],f)){Hd(b,c,d,e);return}a=J[a+8>>2];Xa[J[J[a>>2]+20>>2]](a,b,c,d,e,f);}function sc(a){var b=0,c=0,d=0;b=Ua-16|0;Ua=b;c=K[a+11|0];d=(c&128)>>>7|0;J[b+12>>2]=(d?J[a>>2]:a)+(d?J[a+4>>2]:c&127);Ua=b+16|0;return J[b+12>>2]}function Rl(a,b){a=a|0;b=b|0;var c=0,d=0;c=J[a+40>>2];while(1){if(c){c=c-1|0;d=c<<2;Xa[J[J[a+32>>2]+d>>2]](b,a,J[d+J[a+36>>2]>>2]);continue}break}}function vc(a,b){var c=0;a:{if((a|0)==(b|0)){break a}while(1){b=b-1|0;if(b>>>0<=a>>>0){break a}c=K[a|0];H[a|0]=K[b|0];H[b|0]=c;a=a+1|0;continue}}}function _e(){var a=0,b=0;a=Ua-16|0;Ua=a;J[a+12>>2]=1073741823;J[a+8>>2]=2147483647;Ua=a+16|0;b=a+8|0;a=a+12|0;return J[(M[b>>2]>2]?b:a)>>2]}function ac(a,b){var c=0;if((K[a+11|0]&128)>>>7|0){$a(J[a>>2]);}c=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=c;J[a+8>>2]=J[b+8>>2];H[b+11|0]=0;J[b>>2]=0;}function Ud(a,b){var c=0;if(!((K[b+11|0]&128)>>>7|0)){c=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=c;J[a+8>>2]=J[b+8>>2];return}Zc(a,J[b>>2],J[b+4>>2]);}function rj(a){if(K[25164]){return J[6290]}if(!K[26312]){H[26312]=1;}ib(26288,19200);ib(26300,19212);H[25164]=1;J[6290]=26288;return 26288}function Ab(a,b){var c=0;if((K[a+11|0]&128)>>>7|0){$a(J[a>>2]);}c=J[b+4>>2];J[a>>2]=J[b>>2];J[a+4>>2]=c;J[a+8>>2]=J[b+8>>2];H[b+11|0]=0;H[b|0]=0;}function ue(){var a=0,b=0,c=0;b=Rb(8);J[5996]=0;a=$(125,b|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){na(a|0,22632,7);B();}a=Z()|0;ic(b);da(a|0);B();}function dj(a){if(K[25156]){return J[6288]}if(!K[26280]){H[26280]=1;}hb(26256,3116);hb(26268,3113);H[25156]=1;J[6288]=26256;return 26256}function If(a){var b=0,c=0;b=Rb(8);J[5996]=0;a=_(6,b|0,a|0)|0;c=J[5996];J[5996]=0;if((c|0)!=1){na(a|0,22580,7);B();}a=Z()|0;ic(b);da(a|0);B();}function Ee(a,b,c,d,e){var f=0;f=c;c=0;a:{if(!d){break a}c=b>>8;if(!(b&1)){break a}c=J[c+J[d>>2]>>2];}Xa[J[J[a>>2]+28>>2]](a,f,c+d|0,b&2?e:2);}function og(a,b,c){var d=0;d=Ua-16|0;Ua=d;H[d+15|0]=c;c=a;while(1){if(b){H[c|0]=K[d+15|0];b=b-1|0;c=c+1|0;continue}break}Ua=d+16|0;return a}function Le(a){var b=0,c=0;b=Ua-16|0;Ua=b;a=Xb(b+12|0,a);c=J[J[6178]>>2]?4:1;a=J[a>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=b+16|0;return c}function vg(a,b){var c=0;c=J[a+24>>2];if((c|0)==J[a+28>>2]){return Xa[J[J[a>>2]+52>>2]](a,b&255)|0}J[a+24>>2]=c+1;H[c|0]=b;return b&255}function Me(a,b,c,d,e){var f=0;f=Ua-16|0;Ua=f;e=Xb(f+12|0,e);b=qd(a,b,c,d);a=J[e>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=f+16|0;return b}function Qc(a){a=a|0;var b=0,c=0;J[a>>2]=7896;b=J[a+4>>2];c=J[b+4>>2]-1|0;J[b+4>>2]=c;if((c|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}return a|0}function bi(){var a=0;if(K[25032]){return J[6257]}a=J[Pg()>>2];J[6256]=a;J[a+4>>2]=J[a+4>>2]+1;H[25032]=1;J[6257]=25024;return 25024}function nl(a){if(H[24063]<0){$a(J[6013]);}if(H[24051]<0){$a(J[6010]);}if(H[24039]<0){$a(J[6007]);}if(H[24027]<0){$a(J[6004]);}}function mm(a){a=a|0;var b=0;b=J[a+12>>2];a:{if((b|0)==J[a+16>>2]){a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}a=K[b|0];}return a<<24>>24}function pi(a,b,c,d){b=b|0;c=c|0;d=d|0;while(1){if((b|0)!=(c|0)){J[d>>2]=H[b|0];d=d+4|0;b=b+1|0;continue}break}return c|0}function gd(a){a=a|0;J[a+56>>2]=8316;J[a>>2]=8296;J[a+4>>2]=7960;if(H[a+47|0]<0){$a(J[a+36>>2]);}Qc(a+4|0);Od(a+56|0);return a|0}function Md(a,b,c){var d=0;d=Ua-16|0;Ua=d;c=Xb(d+12|0,c);b=pe(a,b);a=J[c>>2];if(a){J[6178]=(a|0)==-1?24816:a;}Ua=d+16|0;return b}function Df(a,b,c,d,e,f){a=Xa[J[J[a+8>>2]+4>>2]](a+8|0)|0;a=nd(c,d,a,a+288|0,f,e,0)-a|0;if((a|0)<=287){J[b>>2]=((a|0)/12|0)%12;}}function Af(a,b,c,d,e,f){a=Xa[J[J[a+8>>2]+4>>2]](a+8|0)|0;a=ld(c,d,a,a+288|0,f,e,0)-a|0;if((a|0)<=287){J[b>>2]=((a|0)/12|0)%12;}}function um(a){a=a|0;var b=0;if((Xa[J[J[a>>2]+36>>2]](a)|0)!=-1){b=a;a=J[a+12>>2];J[b+12>>2]=a+1;a=K[a|0];}else {a=-1;}return a|0}function gi(a,b,c,d){b=b|0;c=c|0;d=d|0;while(1){if((b|0)!=(c|0)){H[d|0]=K[b|0];d=d+1|0;b=b+1|0;continue}break}return c|0}function bb(a){var b=0,c=0;a:{b=a+8|0;if(J[b>>2]){c=b;b=J[b>>2]-1|0;J[c>>2]=b;if((b|0)!=-1){break a}}Xa[J[J[a>>2]+16>>2]](a);}}function Lh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(Jb(a,J[b+8>>2],0)){Gd(b,c,d);return}a=J[a+8>>2];Xa[J[J[a>>2]+28>>2]](a,b,c,d);}function Ef(a,b,c,d,e,f){a=Xa[J[J[a+8>>2]>>2]](a+8|0)|0;a=nd(c,d,a,a+168|0,f,e,0)-a|0;if((a|0)<=167){J[b>>2]=((a|0)/12|0)%7;}}function Bf(a,b,c,d,e,f){a=Xa[J[J[a+8>>2]>>2]](a+8|0)|0;a=ld(c,d,a,a+168|0,f,e,0)-a|0;if((a|0)<=167){J[b>>2]=((a|0)/12|0)%7;}}function me(a,b,c,d){var e=0,f=0;e=Ua-16|0;Ua=e;f=b;b=c-b|0;J[e+12>>2]=eb(d,f,b)+b;J[a>>2]=c;J[a+4>>2]=J[e+12>>2];Ua=e+16|0;}function dm(a){a=a|0;var b=0;b=J[a+12>>2];a:{if((b|0)==J[a+16>>2]){a=Xa[J[J[a>>2]+36>>2]](a)|0;break a}a=J[b>>2];}return a|0}function mb(a){var b=0;a:{a=J[a+4>>2];if(!a){break a}b=J[a+4>>2];J[a+4>>2]=b-1;if(b){break a}Xa[J[J[a>>2]+8>>2]](a);bb(a);}}function Th(a,b){a=a|0;b=b|0;var c=0;c=a;a=K[b+11|0];return ve(c,(a&128)>>>7|0?J[b>>2]:b,(a&128)>>>7|0?J[b+4>>2]:a&127)|0}function qg(a){var b=0;b=J[a+12>>2];if((b|0)==J[a+16>>2]){return Xa[J[J[a>>2]+40>>2]](a)|0}J[a+12>>2]=b+4;return J[b>>2]}function wg(a){var b=0;b=J[a+12>>2];if((b|0)==J[a+16>>2]){return Xa[J[J[a>>2]+40>>2]](a)|0}J[a+12>>2]=b+1;return K[b|0]}function Fg(a,b){a=a|0;b=b|0;var c=0;c=b;b=J[b>>2]+7&-8;J[c>>2]=b+16;O[a>>3]=ge(J[b>>2],J[b+4>>2],J[b+8>>2],J[b+12>>2]);}function be(a,b,c){c=c&255;while(1){a:{if((a|0)!=(b|0)){if((c|0)!=K[a|0]){break a}}else {a=b;}return a}a=a+1|0;continue}}function El(a){a=a|0;var b=0,c=0;c=J[a+4>>2];b=J[a>>2];a=J[a+8>>2];b=b+(a>>1)|0;if(a&1){c=J[c+J[b>>2]>>2];}Xa[c|0](b);}function kg(a,b,c,d,e,f,g,h,i){J[a>>2]=b;J[a+4>>2]=c;J[a+8>>2]=d;J[a+12>>2]=e&65535|(i>>>16&32768|e>>>16&32767)<<16;}function $e(a){var b=0;b=J[a>>2];J[a>>2]=0;if(b){a=J[b+4>>2]-1|0;J[b+4>>2]=a;if((a|0)==-1){Xa[J[J[b>>2]+8>>2]](b);}}}function sg(a,b){a=a|0;b=b|0;var c=0;c=J[a>>2];a:{if(!c){break a}if((vg(c,b)|0)!=-1){break a}J[a>>2]=0;}return a|0}function Yd(a,b,c){while(1){a:{if((a|0)!=(b|0)){if(J[a>>2]!=(c|0)){break a}}else {a=b;}return a}a=a+4|0;continue}}function Fd(a,b,c,d,e,f,g){var h=0;h=b>>8;if(b&1){h=J[J[e>>2]+h>>2];}Xa[J[J[a>>2]+20>>2]](a,c,d,e+h|0,b&2?f:2,g);}function Ld(a,b){var c=0,d=0;c=Gb(b);d=cb(c+13|0);J[d+8>>2]=0;J[d+4>>2]=c;J[d>>2]=c;J[a>>2]=fb(d+12|0,b,c+1|0);}function Jb(a,b,c){if(!c){return J[a+4>>2]==J[b+4>>2]}if((a|0)==(b|0)){return 1}return !Uc(J[a+4>>2],J[b+4>>2])}function zm(a,b,c,d,e,f){a=a|0;J[a+8>>2]=-1;J[a+12>>2]=-1;J[a>>2]=0;J[a+4>>2]=0;}function _h(a,b){a=a|0;b=b|0;J[a>>2]=22892;J[a>>2]=22500;Ld(a+4|0,(K[b+11|0]&128)>>>7|0?J[b>>2]:b);return a|0}function Rd(a,b){var c=0;c=Ua-16|0;Ua=c;J[c+12>>2]=a;a=c+12|0;J[a>>2]=J[a>>2]+(b<<2);Ua=c+16|0;return J[a>>2]}function zf(a,b,c,d,e){b=bc(b,c,d,e,4);if(!(K[d|0]&4)){J[a>>2]=((b|0)<69?b+2e3|0:(b|0)<100?b+1900|0:b)-1900;}}function Mb(a){var b=0;b=Ua-16|0;Ua=b;J[b+12>>2]=(K[a+11|0]&128)>>>7|0?J[a>>2]:a;Ua=b+16|0;return J[b+12>>2]}function Cf(a,b,c,d,e){b=cc(b,c,d,e,4);if(!(K[d|0]&4)){J[a>>2]=((b|0)<69?b+2e3|0:(b|0)<100?b+1900|0:b)-1900;}}function cd(a,b,c,d,e,f){var g=0;g=b>>8;if(b&1){g=J[J[d>>2]+g>>2];}Xa[J[J[a>>2]+24>>2]](a,c,d+g|0,b&2?e:2,f);}function Ke(a,b,c,d,e,f,g,h){c=c|0;e=e|0;f=f|0;h=h|0;J[e>>2]=c;J[h>>2]=f;return 3}function Td(a,b){var c=0;c=Ua-16|0;Ua=c;J[c+12>>2]=a;a=c+12|0;J[a>>2]=J[a>>2]+b;Ua=c+16|0;return J[a>>2]}function ec(a){a:{a=a&74;if(a){if((a|0)==64){return 8}if((a|0)!=8){break a}return 16}return 0}return 10}function Xb(a,b){var c=0;c=J[6178];if(b){J[6178]=(b|0)==-1?24816:b;}J[a>>2]=(c|0)==24816?-1:c;return a}function Ze(a,b,c){a:{if(!(K[b+120|0]|c>>>0>30)){H[b+120|0]=1;break a}b=$f(c);}J[a+4>>2]=c;J[a>>2]=b;}function af(a,b){J[a+4>>2];J[a+4>>2]=b;}function Yl(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;Xa[J[J[b>>2]+16>>2]](a,b,J[c+8>>2],J[c+12>>2],0,d);}function Mc(a){var b=0;b=J[a+12>>2];if(b){J[a+16>>2]=b;$a(b);}b=J[a>>2];if(b){J[a+4>>2]=b;$a(b);}}function Eh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(Jb(a,J[b+8>>2],f)){Hd(b,c,d,e);}}function xm(a,b,c,d){a=a|0;J[a+8>>2]=-1;J[a+12>>2]=-1;J[a>>2]=0;J[a+4>>2]=0;}function gm(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;return Xa[J[J[a>>2]+24>>2]](a,b,c,d,e)|0}function We(a){var b=0,c=0;c=a;while(1){b=c;c=b+4|0;if(J[b>>2]){continue}break}return b-a>>2}function Je(a){a=a|0;var b=0;J[a>>2]=12684;b=J[a+8>>2];if(!(!b|!K[a+12|0])){$a(b);}return a|0}function Pb(){var a=0;a=Rb(4);J[a>>2]=22892;J[a>>2]=22364;J[a>>2]=22384;na(a|0,22460,5);B();}function sd(a,b,c){a:{if((K[a+11|0]&128)>>>7|0){J[a+4>>2]=c;break a}H[a+11|0]=c;}H[b+c|0]=0;}function od(a,b,c,d){var e=0;e=Ua-16|0;Ua=e;J[e+12>>2]=d;a=pd(a,b,c,d);Ua=e+16|0;return a}function eg(a,b){var c=0;c=Ua-16|0;Ua=c;J[c+12>>2]=b;a=fg(a,2310,b);Ua=c+16|0;return a}function cg(a){if((a|0)!=0&(a|0)!=19324&(a|0)!=19348&(a|0)!=24732&(a|0)!=24756){$a(a);}}function yk(a,b){a=a|0;b=b|0;var c=0;c=wg(J[b>>2]);J[a+4>>2]=J[b>>2];H[a|0]=c<<24>>24;}function wf(a,b){a=a|0;b=b|0;b=Ua-16|0;Ua=b;H[a+11|0]=1;H[og(a,1,45)+1|0]=0;Ua=b+16|0;}function tc(a,b,c){var d=0;d=Ua-16|0;Ua=d;Ag(d+8|0,b,(c<<2)+b|0,a);Ua=d+16|0;return a}function ki(a,b){b=b|0;if((b|0)>=0){b=J[((b&255)<<2)+11184>>2];}return b<<24>>24}function Xn(a){a=a|0;a=J[6144];if(a){J[6145]=a;$a(a);}a=J[6141];if(a){J[6142]=a;$a(a);}}function Bg(a,b,c){var d=0;d=Ua-16|0;Ua=d;Ag(d+8|0,a,b,c);Ua=d+16|0;return J[d+12>>2]}function ii(a,b){b=b|0;if((b|0)>=0){b=J[((b&255)<<2)+9648>>2];}return b<<24>>24}function De(a){var b=0;a=J[a>>2]-12|0;b=J[a+8>>2]-1|0;J[a+8>>2]=b;if((b|0)<0){$a(a);}}function Db(a){if(a){Db(J[a>>2]);Db(J[a+4>>2]);if(H[a+27|0]<0){$a(J[a+16>>2]);}$a(a);}}function ij(a){a=a|0;a=26312;while(1){a=ab(a-12|0);if((a|0)!=26288){continue}break}}function hj(a){a=a|0;a=26240;while(1){a=ab(a-12|0);if((a|0)!=25952){continue}break}}function gj(a){a=a|0;a=25640;while(1){a=ab(a-12|0);if((a|0)!=25472){continue}break}}function Wi(a){a=a|0;a=26280;while(1){a=ab(a-12|0);if((a|0)!=26256){continue}break}}function Vi(a){a=a|0;a=25936;while(1){a=ab(a-12|0);if((a|0)!=25648){continue}break}}function Ui(a){a=a|0;a=25464;while(1){a=ab(a-12|0);if((a|0)!=25296){continue}break}}function Ne(a){a=a|0;J[a>>2]=13768;if(J[a+8>>2]!=(jb()|0)){cg(J[a+8>>2]);}return a|0}function rf(a,b){var c=0;c=J[b>>2];J[b>>2]=0;tb(a,c);J[a+4>>2]=J[b+4>>2];return a}function cf(a){var b=0;b=J[a>>2];if(J[b>>2]){df(b);a=J[a>>2];bf(a+16|0,J[a>>2]);}}function yi(a,b,c){b=b|0;c=c|0;return (J[(c<<2)+12736>>2]&b)!=0&c>>>0<=127}function uh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;Xa[a|0](b,c,d,e,f);}function Vd(a,b){a=a|0;b=b|0;J[a>>2]=22892;J[a>>2]=22480;Ld(a+4|0,b);return a|0}function Tg(a,b){a=a|0;b=b|0;J[a>>2]=22892;J[a>>2]=22500;Ld(a+4|0,b);return a|0}function th(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;return Xa[a|0](b,c,d,e)|0}function rk(a,b){a=a|0;b=b|0;var c=0;c=qg(J[b>>2]);J[a+4>>2]=J[b>>2];J[a>>2]=c;}function Yj(){J[6593]=0;J[6592]=22008;J[6592]=14144;J[6592]=13768;J[6594]=jb();}function fo(a){var b=0;while(1){if(a){a=a-1&a;b=b+1|0;continue}break}return b}function ce(){var a=0;a=Rb(4);J[a>>2]=22892;J[a>>2]=22364;na(a|0,22448,5);B();}function Kh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(Jb(a,J[b+8>>2],0)){Gd(b,c,d);}}function Kd(a,b){var c=0;c=a;a=(b>>>0)/100|0;return uc(uc(c,a),P(a,-100)+b|0)}function Jd(a,b){var c=0;c=a;a=(b>>>0)/1e4|0;return Kd(uc(c,a),P(a,-1e4)+b|0)}function Id(a,b){var c=0;c=a;a=(b>>>0)/1e6|0;return Jd(uc(c,a),P(a,-1e6)+b|0)}function yl(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;Xa[J[J[a>>2]+32>>2]](a,b,c,d)|0;}function rl(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;Xa[J[J[a>>2]+48>>2]](a,b,c,d)|0;}function gf(a){var b=0,c=0;b=Ua-16|0;Ua=b;c=b+12|0;J[c>>2]=a;cf(c);Ua=b+16|0;}function ti(a,b){b=b|0;if(b>>>0<=127){b=J[(b<<2)+11184>>2];}return b|0}function Vh(a,b,c){a=a|0;b=b|0;c=c|0;return J[b+4>>2]==(a|0)&J[b>>2]==(c|0)}function Cj(){J[6651]=0;J[6650]=22008;J[6650]=14144;Ye(26608);J[6650]=16704;}function Aj(){J[6655]=0;J[6654]=22008;J[6654]=14144;Ye(26624);J[6654]=16860;}function ri(a,b){b=b|0;if(b>>>0<=127){b=J[(b<<2)+9648>>2];}return b|0}function qj(a){if(!K[25260]){zc(25248,14004);H[25260]=1;}return 25248}function oj(a){if(!K[25292]){zc(25280,14088);H[25292]=1;}return 25280}function mj(a){if(!K[25196]){zc(25184,13932);H[25196]=1;}return 25184}function kj(a){if(!K[25228]){zc(25216,13968);H[25228]=1;}return 25216}function fm(a,b,c){a=a|0;b=b|0;c=c|0;return Xa[J[J[a>>2]+12>>2]](a,b,c)|0}function cm(a,b,c){a=a|0;b=b|0;c=c|0;return Xa[J[J[a>>2]+48>>2]](a,b,c)|0}function cj(a){if(!K[25244]){Kb(25232,2743);H[25244]=1;}return 25232}function aj(a){if(!K[25276]){Kb(25264,1928);H[25276]=1;}return 25264}function _i(a){if(!K[25180]){Kb(25168,1139);H[25180]=1;}return 25168}function Yi(a){if(!K[25212]){Kb(25200,2881);H[25212]=1;}return 25200}function Pc(a,b,c,d,e){c=c|0;e=e|0;J[e>>2]=c;return 3}function pc(a,b){a=a|0;H[a|0]=2;H[a+1|0]=3;H[a+2|0]=0;H[a+3|0]=4;}function om(a){a=a|0;J[a+16>>2]=J[a+16>>2]|1;if(H[a+20|0]&1){Aa();B();}}function vh(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;Xa[a|0](b,c,d,e);}function Pd(a){a=a|0;if(J[a+8>>2]!=(jb()|0)){cg(J[a+8>>2]);}return a|0}function xh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;return Xa[a|0](b,c,d)|0}function dk(a,b,c,d,e,f){a=a|0;f=f|0;Ud(a,f);}function wc(a,b){return b?a<<24|(a&65280)<<8|(a>>>8&65280|a>>>24):a}function oi(a,b,c){b=b|0;c=c|0;return (b>>>0<128?b:c)<<24>>24}function Gc(a,b){a=a|0;b=b|0;var c=0;c=cb(b);J[a+4>>2]=b;J[a>>2]=c;}function bf(a,b){a:{if((a|0)==(b|0)){H[b+120|0]=0;break a}$a(b);}}function Fl(a){a=a|0;var b=0;b=J[6259]+1|0;J[6259]=b;J[a+4>>2]=b;}function tg(a,b){a=a|0;b=b|0;return Xa[J[J[a>>2]+28>>2]](a,b)|0}function Xk(a,b){a=a|0;b=b|0;a=Vd(a,b);J[a>>2]=22548;return a|0}function Vl(a,b){a=a|0;b=b|0;return Xa[J[J[a>>2]+44>>2]](a,b)|0}function Gl(a,b){a=a|0;b=b|0;return Xa[J[J[a>>2]+12>>2]](a,b)|0}function Ch(a){a=a|0;if(!a){return 0}return (Fe(a,22200)|0)!=0|0}function Ai(a){a=a|0;a=J[a+8>>2];if(!a){return 1}return Le(a)|0}function em(a,b){a=a|0;b=b|0;if(!J[5996]){J[5996]=a;J[5997]=b;}}function Qb(a,b){a=a|0;J[a>>2]=0;J[a+4>>2]=0;J[a+8>>2]=0;}function ab(a){if((K[a+11|0]&128)>>>7|0){$a(J[a>>2]);}return a}function $f(a){if(a>>>0>=1073741824){Pb();B();}return cb(a<<2)}function wh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;Xa[a|0](b,c,d);}function ng(a){a=a|0;J[a>>2]=7960;ab(a+32|0);return Qc(a)|0}function fi(a,b,c){b=b|0;c=c|0;return ((b|0)<0?c:b)|0}function Xm(a){a=a|0;a=Vd(a,2284);J[a>>2]=22600;return a|0}function Xh(a,b,c){a=a|0;b=b|0;c=c|0;J[a+4>>2]=b;J[a>>2]=c;}function Cm(a){a=a|0;a=Tg(a,1241);J[a>>2]=22684;return a|0}function Ve(a){a=a|0;J[a>>2]=13856;ab(a+16|0);return a|0}function Ue(a){a=a|0;J[a>>2]=13816;ab(a+12|0);return a|0}function we(a){a=a|0;J[a>>2]=22500;De(a+4|0);return a|0}function Ff(a){a=a|0;J[a>>2]=22480;De(a+4|0);return a|0}function uc(a,b){b=(b<<1)+21664|0;return Bg(b,b+2|0,a)}function lm(a){a=a|0;return ke(J[J[a>>2]-12>>2]+a|0)|0}function _f(a,b){a=a|0;b=b|0;Xa[J[J[b>>2]+24>>2]](a,b);}function Zf(a,b){a=a|0;b=b|0;Xa[J[J[b>>2]+28>>2]](a,b);}function Xl(a){a=a|0;return gd(J[J[a>>2]-12>>2]+a|0)|0}function Wf(a,b){a=a|0;b=b|0;Xa[J[J[b>>2]+20>>2]](a,b);}function Sh(a){a=a|0;if(a){a=a-24|0;J[a>>2]=J[a>>2]+1;}}function Ml(a,b,c,d){a=a|0;c=c|0;d=d|0;Ad(a,c,d);}function Jl(a,b,c,d){a=a|0;c=c|0;d=d|0;ag(a,c,d);}function Fc(a,b){var c=0;c=$f(b);J[a+4>>2]=b;J[a>>2]=c;}function qm(a){a=a|0;return Xa[J[J[a>>2]+24>>2]](a)|0}function kf(a,b,c){a=qe(a,b,c,0,-2147483648);return a}function Xf(a){a=a|0;return Xa[J[J[a>>2]+16>>2]](a)|0}function Nf(a){a=a|0;return Xa[J[J[a>>2]+12>>2]](a)|0}function Sg(a,b){a=a|0;b=b|0;return ve(a,b,Gb(b))|0}function Ub(a,b){a=a|0;b=b|0;return xg(a)^xg(b)^1}function Tb(a,b){a=a|0;b=b|0;return rg(a)^rg(b)^1}function wl(a){if(H[24003]<0){$a(J[5998]);}}function jm(a){a=a|0;a=Ua-a&-16;Ua=a;return a|0}function Mg(a,b){if(!a){return 0}return pe(a,b)}function Am(a,b,c){a=a|0;return a|0}function nc(a,b,c){return Oa(18,a|0,b|0,c|0)|0}function lf(a,b,c){return -1}function km(a){a=a|0;ug(J[J[a>>2]-12>>2]+a|0);}function hf(a,b,c){a=qe(a,b,c,-1,-1);return a}function Wl(a){a=a|0;mg(J[J[a>>2]-12>>2]+a|0);}function bd(a,b,c,d){Ma(152,a|0,b|0,c|0,d|0);}function Ae(a,b,c,d){La(155,a|0,b|0,c|0,d|0);}function wn(a){a=a|0;J[a>>2]=7e3;return a|0}function uj(a){a=a|0;Xa[J[J[a>>2]+4>>2]](a);}function Ic(a){a=a|0;wg(J[a>>2]);return a|0}function Hc(a){a=a|0;qg(J[a>>2]);return a|0}function zj(a){a=a|0;qb(a,26616,pb(24916));}function yj(a){a=a|0;qb(a,26632,pb(24988));}function xj(a){a=a|0;qb(a,26640,pb(24996));}function bk(a){a=a|0;qb(a,26320,pb(24844));}function ak(a){a=a|0;qb(a,26328,pb(24852));}function _j(a){a=a|0;qb(a,26352,pb(25040));}function Zj(a){a=a|0;qb(a,26360,pb(25056));}function Xj(a){a=a|0;qb(a,26368,pb(25064));}function Wj(a){a=a|0;qb(a,26384,pb(25072));}function Vj(a){a=a|0;qb(a,26392,pb(25088));}function Uj(a){a=a|0;qb(a,26400,pb(25080));}function Tj(a){a=a|0;qb(a,26408,pb(25096));}function Sj(a){a=a|0;qb(a,26416,pb(25104));}function Rj(a){a=a|0;qb(a,26440,pb(25112));}function Qj(a){a=a|0;qb(a,26472,pb(24860));}function Pj(a){a=a|0;qb(a,26480,pb(24868));}function Oj(a){a=a|0;qb(a,26488,pb(24876));}function Nj(a){a=a|0;qb(a,26496,pb(24884));}function Mj(a){a=a|0;qb(a,26504,pb(24924));}function Lj(a){a=a|0;qb(a,26512,pb(24932));}function Kj(a){a=a|0;qb(a,26520,pb(24940));}function Jj(a){a=a|0;qb(a,26528,pb(24948));}function Ij(a){a=a|0;qb(a,26536,pb(24956));}function Hj(a){a=a|0;qb(a,26544,pb(24964));}function Gj(a){a=a|0;qb(a,26552,pb(24972));}function Fj(a){a=a|0;qb(a,26560,pb(24980));}function Ej(a){a=a|0;qb(a,26568,pb(24892));}function Dj(a){a=a|0;qb(a,26584,pb(24900));}function Bj(a){a=a|0;qb(a,26600,pb(24908));}function $j(a){a=a|0;qb(a,26336,pb(25048));}function le(a){a=a|0;return lc(a,25048)|0}function ke(a){a=a|0;Od(a+4|0);return a|0}function je(a){a=a|0;return lc(a,25040)|0}function im(a){a=a|0;return lc(a,24876)|0}function gc(a,b,c){Bg(b,b+c|0,a);return a}function de(a){a=a|0;return lc(a,25104)|0}function Zd(a){a=a|0;return lc(a,25112)|0}function Qi(a,b){a=a|0;b=b|0;Ud(a,b+16|0);}function Ki(a,b){a=a|0;b=b|0;Ud(a,b+12|0);}function Pi(a,b){a=a|0;zc(a,13888);}function Oi(a,b){a=a|0;zc(a,13908);}function zg(a,b){b=b|0;return b|0}function vf(a,b){a=a|0;Hf(a,1,45);}function ae(a,b,c){a=hf(a,b,c);return a}function Uf(a,b,c){a=kf(a,b,c);return a}function Ji(a,b){a=a|0;Kb(a,2331);}function Ii(a,b){a=a|0;Kb(a,2350);}function id(a){return 2147483647}function Ri(a){a=a|0;return J[a+12>>2]}function sb(a){a=a|0;return _c(8,a)|0}function Si(a){a=a|0;return J[a+8>>2]}function Cg(a,b){return -1}function Ce(a){a=a|0;return J[a+4>>2]}function $h(a,b){return 0}function Mi(a){a=a|0;return H[a+8|0]}function Li(a){a=a|0;return H[a+9|0]}function oc(a,b,c){return eb(a,b,c)}function lg(a){a=a|0;return we(a)|0}function ef(a){if(!K[a+4|0]){cf(a);}}function tf(a){return lc(a,24932)}function sf(a){return lc(a,24924)}function qf(a){return lc(a,24948)}function pf(a){return lc(a,24940)}function zh(a){return 2176}function yh(a){return 1304}function Ul(a){return 2042}function Bh(a){return 1969}function Ah(a){return 2524}function jd(a){return 127}function $b(a){a=a|0;return a|0}function ug(a){a=a|0;$a(ke(a));}function rd(a){a=a|0;$a(we(a));}function pj(a){ab(25248);}function nj(a){ab(25280);}function mi(a){a=a|0;$a(Je(a));}function mg(a){a=a|0;$a(gd(a));}function lj(a){ab(25184);}function jj(a){ab(25216);}function di(a){a=a|0;$a(Ie(a));}function bj(a){ab(25232);}function Zl(a){a=a|0;$a(ng(a));}function Zi(a){ab(25168);}function Xi(a){ab(25200);}function Xe(a){a=a|0;$a(Pd(a));}function Ti(a){a=a|0;$a(Ve(a));}function Ql(a){a=a|0;$a(oe(a));}function Ni(a){a=a|0;$a(Ue(a));}function Hi(a){a=a|0;$a(Ne(a));}function Dd(a){a=a|0;$a(Ff(a));}function Bm(a){a=a|0;$a(Qc(a));}function $i(a){ab(25264);}function vm(a){return -1}function ed(a){return 4}function Qd(a){return 1}function Ib(a){return 0}function Gf(a){return 2}function ne(a,b){}function df(a){af(a,J[a>>2]);}function Ye(a){J[a>>2]=jb();}function ub(){If(2284);B();}function nb(){If(1687);B();}function kb(a){a=a|0;$a(a);}function ym(a){a=a|0;Va=a;}function sm(){return Ua|0}function nm(a){a=a|0;Ua=a;}function ai(a){B();}function db(a){tb(a,0);}function Ph(){Ge();B();}function Ge(){za();B();}function Od(a){oe(a);}function Nd(a){} +// EMSCRIPTEN_END_FUNCS +e=K;p();var Xa=c([null,wl,ub,cb,nl,$b,Xk,Ff,nb,Ei,wi,nb,li,ci,Zh,Qh,Jh,Vd,rh,qh,ph,oh,nh,mh,lh,kh,jh,ih,hh,Bd,Kb,pk,gh,mc,nb,Pb,fh,eh,dh,ch,Zc,nb,bh,un,la,_g,ao,nb,$n,_n,$g,bo,nb,Zn,Wb,Yn,nb,hc,Xn,nb,Wn,Zg,nb,Vn,Un,Tn,Sn,Rn,Qn,Pn,On,Nn,Mn,Ln,Kn,Jn,In,Hn,Gn,Fn,En,Dn,Cn,Bn,nb,nb,An,zn,yn,sh,xn,Tg,we,nb,nb,nb,nb,Sg,rn,qn,ve,pn,sn,on,nn,mn,ln,kn,ue,tn,ra,ze,nb,hn,Lc,Kc,gn,fn,en,an,Yh,nb,dn,nb,Ob,Xm,cn,bn,se,Pg,_m,Zm,Ym,Rl,rm,im,hm,gm,pm,om,Vm,Um,nb,Tm,re,Sm,Rm,Qm,Pm,Om,Nm,Mm,Lm,Km,Ad,Jm,Im,$m,Hm,Gm,Fm,Em,re,Dm,Kc,Gg,Fg,Cm,bi,qm,le,tg,ie,$b,Uh,_h,Sl,lg,Pl,Ol,de,_f,Zf,nd,kb,ce,Ub,mm,Gl,Ic,Fl,El,Aa,Xf,Wf,yl,Nf,je,Zd,_f,Zf,ld,Tb,dm,tg,Hc,Xf,Wf,rl,Nf,sg,gl,bl,Ac,pg,Yk,Vl,cm,Sk,Bc,Nd,Ak,xf,zk,yk,xk,uf,vk,tk,sk,fm,rk,qk,uf,nk,mk,kk,jk,gk,fk,bk,ak,$j,_j,Zj,Yj,Xj,Wj,Vj,Uj,Tj,Sj,Rj,Qj,Pj,Oj,Nj,Mj,Lj,Kj,Jj,Ij,Hj,Gj,Fj,Ej,Dj,Cj,Bj,Aj,zj,yj,xj,wj,vj,gj,hj,ij,pj,nj,lj,jj,Ui,Vi,Wi,bj,$i,Zi,Xi,Gc,Th,Ge,wn,kb,vn,$h,kb,Qc,Bm,ne,Am,zm,xm,Ib,Ib,wm,vm,um,Cg,tm,Cg,ng,Zl,_l,Yl,bm,am,$l,gd,mg,Xl,Wl,ke,ug,lm,km,$b,kb,Ul,Xh,Wh,Vh,Tl,rd,Ce,oe,Ql,Ie,di,uj,Je,mi,ki,ji,ii,hi,zg,gi,fi,ei,Ne,Hi,Gi,Fi,Di,Ci,Ib,Bi,Ai,Ue,Ni,Mi,Li,Ki,Ji,Ii,Ve,Ti,Si,Ri,Qi,Pi,Oi,$b,kb,kb,yi,xi,vi,ui,ti,si,ri,qi,zg,pi,oi,ni,kb,Ke,Ke,Pc,Qd,Qd,zi,Qd,kb,Qe,Pe,Pc,Ib,Ib,Oe,ed,kb,Qe,Pe,Pc,Ib,Ib,Oe,ed,kb,Te,Se,Pc,Ib,Ib,Re,ed,kb,Te,Se,Pc,Ib,Ib,Re,ed,$b,kb,Nl,Ml,Ll,$b,kb,Kl,Jl,Il,kb,Hl,Dl,Cl,Bl,Rf,Rf,Al,zl,xl,vl,ul,kb,tl,sl,ql,pl,Jf,Jf,ol,ml,ll,kl,jl,kb,il,hl,fl,el,dl,cl,al,$k,kb,_k,Zk,Wk,Vk,Uk,Tk,Rk,Qk,$b,kb,Gf,Pk,Ok,Nk,Mk,Lk,Kk,fj,ej,dj,cj,aj,_i,Yi,$b,kb,Gf,Jk,Ik,Hk,Gk,Fk,Ek,tj,sj,rj,qj,oj,mj,kj,Pd,Xe,Dk,Pd,Xe,Ck,kb,jd,jd,Qb,Qb,Qb,wf,Ib,pc,pc,kb,jd,jd,Qb,Qb,Qb,wf,Ib,pc,pc,kb,id,id,Qb,Qb,Qb,vf,Ib,pc,pc,kb,id,id,Qb,Qb,Qb,vf,Ib,pc,pc,kb,Bk,wk,kb,uk,ok,kb,lk,ik,kb,hk,ek,kb,lf,dk,ne,kb,lf,ck,ne,lg,rd,$b,ai,Ph,za,$b,kb,Nd,Nd,Oh,Fh,Hh,Ih,kb,Ah,kb,zh,Dd,Ce,rd,Dd,Dd,rd,kb,yh,kb,Eh,Gh,Kh,kb,Nh,Mh,Lh,kb,Bh]);function Ya(){return G.byteLength/65536|0}return {"Y":ah,"Z":kb,"_":sb,"$":jn,"aa":Wm,"ba":Xa,"ca":em,"da":ym,"ea":sm,"fa":nm,"ga":jm,"ha":Rh,"ia":Sh,"ja":Dh,"ka":Ch,"la":xh,"ma":wh,"na":vh,"oa":vh,"pa":uh,"qa":th}}return Za(_a)} +// EMSCRIPTEN_END_ASM -// (protected) this += n << w words, this >= 0 -function bnpDAddOffset(n, w) { - if (n == 0) return - while (this.t <= w) this[this.t++] = 0 - this[w] += n - while (this[w] >= this.DV) { - this[w] -= this.DV - if (++w >= this.t) this[this.t++] = 0 - ++this[w] - } -} -// A "null" reducer -function NullExp() {} +)(info);},instantiate:function(binary,info){return {then:function(ok){var module=new WebAssembly.Module(binary);ok({"instance":new WebAssembly.Instance(module,info)});}}},RuntimeError:Error};wasmBinary=[];if(typeof WebAssembly!="object"){abort("no native wasm support detected");}var wasmMemory;var ABORT=false;function assert(condition,text){if(!condition){abort(text);}}var HEAP8,HEAPU8,HEAP32,HEAPU32;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=new Float32Array(b);Module["HEAPF64"]=new Float64Array(b);}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;assert(INITIAL_MEMORY>=65536,"INITIAL_MEMORY should be larger than STACK_SIZE, was "+INITIAL_MEMORY+"! (STACK_SIZE="+65536+")");if(Module["wasmMemory"]){wasmMemory=Module["wasmMemory"];}else {wasmMemory=new WebAssembly.Memory({"initial":INITIAL_MEMORY/65536,"maximum":INITIAL_MEMORY/65536});}updateMemoryViews();INITIAL_MEMORY=wasmMemory.buffer.byteLength;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift());}}callRuntimeCallbacks(__ATPRERUN__);}function initRuntime(){callRuntimeCallbacks(__ATINIT__);}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift());}}callRuntimeCallbacks(__ATPOSTRUN__);}function addOnPreRun(cb){__ATPRERUN__.unshift(cb);}function addOnInit(cb){__ATINIT__.unshift(cb);}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb);}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies);}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies);}if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback();}}}function abort(what){if(Module["onAbort"]){Module["onAbort"](what);}what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}var wasmBinaryFile;wasmBinaryFile="bindings.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile);}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}var binary=tryParseAsDataURI(file);if(binary){return binary}throw "sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)"}function instantiateSync(file,info){var module;var binary=getBinarySync(file);module=new WebAssembly.Module(binary);var instance=new WebAssembly.Instance(module,info);return [instance,module]}function createWasm(){var info={"a":wasmImports};function receiveInstance(instance,module){var exports=instance.exports;wasmExports=exports;wasmTable=wasmExports["ba"];addOnInit(wasmExports["Y"]);removeRunDependency();return exports}addRunDependency();if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e);}}var result=instantiateSync(wasmBinaryFile,info);return receiveInstance(result[0])}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module);}};var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;var UTF8ArrayToString=(heapOrArray,idx,maxBytesToRead)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023);}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var ___assert_fail=(condition,filename,line,func)=>{abort(`Assertion failed: ${UTF8ToString(condition)}, at: `+[filename?UTF8ToString(filename):"unknown filename",line,func?UTF8ToString(func):"unknown function"]);};var exceptionCaught=[];var uncaughtExceptionCount=0;var ___cxa_begin_catch=ptr=>{var info=new ExceptionInfo(ptr);if(!info.get_caught()){info.set_caught(true);uncaughtExceptionCount--;}info.set_rethrown(false);exceptionCaught.push(info);___cxa_increment_exception_refcount(info.excPtr);return info.get_exception_ptr()};var exceptionLast=0;var ___cxa_end_catch=()=>{_setThrew(0,0);var info=exceptionCaught.pop();___cxa_decrement_exception_refcount(info.excPtr);exceptionLast=0;};function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type;};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor;};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught;};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown;};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr;};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr};}var ___resumeException=ptr=>{if(!exceptionLast){exceptionLast=ptr;}throw exceptionLast};var findMatchingCatch=args=>{var thrown=exceptionLast;if(!thrown){setTempRet0(0);return 0}var info=new ExceptionInfo(thrown);info.set_adjusted_ptr(thrown);var thrownType=info.get_type();if(!thrownType){setTempRet0(0);return thrown}for(var arg in args){var caughtType=args[arg];if(caughtType===0||caughtType===thrownType){break}var adjusted_ptr_addr=info.ptr+16;if(___cxa_can_catch(caughtType,thrownType,adjusted_ptr_addr)){setTempRet0(caughtType);return thrown}}setTempRet0(thrownType);return thrown};var ___cxa_find_matching_catch_2=()=>findMatchingCatch([]);var ___cxa_find_matching_catch_3=arg0=>findMatchingCatch([arg0]);var ___cxa_find_matching_catch_4=(arg0,arg1)=>findMatchingCatch([arg0,arg1]);var ___cxa_rethrow=()=>{var info=exceptionCaught.pop();if(!info){abort("no exception to throw");}var ptr=info.excPtr;if(!info.get_rethrown()){exceptionCaught.push(info);info.set_rethrown(true);info.set_caught(false);uncaughtExceptionCount++;}exceptionLast=ptr;throw exceptionLast};var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast};var ___cxa_uncaught_exceptions=()=>uncaughtExceptionCount;var _abort=()=>{abort("");};var _emscripten_memcpy_big=(dest,src,num)=>HEAPU8.copyWithin(dest,src,src+num);var abortOnCannotGrowMemory=requestedSize=>{abort("OOM");};var _emscripten_resize_heap=requestedSize=>{HEAPU8.length;abortOnCannotGrowMemory();};var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x];}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`);}getEnvStrings.strings=strings;}return getEnvStrings.strings};var stringToAscii=(str,buffer)=>{for(var i=0;i>0]=str.charCodeAt(i);}HEAP8[buffer>>0]=0;};var _environ_get=(__environ,environ_buf)=>{var bufSize=0;getEnvStrings().forEach((string,i)=>{var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;stringToAscii(string,ptr);bufSize+=string.length+1;});return 0};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(string=>bufSize+=string.length+1);HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var _llvm_eh_typeid_for=type=>type;var isLeapYear=year=>year%4===0&&(year%100!==0||year%400===0);var arraySum=(array,index)=>{var sum=0;for(var i=0;i<=index;sum+=array[i++]){}return sum};var MONTH_DAYS_LEAP=[31,29,31,30,31,30,31,31,30,31,30,31];var MONTH_DAYS_REGULAR=[31,28,31,30,31,30,31,31,30,31,30,31];var addDays=(date,days)=>{var newDate=new Date(date.getTime());while(days>0){var leap=isLeapYear(newDate.getFullYear());var currentMonth=newDate.getMonth();var daysInCurrentMonth=(leap?MONTH_DAYS_LEAP:MONTH_DAYS_REGULAR)[currentMonth];if(days>daysInCurrentMonth-newDate.getDate()){days-=daysInCurrentMonth-newDate.getDate()+1;newDate.setDate(1);if(currentMonth<11){newDate.setMonth(currentMonth+1);}else {newDate.setMonth(0);newDate.setFullYear(newDate.getFullYear()+1);}}else {newDate.setDate(newDate.getDate()+days);return newDate}}return newDate};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i;}else {len+=3;}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023;}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u;}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63;}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;}else {if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;}}heap[outIdx]=0;return outIdx-startIdx};function intArrayFromString(stringy,dontAddNull,length){var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer);};var _strftime=(s,maxsize,format,tm)=>{var tm_zone=HEAPU32[tm+40>>2];var date={tm_sec:HEAP32[tm>>2],tm_min:HEAP32[tm+4>>2],tm_hour:HEAP32[tm+8>>2],tm_mday:HEAP32[tm+12>>2],tm_mon:HEAP32[tm+16>>2],tm_year:HEAP32[tm+20>>2],tm_wday:HEAP32[tm+24>>2],tm_yday:HEAP32[tm+28>>2],tm_isdst:HEAP32[tm+32>>2],tm_gmtoff:HEAP32[tm+36>>2],tm_zone:tm_zone?UTF8ToString(tm_zone):""};var pattern=UTF8ToString(format);var EXPANSION_RULES_1={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var rule in EXPANSION_RULES_1){pattern=pattern.replace(new RegExp(rule,"g"),EXPANSION_RULES_1[rule]);}var WEEKDAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var MONTHS=["January","February","March","April","May","June","July","August","September","October","November","December"];function leadingSomething(value,digits,character){var str=typeof value=="number"?value.toString():value||"";while(str.length0?1:0}var compare;if((compare=sgn(date1.getFullYear()-date2.getFullYear()))===0){if((compare=sgn(date1.getMonth()-date2.getMonth()))===0){compare=sgn(date1.getDate()-date2.getDate());}}return compare}function getFirstWeekStartDate(janFourth){switch(janFourth.getDay()){case 0:return new Date(janFourth.getFullYear()-1,11,29);case 1:return janFourth;case 2:return new Date(janFourth.getFullYear(),0,3);case 3:return new Date(janFourth.getFullYear(),0,2);case 4:return new Date(janFourth.getFullYear(),0,1);case 5:return new Date(janFourth.getFullYear()-1,11,31);case 6:return new Date(janFourth.getFullYear()-1,11,30)}}function getWeekBasedYear(date){var thisDate=addDays(new Date(date.tm_year+1900,0,1),date.tm_yday);var janFourthThisYear=new Date(thisDate.getFullYear(),0,4);var janFourthNextYear=new Date(thisDate.getFullYear()+1,0,4);var firstWeekStartThisYear=getFirstWeekStartDate(janFourthThisYear);var firstWeekStartNextYear=getFirstWeekStartDate(janFourthNextYear);if(compareByDay(firstWeekStartThisYear,thisDate)<=0){if(compareByDay(firstWeekStartNextYear,thisDate)<=0){return thisDate.getFullYear()+1}return thisDate.getFullYear()}return thisDate.getFullYear()-1}var EXPANSION_RULES_2={"%a":date=>WEEKDAYS[date.tm_wday].substring(0,3),"%A":date=>WEEKDAYS[date.tm_wday],"%b":date=>MONTHS[date.tm_mon].substring(0,3),"%B":date=>MONTHS[date.tm_mon],"%C":date=>{var year=date.tm_year+1900;return leadingNulls(year/100|0,2)},"%d":date=>leadingNulls(date.tm_mday,2),"%e":date=>leadingSomething(date.tm_mday,2," "),"%g":date=>getWeekBasedYear(date).toString().substring(2),"%G":date=>getWeekBasedYear(date),"%H":date=>leadingNulls(date.tm_hour,2),"%I":date=>{var twelveHour=date.tm_hour;if(twelveHour==0)twelveHour=12;else if(twelveHour>12)twelveHour-=12;return leadingNulls(twelveHour,2)},"%j":date=>leadingNulls(date.tm_mday+arraySum(isLeapYear(date.tm_year+1900)?MONTH_DAYS_LEAP:MONTH_DAYS_REGULAR,date.tm_mon-1),3),"%m":date=>leadingNulls(date.tm_mon+1,2),"%M":date=>leadingNulls(date.tm_min,2),"%n":()=>"\n","%p":date=>{if(date.tm_hour>=0&&date.tm_hour<12){return "AM"}return "PM"},"%S":date=>leadingNulls(date.tm_sec,2),"%t":()=>"\t","%u":date=>date.tm_wday||7,"%U":date=>{var days=date.tm_yday+7-date.tm_wday;return leadingNulls(Math.floor(days/7),2)},"%V":date=>{var val=Math.floor((date.tm_yday+7-(date.tm_wday+6)%7)/7);if((date.tm_wday+371-date.tm_yday-2)%7<=2){val++;}if(!val){val=52;var dec31=(date.tm_wday+7-date.tm_yday-1)%7;if(dec31==4||dec31==5&&isLeapYear(date.tm_year%400-1)){val++;}}else if(val==53){var jan1=(date.tm_wday+371-date.tm_yday)%7;if(jan1!=4&&(jan1!=3||!isLeapYear(date.tm_year)))val=1;}return leadingNulls(val,2)},"%w":date=>date.tm_wday,"%W":date=>{var days=date.tm_yday+7-(date.tm_wday+6)%7;return leadingNulls(Math.floor(days/7),2)},"%y":date=>(date.tm_year+1900).toString().substring(2),"%Y":date=>date.tm_year+1900,"%z":date=>{var off=date.tm_gmtoff;var ahead=off>=0;off=Math.abs(off)/60;off=off/60*100+off%60;return (ahead?"+":"-")+String("0000"+off).slice(-4)},"%Z":date=>date.tm_zone,"%%":()=>"%"};pattern=pattern.replace(/%%/g,"\0\0");for(var rule in EXPANSION_RULES_2){if(pattern.includes(rule)){pattern=pattern.replace(new RegExp(rule,"g"),EXPANSION_RULES_2[rule](date));}}pattern=pattern.replace(/\0\0/g,"%");var bytes=intArrayFromString(pattern,false);if(bytes.length>maxsize){return 0}writeArrayToMemory(bytes,s);return bytes.length-1};var _strftime_l=(s,maxsize,format,tm,loc)=>_strftime(s,maxsize,format,tm);var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){if(funcPtr>=wasmTableMirror.length)wasmTableMirror.length=funcPtr+1;wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr);}return func};var getCFunc=ident=>{var func=Module["_"+ident];return func};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={"string":str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str);}return ret},"array":arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(ret)}if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i{var numericArgs=!argTypes||argTypes.every(type=>type==="number"||type==="boolean");var numericRet=returnType!=="string";if(numericRet&&numericArgs&&!opts){return getCFunc(ident)}return function(){return ccall(ident,returnType,argTypes,arguments)}};var wasmImports={p:___assert_fail,t:___cxa_begin_catch,v:___cxa_end_catch,b:___cxa_find_matching_catch_2,j:___cxa_find_matching_catch_3,V:___cxa_find_matching_catch_4,E:___cxa_rethrow,r:___cxa_throw,L:___cxa_uncaught_exceptions,h:___resumeException,D:_abort,M:_emscripten_memcpy_big,U:_emscripten_resize_heap,J:_environ_get,K:_environ_sizes_get,G:invoke_i,d:invoke_ii,u:invoke_iiddi,c:invoke_iii,W:invoke_iiid,f:invoke_iiii,C:invoke_iiiid,m:invoke_iiiii,B:invoke_iiiiii,o:invoke_iiiiiii,F:invoke_iiiiiiii,y:invoke_iiiiiiiiiiii,N:invoke_iiij,S:invoke_iij,g:invoke_v,l:invoke_vi,H:invoke_vid,e:invoke_vii,T:invoke_viid,i:invoke_viii,I:invoke_viiidi,k:invoke_viiii,z:invoke_viiiid,n:invoke_viiiidi,s:invoke_viiiii,q:invoke_viiiiiii,w:invoke_viiiiiiiiii,x:invoke_viiiiiiiiiiiiiii,O:invoke_viiij,P:invoke_viij,R:invoke_vij,Q:invoke_viji,A:_llvm_eh_typeid_for,a:wasmMemory,X:_strftime_l};var wasmExports=createWasm();wasmExports["Y"];wasmExports["__errno_location"];wasmExports["__cxa_free_exception"];Module["_free"]=wasmExports["Z"];Module["_malloc"]=wasmExports["_"];Module["_miniscript_compile"]=wasmExports["$"];Module["_miniscript_analyze"]=wasmExports["aa"];var _setThrew=wasmExports["ca"];var setTempRet0=wasmExports["da"];var stackSave=wasmExports["ea"];var stackRestore=wasmExports["fa"];var stackAlloc=wasmExports["ga"];var ___cxa_decrement_exception_refcount=wasmExports["ha"];var ___cxa_increment_exception_refcount=wasmExports["ia"];var ___cxa_can_catch=wasmExports["ja"];var ___cxa_is_pointer_type=wasmExports["ka"];var dynCall_iij=Module["dynCall_iij"]=wasmExports["la"];var dynCall_vij=Module["dynCall_vij"]=wasmExports["ma"];var dynCall_viji=Module["dynCall_viji"]=wasmExports["na"];var dynCall_viij=Module["dynCall_viij"]=wasmExports["oa"];var dynCall_viiij=Module["dynCall_viiij"]=wasmExports["pa"];var dynCall_iiij=Module["dynCall_iiij"]=wasmExports["qa"];function invoke_v(index){var sp=stackSave();try{getWasmTableEntry(index)();}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_ii(index,a1){var sp=stackSave();try{return getWasmTableEntry(index)(a1)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iii(index,a1,a2){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiii(index,a1,a2,a3){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiii(index,a1,a2,a3,a4){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viii(index,a1,a2,a3){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_vii(index,a1,a2){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiid(index,a1,a2,a3,a4){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiid(index,a1,a2,a3){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiii(index,a1,a2,a3,a4){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiddi(index,a1,a2,a3,a4){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiidi(index,a1,a2,a3,a4,a5){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiidi(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiiii(index,a1,a2,a3,a4,a5){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4,a5)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiid(index,a1,a2,a3,a4,a5){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_vid(index,a1,a2){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_i(index){var sp=stackSave();try{return getWasmTableEntry(index)()}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_vi(index,a1){var sp=stackSave();try{getWasmTableEntry(index)(a1);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11){var sp=stackSave();try{return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiiiiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viid(index,a1,a2,a3){var sp=stackSave();try{getWasmTableEntry(index)(a1,a2,a3);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iij(index,a1,a2,a3){var sp=stackSave();try{return dynCall_iij(index,a1,a2,a3)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_vij(index,a1,a2,a3){var sp=stackSave();try{dynCall_vij(index,a1,a2,a3);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viji(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viji(index,a1,a2,a3,a4);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viij(index,a1,a2,a3,a4){var sp=stackSave();try{dynCall_viij(index,a1,a2,a3,a4);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_viiij(index,a1,a2,a3,a4,a5){var sp=stackSave();try{dynCall_viiij(index,a1,a2,a3,a4,a5);}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function invoke_iiij(index,a1,a2,a3,a4){var sp=stackSave();try{return dynCall_iiij(index,a1,a2,a3,a4)}catch(e){stackRestore(sp);if(e!==e+0)throw e;_setThrew(1,0);}}function intArrayFromBase64(s){try{var decoded=atob(s);var bytes=new Uint8Array(decoded.length);for(var i=0;i0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun();}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("");},1);doRun();},1);}else {doRun();}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()();}}run(); -function nNop(x) { - return x -} -function nMulTo(x, y, r) { - x.multiplyTo(y, r) + return moduleArg } -function nSqrTo(x, r) { - x.squareTo(r) -} +); +})(); +module.exports = Module; +}); -NullExp.prototype.convert = nNop -NullExp.prototype.revert = nNop -NullExp.prototype.mulTo = nMulTo -NullExp.prototype.sqrTo = nSqrTo +// Initial author: Pieter Wuille ( https://github.com/sipa/miniscript/blob/master/index.html) +const Module = bindings(); + +const em_miniscript_compile = Module.cwrap('miniscript_compile', 'none', [ + 'string', + 'number', + 'number', + 'number', + 'number', + 'number', + 'number' +]); +const em_miniscript_analyze = Module.cwrap('miniscript_analyze', 'none', [ + 'string', + 'number', + 'number', + 'number', + 'number' +]); -// (public) this^e -function bnPow(e) { - return this.exp(e, new NullExp()) -} +const cleanAsm = asm => + asm + .trim() + .replace(/\n/g, ' ') + .replace(/ +(?= )/g, ''); -// (protected) r = lower n words of "this * a", a.t <= n -// "this" should be the larger one if appropriate. -function bnpMultiplyLowerTo(a, n, r) { - var i = Math.min(this.t + a.t, n) - r.s = 0; // assumes a,this >= 0 - r.t = i - while (i > 0) r[--i] = 0 - var j - for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t) - for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i) - r.clamp() -} +/** + * @typedef {Object} CompilePolicyResult + * @property {string} miniscript - The compiled miniscript expression. + * @property {string} asm - The compiled miniscript as Bitcoin asm code. + * @property {boolean} issane - Whether the miniscript is sane at the top level. + * @property {boolean} issanesublevel - Whether the miniscript is sane at the sublevel. + */ -// (protected) r = "this * a" without lower n words, n > 0 -// "this" should be the larger one if appropriate. -function bnpMultiplyUpperTo(a, n, r) { - --n - var i = r.t = this.t + a.t - n - r.s = 0; // assumes a,this >= 0 - while (--i >= 0) r[i] = 0 - for (i = Math.max(n - this.t, 0); i < a.t; ++i) - r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n) - r.clamp() - r.drShiftTo(1, r) -} +/** + * @typedef {Object} CompileMiniscriptResult + * @property {string} asm - The Bitcoin asm code of the compiled miniscript expression. + * @property {boolean} issane - Whether the miniscript is sane at the top level. + * @property {boolean} issanesublevel - Whether the miniscript is sane at the sublevel. + */ -// Barrett modular reduction -function Barrett(m) { - // setup Barrett - this.r2 = new BigInteger() - this.q3 = new BigInteger() - BigInteger.ONE.dlShiftTo(2 * m.t, this.r2) - this.mu = this.r2.divide(m) - this.m = m -} -function barrettConvert(x) { - if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m) - else if (x.compareTo(this.m) < 0) return x - else { - var r = new BigInteger() - x.copyTo(r) - this.reduce(r) - return r - } -} +/** + * Compiles a miniscript policy into a miniscript expression (if possible). + * @Function + * + * @param {string} policy - The miniscript policy to compile. + * @returns {CompilePolicyResult} + */ +const compilePolicy = policy => { + const miniscript = Module._malloc(10000); + const cost = Module._malloc(500); + const asm = Module._malloc(100000); + const issane = Module._malloc(10); + const issanesublevel = Module._malloc(10); + em_miniscript_compile( + policy, + miniscript, + 10000, + cost, + 500, + asm, + 100000, + issane, + 10, + issanesublevel, + 10 + ); + const result = { + miniscript: Module.UTF8ToString(miniscript), + asm: cleanAsm(Module.UTF8ToString(asm)), + issane: Module.UTF8ToString(issane) === 'true' ? true : false, + issanesublevel: + Module.UTF8ToString(issanesublevel) === 'true' ? true : false + }; + Module._free(miniscript); + Module._free(cost); + Module._free(asm); + Module._free(issane); + Module._free(issanesublevel); -function barrettRevert(x) { - return x -} + return result; +}; -// x = x mod m (HAC 14.42) -function barrettReduce(x) { - var self = this - x.drShiftTo(self.m.t - 1, self.r2) - if (x.t > self.m.t + 1) { - x.t = self.m.t + 1 - x.clamp() - } - self.mu.multiplyUpperTo(self.r2, self.m.t + 1, self.q3) - self.m.multiplyLowerTo(self.q3, self.m.t + 1, self.r2) - while (x.compareTo(self.r2) < 0) x.dAddOffset(1, self.m.t + 1) - x.subTo(self.r2, x) - while (x.compareTo(self.m) >= 0) x.subTo(self.m, x) -} +/** + * Compiles a miniscript expression and returns its asm code. + * @Function + * + * @param {string} miniscript - A miniscript expression. + * @returns {CompileMiniscriptResult} + */ +const compileMiniscript = miniscript => { + const analysis = Module._malloc(50000); + const asm = Module._malloc(100000); + const issane = Module._malloc(10); + const issanesublevel = Module._malloc(10); + em_miniscript_analyze( + miniscript, + analysis, + 50000, + asm, + 100000, + issane, + 10, + issanesublevel, + 10 + ); + const result_asm = Module.UTF8ToString(asm); + const result_issane = Module.UTF8ToString(issane); + const result_issanesublebel = Module.UTF8ToString(issanesublevel); + Module._free(analysis); + Module._free(asm); + Module._free(issane); + Module._free(issanesublevel); -// r = x^2 mod m; x != r -function barrettSqrTo(x, r) { - x.squareTo(r) - this.reduce(r) -} + return { + asm: cleanAsm(result_asm), + issane: result_issane === 'true' ? true : false, + issanesublevel: result_issanesublebel === 'true' ? true : false + }; +}; -// r = x*y mod m; x,y != r -function barrettMulTo(x, y, r) { - x.multiplyTo(y, r) - this.reduce(r) -} +// Copyright (c) 2022 Jose-Luis Landabaso - https://bitcoinerlab.com -Barrett.prototype.convert = barrettConvert -Barrett.prototype.revert = barrettRevert -Barrett.prototype.reduce = barrettReduce -Barrett.prototype.mulTo = barrettMulTo -Barrett.prototype.sqrTo = barrettSqrTo +/** + * @typedef {Object} Solution + * @property {number} nSequence - the maximum nSequence time of all the sat() or dsat() expressions in the solution. + * @property {number} nLockTime - the maximum nLockTime of all the sat() or dsat() expressions in the solution. + * @property {string} asm - the resulting witness after combining all the sat() or dsat() expressions. + */ -// (public) this^e % m (HAC 14.85) -function bnModPow(e, m) { - var i = e.bitLength(), - k, r = nbv(1), - z - if (i <= 0) return r - else if (i < 18) k = 1 - else if (i < 48) k = 3 - else if (i < 144) k = 4 - else if (i < 768) k = 5 - else k = 6 - if (i < 8) - z = new Classic(m) - else if (m.isEven()) - z = new Barrett(m) - else - z = new Montgomery(m) +/** + * @typedef {Object} Satisfactions + * @property {Solution[]} sats - An array of {@link Solution} objects representing the sat() expressions. + * @property {Solution[]} dsats - An array of {@link Solution} objects representing the dsat() expressions. + * @see {@link Solution} + */ - // precomputation - var g = new Array(), - n = 3, - k1 = k - 1, - km = (1 << k) - 1 - g[1] = z.convert(this) - if (k > 1) { - var g2 = new BigInteger() - z.sqrTo(g[1], g2) - while (n <= km) { - g[n] = new BigInteger() - z.mulTo(g2, g[n - 2], g[n]) - n += 2 +/** + * @typedef {Object} SatisfierResult + * @property {Solution[]} nonMalleableSats - An array of {@link Solution} objects representing the non-malleable sat() expressions. + * @property {Solution[]} malleableSats - An array of {@link Solution} objects representing the malleable sat() expressions. + * @property {Solution[]} unknownSats - An array of {@link Solution} objects representing the sat() expressions that contain some of the `unknown` pieces of information. + * @see {@link Solution} + */ + + +/** + * Computes the weight units (WU) of a witness. + * @param {string} asm - the witness to compute the WU of. + * @returns {number} the weight units (WU) of the witness. + */ +function witnessWU(asm) { + // Split the witness string into an array of substrings + // a miniscipt witness is either, ') + ) { + //any preimage is checked against <32> with SIZE <32> EQUALVERIFY: + //See the miniscript Translation table: + //https://bitcoin.sipa.be/miniscript/ + //SIZE <32> EQUALVERIFY {SHA256,RIPEMD,160,HASH160,HASH256} EQUAL + wu += 33; //32 + push op code + } + // Pub keys + else if (substring.startsWith('<')) { + //https://en.bitcoin.it/wiki/BIP_0137 + //Compressed public keys are 33 bytes + wu += 34; //33 + push op code + } else if (substring === '1' || substring === '0') { + wu += 1; + } else { + throw new Error(`Invalid witness substring ${substring}`); } } - var j = e.t - 1, - w, is1 = true, - r2 = new BigInteger(), - t - i = nbits(e[j]) - 1 - while (j >= 0) { - if (i >= k1) w = (e[j] >> (i - k1)) & km - else { - w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i) - if (j > 0) w |= e[j - 1] >> (this.DB + i - k1) - } + // Return the final wu + return wu; +} - n = k - while ((w & 1) == 0) { - w >>= 1 - --n - } - if ((i -= n) < 0) { - i += this.DB - --j - } - if (is1) { // ret == 1, don't bother squaring or multiplying it - g[w].copyTo(r) - is1 = false - } else { - while (n > 1) { - z.sqrTo(r, r2) - z.sqrTo(r2, r) - n -= 2 +/** + * Performs a malleability analysis on an array of sat() solutions. + * @param {Solution[]} sats - the array of sat() solutions to perform the analysis on. + * @returns {Object} An object with two keys: + * - `nonMalleableSats`: an array of {@link Solution} objects representing the non-malleable sat() expressions. + * - `malleableSats`: an array of {@link Solution} objects representing the malleable sat() expressions. + * @see {@link Solution} + */ +function malleabilityAnalysis(sats) { + sats = sats + .map(sat => { + //Deep copy the objects so that this function is pure + //(does not mutate sats) + sat = { ...sat }; + //Extract the signatures used in this witness as an array + sat.signatures = sat.asm.split(' ').filter(op => { + return op.startsWith(' 0) z.sqrTo(r, r2) - else { - t = r - r = r2 - r2 = t + // is a dissatisfaction for a preimage. It is + //interchangable for any 32 bytes random number and thus, it is malleable. + if (sat.asm.includes('')) { + sat.dontuse = true; } - z.mulTo(r2, g[w], r) - } - - while (j >= 0 && (e[j] & (1 << i)) == 0) { - z.sqrTo(r, r2) - t = r - r = r2 - r2 = t - if (--i < 0) { - i = this.DB - 1 - --j + return sat; + }) + // Sort sats by weight unit in ascending order + .sort((a, b) => witnessWU(a.asm) - witnessWU(b.asm)); + + for (const sat of sats) { + //For the same nLockTime and nSequence, check if otherSat signatures are a + //subset of sat. If this is the case then sat cannot be used. + //"For the same nLockTime and nSequence" condition is set because signatures + //change for each tuple of (nLockTime, nSequence): + for (const otherSat of sats) { + if ( + otherSat !== sat && + //for the same nLockTime and nSequence + otherSat.nLockTime === sat.nLockTime && + otherSat.nSequence === sat.nSequence && + //is otherSat.signatures equal or a subset of sat.signatures? + otherSat.signatures.every(sig => sat.signatures.includes(sig)) + ) { + //sat is for example and otherSat is + //otherSat cannot be used because an attacker could use it to create + // 0) { - x.rShiftTo(g, x) - y.rShiftTo(g, y) - } - while (x.signum() > 0) { - if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x) - if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y) - if (x.compareTo(y) >= 0) { - x.subTo(y, x) - x.rShiftTo(1, x) - } else { - y.subTo(x, y) - y.rShiftTo(1, y) - } + const nonMalleableSats = sats.filter(sat => !sat.dontuse); + const malleableSats = sats.filter(sat => sat.dontuse); + + //Clean the objects before returning them + for (const sats of [nonMalleableSats, malleableSats]) { + sats.forEach(sat => { + delete sat.signatures; + delete sat.dontuse; + }); } - if (g > 0) y.lShiftTo(g, y) - return y + + return { nonMalleableSats, malleableSats }; } -// (protected) this % n, n < 2^26 -function bnpModInt(n) { - if (n <= 0) return 0 - var d = this.DV % n, - r = (this.s < 0) ? n - 1 : 0 - if (this.t > 0) - if (d == 0) r = this[0] % n - else - for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n - return r +/** + * Determines whether the specified argument of the given miniscript expression + * is a scalar. + * @param {string} functionName - the name of the function to check. + * @param {number} argPosition - the position of the argument to check, + * starting from 0. + * @returns {boolean} `true` if the specified argument of the given function is + * a scalar; `false` otherwise. + */ +function isScalarArg(functionName, argPosition) { + switch (functionName) { + case 'pk_k': + case 'pk_h': + case 'older': + case 'after': + case 'sha256': + case 'ripemd160': + case 'hash256': + case 'hash160': + case 'multi': + return true; + case 'thresh': + if (argPosition === 0) return true; + } + return false; } -// (public) 1/this % m (HAC 14.61) -function bnModInverse(m) { - var ac = m.isEven() - if (this.signum() === 0) throw new Error('division by zero') - if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO - var u = m.clone(), - v = this.clone() - var a = nbv(1), - b = nbv(0), - c = nbv(0), - d = nbv(1) - while (u.signum() != 0) { - while (u.isEven()) { - u.rShiftTo(1, u) - if (ac) { - if (!a.isEven() || !b.isEven()) { - a.addTo(this, a) - b.subTo(m, b) +/** + * Evaluates a miniscript expression and returns its satisfactions. + * + * This function is called recursively to find subexpressions + * within subexpressions until all the arguments of a subexpression are + * scalars. + * + * @param {string} miniscript - A miniscript expression. + * + * @returns {Satisfactions} - The satisfactions. + */ +const evaluate = miniscript => { + if (typeof miniscript !== 'string') + throw new Error('Invalid expression: ' + miniscript); + //convert wrappers like this "sln:" into "s:l:n:" + while (miniscript.match(/^[a-z]{2,}:/)) { + miniscript = miniscript.replace(/^[a-z]{2,}:/, match => + match.replace(match[0], match[0] + ':') + ); + } + //https://bitcoin.sipa.be/miniscript/ + //The pk, pkh, and and_n fragments and t:, l:, and u: wrappers are syntactic + //sugar for other miniscripts: + miniscript = miniscript + .replace(/^pk\(/, 'c:pk_k(') + .replace(/^pkh\(/, 'c:pk_h(') + .replace(/^and_n\(.*\)/, match => + match.replace('and_n', 'andor').replace(/\)$/, ',0)') + ) + .replace(/^t:(.*)/, match => match.replace('t:', 'and_v(') + ',1)') + .replace(/^l:(.*)/, match => match.replace('l:', 'or_i(0,') + ')') + .replace(/^u:(.*)/, match => match.replace('u:', 'or_i(') + ',0)'); + const reFunctionName = String.raw`([^\(:]*)`; + const matchFunctionName = miniscript.match(reFunctionName); + if (!matchFunctionName) throw new Error('Invalid expression: ' + miniscript); + const functionName = matchFunctionName[0]; + if (typeof satisfactionsMaker[functionName] !== 'function') + throw new Error(functionName + ' not implemented'); + + let args; + if (miniscript[functionName.length] === '(') + args = miniscript.substring(functionName.length + 1, miniscript.length - 1); + else if (miniscript[functionName.length] === ':') + args = miniscript.substring(functionName.length + 1); + + //the function arguments for satisfactionsMaker[functionName]: + //They will be called like using ES6 spread operator: + //satisfactionsMaker[functionName](...satisfactionMakerArgs) + const satisfactionMakerArgs = []; + if (args) { + let lastCommaPosition = -1; + let argLevel = 0; //argLevel tracks nested parenthesis + let argPosition = 0; //argPosition tracks argument order within functionName + for (let i = 0; i < args.length; i++) { + args[i] === '(' && argLevel++; + args[i] === ')' && argLevel--; + if (argLevel === 0) { + let arg; + if (args[i] === ',') { + arg = args.substring(lastCommaPosition + 1, i); + lastCommaPosition = i; + } else if (i === args.length - 1) { + arg = args.substring(lastCommaPosition + 1); } - a.rShiftTo(1, a) - } else if (!b.isEven()) b.subTo(m, b) - b.rShiftTo(1, b) - } - while (v.isEven()) { - v.rShiftTo(1, v) - if (ac) { - if (!c.isEven() || !d.isEven()) { - c.addTo(this, c) - d.subTo(m, d) + if (arg) { + if (isScalarArg(functionName, argPosition)) { + //This is the case when arg is a scalar value that will be directly + //passed to a satisfier maker function (arg is not a nested + //miniscript expression). + //That is, arg is one of these: a key or a hash or an nLockTime, + //nSequence, or the k (number of keys) in thresh/multi. + satisfactionMakerArgs.push(arg); + } else { + //arg is a miniscript expression that has to be further evaluated: + satisfactionMakerArgs.push(evaluate(arg)); + } + argPosition++; } - c.rShiftTo(1, c) - } else if (!d.isEven()) d.subTo(m, d) - d.rShiftTo(1, d) - } - if (u.compareTo(v) >= 0) { - u.subTo(v, u) - if (ac) a.subTo(c, a) - b.subTo(d, b) - } else { - v.subTo(u, v) - if (ac) c.subTo(a, c) - d.subTo(b, d) + } } } - if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO - while (d.compareTo(m) >= 0) d.subTo(m, d) - while (d.signum() < 0) d.addTo(m, d) - return d -} -var lowprimes = [ - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, - 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, - 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, - 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, - 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, - 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, - 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, - 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, - 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, - 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 -] + return satisfactionsMaker[functionName](...satisfactionMakerArgs); +}; -var lplim = (1 << 26) / lowprimes[lowprimes.length - 1] +/** + * Obtains the satisfactions of a miniscript. + * @Function + * + * @param {string} miniscript - A miniscript expression. + * @param {object} [options] + * @param {string[]} [options.unknowns] - An array with the pieces of information that + * cannot be used to construct solutions because they are unknown. + * + * For example, if a honest user cannot sign with `key`, doesn't know the + * preimage of `H` and the preimage of `e946029032eae1752e181bebab65de15cf0b93aaac4ee0ffdcfccb683c874d43` then `unknown` must be: + * ``` + * [ + * '', + * '', + * '' + * ] + * ``` + * + * Note that an expression will allways be NOT sane if it is NOT sane at the the + * miniscript top level as per {@link https://bitcoin.sipa.be/miniscript/ + * Wuille's algorithm}. + * + * For example; if a miniscript is NOT sane at the top level because it can be + * satisfyed using only preimages, then setting preimages as unknowns will not + * change this behaviour. + * + * The reason for this limitation is that the satisfier uses an unmodified + * version of Wuille's algorithm as an initial precondition before finding + * solutions. If the miniscript is sane, then unknowns can be set to produce + * more possible solutions, including preimages, as described above. + * + * @param {string[]} [options.knowns] - An array + * with the only pieces of information that can be used to build satisfactions. + * This is the complimentary to unknowns. Only `knowns` or `unknowns` must be + * passed. + * + * If neither knowns and unknowns is passed then it is assumed that there are + * no unknowns, in other words, that all pieces of information are known. + * + * @returns {SatisfierResult} + * + * @see {@link Solution} + */ +const satisfier = (miniscript, options = {}) => { + let { unknowns, knowns } = options; + const { issane, issanesublevel } = compileMiniscript(miniscript); -// (public) test primality with certainty >= 1-.5^t -function bnIsProbablePrime(t) { - var i, x = this.abs() - if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) { - for (i = 0; i < lowprimes.length; ++i) - if (x[0] == lowprimes[i]) return true - return false + if (!issane) { + throw new Error(`Miniscript ${miniscript} is not sane.`); } - if (x.isEven()) return false - i = 1 - while (i < lowprimes.length) { - var m = lowprimes[i], - j = i + 1 - while (j < lowprimes.length && m < lplim) m *= lowprimes[j++] - m = x.modInt(m) - while (i < j) if (m % lowprimes[i++] == 0) return false + + if (typeof unknowns === 'undefined' && typeof knowns === 'undefined') { + unknowns = []; + } else if (typeof unknowns !== 'undefined' && typeof knowns !== 'undefined') { + throw new Error(`Cannot pass both knowns and unknowns`); + } else if ( + (knowns && !Array.isArray(knowns)) || + (unknowns && !Array.isArray(unknowns)) + ) { + throw new Error(`Incorrect types for unknowns / knowns`); } - return x.millerRabin(t) -} -// (protected) true if probably prime (HAC 4.24, Miller-Rabin) -function bnpMillerRabin(t) { - var n1 = this.subtract(BigInteger.ONE) - var k = n1.getLowestSetBit() - if (k <= 0) return false - var r = n1.shiftRight(k) - t = (t + 1) >> 1 - if (t > lowprimes.length) t = lowprimes.length - var a = new BigInteger(null) - var j, bases = [] - for (var i = 0; i < t; ++i) { - for (;;) { - j = lowprimes[Math.floor(Math.random() * lowprimes.length)] - if (bases.indexOf(j) == -1) break - } - bases.push(j) - a.fromInt(j) - var y = a.modPow(r, this) - if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1 - while (j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2, this) - if (y.compareTo(BigInteger.ONE) == 0) return false + const knownSats = []; + const unknownSats = []; + const sats = evaluate(miniscript).sats || []; + sats.map(sat => { + if (typeof sat.nSequence === 'undefined') delete sat.nSequence; + if (typeof sat.nLockTime === 'undefined') delete sat.nLockTime; + //Clean format: 1 consecutive spaces at most, no leading & trailing spaces + sat.asm = sat.asm.replace(/ +/g, ' ').trim(); + + if (unknowns) { + if (unknowns.some(unknown => sat.asm.includes(unknown))) { + unknownSats.push(sat); + } else { + knownSats.push(sat); + } + } else { + const delKnowns = knowns.reduce( + (acc, known) => acc.replace(known, ''), + sat.asm + ); + if ( + delKnowns.match( + / + hmac.hmac(sha256.sha256, key, necc__namespace.utils.concatBytes(...msgs)); +necc__namespace.utils.sha256Sync = (...msgs) => sha256.sha256(necc__namespace.utils.concatBytes(...msgs)); + +const normalizePrivateKey = necc__namespace.utils._normalizePrivateKey; + +const HASH_SIZE = 32; +const TWEAK_SIZE = 32; +const BN32_N = new Uint8Array([ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 254, 186, 174, 220, 230, 175, 72, 160, 59, 191, 210, 94, 140, 208, 54, 65, 65 +]); +const EXTRA_DATA_SIZE = 32; -// constants -BigInteger.ZERO = nbv(0) -BigInteger.ONE = nbv(1) -BigInteger.valueOf = nbv +const BN32_ZERO = new Uint8Array(32); +const BN32_P_MINUS_N = new Uint8Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 69, 81, 35, 25, 80, 183, 95, + 196, 64, 45, 161, 114, 47, 201, 186, 238, +]); -module.exports = BigInteger +function isUint8Array(value) { + return value instanceof Uint8Array; +} -},{"../package.json":31}],29:[function(require,module,exports){ -(function (Buffer){ -// FIXME: Kind of a weird way to throw exceptions, consider removing -var assert = require('assert') -var BigInteger = require('./bigi') +function cmpBN32(data1, data2) { + for (let i = 0; i < 32; ++i) { + if (data1[i] !== data2[i]) { + return data1[i] < data2[i] ? -1 : 1; + } + } + return 0; +} -/** - * Turns a byte array into a big integer. - * - * This function will interpret a byte array as a big integer in big - * endian notation. - */ -BigInteger.fromByteArrayUnsigned = function(byteArray) { - // BigInteger expects a DER integer conformant byte array - if (byteArray[0] & 0x80) { - return new BigInteger([0].concat(byteArray)) +function isZero(x) { + return cmpBN32(x, BN32_ZERO) === 0; +} + + +function isTweak(tweak) { + // Check that the tweak is a Uint8Array of the correct length + if ( + !(tweak instanceof Uint8Array) || + tweak.length !== TWEAK_SIZE || + cmpBN32(tweak, BN32_N) >= 0 + ) { + return false; } + return true; +} - return new BigInteger(byteArray) +function isSignature(signature) { + return ( + signature instanceof Uint8Array && + signature.length === 64 && + cmpBN32(signature.subarray(0, 32), BN32_N) < 0 && + cmpBN32(signature.subarray(32, 64), BN32_N) < 0 + ); } -/** - * Returns a byte array representation of the big integer. - * - * This returns the absolute of the contained value in big endian - * form. A value of zero results in an empty array. - */ -BigInteger.prototype.toByteArrayUnsigned = function() { - var byteArray = this.toByteArray() - return byteArray[0] === 0 ? byteArray.slice(1) : byteArray +function isSigrLessThanPMinusN(signature) { + return ( + isUint8Array(signature) && + signature.length === 64 && + cmpBN32(signature.subarray(0, 32), BN32_P_MINUS_N) < 0 + ); } -BigInteger.fromDERInteger = function(byteArray) { - return new BigInteger(byteArray) +function isSignatureNonzeroRS(signature) { + return !(isZero(signature.subarray(0, 32)) || isZero(signature.subarray(32, 64))) } -/* - * Converts BigInteger to a DER integer representation. - * - * The format for this value uses the most significant bit as a sign - * bit. If the most significant bit is already set and the integer is - * positive, a 0x00 is prepended. - * - * Examples: - * - * 0 => 0x00 - * 1 => 0x01 - * -1 => 0xff - * 127 => 0x7f - * -127 => 0x81 - * 128 => 0x0080 - * -128 => 0x80 - * 255 => 0x00ff - * -255 => 0xff01 - * 16300 => 0x3fac - * -16300 => 0xc054 - * 62300 => 0x00f35c - * -62300 => 0xff0ca4 -*/ -BigInteger.prototype.toDERInteger = BigInteger.prototype.toByteArray +function isHash(h) { + return h instanceof Uint8Array && h.length === HASH_SIZE; +} -BigInteger.fromBuffer = function(buffer) { - // BigInteger expects a DER integer conformant byte array - if (buffer[0] & 0x80) { - var byteArray = Array.prototype.slice.call(buffer) +function isExtraData(e) { + return ( + e === undefined || (e instanceof Uint8Array && e.length === EXTRA_DATA_SIZE) + ); +} - return new BigInteger([0].concat(byteArray)) +function hexToNumber(hex) { + if (typeof hex !== 'string') { + throw new TypeError('hexToNumber: expected string, got ' + typeof hex); } - - return new BigInteger(buffer) + return BigInt(`0x${hex}`); } -BigInteger.fromHex = function(hex) { - if (hex === '') return BigInteger.ZERO +function bytesToNumber(bytes) { + return hexToNumber(necc__namespace.utils.bytesToHex(bytes)); +} - assert.equal(hex, hex.match(/^[A-Fa-f0-9]+/), 'Invalid hex string') - assert.equal(hex.length % 2, 0, 'Incomplete hex') - return new BigInteger(hex, 16) +function normalizeScalar(scalar) { + let num; + if (typeof scalar === 'bigint') { + num = scalar; + } else if ( + typeof scalar === 'number' && + Number.isSafeInteger(scalar) && + scalar >= 0 + ) { + num = BigInt(scalar); + } else if (typeof scalar === 'string') { + if (scalar.length !== 64) + throw new Error('Expected 32 bytes of private scalar'); + num = hexToNumber(scalar); + } else if (scalar instanceof Uint8Array) { + if (scalar.length !== 32) + throw new Error('Expected 32 bytes of private scalar'); + num = bytesToNumber(scalar); + } else { + throw new TypeError('Expected valid private scalar'); + } + if (num < 0) throw new Error('Expected private scalar >= 0'); + return num; } -BigInteger.prototype.toBuffer = function(size) { - var byteArray = this.toByteArrayUnsigned() - var zeros = [] +const _privateAdd = (privateKey, tweak) => { + const p = normalizePrivateKey(privateKey); + const t = normalizeScalar(tweak); + const add = necc__namespace.utils._bigintTo32Bytes(necc__namespace.utils.mod(p + t, necc__namespace.CURVE.n)); + if (necc__namespace.utils.isValidPrivateKey(add)) return add; + else return null; +}; - var padding = size - byteArray.length - while (zeros.length < padding) zeros.push(0) +const _privateSub = (privateKey, tweak) => { + const p = normalizePrivateKey(privateKey); + const t = normalizeScalar(tweak); + const sub = necc__namespace.utils._bigintTo32Bytes(necc__namespace.utils.mod(p - t, necc__namespace.CURVE.n)); + if (necc__namespace.utils.isValidPrivateKey(sub)) return sub; + else return null; +}; - return new Buffer(zeros.concat(byteArray)) +const _privateNegate = privateKey => { + const p = normalizePrivateKey(privateKey); + const not = necc__namespace.utils._bigintTo32Bytes(necc__namespace.CURVE.n - p); + if (necc__namespace.utils.isValidPrivateKey(not)) return not; + else return null; +}; + +const _pointAddScalar = (p, tweak, isCompressed) => { + const P = necc__namespace.Point.fromHex(p); + const t = normalizeScalar(tweak); + const Q = necc__namespace.Point.BASE.multiplyAndAddUnsafe(P, t, BigInt(1)); + if (!Q) throw new Error('Tweaked point at infinity'); + return Q.toRawBytes(isCompressed); +}; + +const _pointMultiply = (p, tweak, isCompressed) => { + const P = necc__namespace.Point.fromHex(p); + const h = typeof tweak === 'string' ? tweak : necc__namespace.utils.bytesToHex(tweak); + const t = BigInt(`0x${h}`); + return P.multiply(t).toRawBytes(isCompressed); +}; + +function assumeCompression(compressed, p) { + if (compressed === undefined) { + return p !== undefined ? isPointCompressed(p) : true; + } + return compressed ? true : false; } -BigInteger.prototype.toHex = function(size) { - return this.toBuffer(size).toString('hex') +function throwToNull(fn) { + try { + return fn(); + } catch (e) { + return null; + } } -}).call(this,require("buffer").Buffer) -},{"./bigi":28,"assert":21,"buffer":155}],30:[function(require,module,exports){ -var BigInteger = require('./bigi') +function _isPoint(p, xOnly) { + if ((p.length === 32) !== xOnly) return false; + try { + return !!necc__namespace.Point.fromHex(p); + } catch (e) { + return false; + } +} -//addons -require('./convert') +function isPoint(p) { + return _isPoint(p, false); +} -module.exports = BigInteger -},{"./bigi":28,"./convert":29}],31:[function(require,module,exports){ -module.exports={ - "name": "bigi", - "version": "1.4.2", - "description": "Big integers.", - "keywords": [ - "cryptography", - "math", - "bitcoin", - "arbitrary", - "precision", - "arithmetic", - "big", - "integer", - "int", - "number", - "biginteger", - "bigint", - "bignumber", - "decimal", - "float" - ], - "devDependencies": { - "coveralls": "^2.11.2", - "istanbul": "^0.3.5", - "jshint": "^2.5.1", - "mocha": "^2.1.0", - "mochify": "^2.1.0" - }, - "repository": { - "url": "https://github.com/cryptocoinjs/bigi", - "type": "git" - }, - "main": "./lib/index.js", - "scripts": { - "browser-test": "./node_modules/.bin/mochify --wd -R spec", - "test": "./node_modules/.bin/_mocha -- test/*.js", - "jshint": "./node_modules/.bin/jshint --config jshint.json lib/*.js ; true", - "unit": "./node_modules/.bin/mocha", - "coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js", - "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info" - }, - "dependencies": {}, - "testling": { - "files": "test/*.js", - "harness": "mocha", - "browsers": [ - "ie/9..latest", - "firefox/latest", - "chrome/latest", - "safari/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2..latest" - ] - } +function isPointCompressed(p) { + const PUBLIC_KEY_COMPRESSED_SIZE = 33; + return _isPoint(p, false) && p.length === PUBLIC_KEY_COMPRESSED_SIZE; } -},{}],32:[function(require,module,exports){ -const BigInteger = require('bigi'); -const Buffer = require('safe-buffer').Buffer; -const ecurve = require('ecurve'); -const curve = ecurve.getCurveByName('secp256k1'); +function isPrivate(d) { + return necc__namespace.utils.isValidPrivateKey(d); +} -const one = BigInteger.ONE; -const n = curve.n; -const p = curve.p; +function isXOnlyPoint(p) { + return _isPoint(p, true); +} -function checkBuffer(name, buf, len, idx) { - const idxStr = (idx !== undefined ? '[' + idx + ']' : ''); - if (!Buffer.isBuffer(buf)) { - throw new Error(name + idxStr + ' must be a Buffer'); +function xOnlyPointAddTweak(p, tweak) { + if (!isXOnlyPoint(p)) { + throw new Error(THROW_BAD_POINT); } - if (buf.length !== len) { - throw new Error(name + idxStr + ' must be ' + len + ' bytes long'); + if (!isTweak(tweak)) { + throw new Error(THROW_BAD_TWEAK); } + return throwToNull(() => { + const P = _pointAddScalar(p, tweak, true); + const parity = P[0] % 2 === 1 ? 1 : 0; + return { parity, xOnlyPubkey: P.slice(1) }; + }); } -function checkArray(name, arr) { - if (!arr || !arr.length) { - throw new Error(name + ' must be an array with one or more elements'); +function xOnlyPointFromPoint(p) { + if (!isPoint(p)) { + throw new Error(THROW_BAD_POINT); } + return p.slice(1, 33); } -function checkPubKeyArr(pubKeys) { - checkArray('pubKeys', pubKeys); - for (let i = 0; i < pubKeys.length; i++) { - checkBuffer('pubKey', pubKeys[i], 32, i); +function pointFromScalar(sk, compressed) { + if (!isPrivate(sk)) { + throw new Error(THROW_BAD_PRIVATE); } + return throwToNull(() => + necc__namespace.getPublicKey(sk, assumeCompression(compressed)) + ); } -function checkMessageArr(messages) { - checkArray('messages', messages); - for (let i = 0; i < messages.length; i++) { - checkBuffer('message', messages[i], 32, i); +function xOnlyPointFromScalar(d) { + if (!isPrivate(d)) { + throw new Error(THROW_BAD_PRIVATE); } + return xOnlyPointFromPoint(pointFromScalar(d)); } -function checkSignatureArr(signatures) { - checkArray('signatures', signatures); - for (let i = 0; i < signatures.length; i++) { - checkBuffer('signature', signatures[i], 64, i); +function pointCompress(p, compressed) { + if (!isPoint(p)) { + throw new Error(THROW_BAD_POINT); } + return necc__namespace.Point.fromHex(p).toRawBytes(assumeCompression(compressed, p)); } -function checkNonceArr(nonces) { - checkArray('nonces', nonces); - for (let i = 0; i < nonces.length; i++) { - checkBuffer('nonce', nonces[i], 32, i); +function pointMultiply(a, tweak, compressed) { + if (!isPoint(a)) { + throw new Error(THROW_BAD_POINT); + } + if (!isTweak(tweak)) { + throw new Error(THROW_BAD_TWEAK); } + return throwToNull(() => + _pointMultiply(a, tweak, assumeCompression(compressed, a)) + ); } -function checkPrivateKey(privateKey, idx) { - const idxStr = (idx !== undefined ? '[' + idx + ']' : ''); - if (!BigInteger.isBigInteger(privateKey) && !(typeof privateKey == 'string')) { - throw new Error('privateKey' + idxStr + ' must be a BigInteger or valid hex string'); +function pointAdd(a, b, compressed) { + if (!isPoint(a) || !isPoint(b)) { + throw new Error(THROW_BAD_POINT); } - - if (typeof(privateKey) == 'string') { - if (privateKey.match(/[^a-f^A-F^0-9]+/)) { - throw new Error('privateKey must be a BigInteger or valid hex string'); + return throwToNull(() => { + const A = necc__namespace.Point.fromHex(a); + const B = necc__namespace.Point.fromHex(b); + if (A.equals(B.negate())) { + //https://github.com/paulmillr/noble-secp256k1/issues/91 + return null; + } else { + return A.add(B).toRawBytes(assumeCompression(compressed, a)); } - - checkRange('privateKey', BigInteger.fromHex(privateKey)); - return - } - - checkRange('privateKey', privateKey); + }); } - -function checkSignParams(privateKey, message) { - checkPrivateKey(privateKey); - checkBuffer('message', message, 32); +function pointAddScalar(p, tweak, compressed) { + if (!isPoint(p)) { + throw new Error(THROW_BAD_POINT); + } + if (!isTweak(tweak)) { + throw new Error(THROW_BAD_TWEAK); + } + return throwToNull(() => + _pointAddScalar(p, tweak, assumeCompression(compressed, p)) + ); } -function checkVerifyParams(pubKey, message, signature) { - checkBuffer('pubKey', pubKey, 32); - checkBuffer('message', message, 32); - checkBuffer('signature', signature, 64); +function privateAdd(d, tweak) { + if (isPrivate(d) === false) { + throw new Error(THROW_BAD_PRIVATE); + } + if (isTweak(tweak) === false) { + throw new Error(THROW_BAD_TWEAK); + } + return throwToNull(() => _privateAdd(d, tweak)); } -function checkBatchVerifyParams(pubKeys, messages, signatures) { - checkPubKeyArr(pubKeys); - checkMessageArr(messages); - checkSignatureArr(signatures); - if (pubKeys.length !== messages.length || messages.length !== signatures.length) { - throw new Error('all parameters must be an array with the same length') +function privateSub(d, tweak) { + if (isPrivate(d) === false) { + throw new Error(THROW_BAD_PRIVATE); } + if (isTweak(tweak) === false) { + throw new Error(THROW_BAD_TWEAK); + } + return throwToNull(() => _privateSub(d, tweak)); } -function checkSessionParams(sessionId, privateKey, message, pubKeyCombined, ell) { - checkSignParams(privateKey, message); - checkBuffer('sessionId', sessionId, 32); - checkBuffer('pubKeyCombined', pubKeyCombined, 32); - checkBuffer('ell', ell, 32); +function privateNegate(d) { + if (isPrivate(d) === false) { + throw new Error(THROW_BAD_PRIVATE); + } + return _privateNegate(d); } -function checkRange(name, scalar) { - if (scalar.compareTo(one) < 0 || scalar.compareTo(n.subtract(one)) > 0) { - throw new Error(name + ' must be an integer in the range 1..n-1') +function sign(h, d, e) { + if (!isPrivate(d)) { + throw new Error(THROW_BAD_PRIVATE); } + if (!isHash(h)) { + throw new Error(THROW_BAD_SCALAR); + } + if (!isExtraData(e)) { + throw new Error(THROW_BAD_EXTRA_DATA); + } + return necc__namespace.signSync(h, d, { der: false, extraEntropy: e }); } -function checkSignatureInput(r, s) { - if (r.compareTo(p) >= 0) { - throw new Error('r is larger than or equal to field size'); +function signRecoverable(h, d, e) { + if (!isPrivate(d)) { + throw new Error(THROW_BAD_PRIVATE); } - if (s.compareTo(n) >= 0) { - throw new Error('s is larger than or equal to curve order'); + if (!isHash(h)) { + throw new Error(THROW_BAD_SCALAR); + } + if (!isExtraData(e)) { + throw new Error(THROW_BAD_EXTRA_DATA); } + const [signature, recoveryId] = necc__namespace.signSync(h, d, { der: false, extraEntropy: e, recovered: true }); + return { signature, recoveryId } } -function checkPointExists(pubKeyEven, P) { - if (P.curve.isInfinity(P)) { - throw new Error('point is at infinity'); +function signSchnorr(h, d, e = Buffer.alloc(32, 0x00)) { + if (!isPrivate(d)) { + throw new Error(THROW_BAD_PRIVATE); } - const pEven = P.affineY.isEven(); - if (pubKeyEven !== pEven) { - throw new Error('point does not exist'); + if (!isHash(h)) { + throw new Error(THROW_BAD_SCALAR); } + if (!isExtraData(e)) { + throw new Error(THROW_BAD_EXTRA_DATA); + } + return necc__namespace.schnorr.signSync(h, d, e); } -function checkAux(aux) { - if (aux.length !== 32) { - throw new Error('aux must be 32 bytes'); +function recover(h, signature, recoveryId, compressed){ + if (!isHash(h)){ + throw new Error(THROW_BAD_HASH); } -} -module.exports = { - checkSessionParams, - checkSignParams, - checkVerifyParams, - checkBatchVerifyParams, - checkRange, - checkSignatureInput, - checkPointExists, - checkPubKeyArr, - checkArray, - checkNonceArr, - checkAux, -}; + if(!isSignature(signature) || !isSignatureNonzeroRS(signature)){ + throw new Error(THROW_BAD_SIGNATURE) + } -},{"bigi":30,"ecurve":176,"safe-buffer":280}],33:[function(require,module,exports){ -const BigInteger = require('bigi'); -const Buffer = require('safe-buffer').Buffer; -const sha256 = require('js-sha256'); + if (recoveryId & 2) { + if (!isSigrLessThanPMinusN(signature)) throw new Error(THROW_BAD_RECOVERY_ID) + } + + if (!isXOnlyPoint(signature.subarray(0, 32))){ + throw new Error(THROW_BAD_SIGNATURE) + } -function bufferToInt(buffer) { - return BigInteger.fromBuffer(buffer); + return necc__namespace.recoverPublicKey(h, signature, recoveryId, assumeCompression(compressed)); } -function intToBuffer(bigInteger) { - return bigInteger.toBuffer(32); +function verify(h, Q, signature, strict) { + if (!isPoint(Q)) { + throw new Error(THROW_BAD_POINT); + } + if (!isSignature(signature)) { + throw new Error(THROW_BAD_SIGNATURE); + } + if (!isHash(h)) { + throw new Error(THROW_BAD_SCALAR); + } + return necc__namespace.verify(signature, h, Q, { strict }); } -function hash(buffer) { - return Buffer.from(sha256.create().update(buffer).array()); +function verifySchnorr(h, Q, signature) { + if (!isXOnlyPoint(Q)) { + throw new Error(THROW_BAD_POINT); + } + if (!isSignature(signature)) { + throw new Error(THROW_BAD_SIGNATURE); + } + if (!isHash(h)) { + throw new Error(THROW_BAD_SCALAR); + } + return necc__namespace.schnorr.verifySync(signature, h, Q); } -module.exports = { - bufferToInt, - intToBuffer, - hash, -}; - -},{"bigi":30,"js-sha256":233,"safe-buffer":280}],34:[function(require,module,exports){ -const schnorr = require('./schnorr'); -schnorr.check = require('./check'); -schnorr.convert = require('./convert'); -schnorr.math = require('./math'); -schnorr.muSig = require('./mu-sig'); -schnorr.taproot = require('./taproot'); +exports.isPoint = isPoint; +exports.isPointCompressed = isPointCompressed; +exports.isPrivate = isPrivate; +exports.isXOnlyPoint = isXOnlyPoint; +exports.pointAdd = pointAdd; +exports.pointAddScalar = pointAddScalar; +exports.pointCompress = pointCompress; +exports.pointFromScalar = pointFromScalar; +exports.pointMultiply = pointMultiply; +exports.privateAdd = privateAdd; +exports.privateNegate = privateNegate; +exports.privateSub = privateSub; +exports.recover = recover; +exports.sign = sign; +exports.signRecoverable = signRecoverable; +exports.signSchnorr = signSchnorr; +exports.verify = verify; +exports.verifySchnorr = verifySchnorr; +exports.xOnlyPointAddTweak = xOnlyPointAddTweak; +exports.xOnlyPointFromPoint = xOnlyPointFromPoint; +exports.xOnlyPointFromScalar = xOnlyPointFromScalar; -module.exports = schnorr; +}).call(this)}).call(this,require("buffer").Buffer) +},{"@noble/hashes/hmac":86,"@noble/hashes/sha256":89,"@noble/secp256k1":92,"buffer":249}],82:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.output = exports.exists = exports.hash = exports.bytes = exports.bool = exports.number = exports.isBytes = void 0; +function number(n) { + if (!Number.isSafeInteger(n) || n < 0) + throw new Error(`positive integer expected, not ${n}`); +} +exports.number = number; +function bool(b) { + if (typeof b !== 'boolean') + throw new Error(`boolean expected, not ${b}`); +} +exports.bool = bool; +// copied from utils +function isBytes(a) { + return (a instanceof Uint8Array || + (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')); +} +exports.isBytes = isBytes; +function bytes(b, ...lengths) { + if (!isBytes(b)) + throw new Error('Uint8Array expected'); + if (lengths.length > 0 && !lengths.includes(b.length)) + throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`); +} +exports.bytes = bytes; +function hash(h) { + if (typeof h !== 'function' || typeof h.create !== 'function') + throw new Error('Hash should be wrapped by utils.wrapConstructor'); + number(h.outputLen); + number(h.blockLen); +} +exports.hash = hash; +function exists(instance, checkFinished = true) { + if (instance.destroyed) + throw new Error('Hash instance has been destroyed'); + if (checkFinished && instance.finished) + throw new Error('Hash#digest() has already been called'); +} +exports.exists = exists; +function output(out, instance) { + bytes(out); + const min = instance.outputLen; + if (out.length < min) { + throw new Error(`digestInto() expects output buffer of length at least ${min}`); + } +} +exports.output = output; +const assert = { number, bool, bytes, hash, exists, output }; +exports.default = assert; -},{"./check":32,"./convert":33,"./math":35,"./mu-sig":36,"./schnorr":37,"./taproot":38}],35:[function(require,module,exports){ -const BigInteger = require('bigi'); -const Buffer = require('safe-buffer').Buffer; -const ecurve = require('ecurve'); -const randomBytes = require('randombytes'); -const curve = ecurve.getCurveByName('secp256k1'); -const check = require('./check'); -const convert = require('./convert'); +},{}],83:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.HashMD = exports.Maj = exports.Chi = void 0; +const _assert_js_1 = require("./_assert.js"); +const utils_js_1 = require("./utils.js"); +// Polyfill for Safari 14 +function setBigUint64(view, byteOffset, value, isLE) { + if (typeof view.setBigUint64 === 'function') + return view.setBigUint64(byteOffset, value, isLE); + const _32n = BigInt(32); + const _u32_max = BigInt(0xffffffff); + const wh = Number((value >> _32n) & _u32_max); + const wl = Number(value & _u32_max); + const h = isLE ? 4 : 0; + const l = isLE ? 0 : 4; + view.setUint32(byteOffset + h, wh, isLE); + view.setUint32(byteOffset + l, wl, isLE); +} +// Choice: a ? b : c +const Chi = (a, b, c) => (a & b) ^ (~a & c); +exports.Chi = Chi; +// Majority function, true if any two inpust is true +const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c); +exports.Maj = Maj; +/** + * Merkle-Damgard hash construction base class. + * Could be used to create MD5, RIPEMD, SHA1, SHA2. + */ +class HashMD extends utils_js_1.Hash { + constructor(blockLen, outputLen, padOffset, isLE) { + super(); + this.blockLen = blockLen; + this.outputLen = outputLen; + this.padOffset = padOffset; + this.isLE = isLE; + this.finished = false; + this.length = 0; + this.pos = 0; + this.destroyed = false; + this.buffer = new Uint8Array(blockLen); + this.view = (0, utils_js_1.createView)(this.buffer); + } + update(data) { + (0, _assert_js_1.exists)(this); + const { view, buffer, blockLen } = this; + data = (0, utils_js_1.toBytes)(data); + const len = data.length; + for (let pos = 0; pos < len;) { + const take = Math.min(blockLen - this.pos, len - pos); + // Fast path: we have at least one block in input, cast it to view and process + if (take === blockLen) { + const dataView = (0, utils_js_1.createView)(data); + for (; blockLen <= len - pos; pos += blockLen) + this.process(dataView, pos); + continue; + } + buffer.set(data.subarray(pos, pos + take), this.pos); + this.pos += take; + pos += take; + if (this.pos === blockLen) { + this.process(view, 0); + this.pos = 0; + } + } + this.length += data.length; + this.roundClean(); + return this; + } + digestInto(out) { + (0, _assert_js_1.exists)(this); + (0, _assert_js_1.output)(out, this); + this.finished = true; + // Padding + // We can avoid allocation of buffer for padding completely if it + // was previously not allocated here. But it won't change performance. + const { buffer, view, blockLen, isLE } = this; + let { pos } = this; + // append the bit '1' to the message + buffer[pos++] = 0b10000000; + this.buffer.subarray(pos).fill(0); + // we have less than padOffset left in buffer, so we cannot put length in + // current block, need process it and pad again + if (this.padOffset > blockLen - pos) { + this.process(view, 0); + pos = 0; + } + // Pad until full block byte with zeros + for (let i = pos; i < blockLen; i++) + buffer[i] = 0; + // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that + // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen. + // So we just write lowest 64 bits of that value. + setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE); + this.process(view, 0); + const oview = (0, utils_js_1.createView)(out); + const len = this.outputLen; + // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT + if (len % 4) + throw new Error('_sha2: outputLen should be aligned to 32bit'); + const outLen = len / 4; + const state = this.get(); + if (outLen > state.length) + throw new Error('_sha2: outputLen bigger than state'); + for (let i = 0; i < outLen; i++) + oview.setUint32(4 * i, state[i], isLE); + } + digest() { + const { buffer, outputLen } = this; + this.digestInto(buffer); + const res = buffer.slice(0, outputLen); + this.destroy(); + return res; + } + _cloneInto(to) { + to || (to = new this.constructor()); + to.set(...this.get()); + const { blockLen, buffer, length, finished, destroyed, pos } = this; + to.length = length; + to.pos = pos; + to.finished = finished; + to.destroyed = destroyed; + if (length % blockLen) + to.buffer.set(buffer); + return to; + } +} +exports.HashMD = HashMD; -const concat = Buffer.concat; -const G = curve.G; -const p = curve.p; -const n = curve.n; -const zero = BigInteger.ZERO; -const one = BigInteger.ONE; -const two = BigInteger.valueOf(2); -const three = BigInteger.valueOf(3); -const four = BigInteger.valueOf(4); -const seven = BigInteger.valueOf(7); +},{"./_assert.js":82,"./utils.js":91}],84:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.add5L = exports.add5H = exports.add4H = exports.add4L = exports.add3H = exports.add3L = exports.add = exports.rotlBL = exports.rotlBH = exports.rotlSL = exports.rotlSH = exports.rotr32L = exports.rotr32H = exports.rotrBL = exports.rotrBH = exports.rotrSL = exports.rotrSH = exports.shrSL = exports.shrSH = exports.toBig = exports.split = exports.fromBig = void 0; +const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1); +const _32n = /* @__PURE__ */ BigInt(32); +// We are not using BigUint64Array, because they are extremely slow as per 2022 +function fromBig(n, le = false) { + if (le) + return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) }; + return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 }; +} +exports.fromBig = fromBig; +function split(lst, le = false) { + let Ah = new Uint32Array(lst.length); + let Al = new Uint32Array(lst.length); + for (let i = 0; i < lst.length; i++) { + const { h, l } = fromBig(lst[i], le); + [Ah[i], Al[i]] = [h, l]; + } + return [Ah, Al]; +} +exports.split = split; +const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0); +exports.toBig = toBig; +// for Shift in [0, 32) +const shrSH = (h, _l, s) => h >>> s; +exports.shrSH = shrSH; +const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s); +exports.shrSL = shrSL; +// Right rotate for Shift in [1, 32) +const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s)); +exports.rotrSH = rotrSH; +const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s); +exports.rotrSL = rotrSL; +// Right rotate for Shift in (32, 64), NOTE: 32 is special case. +const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32)); +exports.rotrBH = rotrBH; +const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s)); +exports.rotrBL = rotrBL; +// Right rotate for shift===32 (just swaps l&h) +const rotr32H = (_h, l) => l; +exports.rotr32H = rotr32H; +const rotr32L = (h, _l) => h; +exports.rotr32L = rotr32L; +// Left rotate for Shift in [1, 32) +const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s)); +exports.rotlSH = rotlSH; +const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s)); +exports.rotlSL = rotlSL; +// Left rotate for Shift in (32, 64), NOTE: 32 is special case. +const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s)); +exports.rotlBH = rotlBH; +const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s)); +exports.rotlBL = rotlBL; +// JS uses 32-bit signed integers for bitwise operations which means we cannot +// simple take carry out of low bit sum by shift, we need to use division. +function add(Ah, Al, Bh, Bl) { + const l = (Al >>> 0) + (Bl >>> 0); + return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 }; +} +exports.add = add; +// Addition with more than 2 elements +const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0); +exports.add3L = add3L; +const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0; +exports.add3H = add3H; +const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0); +exports.add4L = add4L; +const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0; +exports.add4H = add4H; +const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0); +exports.add5L = add5L; +const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0; +exports.add5H = add5H; +// prettier-ignore +const u64 = { + fromBig, split, toBig, + shrSH, shrSL, + rotrSH, rotrSL, rotrBH, rotrBL, + rotr32H, rotr32L, + rotlSH, rotlSL, rotlBH, rotlBL, + add, add3L, add3H, add4L, add4H, add5H, add5L, +}; +exports.default = u64; + +},{}],85:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.crypto = void 0; +exports.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined; -function deterministicGetK0(privateKey, publicKey, message) { - check.checkSignParams(privateKey, message); +},{}],86:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hmac = exports.HMAC = void 0; +const _assert_js_1 = require("./_assert.js"); +const utils_js_1 = require("./utils.js"); +// HMAC (RFC 2104) +class HMAC extends utils_js_1.Hash { + constructor(hash, _key) { + super(); + this.finished = false; + this.destroyed = false; + (0, _assert_js_1.hash)(hash); + const key = (0, utils_js_1.toBytes)(_key); + this.iHash = hash.create(); + if (typeof this.iHash.update !== 'function') + throw new Error('Expected instance of class which extends utils.Hash'); + this.blockLen = this.iHash.blockLen; + this.outputLen = this.iHash.outputLen; + const blockLen = this.blockLen; + const pad = new Uint8Array(blockLen); + // blockLen can be bigger than outputLen + pad.set(key.length > blockLen ? hash.create().update(key).digest() : key); + for (let i = 0; i < pad.length; i++) + pad[i] ^= 0x36; + this.iHash.update(pad); + // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone + this.oHash = hash.create(); + // Undo internal XOR && apply outer XOR + for (let i = 0; i < pad.length; i++) + pad[i] ^= 0x36 ^ 0x5c; + this.oHash.update(pad); + pad.fill(0); + } + update(buf) { + (0, _assert_js_1.exists)(this); + this.iHash.update(buf); + return this; + } + digestInto(out) { + (0, _assert_js_1.exists)(this); + (0, _assert_js_1.bytes)(out, this.outputLen); + this.finished = true; + this.iHash.digestInto(out); + this.oHash.update(out); + this.oHash.digestInto(out); + this.destroy(); + } + digest() { + const out = new Uint8Array(this.oHash.outputLen); + this.digestInto(out); + return out; + } + _cloneInto(to) { + // Create new instance without calling constructor since key already in state and we don't know it. + to || (to = Object.create(Object.getPrototypeOf(this), {})); + const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this; + to = to; + to.finished = finished; + to.destroyed = destroyed; + to.blockLen = blockLen; + to.outputLen = outputLen; + to.oHash = oHash._cloneInto(to.oHash); + to.iHash = iHash._cloneInto(to.iHash); + return to; + } + destroy() { + this.destroyed = true; + this.oHash.destroy(); + this.iHash.destroy(); + } +} +exports.HMAC = HMAC; +/** + * HMAC: RFC2104 message authentication code. + * @param hash - function that would be used e.g. sha256 + * @param key - message key + * @param message - message data + */ +const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest(); +exports.hmac = hmac; +exports.hmac.create = (hash, key) => new HMAC(hash, key); - const h = taggedHash('BIP0340/nonce', concat([convert.intToBuffer(privateKey), publicKey, message])); - const i = convert.bufferToInt(h); - return i.mod(n); +},{"./_assert.js":82,"./utils.js":91}],87:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ripemd160 = exports.RIPEMD160 = void 0; +const _md_js_1 = require("./_md.js"); +const utils_js_1 = require("./utils.js"); +// https://homes.esat.kuleuven.be/~bosselae/ripemd160.html +// https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf +const Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]); +const Id = /* @__PURE__ */ new Uint8Array(new Array(16).fill(0).map((_, i) => i)); +const Pi = /* @__PURE__ */ Id.map((i) => (9 * i + 5) % 16); +let idxL = [Id]; +let idxR = [Pi]; +for (let i = 0; i < 4; i++) + for (let j of [idxL, idxR]) + j.push(j[i].map((k) => Rho[k])); +const shifts = /* @__PURE__ */ [ + [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8], + [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7], + [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9], + [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6], + [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5], +].map((i) => new Uint8Array(i)); +const shiftsL = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts[i][j])); +const shiftsR = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts[i][j])); +const Kl = /* @__PURE__ */ new Uint32Array([ + 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e, +]); +const Kr = /* @__PURE__ */ new Uint32Array([ + 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000, +]); +// It's called f() in spec. +function f(group, x, y, z) { + if (group === 0) + return x ^ y ^ z; + else if (group === 1) + return (x & y) | (~x & z); + else if (group === 2) + return (x | ~y) ^ z; + else if (group === 3) + return (x & z) | (y & ~z); + else + return x ^ (y | ~z); +} +// Temporary buffer, not used to store anything between runs +const R_BUF = /* @__PURE__ */ new Uint32Array(16); +class RIPEMD160 extends _md_js_1.HashMD { + constructor() { + super(64, 20, 8, true); + this.h0 = 0x67452301 | 0; + this.h1 = 0xefcdab89 | 0; + this.h2 = 0x98badcfe | 0; + this.h3 = 0x10325476 | 0; + this.h4 = 0xc3d2e1f0 | 0; + } + get() { + const { h0, h1, h2, h3, h4 } = this; + return [h0, h1, h2, h3, h4]; + } + set(h0, h1, h2, h3, h4) { + this.h0 = h0 | 0; + this.h1 = h1 | 0; + this.h2 = h2 | 0; + this.h3 = h3 | 0; + this.h4 = h4 | 0; + } + process(view, offset) { + for (let i = 0; i < 16; i++, offset += 4) + R_BUF[i] = view.getUint32(offset, true); + // prettier-ignore + let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el; + // Instead of iterating 0 to 80, we split it into 5 groups + // And use the groups in constants, functions, etc. Much simpler + for (let group = 0; group < 5; group++) { + const rGroup = 4 - group; + const hbl = Kl[group], hbr = Kr[group]; // prettier-ignore + const rl = idxL[group], rr = idxR[group]; // prettier-ignore + const sl = shiftsL[group], sr = shiftsR[group]; // prettier-ignore + for (let i = 0; i < 16; i++) { + const tl = ((0, utils_js_1.rotl)(al + f(group, bl, cl, dl) + R_BUF[rl[i]] + hbl, sl[i]) + el) | 0; + al = el, el = dl, dl = (0, utils_js_1.rotl)(cl, 10) | 0, cl = bl, bl = tl; // prettier-ignore + } + // 2 loops are 10% faster + for (let i = 0; i < 16; i++) { + const tr = ((0, utils_js_1.rotl)(ar + f(rGroup, br, cr, dr) + R_BUF[rr[i]] + hbr, sr[i]) + er) | 0; + ar = er, er = dr, dr = (0, utils_js_1.rotl)(cr, 10) | 0, cr = br, br = tr; // prettier-ignore + } + } + // Add the compressed chunk to the current hash value + this.set((this.h1 + cl + dr) | 0, (this.h2 + dl + er) | 0, (this.h3 + el + ar) | 0, (this.h4 + al + br) | 0, (this.h0 + bl + cr) | 0); + } + roundClean() { + R_BUF.fill(0); + } + destroy() { + this.destroyed = true; + this.buffer.fill(0); + this.set(0, 0, 0, 0, 0); + } } +exports.RIPEMD160 = RIPEMD160; +/** + * RIPEMD-160 - a hash function from 1990s. + * @param message - msg that would be hashed + */ +exports.ripemd160 = (0, utils_js_1.wrapConstructor)(() => new RIPEMD160()); -function isEven(pubKey) { - return pubKey.affineY.mod(two).equals(zero); +},{"./_md.js":83,"./utils.js":91}],88:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.sha1 = void 0; +const _md_js_1 = require("./_md.js"); +const utils_js_1 = require("./utils.js"); +// SHA1 (RFC 3174) was cryptographically broken. It's still used. Don't use it for a new protocol. +// Initial state +const SHA1_IV = /* @__PURE__ */ new Uint32Array([ + 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, +]); +// Temporary buffer, not used to store anything between runs +// Named this way because it matches specification. +const SHA1_W = /* @__PURE__ */ new Uint32Array(80); +class SHA1 extends _md_js_1.HashMD { + constructor() { + super(64, 20, 8, false); + this.A = SHA1_IV[0] | 0; + this.B = SHA1_IV[1] | 0; + this.C = SHA1_IV[2] | 0; + this.D = SHA1_IV[3] | 0; + this.E = SHA1_IV[4] | 0; + } + get() { + const { A, B, C, D, E } = this; + return [A, B, C, D, E]; + } + set(A, B, C, D, E) { + this.A = A | 0; + this.B = B | 0; + this.C = C | 0; + this.D = D | 0; + this.E = E | 0; + } + process(view, offset) { + for (let i = 0; i < 16; i++, offset += 4) + SHA1_W[i] = view.getUint32(offset, false); + for (let i = 16; i < 80; i++) + SHA1_W[i] = (0, utils_js_1.rotl)(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1); + // Compression function main loop, 80 rounds + let { A, B, C, D, E } = this; + for (let i = 0; i < 80; i++) { + let F, K; + if (i < 20) { + F = (0, _md_js_1.Chi)(B, C, D); + K = 0x5a827999; + } + else if (i < 40) { + F = B ^ C ^ D; + K = 0x6ed9eba1; + } + else if (i < 60) { + F = (0, _md_js_1.Maj)(B, C, D); + K = 0x8f1bbcdc; + } + else { + F = B ^ C ^ D; + K = 0xca62c1d6; + } + const T = ((0, utils_js_1.rotl)(A, 5) + F + E + K + SHA1_W[i]) | 0; + E = D; + D = C; + C = (0, utils_js_1.rotl)(B, 30); + B = A; + A = T; + } + // Add the compressed chunk to the current hash value + A = (A + this.A) | 0; + B = (B + this.B) | 0; + C = (C + this.C) | 0; + D = (D + this.D) | 0; + E = (E + this.E) | 0; + this.set(A, B, C, D, E); + } + roundClean() { + SHA1_W.fill(0); + } + destroy() { + this.set(0, 0, 0, 0, 0); + this.buffer.fill(0); + } } +exports.sha1 = (0, utils_js_1.wrapConstructor)(() => new SHA1()); -function getEvenKey(pubKey, privateKey) { - if (isEven(pubKey)) { - return privateKey.clone(); - } - - return n.subtract(privateKey); +},{"./_md.js":83,"./utils.js":91}],89:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.sha224 = exports.sha256 = void 0; +const _md_js_1 = require("./_md.js"); +const utils_js_1 = require("./utils.js"); +// SHA2-256 need to try 2^128 hashes to execute birthday attack. +// BTC network is doing 2^67 hashes/sec as per early 2023. +// Round constants: +// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311) +// prettier-ignore +const SHA256_K = /* @__PURE__ */ new Uint32Array([ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +]); +// Initial state: +// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19 +// prettier-ignore +const SHA256_IV = /* @__PURE__ */ new Uint32Array([ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 +]); +// Temporary buffer, not used to store anything between runs +// Named this way because it matches specification. +const SHA256_W = /* @__PURE__ */ new Uint32Array(64); +class SHA256 extends _md_js_1.HashMD { + constructor() { + super(64, 32, 8, false); + // We cannot use array here since array allows indexing by variable + // which means optimizer/compiler cannot use registers. + this.A = SHA256_IV[0] | 0; + this.B = SHA256_IV[1] | 0; + this.C = SHA256_IV[2] | 0; + this.D = SHA256_IV[3] | 0; + this.E = SHA256_IV[4] | 0; + this.F = SHA256_IV[5] | 0; + this.G = SHA256_IV[6] | 0; + this.H = SHA256_IV[7] | 0; + } + get() { + const { A, B, C, D, E, F, G, H } = this; + return [A, B, C, D, E, F, G, H]; + } + // prettier-ignore + set(A, B, C, D, E, F, G, H) { + this.A = A | 0; + this.B = B | 0; + this.C = C | 0; + this.D = D | 0; + this.E = E | 0; + this.F = F | 0; + this.G = G | 0; + this.H = H | 0; + } + process(view, offset) { + // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array + for (let i = 0; i < 16; i++, offset += 4) + SHA256_W[i] = view.getUint32(offset, false); + for (let i = 16; i < 64; i++) { + const W15 = SHA256_W[i - 15]; + const W2 = SHA256_W[i - 2]; + const s0 = (0, utils_js_1.rotr)(W15, 7) ^ (0, utils_js_1.rotr)(W15, 18) ^ (W15 >>> 3); + const s1 = (0, utils_js_1.rotr)(W2, 17) ^ (0, utils_js_1.rotr)(W2, 19) ^ (W2 >>> 10); + SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0; + } + // Compression function main loop, 64 rounds + let { A, B, C, D, E, F, G, H } = this; + for (let i = 0; i < 64; i++) { + const sigma1 = (0, utils_js_1.rotr)(E, 6) ^ (0, utils_js_1.rotr)(E, 11) ^ (0, utils_js_1.rotr)(E, 25); + const T1 = (H + sigma1 + (0, _md_js_1.Chi)(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0; + const sigma0 = (0, utils_js_1.rotr)(A, 2) ^ (0, utils_js_1.rotr)(A, 13) ^ (0, utils_js_1.rotr)(A, 22); + const T2 = (sigma0 + (0, _md_js_1.Maj)(A, B, C)) | 0; + H = G; + G = F; + F = E; + E = (D + T1) | 0; + D = C; + C = B; + B = A; + A = (T1 + T2) | 0; + } + // Add the compressed chunk to the current hash value + A = (A + this.A) | 0; + B = (B + this.B) | 0; + C = (C + this.C) | 0; + D = (D + this.D) | 0; + E = (E + this.E) | 0; + F = (F + this.F) | 0; + G = (G + this.G) | 0; + H = (H + this.H) | 0; + this.set(A, B, C, D, E, F, G, H); + } + roundClean() { + SHA256_W.fill(0); + } + destroy() { + this.set(0, 0, 0, 0, 0, 0, 0, 0); + this.buffer.fill(0); + } +} +// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf +class SHA224 extends SHA256 { + constructor() { + super(); + this.A = 0xc1059ed8 | 0; + this.B = 0x367cd507 | 0; + this.C = 0x3070dd17 | 0; + this.D = 0xf70e5939 | 0; + this.E = 0xffc00b31 | 0; + this.F = 0x68581511 | 0; + this.G = 0x64f98fa7 | 0; + this.H = 0xbefa4fa4 | 0; + this.outputLen = 28; + } } +/** + * SHA2-256 hash function + * @param message - data that would be hashed + */ +exports.sha256 = (0, utils_js_1.wrapConstructor)(() => new SHA256()); +exports.sha224 = (0, utils_js_1.wrapConstructor)(() => new SHA224()); -function getE(Rx, Px, m) { - const hash = taggedHash('BIP0340/challenge', concat([Rx, Px, m])); - return convert.bufferToInt(hash).mod(n); +},{"./_md.js":83,"./utils.js":91}],90:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.sha384 = exports.sha512_256 = exports.sha512_224 = exports.sha512 = exports.SHA512 = void 0; +const _md_js_1 = require("./_md.js"); +const _u64_js_1 = require("./_u64.js"); +const utils_js_1 = require("./utils.js"); +// Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409): +// prettier-ignore +const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => _u64_js_1.default.split([ + '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc', + '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118', + '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2', + '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694', + '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65', + '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5', + '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4', + '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70', + '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df', + '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b', + '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30', + '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8', + '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8', + '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3', + '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec', + '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b', + '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178', + '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b', + '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c', + '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817' +].map(n => BigInt(n))))(); +// Temporary buffer, not used to store anything between runs +const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80); +const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80); +class SHA512 extends _md_js_1.HashMD { + constructor() { + super(128, 64, 16, false); + // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers. + // Also looks cleaner and easier to verify with spec. + // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19): + // h -- high 32 bits, l -- low 32 bits + this.Ah = 0x6a09e667 | 0; + this.Al = 0xf3bcc908 | 0; + this.Bh = 0xbb67ae85 | 0; + this.Bl = 0x84caa73b | 0; + this.Ch = 0x3c6ef372 | 0; + this.Cl = 0xfe94f82b | 0; + this.Dh = 0xa54ff53a | 0; + this.Dl = 0x5f1d36f1 | 0; + this.Eh = 0x510e527f | 0; + this.El = 0xade682d1 | 0; + this.Fh = 0x9b05688c | 0; + this.Fl = 0x2b3e6c1f | 0; + this.Gh = 0x1f83d9ab | 0; + this.Gl = 0xfb41bd6b | 0; + this.Hh = 0x5be0cd19 | 0; + this.Hl = 0x137e2179 | 0; + } + // prettier-ignore + get() { + const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this; + return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl]; + } + // prettier-ignore + set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) { + this.Ah = Ah | 0; + this.Al = Al | 0; + this.Bh = Bh | 0; + this.Bl = Bl | 0; + this.Ch = Ch | 0; + this.Cl = Cl | 0; + this.Dh = Dh | 0; + this.Dl = Dl | 0; + this.Eh = Eh | 0; + this.El = El | 0; + this.Fh = Fh | 0; + this.Fl = Fl | 0; + this.Gh = Gh | 0; + this.Gl = Gl | 0; + this.Hh = Hh | 0; + this.Hl = Hl | 0; + } + process(view, offset) { + // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array + for (let i = 0; i < 16; i++, offset += 4) { + SHA512_W_H[i] = view.getUint32(offset); + SHA512_W_L[i] = view.getUint32((offset += 4)); + } + for (let i = 16; i < 80; i++) { + // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7) + const W15h = SHA512_W_H[i - 15] | 0; + const W15l = SHA512_W_L[i - 15] | 0; + const s0h = _u64_js_1.default.rotrSH(W15h, W15l, 1) ^ _u64_js_1.default.rotrSH(W15h, W15l, 8) ^ _u64_js_1.default.shrSH(W15h, W15l, 7); + const s0l = _u64_js_1.default.rotrSL(W15h, W15l, 1) ^ _u64_js_1.default.rotrSL(W15h, W15l, 8) ^ _u64_js_1.default.shrSL(W15h, W15l, 7); + // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6) + const W2h = SHA512_W_H[i - 2] | 0; + const W2l = SHA512_W_L[i - 2] | 0; + const s1h = _u64_js_1.default.rotrSH(W2h, W2l, 19) ^ _u64_js_1.default.rotrBH(W2h, W2l, 61) ^ _u64_js_1.default.shrSH(W2h, W2l, 6); + const s1l = _u64_js_1.default.rotrSL(W2h, W2l, 19) ^ _u64_js_1.default.rotrBL(W2h, W2l, 61) ^ _u64_js_1.default.shrSL(W2h, W2l, 6); + // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16]; + const SUMl = _u64_js_1.default.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]); + const SUMh = _u64_js_1.default.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]); + SHA512_W_H[i] = SUMh | 0; + SHA512_W_L[i] = SUMl | 0; + } + let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this; + // Compression function main loop, 80 rounds + for (let i = 0; i < 80; i++) { + // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41) + const sigma1h = _u64_js_1.default.rotrSH(Eh, El, 14) ^ _u64_js_1.default.rotrSH(Eh, El, 18) ^ _u64_js_1.default.rotrBH(Eh, El, 41); + const sigma1l = _u64_js_1.default.rotrSL(Eh, El, 14) ^ _u64_js_1.default.rotrSL(Eh, El, 18) ^ _u64_js_1.default.rotrBL(Eh, El, 41); + //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0; + const CHIh = (Eh & Fh) ^ (~Eh & Gh); + const CHIl = (El & Fl) ^ (~El & Gl); + // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i] + // prettier-ignore + const T1ll = _u64_js_1.default.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]); + const T1h = _u64_js_1.default.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]); + const T1l = T1ll | 0; + // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39) + const sigma0h = _u64_js_1.default.rotrSH(Ah, Al, 28) ^ _u64_js_1.default.rotrBH(Ah, Al, 34) ^ _u64_js_1.default.rotrBH(Ah, Al, 39); + const sigma0l = _u64_js_1.default.rotrSL(Ah, Al, 28) ^ _u64_js_1.default.rotrBL(Ah, Al, 34) ^ _u64_js_1.default.rotrBL(Ah, Al, 39); + const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch); + const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl); + Hh = Gh | 0; + Hl = Gl | 0; + Gh = Fh | 0; + Gl = Fl | 0; + Fh = Eh | 0; + Fl = El | 0; + ({ h: Eh, l: El } = _u64_js_1.default.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0)); + Dh = Ch | 0; + Dl = Cl | 0; + Ch = Bh | 0; + Cl = Bl | 0; + Bh = Ah | 0; + Bl = Al | 0; + const All = _u64_js_1.default.add3L(T1l, sigma0l, MAJl); + Ah = _u64_js_1.default.add3H(All, T1h, sigma0h, MAJh); + Al = All | 0; + } + // Add the compressed chunk to the current hash value + ({ h: Ah, l: Al } = _u64_js_1.default.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0)); + ({ h: Bh, l: Bl } = _u64_js_1.default.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0)); + ({ h: Ch, l: Cl } = _u64_js_1.default.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0)); + ({ h: Dh, l: Dl } = _u64_js_1.default.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0)); + ({ h: Eh, l: El } = _u64_js_1.default.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0)); + ({ h: Fh, l: Fl } = _u64_js_1.default.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0)); + ({ h: Gh, l: Gl } = _u64_js_1.default.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0)); + ({ h: Hh, l: Hl } = _u64_js_1.default.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0)); + this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl); + } + roundClean() { + SHA512_W_H.fill(0); + SHA512_W_L.fill(0); + } + destroy() { + this.buffer.fill(0); + this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + } +} +exports.SHA512 = SHA512; +class SHA512_224 extends SHA512 { + constructor() { + super(); + // h -- high 32 bits, l -- low 32 bits + this.Ah = 0x8c3d37c8 | 0; + this.Al = 0x19544da2 | 0; + this.Bh = 0x73e19966 | 0; + this.Bl = 0x89dcd4d6 | 0; + this.Ch = 0x1dfab7ae | 0; + this.Cl = 0x32ff9c82 | 0; + this.Dh = 0x679dd514 | 0; + this.Dl = 0x582f9fcf | 0; + this.Eh = 0x0f6d2b69 | 0; + this.El = 0x7bd44da8 | 0; + this.Fh = 0x77e36f73 | 0; + this.Fl = 0x04c48942 | 0; + this.Gh = 0x3f9d85a8 | 0; + this.Gl = 0x6a1d36c8 | 0; + this.Hh = 0x1112e6ad | 0; + this.Hl = 0x91d692a1 | 0; + this.outputLen = 28; + } +} +class SHA512_256 extends SHA512 { + constructor() { + super(); + // h -- high 32 bits, l -- low 32 bits + this.Ah = 0x22312194 | 0; + this.Al = 0xfc2bf72c | 0; + this.Bh = 0x9f555fa3 | 0; + this.Bl = 0xc84c64c2 | 0; + this.Ch = 0x2393b86b | 0; + this.Cl = 0x6f53b151 | 0; + this.Dh = 0x96387719 | 0; + this.Dl = 0x5940eabd | 0; + this.Eh = 0x96283ee2 | 0; + this.El = 0xa88effe3 | 0; + this.Fh = 0xbe5e1e25 | 0; + this.Fl = 0x53863992 | 0; + this.Gh = 0x2b0199fc | 0; + this.Gl = 0x2c85b8aa | 0; + this.Hh = 0x0eb72ddc | 0; + this.Hl = 0x81c52ca2 | 0; + this.outputLen = 32; + } +} +class SHA384 extends SHA512 { + constructor() { + super(); + // h -- high 32 bits, l -- low 32 bits + this.Ah = 0xcbbb9d5d | 0; + this.Al = 0xc1059ed8 | 0; + this.Bh = 0x629a292a | 0; + this.Bl = 0x367cd507 | 0; + this.Ch = 0x9159015a | 0; + this.Cl = 0x3070dd17 | 0; + this.Dh = 0x152fecd8 | 0; + this.Dl = 0xf70e5939 | 0; + this.Eh = 0x67332667 | 0; + this.El = 0xffc00b31 | 0; + this.Fh = 0x8eb44a87 | 0; + this.Fl = 0x68581511 | 0; + this.Gh = 0xdb0c2e0d | 0; + this.Gl = 0x64f98fa7 | 0; + this.Hh = 0x47b5481d | 0; + this.Hl = 0xbefa4fa4 | 0; + this.outputLen = 48; + } +} +exports.sha512 = (0, utils_js_1.wrapConstructor)(() => new SHA512()); +exports.sha512_224 = (0, utils_js_1.wrapConstructor)(() => new SHA512_224()); +exports.sha512_256 = (0, utils_js_1.wrapConstructor)(() => new SHA512_256()); +exports.sha384 = (0, utils_js_1.wrapConstructor)(() => new SHA384()); + +},{"./_md.js":83,"./_u64.js":84,"./utils.js":91}],91:[function(require,module,exports){ +"use strict"; +/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.randomBytes = exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.utf8ToBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.byteSwap32 = exports.byteSwapIfBE = exports.byteSwap = exports.isLE = exports.rotl = exports.rotr = exports.createView = exports.u32 = exports.u8 = exports.isBytes = void 0; +// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+. +// node.js versions earlier than v19 don't declare it in global scope. +// For node.js, package.json#exports field mapping rewrites import +// from `crypto` to `cryptoNode`, which imports native module. +// Makes the utils un-importable in browsers without a bundler. +// Once node.js 18 is deprecated (2025-04-30), we can just drop the import. +const crypto_1 = require("@noble/hashes/crypto"); +const _assert_js_1 = require("./_assert.js"); +// export { isBytes } from './_assert.js'; +// We can't reuse isBytes from _assert, because somehow this causes huge perf issues +function isBytes(a) { + return (a instanceof Uint8Array || + (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')); +} +exports.isBytes = isBytes; +// Cast array to different type +const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength); +exports.u8 = u8; +const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4)); +exports.u32 = u32; +// Cast array to view +const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength); +exports.createView = createView; +// The rotate right (circular right shift) operation for uint32 +const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift); +exports.rotr = rotr; +// The rotate left (circular left shift) operation for uint32 +const rotl = (word, shift) => (word << shift) | ((word >>> (32 - shift)) >>> 0); +exports.rotl = rotl; +exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44; +// The byte swap operation for uint32 +const byteSwap = (word) => ((word << 24) & 0xff000000) | + ((word << 8) & 0xff0000) | + ((word >>> 8) & 0xff00) | + ((word >>> 24) & 0xff); +exports.byteSwap = byteSwap; +// Conditionally byte swap if on a big-endian platform +exports.byteSwapIfBE = exports.isLE ? (n) => n : (n) => (0, exports.byteSwap)(n); +// In place byte swap for Uint32Array +function byteSwap32(arr) { + for (let i = 0; i < arr.length; i++) { + arr[i] = (0, exports.byteSwap)(arr[i]); + } +} +exports.byteSwap32 = byteSwap32; +// Array where index 0xf0 (240) is mapped to string 'f0' +const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0')); +/** + * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123' + */ +function bytesToHex(bytes) { + (0, _assert_js_1.bytes)(bytes); + // pre-caching improves the speed 6x + let hex = ''; + for (let i = 0; i < bytes.length; i++) { + hex += hexes[bytes[i]]; + } + return hex; } - -function getR(s, e, P) { - const sG = G.multiply(s); - const eP = P.multiply(e); - return sG.add(eP.negate()); +exports.bytesToHex = bytesToHex; +// We use optimized technique to convert hex string to byte array +const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 }; +function asciiToBase16(char) { + if (char >= asciis._0 && char <= asciis._9) + return char - asciis._0; + if (char >= asciis._A && char <= asciis._F) + return char - (asciis._A - 10); + if (char >= asciis._a && char <= asciis._f) + return char - (asciis._a - 10); + return; } - -function taggedHash(tag, msg) { - const tagHash = convert.hash(tag); - return convert.hash(concat([tagHash, tagHash, Buffer.from(msg)])); +/** + * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23]) + */ +function hexToBytes(hex) { + if (typeof hex !== 'string') + throw new Error('hex string expected, got ' + typeof hex); + const hl = hex.length; + const al = hl / 2; + if (hl % 2) + throw new Error('padded hex string expected, got unpadded hex of length ' + hl); + const array = new Uint8Array(al); + for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) { + const n1 = asciiToBase16(hex.charCodeAt(hi)); + const n2 = asciiToBase16(hex.charCodeAt(hi + 1)); + if (n1 === undefined || n2 === undefined) { + const char = hex[hi] + hex[hi + 1]; + throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi); + } + array[ai] = n1 * 16 + n2; + } + return array; +} +exports.hexToBytes = hexToBytes; +// There is no setImmediate in browser and setTimeout is slow. +// call of async fn will return Promise, which will be fullfiled only on +// next scheduler queue processing step and this is exactly what we need. +const nextTick = async () => { }; +exports.nextTick = nextTick; +// Returns control to thread each 'tick' ms to avoid blocking +async function asyncLoop(iters, tick, cb) { + let ts = Date.now(); + for (let i = 0; i < iters; i++) { + cb(i); + // Date.now() is not monotonic, so in case if clock goes backwards we return return control too + const diff = Date.now() - ts; + if (diff >= 0 && diff < tick) + continue; + await (0, exports.nextTick)(); + ts += diff; + } } - -function liftX(Px) { - const x = convert.bufferToInt(Px); - - const c = x.pow(three).add(seven).mod(p); - const y = c.modPow(p.add(one).divide(four), p); - if (c.compareTo(y.modPow(two, p)) !== 0) { - throw new Error('c is not equal to y^2'); - } - let P = ecurve.Point.fromAffine(curve, x, y); - if (!isEven(P)) { - P = ecurve.Point.fromAffine(curve, x, p.subtract(y)); - } - - check.checkPointExists(true, P); - return P; +exports.asyncLoop = asyncLoop; +/** + * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99]) + */ +function utf8ToBytes(str) { + if (typeof str !== 'string') + throw new Error(`utf8ToBytes expected string, got ${typeof str}`); + return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809 } - -function randomA() { - let a = null; - for (; ;) { - a = convert.bufferToInt(Buffer.from(randomBytes(32))); - try { - check.checkRange('a', a); - return a; - } catch (e) { - // out of range, generate another one +exports.utf8ToBytes = utf8ToBytes; +/** + * Normalizes (non-hex) string or Uint8Array to Uint8Array. + * Warning: when Uint8Array is passed, it would NOT get copied. + * Keep in mind for future mutable operations. + */ +function toBytes(data) { + if (typeof data === 'string') + data = utf8ToBytes(data); + (0, _assert_js_1.bytes)(data); + return data; +} +exports.toBytes = toBytes; +/** + * Copies several Uint8Arrays into one. + */ +function concatBytes(...arrays) { + let sum = 0; + for (let i = 0; i < arrays.length; i++) { + const a = arrays[i]; + (0, _assert_js_1.bytes)(a); + sum += a.length; + } + const res = new Uint8Array(sum); + for (let i = 0, pad = 0; i < arrays.length; i++) { + const a = arrays[i]; + res.set(a, pad); + pad += a.length; } - } + return res; } - -module.exports = { - deterministicGetK0, - isEven, - getEvenKey, - getE, - getR, - taggedHash, - liftX, - randomA, -}; - -},{"./check":32,"./convert":33,"bigi":30,"ecurve":176,"randombytes":262,"safe-buffer":280}],36:[function(require,module,exports){ -const Buffer = require('safe-buffer').Buffer; -const ecurve = require('ecurve'); -const curve = ecurve.getCurveByName('secp256k1'); -const math = require('./math'); -const check = require('./check'); -const convert = require('./convert'); - -const concat = Buffer.concat; -const G = curve.G; -const n = curve.n; -const MUSIG_TAG = convert.hash(Buffer.from('MuSig coefficient')); - -// Computes ell = SHA256(pubKeys[0], ..., pubKeys[pubKeys.length-1]) with -// pubKeys serialized in compressed form. -function computeEll(pubKeys) { - check.checkPubKeyArr(pubKeys); - return convert.hash(concat(pubKeys)) +exports.concatBytes = concatBytes; +// For runtime check if class implements interface +class Hash { + // Safe version that clones internal state + clone() { + return this._cloneInto(); + } +} +exports.Hash = Hash; +const toStr = {}.toString; +function checkOpts(defaults, opts) { + if (opts !== undefined && toStr.call(opts) !== '[object Object]') + throw new Error('Options should be object or undefined'); + const merged = Object.assign(defaults, opts); + return merged; +} +exports.checkOpts = checkOpts; +function wrapConstructor(hashCons) { + const hashC = (msg) => hashCons().update(toBytes(msg)).digest(); + const tmp = hashCons(); + hashC.outputLen = tmp.outputLen; + hashC.blockLen = tmp.blockLen; + hashC.create = () => hashCons(); + return hashC; +} +exports.wrapConstructor = wrapConstructor; +function wrapConstructorWithOpts(hashCons) { + const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest(); + const tmp = hashCons({}); + hashC.outputLen = tmp.outputLen; + hashC.blockLen = tmp.blockLen; + hashC.create = (opts) => hashCons(opts); + return hashC; +} +exports.wrapConstructorWithOpts = wrapConstructorWithOpts; +function wrapXOFConstructorWithOpts(hashCons) { + const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest(); + const tmp = hashCons({}); + hashC.outputLen = tmp.outputLen; + hashC.blockLen = tmp.blockLen; + hashC.create = (opts) => hashCons(opts); + return hashC; +} +exports.wrapXOFConstructorWithOpts = wrapXOFConstructorWithOpts; +/** + * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS. + */ +function randomBytes(bytesLength = 32) { + if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') { + return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength)); + } + throw new Error('crypto.getRandomValues must be defined'); } +exports.randomBytes = randomBytes; -function computeCoefficient(ell, idx) { - const idxBuf = Buffer.alloc(4); - idxBuf.writeUInt32LE(idx); - const data = concat([MUSIG_TAG, MUSIG_TAG, ell, idxBuf]); - return convert.bufferToInt(convert.hash(data)).mod(n); +},{"./_assert.js":82,"@noble/hashes/crypto":85}],92:[function(require,module,exports){ +"use strict"; +/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.utils = exports.schnorr = exports.verify = exports.signSync = exports.sign = exports.getSharedSecret = exports.recoverPublicKey = exports.getPublicKey = exports.Signature = exports.Point = exports.CURVE = void 0; +const nodeCrypto = require("crypto"); +const _0n = BigInt(0); +const _1n = BigInt(1); +const _2n = BigInt(2); +const _3n = BigInt(3); +const _8n = BigInt(8); +const CURVE = Object.freeze({ + a: _0n, + b: BigInt(7), + P: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'), + n: BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'), + h: _1n, + Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'), + Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'), + beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'), +}); +exports.CURVE = CURVE; +const divNearest = (a, b) => (a + b / _2n) / b; +const endo = { + beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'), + splitScalar(k) { + const { n } = CURVE; + const a1 = BigInt('0x3086d221a7d46bcde86c90e49284eb15'); + const b1 = -_1n * BigInt('0xe4437ed6010e88286f547fa90abfe4c3'); + const a2 = BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8'); + const b2 = a1; + const POW_2_128 = BigInt('0x100000000000000000000000000000000'); + const c1 = divNearest(b2 * k, n); + const c2 = divNearest(-b1 * k, n); + let k1 = mod(k - c1 * a1 - c2 * a2, n); + let k2 = mod(-c1 * b1 - c2 * b2, n); + const k1neg = k1 > POW_2_128; + const k2neg = k2 > POW_2_128; + if (k1neg) + k1 = n - k1; + if (k2neg) + k2 = n - k2; + if (k1 > POW_2_128 || k2 > POW_2_128) { + throw new Error('splitScalarEndo: Endomorphism failed, k=' + k); + } + return { k1neg, k1, k2neg, k2 }; + }, +}; +const fieldLen = 32; +const groupLen = 32; +const hashLen = 32; +const compressedLen = fieldLen + 1; +const uncompressedLen = 2 * fieldLen + 1; +function weierstrass(x) { + const { a, b } = CURVE; + const x2 = mod(x * x); + const x3 = mod(x2 * x); + return mod(x3 + a * x + b); +} +const USE_ENDOMORPHISM = CURVE.a === _0n; +class ShaError extends Error { + constructor(message) { + super(message); + } +} +function assertJacPoint(other) { + if (!(other instanceof JacobianPoint)) + throw new TypeError('JacobianPoint expected'); +} +class JacobianPoint { + constructor(x, y, z) { + this.x = x; + this.y = y; + this.z = z; + } + static fromAffine(p) { + if (!(p instanceof Point)) { + throw new TypeError('JacobianPoint#fromAffine: expected Point'); + } + if (p.equals(Point.ZERO)) + return JacobianPoint.ZERO; + return new JacobianPoint(p.x, p.y, _1n); + } + static toAffineBatch(points) { + const toInv = invertBatch(points.map((p) => p.z)); + return points.map((p, i) => p.toAffine(toInv[i])); + } + static normalizeZ(points) { + return JacobianPoint.toAffineBatch(points).map(JacobianPoint.fromAffine); + } + equals(other) { + assertJacPoint(other); + const { x: X1, y: Y1, z: Z1 } = this; + const { x: X2, y: Y2, z: Z2 } = other; + const Z1Z1 = mod(Z1 * Z1); + const Z2Z2 = mod(Z2 * Z2); + const U1 = mod(X1 * Z2Z2); + const U2 = mod(X2 * Z1Z1); + const S1 = mod(mod(Y1 * Z2) * Z2Z2); + const S2 = mod(mod(Y2 * Z1) * Z1Z1); + return U1 === U2 && S1 === S2; + } + negate() { + return new JacobianPoint(this.x, mod(-this.y), this.z); + } + double() { + const { x: X1, y: Y1, z: Z1 } = this; + const A = mod(X1 * X1); + const B = mod(Y1 * Y1); + const C = mod(B * B); + const x1b = X1 + B; + const D = mod(_2n * (mod(x1b * x1b) - A - C)); + const E = mod(_3n * A); + const F = mod(E * E); + const X3 = mod(F - _2n * D); + const Y3 = mod(E * (D - X3) - _8n * C); + const Z3 = mod(_2n * Y1 * Z1); + return new JacobianPoint(X3, Y3, Z3); + } + add(other) { + assertJacPoint(other); + const { x: X1, y: Y1, z: Z1 } = this; + const { x: X2, y: Y2, z: Z2 } = other; + if (X2 === _0n || Y2 === _0n) + return this; + if (X1 === _0n || Y1 === _0n) + return other; + const Z1Z1 = mod(Z1 * Z1); + const Z2Z2 = mod(Z2 * Z2); + const U1 = mod(X1 * Z2Z2); + const U2 = mod(X2 * Z1Z1); + const S1 = mod(mod(Y1 * Z2) * Z2Z2); + const S2 = mod(mod(Y2 * Z1) * Z1Z1); + const H = mod(U2 - U1); + const r = mod(S2 - S1); + if (H === _0n) { + if (r === _0n) { + return this.double(); + } + else { + return JacobianPoint.ZERO; + } + } + const HH = mod(H * H); + const HHH = mod(H * HH); + const V = mod(U1 * HH); + const X3 = mod(r * r - HHH - _2n * V); + const Y3 = mod(r * (V - X3) - S1 * HHH); + const Z3 = mod(Z1 * Z2 * H); + return new JacobianPoint(X3, Y3, Z3); + } + subtract(other) { + return this.add(other.negate()); + } + multiplyUnsafe(scalar) { + const P0 = JacobianPoint.ZERO; + if (typeof scalar === 'bigint' && scalar === _0n) + return P0; + let n = normalizeScalar(scalar); + if (n === _1n) + return this; + if (!USE_ENDOMORPHISM) { + let p = P0; + let d = this; + while (n > _0n) { + if (n & _1n) + p = p.add(d); + d = d.double(); + n >>= _1n; + } + return p; + } + let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n); + let k1p = P0; + let k2p = P0; + let d = this; + while (k1 > _0n || k2 > _0n) { + if (k1 & _1n) + k1p = k1p.add(d); + if (k2 & _1n) + k2p = k2p.add(d); + d = d.double(); + k1 >>= _1n; + k2 >>= _1n; + } + if (k1neg) + k1p = k1p.negate(); + if (k2neg) + k2p = k2p.negate(); + k2p = new JacobianPoint(mod(k2p.x * endo.beta), k2p.y, k2p.z); + return k1p.add(k2p); + } + precomputeWindow(W) { + const windows = USE_ENDOMORPHISM ? 128 / W + 1 : 256 / W + 1; + const points = []; + let p = this; + let base = p; + for (let window = 0; window < windows; window++) { + base = p; + points.push(base); + for (let i = 1; i < 2 ** (W - 1); i++) { + base = base.add(p); + points.push(base); + } + p = base.double(); + } + return points; + } + wNAF(n, affinePoint) { + if (!affinePoint && this.equals(JacobianPoint.BASE)) + affinePoint = Point.BASE; + const W = (affinePoint && affinePoint._WINDOW_SIZE) || 1; + if (256 % W) { + throw new Error('Point#wNAF: Invalid precomputation window, must be power of 2'); + } + let precomputes = affinePoint && pointPrecomputes.get(affinePoint); + if (!precomputes) { + precomputes = this.precomputeWindow(W); + if (affinePoint && W !== 1) { + precomputes = JacobianPoint.normalizeZ(precomputes); + pointPrecomputes.set(affinePoint, precomputes); + } + } + let p = JacobianPoint.ZERO; + let f = JacobianPoint.BASE; + const windows = 1 + (USE_ENDOMORPHISM ? 128 / W : 256 / W); + const windowSize = 2 ** (W - 1); + const mask = BigInt(2 ** W - 1); + const maxNumber = 2 ** W; + const shiftBy = BigInt(W); + for (let window = 0; window < windows; window++) { + const offset = window * windowSize; + let wbits = Number(n & mask); + n >>= shiftBy; + if (wbits > windowSize) { + wbits -= maxNumber; + n += _1n; + } + const offset1 = offset; + const offset2 = offset + Math.abs(wbits) - 1; + const cond1 = window % 2 !== 0; + const cond2 = wbits < 0; + if (wbits === 0) { + f = f.add(constTimeNegate(cond1, precomputes[offset1])); + } + else { + p = p.add(constTimeNegate(cond2, precomputes[offset2])); + } + } + return { p, f }; + } + multiply(scalar, affinePoint) { + let n = normalizeScalar(scalar); + let point; + let fake; + if (USE_ENDOMORPHISM) { + const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n); + let { p: k1p, f: f1p } = this.wNAF(k1, affinePoint); + let { p: k2p, f: f2p } = this.wNAF(k2, affinePoint); + k1p = constTimeNegate(k1neg, k1p); + k2p = constTimeNegate(k2neg, k2p); + k2p = new JacobianPoint(mod(k2p.x * endo.beta), k2p.y, k2p.z); + point = k1p.add(k2p); + fake = f1p.add(f2p); + } + else { + const { p, f } = this.wNAF(n, affinePoint); + point = p; + fake = f; + } + return JacobianPoint.normalizeZ([point, fake])[0]; + } + toAffine(invZ) { + const { x, y, z } = this; + const is0 = this.equals(JacobianPoint.ZERO); + if (invZ == null) + invZ = is0 ? _8n : invert(z); + const iz1 = invZ; + const iz2 = mod(iz1 * iz1); + const iz3 = mod(iz2 * iz1); + const ax = mod(x * iz2); + const ay = mod(y * iz3); + const zz = mod(z * iz1); + if (is0) + return Point.ZERO; + if (zz !== _1n) + throw new Error('invZ was invalid'); + return new Point(ax, ay); + } +} +JacobianPoint.BASE = new JacobianPoint(CURVE.Gx, CURVE.Gy, _1n); +JacobianPoint.ZERO = new JacobianPoint(_0n, _1n, _0n); +function constTimeNegate(condition, item) { + const neg = item.negate(); + return condition ? neg : item; +} +const pointPrecomputes = new WeakMap(); +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + _setWindowSize(windowSize) { + this._WINDOW_SIZE = windowSize; + pointPrecomputes.delete(this); + } + hasEvenY() { + return this.y % _2n === _0n; + } + static fromCompressedHex(bytes) { + const isShort = bytes.length === 32; + const x = bytesToNumber(isShort ? bytes : bytes.subarray(1)); + if (!isValidFieldElement(x)) + throw new Error('Point is not on curve'); + const y2 = weierstrass(x); + let y = sqrtMod(y2); + const isYOdd = (y & _1n) === _1n; + if (isShort) { + if (isYOdd) + y = mod(-y); + } + else { + const isFirstByteOdd = (bytes[0] & 1) === 1; + if (isFirstByteOdd !== isYOdd) + y = mod(-y); + } + const point = new Point(x, y); + point.assertValidity(); + return point; + } + static fromUncompressedHex(bytes) { + const x = bytesToNumber(bytes.subarray(1, fieldLen + 1)); + const y = bytesToNumber(bytes.subarray(fieldLen + 1, fieldLen * 2 + 1)); + const point = new Point(x, y); + point.assertValidity(); + return point; + } + static fromHex(hex) { + const bytes = ensureBytes(hex); + const len = bytes.length; + const header = bytes[0]; + if (len === fieldLen) + return this.fromCompressedHex(bytes); + if (len === compressedLen && (header === 0x02 || header === 0x03)) { + return this.fromCompressedHex(bytes); + } + if (len === uncompressedLen && header === 0x04) + return this.fromUncompressedHex(bytes); + throw new Error(`Point.fromHex: received invalid point. Expected 32-${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes, not ${len}`); + } + static fromPrivateKey(privateKey) { + return Point.BASE.multiply(normalizePrivateKey(privateKey)); + } + static fromSignature(msgHash, signature, recovery) { + const { r, s } = normalizeSignature(signature); + if (![0, 1, 2, 3].includes(recovery)) + throw new Error('Cannot recover: invalid recovery bit'); + const h = truncateHash(ensureBytes(msgHash)); + const { n } = CURVE; + const radj = recovery === 2 || recovery === 3 ? r + n : r; + const rinv = invert(radj, n); + const u1 = mod(-h * rinv, n); + const u2 = mod(s * rinv, n); + const prefix = recovery & 1 ? '03' : '02'; + const R = Point.fromHex(prefix + numTo32bStr(radj)); + const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2); + if (!Q) + throw new Error('Cannot recover signature: point at infinify'); + Q.assertValidity(); + return Q; + } + toRawBytes(isCompressed = false) { + return hexToBytes(this.toHex(isCompressed)); + } + toHex(isCompressed = false) { + const x = numTo32bStr(this.x); + if (isCompressed) { + const prefix = this.hasEvenY() ? '02' : '03'; + return `${prefix}${x}`; + } + else { + return `04${x}${numTo32bStr(this.y)}`; + } + } + toHexX() { + return this.toHex(true).slice(2); + } + toRawX() { + return this.toRawBytes(true).slice(1); + } + assertValidity() { + const msg = 'Point is not on elliptic curve'; + const { x, y } = this; + if (!isValidFieldElement(x) || !isValidFieldElement(y)) + throw new Error(msg); + const left = mod(y * y); + const right = weierstrass(x); + if (mod(left - right) !== _0n) + throw new Error(msg); + } + equals(other) { + return this.x === other.x && this.y === other.y; + } + negate() { + return new Point(this.x, mod(-this.y)); + } + double() { + return JacobianPoint.fromAffine(this).double().toAffine(); + } + add(other) { + return JacobianPoint.fromAffine(this).add(JacobianPoint.fromAffine(other)).toAffine(); + } + subtract(other) { + return this.add(other.negate()); + } + multiply(scalar) { + return JacobianPoint.fromAffine(this).multiply(scalar, this).toAffine(); + } + multiplyAndAddUnsafe(Q, a, b) { + const P = JacobianPoint.fromAffine(this); + const aP = a === _0n || a === _1n || this !== Point.BASE ? P.multiplyUnsafe(a) : P.multiply(a); + const bQ = JacobianPoint.fromAffine(Q).multiplyUnsafe(b); + const sum = aP.add(bQ); + return sum.equals(JacobianPoint.ZERO) ? undefined : sum.toAffine(); + } } - -function pubKeyCombine(pubKeys, pubKeyHash) { - const ell = pubKeyHash || computeEll(pubKeys); - let X = null; - for (let i = 0; i < pubKeys.length; i++) { - const Xi = math.liftX(pubKeys[i]); - const coefficient = computeCoefficient(ell, i); - const summand = Xi.multiply(coefficient); - if (X === null) { - X = summand; - } else { - X = X.add(summand); +exports.Point = Point; +Point.BASE = new Point(CURVE.Gx, CURVE.Gy); +Point.ZERO = new Point(_0n, _0n); +function sliceDER(s) { + return Number.parseInt(s[0], 16) >= 8 ? '00' + s : s; +} +function parseDERInt(data) { + if (data.length < 2 || data[0] !== 0x02) { + throw new Error(`Invalid signature integer tag: ${bytesToHex(data)}`); + } + const len = data[1]; + const res = data.subarray(2, len + 2); + if (!len || res.length !== len) { + throw new Error(`Invalid signature integer: wrong length`); + } + if (res[0] === 0x00 && res[1] <= 0x7f) { + throw new Error('Invalid signature integer: trailing length'); + } + return { data: bytesToNumber(res), left: data.subarray(len + 2) }; +} +function parseDERSignature(data) { + if (data.length < 2 || data[0] != 0x30) { + throw new Error(`Invalid signature tag: ${bytesToHex(data)}`); + } + if (data[1] !== data.length - 2) { + throw new Error('Invalid signature: incorrect length'); + } + const { data: r, left: sBytes } = parseDERInt(data.subarray(2)); + const { data: s, left: rBytesLeft } = parseDERInt(sBytes); + if (rBytesLeft.length) { + throw new Error(`Invalid signature: left bytes after parsing: ${bytesToHex(rBytesLeft)}`); + } + return { r, s }; +} +class Signature { + constructor(r, s) { + this.r = r; + this.s = s; + this.assertValidity(); + } + static fromCompact(hex) { + const arr = hex instanceof Uint8Array; + const name = 'Signature.fromCompact'; + if (typeof hex !== 'string' && !arr) + throw new TypeError(`${name}: Expected string or Uint8Array`); + const str = arr ? bytesToHex(hex) : hex; + if (str.length !== 128) + throw new Error(`${name}: Expected 64-byte hex`); + return new Signature(hexToNumber(str.slice(0, 64)), hexToNumber(str.slice(64, 128))); + } + static fromDER(hex) { + const arr = hex instanceof Uint8Array; + if (typeof hex !== 'string' && !arr) + throw new TypeError(`Signature.fromDER: Expected string or Uint8Array`); + const { r, s } = parseDERSignature(arr ? hex : hexToBytes(hex)); + return new Signature(r, s); + } + static fromHex(hex) { + return this.fromDER(hex); + } + assertValidity() { + const { r, s } = this; + if (!isWithinCurveOrder(r)) + throw new Error('Invalid Signature: r must be 0 < r < n'); + if (!isWithinCurveOrder(s)) + throw new Error('Invalid Signature: s must be 0 < s < n'); + } + hasHighS() { + const HALF = CURVE.n >> _1n; + return this.s > HALF; + } + normalizeS() { + return this.hasHighS() ? new Signature(this.r, mod(-this.s, CURVE.n)) : this; + } + toDERRawBytes() { + return hexToBytes(this.toDERHex()); + } + toDERHex() { + const sHex = sliceDER(numberToHexUnpadded(this.s)); + const rHex = sliceDER(numberToHexUnpadded(this.r)); + const sHexL = sHex.length / 2; + const rHexL = rHex.length / 2; + const sLen = numberToHexUnpadded(sHexL); + const rLen = numberToHexUnpadded(rHexL); + const length = numberToHexUnpadded(rHexL + sHexL + 4); + return `30${length}02${rLen}${rHex}02${sLen}${sHex}`; + } + toRawBytes() { + return this.toDERRawBytes(); + } + toHex() { + return this.toDERHex(); + } + toCompactRawBytes() { + return hexToBytes(this.toCompactHex()); + } + toCompactHex() { + return numTo32bStr(this.r) + numTo32bStr(this.s); + } +} +exports.Signature = Signature; +function concatBytes(...arrays) { + if (!arrays.every((b) => b instanceof Uint8Array)) + throw new Error('Uint8Array list expected'); + if (arrays.length === 1) + return arrays[0]; + const length = arrays.reduce((a, arr) => a + arr.length, 0); + const result = new Uint8Array(length); + for (let i = 0, pad = 0; i < arrays.length; i++) { + const arr = arrays[i]; + result.set(arr, pad); + pad += arr.length; } - } - return X; + return result; } - -function sessionInitialize(sessionId, privateKey, message, pubKeyCombined, pkParity, ell, idx) { - check.checkSessionParams(sessionId, privateKey, message, pubKeyCombined, ell); - - const session = { - sessionId, - message, - pubKeyCombined, - pkParity, - ell, - idx, - }; - - const coefficient = computeCoefficient(ell, idx); - session.secretKey = privateKey.multiply(coefficient).mod(n); - session.ownKeyParity = math.isEven(G.multiply(privateKey)); - if (session.pkParity !== session.ownKeyParity) { - session.secretKey = n.subtract(session.secretKey); - } - - const nonceData = concat([sessionId, message, session.pubKeyCombined, convert.intToBuffer(privateKey)]); - session.secretNonce = convert.bufferToInt(convert.hash(nonceData)); - check.checkRange('secretNonce', session.secretNonce); - const R = G.multiply(session.secretNonce); - session.nonce = convert.intToBuffer(R.affineX); - session.nonceParity = math.isEven(R); - session.commitment = convert.hash(session.nonce); - return session; +const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0')); +function bytesToHex(uint8a) { + if (!(uint8a instanceof Uint8Array)) + throw new Error('Expected Uint8Array'); + let hex = ''; + for (let i = 0; i < uint8a.length; i++) { + hex += hexes[uint8a[i]]; + } + return hex; } - -function sessionNonceCombine(session, nonces) { - check.checkNonceArr(nonces); - let R = math.liftX(nonces[0]); - for (let i = 1; i < nonces.length; i++) { - R = R.add(math.liftX(nonces[i])); - } - session.combinedNonceParity = math.isEven(R); - return convert.intToBuffer(R.affineX); +const POW_2_256 = BigInt('0x10000000000000000000000000000000000000000000000000000000000000000'); +function numTo32bStr(num) { + if (typeof num !== 'bigint') + throw new Error('Expected bigint'); + if (!(_0n <= num && num < POW_2_256)) + throw new Error('Expected number 0 <= n < 2^256'); + return num.toString(16).padStart(64, '0'); +} +function numTo32b(num) { + const b = hexToBytes(numTo32bStr(num)); + if (b.length !== 32) + throw new Error('Error: expected 32 bytes'); + return b; } - -function partialSign(session, message, nonceCombined, pubKeyCombined) { - const e = math.getE(nonceCombined, pubKeyCombined, message); - const sk = session.secretKey; - let k = session.secretNonce; - if (session.nonceParity !== session.combinedNonceParity) { - k = n.subtract(k); - } - return sk.multiply(e).add(k).mod(n); +function numberToHexUnpadded(num) { + const hex = num.toString(16); + return hex.length & 1 ? `0${hex}` : hex; +} +function hexToNumber(hex) { + if (typeof hex !== 'string') { + throw new TypeError('hexToNumber: expected string, got ' + typeof hex); + } + return BigInt(`0x${hex}`); +} +function hexToBytes(hex) { + if (typeof hex !== 'string') { + throw new TypeError('hexToBytes: expected string, got ' + typeof hex); + } + if (hex.length % 2) + throw new Error('hexToBytes: received invalid unpadded hex' + hex.length); + const array = new Uint8Array(hex.length / 2); + for (let i = 0; i < array.length; i++) { + const j = i * 2; + const hexByte = hex.slice(j, j + 2); + const byte = Number.parseInt(hexByte, 16); + if (Number.isNaN(byte) || byte < 0) + throw new Error('Invalid byte sequence'); + array[i] = byte; + } + return array; +} +function bytesToNumber(bytes) { + return hexToNumber(bytesToHex(bytes)); +} +function ensureBytes(hex) { + return hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes(hex); +} +function normalizeScalar(num) { + if (typeof num === 'number' && Number.isSafeInteger(num) && num > 0) + return BigInt(num); + if (typeof num === 'bigint' && isWithinCurveOrder(num)) + return num; + throw new TypeError('Expected valid private scalar: 0 < scalar < curve.n'); +} +function mod(a, b = CURVE.P) { + const result = a % b; + return result >= _0n ? result : b + result; +} +function pow2(x, power) { + const { P } = CURVE; + let res = x; + while (power-- > _0n) { + res *= res; + res %= P; + } + return res; } - -function partialSigVerify(session, partialSig, nonceCombined, idx, pubKey, nonce) { - let e = math.getE(nonceCombined, session.pubKeyCombined, session.message); - const coefficient = computeCoefficient(session.ell, idx); - const Pj = math.liftX(pubKey); - const Ri = math.liftX(nonce); - - if (!session.pkParity) { - e = n.subtract(e); - } - - let RP = math.getR(partialSig, e.multiply(coefficient).mod(n), Pj); - if (session.combinedNonceParity) { - RP = RP.negate(); - } - const sum = RP.add(Ri); - if (!sum.curve.isInfinity(sum)) { - throw new Error('partial signature verification failed'); - } +function sqrtMod(x) { + const { P } = CURVE; + const _6n = BigInt(6); + const _11n = BigInt(11); + const _22n = BigInt(22); + const _23n = BigInt(23); + const _44n = BigInt(44); + const _88n = BigInt(88); + const b2 = (x * x * x) % P; + const b3 = (b2 * b2 * x) % P; + const b6 = (pow2(b3, _3n) * b3) % P; + const b9 = (pow2(b6, _3n) * b3) % P; + const b11 = (pow2(b9, _2n) * b2) % P; + const b22 = (pow2(b11, _11n) * b11) % P; + const b44 = (pow2(b22, _22n) * b22) % P; + const b88 = (pow2(b44, _44n) * b44) % P; + const b176 = (pow2(b88, _88n) * b88) % P; + const b220 = (pow2(b176, _44n) * b44) % P; + const b223 = (pow2(b220, _3n) * b3) % P; + const t1 = (pow2(b223, _23n) * b22) % P; + const t2 = (pow2(t1, _6n) * b2) % P; + const rt = pow2(t2, _2n); + const xc = (rt * rt) % P; + if (xc !== x) + throw new Error('Cannot find square root'); + return rt; +} +function invert(number, modulo = CURVE.P) { + if (number === _0n || modulo <= _0n) { + throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`); + } + let a = mod(number, modulo); + let b = modulo; + let x = _0n, y = _1n, u = _1n, v = _0n; + while (a !== _0n) { + const q = b / a; + const r = b % a; + const m = x - u * q; + const n = y - v * q; + b = a, a = r, x = u, y = v, u = m, v = n; + } + const gcd = b; + if (gcd !== _1n) + throw new Error('invert: does not exist'); + return mod(x, modulo); +} +function invertBatch(nums, p = CURVE.P) { + const scratch = new Array(nums.length); + const lastMultiplied = nums.reduce((acc, num, i) => { + if (num === _0n) + return acc; + scratch[i] = acc; + return mod(acc * num, p); + }, _1n); + const inverted = invert(lastMultiplied, p); + nums.reduceRight((acc, num, i) => { + if (num === _0n) + return acc; + scratch[i] = mod(acc * scratch[i], p); + return mod(acc * num, p); + }, inverted); + return scratch; +} +function bits2int_2(bytes) { + const delta = bytes.length * 8 - groupLen * 8; + const num = bytesToNumber(bytes); + return delta > 0 ? num >> BigInt(delta) : num; +} +function truncateHash(hash, truncateOnly = false) { + const h = bits2int_2(hash); + if (truncateOnly) + return h; + const { n } = CURVE; + return h >= n ? h - n : h; +} +let _sha256Sync; +let _hmacSha256Sync; +class HmacDrbg { + constructor(hashLen, qByteLen) { + this.hashLen = hashLen; + this.qByteLen = qByteLen; + if (typeof hashLen !== 'number' || hashLen < 2) + throw new Error('hashLen must be a number'); + if (typeof qByteLen !== 'number' || qByteLen < 2) + throw new Error('qByteLen must be a number'); + this.v = new Uint8Array(hashLen).fill(1); + this.k = new Uint8Array(hashLen).fill(0); + this.counter = 0; + } + hmac(...values) { + return exports.utils.hmacSha256(this.k, ...values); + } + hmacSync(...values) { + return _hmacSha256Sync(this.k, ...values); + } + checkSync() { + if (typeof _hmacSha256Sync !== 'function') + throw new ShaError('hmacSha256Sync needs to be set'); + } + incr() { + if (this.counter >= 1000) + throw new Error('Tried 1,000 k values for sign(), all were invalid'); + this.counter += 1; + } + async reseed(seed = new Uint8Array()) { + this.k = await this.hmac(this.v, Uint8Array.from([0x00]), seed); + this.v = await this.hmac(this.v); + if (seed.length === 0) + return; + this.k = await this.hmac(this.v, Uint8Array.from([0x01]), seed); + this.v = await this.hmac(this.v); + } + reseedSync(seed = new Uint8Array()) { + this.checkSync(); + this.k = this.hmacSync(this.v, Uint8Array.from([0x00]), seed); + this.v = this.hmacSync(this.v); + if (seed.length === 0) + return; + this.k = this.hmacSync(this.v, Uint8Array.from([0x01]), seed); + this.v = this.hmacSync(this.v); + } + async generate() { + this.incr(); + let len = 0; + const out = []; + while (len < this.qByteLen) { + this.v = await this.hmac(this.v); + const sl = this.v.slice(); + out.push(sl); + len += this.v.length; + } + return concatBytes(...out); + } + generateSync() { + this.checkSync(); + this.incr(); + let len = 0; + const out = []; + while (len < this.qByteLen) { + this.v = this.hmacSync(this.v); + const sl = this.v.slice(); + out.push(sl); + len += this.v.length; + } + return concatBytes(...out); + } } - -function partialSigCombine(nonceCombined, partialSigs) { - const R = math.liftX(nonceCombined); - check.checkArray('partialSigs', partialSigs); - const Rx = convert.intToBuffer(R.affineX); - let s = partialSigs[0]; - for (let i = 1; i < partialSigs.length; i++) { - s = s.add(partialSigs[i]).mod(n); - } - return concat([Rx, convert.intToBuffer(s)]); +function isWithinCurveOrder(num) { + return _0n < num && num < CURVE.n; } - -module.exports = { - computeEll, - computeCoefficient, - pubKeyCombine, - sessionInitialize, - sessionNonceCombine, - partialSign, - partialSigVerify, - partialSigCombine, -}; - -},{"./check":32,"./convert":33,"./math":35,"ecurve":176,"safe-buffer":280}],37:[function(require,module,exports){ -const BigInteger = require('bigi'); -const Buffer = require('safe-buffer').Buffer; -const ecurve = require('ecurve'); -const curve = ecurve.getCurveByName('secp256k1'); -const math = require('./math'); -const check = require('./check'); -const convert = require('./convert'); - -const concat = Buffer.concat; -const G = curve.G; -const p = curve.p; -const n = curve.n; -const zero = BigInteger.ZERO; - -function sign(privateKey, message, aux) { - // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#signing - check.checkSignParams(privateKey, message); - privateKey = typeof (privateKey) == 'string' ? BigInteger.fromHex(privateKey) : privateKey; - - const P = G.multiply(privateKey); - const Px = convert.intToBuffer(P.affineX); - - const d = math.getEvenKey(P, privateKey); - let kPrime - if (aux) { - check.checkAux(aux); - - const t = convert.intToBuffer(d.xor(convert.bufferToInt(math.taggedHash('BIP0340/aux', aux)))); - const rand = math.taggedHash('BIP0340/nonce', concat([t, Px, message])) - kPrime = convert.bufferToInt(rand).mod(n); - } else { - kPrime = math.deterministicGetK0(d, Px, message); - } - - if (kPrime.signum() === 0) { - throw new Error('kPrime is zero'); - } - - const R = G.multiply(kPrime); - const k = math.getEvenKey(R, kPrime); - const Rx = convert.intToBuffer(R.affineX); - const e = math.getE(Rx, Px, message); - return concat([Rx, convert.intToBuffer(k.add(e.multiply(d)).mod(n))]); +function isValidFieldElement(num) { + return _0n < num && num < CURVE.P; } - -function verify(pubKey, message, signature) { - check.checkVerifyParams(pubKey, message, signature); - - // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#verification - const P = math.liftX(pubKey); - const Px = convert.intToBuffer(P.affineX); - const r = convert.bufferToInt(signature.slice(0, 32)); - const s = convert.bufferToInt(signature.slice(32, 64)); - check.checkSignatureInput(r, s); - const e = math.getE(convert.intToBuffer(r), Px, message); - const R = math.getR(s, e, P); - if (R.curve.isInfinity(R) || !math.isEven(R) || !R.affineX.equals(r)) { - throw new Error('signature verification failed'); - } -} - -function batchVerify(pubKeys, messages, signatures) { - check.checkBatchVerifyParams(pubKeys, messages, signatures); - - // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#Batch_Verification - let leftSide = zero; - let rightSide = null; - for (let i = 0; i < pubKeys.length; i++) { - const P = math.liftX(pubKeys[i]); - const Px = convert.intToBuffer(P.affineX); - const r = convert.bufferToInt(signatures[i].slice(0, 32)); - const s = convert.bufferToInt(signatures[i].slice(32, 64)); - check.checkSignatureInput(r, s); - const e = math.getE(convert.intToBuffer(r), Px, messages[i]); - const R = math.liftX(signatures[i].slice(0, 32)); - - if (i === 0) { - leftSide = leftSide.add(s); - rightSide = R; - rightSide = rightSide.add(P.multiply(e)); - } else { - const a = math.randomA(); - leftSide = leftSide.add(a.multiply(s)); - rightSide = rightSide.add(R.multiply(a)); - rightSide = rightSide.add(P.multiply(a.multiply(e))); +function kmdToSig(kBytes, m, d, lowS = true) { + const { n } = CURVE; + const k = truncateHash(kBytes, true); + if (!isWithinCurveOrder(k)) + return; + const kinv = invert(k, n); + const q = Point.BASE.multiply(k); + const r = mod(q.x, n); + if (r === _0n) + return; + const s = mod(kinv * mod(m + d * r, n), n); + if (s === _0n) + return; + let sig = new Signature(r, s); + let recovery = (q.x === sig.r ? 0 : 2) | Number(q.y & _1n); + if (lowS && sig.hasHighS()) { + sig = sig.normalizeS(); + recovery ^= 1; } - } - - if (!G.multiply(leftSide).equals(rightSide)) { - throw new Error('signature verification failed'); - } -} - -module.exports = { - sign, - verify, - batchVerify, -}; - -},{"./check":32,"./convert":33,"./math":35,"bigi":30,"ecurve":176,"safe-buffer":280}],38:[function(require,module,exports){ -const Buffer = require('safe-buffer').Buffer; -const ecurve = require('ecurve'); -const curve = ecurve.getCurveByName('secp256k1'); -const math = require('./math'); -const convert = require('./convert'); - -const concat = Buffer.concat; -const G = curve.G; - -function taprootConstruct(pubKey, merkleRoot) { - // If the spending conditions do not require a script path, the output key should commit to an unspendable script path - // instead of having no script path. This can be achieved by computing the output key point as - // Q = P + int(hashTapTweak(bytes(P)))G. - // https://en.bitcoin.it/wiki/BIP_0341#cite_note-22 - if (!merkleRoot || merkleRoot.length === 0) { - merkleRoot = Buffer.alloc(0, 0); - } - const Px = convert.intToBuffer(pubKey.affineX); - const P = math.liftX(Px); - const tweak = convert.bufferToInt(math.taggedHash('TapTweak', concat([Px, merkleRoot]))); - const Q = P.add(G.multiply(tweak)); - return convert.intToBuffer(Q.affineX); + return { sig, recovery }; } - -module.exports = { - taprootConstruct, -}; - -},{"./convert":33,"./math":35,"ecurve":176,"safe-buffer":280}],39:[function(require,module,exports){ -(function (Buffer){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const crypto = require("./crypto"); -const bs58check = require('bs58check'); -const ecc = require('tiny-secp256k1'); -const typeforce = require('typeforce'); -const wif = require('wif'); -const UINT256_TYPE = typeforce.BufferN(32); -const NETWORK_TYPE = typeforce.compile({ - wif: typeforce.UInt8, - bip32: { - public: typeforce.UInt32, - private: typeforce.UInt32, - }, -}); -const BITCOIN = { - messagePrefix: '\x18Bitcoin Signed Message:\n', - bech32: 'bc', - bip32: { - public: 0x0488b21e, - private: 0x0488ade4, - }, - pubKeyHash: 0x00, - scriptHash: 0x05, - wif: 0x80, -}; -const HIGHEST_BIT = 0x80000000; -const UINT31_MAX = Math.pow(2, 31) - 1; -function BIP32Path(value) { - return (typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null); +function normalizePrivateKey(key) { + let num; + if (typeof key === 'bigint') { + num = key; + } + else if (typeof key === 'number' && Number.isSafeInteger(key) && key > 0) { + num = BigInt(key); + } + else if (typeof key === 'string') { + if (key.length !== 2 * groupLen) + throw new Error('Expected 32 bytes of private key'); + num = hexToNumber(key); + } + else if (key instanceof Uint8Array) { + if (key.length !== groupLen) + throw new Error('Expected 32 bytes of private key'); + num = bytesToNumber(key); + } + else { + throw new TypeError('Expected valid private key'); + } + if (!isWithinCurveOrder(num)) + throw new Error('Expected private key: 0 < key < n'); + return num; } -function UInt31(value) { - return typeforce.UInt32(value) && value <= UINT31_MAX; +function normalizePublicKey(publicKey) { + if (publicKey instanceof Point) { + publicKey.assertValidity(); + return publicKey; + } + else { + return Point.fromHex(publicKey); + } } -class BIP32 { - constructor(__D, __Q, chainCode, network, __DEPTH = 0, __INDEX = 0, __PARENT_FINGERPRINT = 0x00000000) { - this.__D = __D; - this.__Q = __Q; - this.chainCode = chainCode; - this.network = network; - this.__DEPTH = __DEPTH; - this.__INDEX = __INDEX; - this.__PARENT_FINGERPRINT = __PARENT_FINGERPRINT; - typeforce(NETWORK_TYPE, network); - this.lowR = false; +function normalizeSignature(signature) { + if (signature instanceof Signature) { + signature.assertValidity(); + return signature; } - get depth() { - return this.__DEPTH; + try { + return Signature.fromDER(signature); } - get index() { - return this.__INDEX; + catch (error) { + return Signature.fromCompact(signature); } - get parentFingerprint() { - return this.__PARENT_FINGERPRINT; +} +function getPublicKey(privateKey, isCompressed = false) { + return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed); +} +exports.getPublicKey = getPublicKey; +function recoverPublicKey(msgHash, signature, recovery, isCompressed = false) { + return Point.fromSignature(msgHash, signature, recovery).toRawBytes(isCompressed); +} +exports.recoverPublicKey = recoverPublicKey; +function isProbPub(item) { + const arr = item instanceof Uint8Array; + const str = typeof item === 'string'; + const len = (arr || str) && item.length; + if (arr) + return len === compressedLen || len === uncompressedLen; + if (str) + return len === compressedLen * 2 || len === uncompressedLen * 2; + if (item instanceof Point) + return true; + return false; +} +function getSharedSecret(privateA, publicB, isCompressed = false) { + if (isProbPub(privateA)) + throw new TypeError('getSharedSecret: first arg must be private key'); + if (!isProbPub(publicB)) + throw new TypeError('getSharedSecret: second arg must be public key'); + const b = normalizePublicKey(publicB); + b.assertValidity(); + return b.multiply(normalizePrivateKey(privateA)).toRawBytes(isCompressed); +} +exports.getSharedSecret = getSharedSecret; +function bits2int(bytes) { + const slice = bytes.length > fieldLen ? bytes.slice(0, fieldLen) : bytes; + return bytesToNumber(slice); +} +function bits2octets(bytes) { + const z1 = bits2int(bytes); + const z2 = mod(z1, CURVE.n); + return int2octets(z2 < _0n ? z1 : z2); +} +function int2octets(num) { + return numTo32b(num); +} +function initSigArgs(msgHash, privateKey, extraEntropy) { + if (msgHash == null) + throw new Error(`sign: expected valid message hash, not "${msgHash}"`); + const h1 = ensureBytes(msgHash); + const d = normalizePrivateKey(privateKey); + const seedArgs = [int2octets(d), bits2octets(h1)]; + if (extraEntropy != null) { + if (extraEntropy === true) + extraEntropy = exports.utils.randomBytes(fieldLen); + const e = ensureBytes(extraEntropy); + if (e.length !== fieldLen) + throw new Error(`sign: Expected ${fieldLen} bytes of extra data`); + seedArgs.push(e); + } + const seed = concatBytes(...seedArgs); + const m = bits2int(h1); + return { seed, m, d }; +} +function finalizeSig(recSig, opts) { + const { sig, recovery } = recSig; + const { der, recovered } = Object.assign({ canonical: true, der: true }, opts); + const hashed = der ? sig.toDERRawBytes() : sig.toCompactRawBytes(); + return recovered ? [hashed, recovery] : hashed; +} +async function sign(msgHash, privKey, opts = {}) { + const { seed, m, d } = initSigArgs(msgHash, privKey, opts.extraEntropy); + const drbg = new HmacDrbg(hashLen, groupLen); + await drbg.reseed(seed); + let sig; + while (!(sig = kmdToSig(await drbg.generate(), m, d, opts.canonical))) + await drbg.reseed(); + return finalizeSig(sig, opts); +} +exports.sign = sign; +function signSync(msgHash, privKey, opts = {}) { + const { seed, m, d } = initSigArgs(msgHash, privKey, opts.extraEntropy); + const drbg = new HmacDrbg(hashLen, groupLen); + drbg.reseedSync(seed); + let sig; + while (!(sig = kmdToSig(drbg.generateSync(), m, d, opts.canonical))) + drbg.reseedSync(); + return finalizeSig(sig, opts); +} +exports.signSync = signSync; +const vopts = { strict: true }; +function verify(signature, msgHash, publicKey, opts = vopts) { + let sig; + try { + sig = normalizeSignature(signature); + msgHash = ensureBytes(msgHash); } - get publicKey() { - if (this.__Q === undefined) - this.__Q = ecc.pointFromScalar(this.__D, true); - return this.__Q; + catch (error) { + return false; } - get privateKey() { - return this.__D; + const { r, s } = sig; + if (opts.strict && sig.hasHighS()) + return false; + const h = truncateHash(msgHash); + let P; + try { + P = normalizePublicKey(publicKey); } - get identifier() { - return crypto.hash160(this.publicKey); + catch (error) { + return false; } - get fingerprint() { - return this.identifier.slice(0, 4); + const { n } = CURVE; + const sinv = invert(s, n); + const u1 = mod(h * sinv, n); + const u2 = mod(r * sinv, n); + const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2); + if (!R) + return false; + const v = mod(R.x, n); + return v === r; +} +exports.verify = verify; +function schnorrChallengeFinalize(ch) { + return mod(bytesToNumber(ch), CURVE.n); +} +class SchnorrSignature { + constructor(r, s) { + this.r = r; + this.s = s; + this.assertValidity(); + } + static fromHex(hex) { + const bytes = ensureBytes(hex); + if (bytes.length !== 64) + throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${bytes.length}`); + const r = bytesToNumber(bytes.subarray(0, 32)); + const s = bytesToNumber(bytes.subarray(32, 64)); + return new SchnorrSignature(r, s); + } + assertValidity() { + const { r, s } = this; + if (!isValidFieldElement(r) || !isWithinCurveOrder(s)) + throw new Error('Invalid signature'); + } + toHex() { + return numTo32bStr(this.r) + numTo32bStr(this.s); + } + toRawBytes() { + return hexToBytes(this.toHex()); + } +} +function schnorrGetPublicKey(privateKey) { + return Point.fromPrivateKey(privateKey).toRawX(); +} +class InternalSchnorrSignature { + constructor(message, privateKey, auxRand = exports.utils.randomBytes()) { + if (message == null) + throw new TypeError(`sign: Expected valid message, not "${message}"`); + this.m = ensureBytes(message); + const { x, scalar } = this.getScalar(normalizePrivateKey(privateKey)); + this.px = x; + this.d = scalar; + this.rand = ensureBytes(auxRand); + if (this.rand.length !== 32) + throw new TypeError('sign: Expected 32 bytes of aux randomness'); + } + getScalar(priv) { + const point = Point.fromPrivateKey(priv); + const scalar = point.hasEvenY() ? priv : CURVE.n - priv; + return { point, scalar, x: point.toRawX() }; + } + initNonce(d, t0h) { + return numTo32b(d ^ bytesToNumber(t0h)); + } + finalizeNonce(k0h) { + const k0 = mod(bytesToNumber(k0h), CURVE.n); + if (k0 === _0n) + throw new Error('sign: Creation of signature failed. k is zero'); + const { point: R, x: rx, scalar: k } = this.getScalar(k0); + return { R, rx, k }; + } + finalizeSig(R, k, e, d) { + return new SchnorrSignature(R.x, mod(k + e * d, CURVE.n)).toRawBytes(); + } + error() { + throw new Error('sign: Invalid signature produced'); + } + async calc() { + const { m, d, px, rand } = this; + const tag = exports.utils.taggedHash; + const t = this.initNonce(d, await tag(TAGS.aux, rand)); + const { R, rx, k } = this.finalizeNonce(await tag(TAGS.nonce, t, px, m)); + const e = schnorrChallengeFinalize(await tag(TAGS.challenge, rx, px, m)); + const sig = this.finalizeSig(R, k, e, d); + if (!(await schnorrVerify(sig, m, px))) + this.error(); + return sig; + } + calcSync() { + const { m, d, px, rand } = this; + const tag = exports.utils.taggedHashSync; + const t = this.initNonce(d, tag(TAGS.aux, rand)); + const { R, rx, k } = this.finalizeNonce(tag(TAGS.nonce, t, px, m)); + const e = schnorrChallengeFinalize(tag(TAGS.challenge, rx, px, m)); + const sig = this.finalizeSig(R, k, e, d); + if (!schnorrVerifySync(sig, m, px)) + this.error(); + return sig; + } +} +async function schnorrSign(msg, privKey, auxRand) { + return new InternalSchnorrSignature(msg, privKey, auxRand).calc(); +} +function schnorrSignSync(msg, privKey, auxRand) { + return new InternalSchnorrSignature(msg, privKey, auxRand).calcSync(); +} +function initSchnorrVerify(signature, message, publicKey) { + const raw = signature instanceof SchnorrSignature; + const sig = raw ? signature : SchnorrSignature.fromHex(signature); + if (raw) + sig.assertValidity(); + return { + ...sig, + m: ensureBytes(message), + P: normalizePublicKey(publicKey), + }; +} +function finalizeSchnorrVerify(r, P, s, e) { + const R = Point.BASE.multiplyAndAddUnsafe(P, normalizePrivateKey(s), mod(-e, CURVE.n)); + if (!R || !R.hasEvenY() || R.x !== r) + return false; + return true; +} +async function schnorrVerify(signature, message, publicKey) { + try { + const { r, s, m, P } = initSchnorrVerify(signature, message, publicKey); + const e = schnorrChallengeFinalize(await exports.utils.taggedHash(TAGS.challenge, numTo32b(r), P.toRawX(), m)); + return finalizeSchnorrVerify(r, P, s, e); } - get compressed() { - return true; + catch (error) { + return false; } - // Private === not neutered - // Public === neutered - isNeutered() { - return this.__D === undefined; +} +function schnorrVerifySync(signature, message, publicKey) { + try { + const { r, s, m, P } = initSchnorrVerify(signature, message, publicKey); + const e = schnorrChallengeFinalize(exports.utils.taggedHashSync(TAGS.challenge, numTo32b(r), P.toRawX(), m)); + return finalizeSchnorrVerify(r, P, s, e); } - neutered() { - return fromPublicKeyLocal(this.publicKey, this.chainCode, this.network, this.depth, this.index, this.parentFingerprint); + catch (error) { + if (error instanceof ShaError) + throw error; + return false; } - toBase58() { - const network = this.network; - const version = !this.isNeutered() - ? network.bip32.private - : network.bip32.public; - const buffer = Buffer.allocUnsafe(78); - // 4 bytes: version bytes - buffer.writeUInt32BE(version, 0); - // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... - buffer.writeUInt8(this.depth, 4); - // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) - buffer.writeUInt32BE(this.parentFingerprint, 5); - // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. - // This is encoded in big endian. (0x00000000 if master key) - buffer.writeUInt32BE(this.index, 9); - // 32 bytes: the chain code - this.chainCode.copy(buffer, 13); - // 33 bytes: the public key or private key data - if (!this.isNeutered()) { - // 0x00 + k for private keys - buffer.writeUInt8(0, 45); - this.privateKey.copy(buffer, 46); - // 33 bytes: the public key +} +exports.schnorr = { + Signature: SchnorrSignature, + getPublicKey: schnorrGetPublicKey, + sign: schnorrSign, + verify: schnorrVerify, + signSync: schnorrSignSync, + verifySync: schnorrVerifySync, +}; +Point.BASE._setWindowSize(8); +const crypto = { + node: nodeCrypto, + web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined, +}; +const TAGS = { + challenge: 'BIP0340/challenge', + aux: 'BIP0340/aux', + nonce: 'BIP0340/nonce', +}; +const TAGGED_HASH_PREFIXES = {}; +exports.utils = { + bytesToHex, + hexToBytes, + concatBytes, + mod, + invert, + isValidPrivateKey(privateKey) { + try { + normalizePrivateKey(privateKey); + return true; } - else { - // X9.62 encoding for public keys - this.publicKey.copy(buffer, 45); + catch (error) { + return false; } - return bs58check.encode(buffer); - } - toWIF() { - if (!this.privateKey) - throw new TypeError('Missing private key'); - return wif.encode(this.network.wif, this.privateKey, true); - } - // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions - derive(index) { - typeforce(typeforce.UInt32, index); - const isHardened = index >= HIGHEST_BIT; - const data = Buffer.allocUnsafe(37); - // Hardened child - if (isHardened) { - if (this.isNeutered()) - throw new TypeError('Missing private key for hardened child key'); - // data = 0x00 || ser256(kpar) || ser32(index) - data[0] = 0x00; - this.privateKey.copy(data, 1); - data.writeUInt32BE(index, 33); - // Normal child + }, + _bigintTo32Bytes: numTo32b, + _normalizePrivateKey: normalizePrivateKey, + hashToPrivateKey: (hash) => { + hash = ensureBytes(hash); + const minLen = groupLen + 8; + if (hash.length < minLen || hash.length > 1024) { + throw new Error(`Expected valid bytes of private key as per FIPS 186`); + } + const num = mod(bytesToNumber(hash), CURVE.n - _1n) + _1n; + return numTo32b(num); + }, + randomBytes: (bytesLength = 32) => { + if (crypto.web) { + return crypto.web.getRandomValues(new Uint8Array(bytesLength)); + } + else if (crypto.node) { + const { randomBytes } = crypto.node; + return Uint8Array.from(randomBytes(bytesLength)); } else { - // data = serP(point(kpar)) || ser32(index) - // = serP(Kpar) || ser32(index) - this.publicKey.copy(data, 0); - data.writeUInt32BE(index, 33); + throw new Error("The environment doesn't have randomBytes function"); } - const I = crypto.hmacSHA512(this.chainCode, data); - const IL = I.slice(0, 32); - const IR = I.slice(32); - // if parse256(IL) >= n, proceed with the next value for i - if (!ecc.isPrivate(IL)) - return this.derive(index + 1); - // Private parent key -> private child key - let hd; - if (!this.isNeutered()) { - // ki = parse256(IL) + kpar (mod n) - const ki = ecc.privateAdd(this.privateKey, IL); - // In case ki == 0, proceed with the next value for i - if (ki == null) - return this.derive(index + 1); - hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); - // Public parent key -> public child key + }, + randomPrivateKey: () => exports.utils.hashToPrivateKey(exports.utils.randomBytes(groupLen + 8)), + precompute(windowSize = 8, point = Point.BASE) { + const cached = point === Point.BASE ? point : new Point(point.x, point.y); + cached._setWindowSize(windowSize); + cached.multiply(_3n); + return cached; + }, + sha256: async (...messages) => { + if (crypto.web) { + const buffer = await crypto.web.subtle.digest('SHA-256', concatBytes(...messages)); + return new Uint8Array(buffer); + } + else if (crypto.node) { + const { createHash } = crypto.node; + const hash = createHash('sha256'); + messages.forEach((m) => hash.update(m)); + return Uint8Array.from(hash.digest()); } else { - // Ki = point(parse256(IL)) + Kpar - // = G*IL + Kpar - const Ki = ecc.pointAddScalar(this.publicKey, IL, true); - // In case Ki is the point at infinity, proceed with the next value for i - if (Ki === null) - return this.derive(index + 1); - hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); + throw new Error("The environment doesn't have sha256 function"); } - return hd; - } - deriveHardened(index) { - typeforce(UInt31, index); - // Only derives hardened private keys by default - return this.derive(index + HIGHEST_BIT); - } - derivePath(path) { - typeforce(BIP32Path, path); - let splitPath = path.split('/'); - if (splitPath[0] === 'm') { - if (this.parentFingerprint) - throw new TypeError('Expected master, got child'); - splitPath = splitPath.slice(1); + }, + hmacSha256: async (key, ...messages) => { + if (crypto.web) { + const ckey = await crypto.web.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']); + const message = concatBytes(...messages); + const buffer = await crypto.web.subtle.sign('HMAC', ckey, message); + return new Uint8Array(buffer); } - return splitPath.reduce((prevHd, indexStr) => { - let index; - if (indexStr.slice(-1) === `'`) { - index = parseInt(indexStr.slice(0, -1), 10); - return prevHd.deriveHardened(index); - } - else { - index = parseInt(indexStr, 10); - return prevHd.derive(index); - } - }, this); - } - sign(hash, lowR) { - if (!this.privateKey) - throw new Error('Missing private key'); - if (lowR === undefined) - lowR = this.lowR; - if (lowR === false) { - return ecc.sign(hash, this.privateKey); + else if (crypto.node) { + const { createHmac } = crypto.node; + const hash = createHmac('sha256', key); + messages.forEach((m) => hash.update(m)); + return Uint8Array.from(hash.digest()); } else { - let sig = ecc.sign(hash, this.privateKey); - const extraData = Buffer.alloc(32, 0); - let counter = 0; - // if first try is lowR, skip the loop - // for second try and on, add extra entropy counting up - while (sig[0] > 0x7f) { - counter++; - extraData.writeUIntLE(counter, 0, 6); - sig = ecc.signWithEntropy(hash, this.privateKey, extraData); - } - return sig; + throw new Error("The environment doesn't have hmac-sha256 function"); } - } - verify(hash, signature) { - return ecc.verify(hash, this.publicKey, signature); - } + }, + sha256Sync: undefined, + hmacSha256Sync: undefined, + taggedHash: async (tag, ...messages) => { + let tagP = TAGGED_HASH_PREFIXES[tag]; + if (tagP === undefined) { + const tagH = await exports.utils.sha256(Uint8Array.from(tag, (c) => c.charCodeAt(0))); + tagP = concatBytes(tagH, tagH); + TAGGED_HASH_PREFIXES[tag] = tagP; + } + return exports.utils.sha256(tagP, ...messages); + }, + taggedHashSync: (tag, ...messages) => { + if (typeof _sha256Sync !== 'function') + throw new ShaError('sha256Sync is undefined, you need to set it'); + let tagP = TAGGED_HASH_PREFIXES[tag]; + if (tagP === undefined) { + const tagH = _sha256Sync(Uint8Array.from(tag, (c) => c.charCodeAt(0))); + tagP = concatBytes(tagH, tagH); + TAGGED_HASH_PREFIXES[tag] = tagP; + } + return _sha256Sync(tagP, ...messages); + }, + _JacobianPoint: JacobianPoint, +}; +Object.defineProperties(exports.utils, { + sha256Sync: { + configurable: false, + get() { + return _sha256Sync; + }, + set(val) { + if (!_sha256Sync) + _sha256Sync = val; + }, + }, + hmacSha256Sync: { + configurable: false, + get() { + return _hmacSha256Sync; + }, + set(val) { + if (!_hmacSha256Sync) + _hmacSha256Sync = val; + }, + }, +}); + +},{"crypto":200}],93:[function(require,module,exports){ +"use strict"; +/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.bytes = exports.stringToBytes = exports.str = exports.bytesToString = exports.hex = exports.utf8 = exports.bech32m = exports.bech32 = exports.base58check = exports.createBase58check = exports.base58xmr = exports.base58xrp = exports.base58flickr = exports.base58 = exports.base64urlnopad = exports.base64url = exports.base64nopad = exports.base64 = exports.base32crockford = exports.base32hexnopad = exports.base32hex = exports.base32nopad = exports.base32 = exports.base16 = exports.utils = exports.assertNumber = void 0; +// Utilities +/** + * @__NO_SIDE_EFFECTS__ + */ +function assertNumber(n) { + if (!Number.isSafeInteger(n)) + throw new Error(`Wrong integer: ${n}`); } -function fromBase58(inString, network) { - const buffer = bs58check.decode(inString); - if (buffer.length !== 78) - throw new TypeError('Invalid buffer length'); - network = network || BITCOIN; - // 4 bytes: version bytes - const version = buffer.readUInt32BE(0); - if (version !== network.bip32.private && version !== network.bip32.public) - throw new TypeError('Invalid network version'); - // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ... - const depth = buffer[4]; - // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) - const parentFingerprint = buffer.readUInt32BE(5); - if (depth === 0) { - if (parentFingerprint !== 0x00000000) - throw new TypeError('Invalid parent fingerprint'); - } - // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. - // This is encoded in MSB order. (0x00000000 if master key) - const index = buffer.readUInt32BE(9); - if (depth === 0 && index !== 0) - throw new TypeError('Invalid index'); - // 32 bytes: the chain code - const chainCode = buffer.slice(13, 45); - let hd; - // 33 bytes: private key data (0x00 + k) - if (version === network.bip32.private) { - if (buffer.readUInt8(45) !== 0x00) - throw new TypeError('Invalid private key'); - const k = buffer.slice(46, 78); - hd = fromPrivateKeyLocal(k, chainCode, network, depth, index, parentFingerprint); - // 33 bytes: public key data (0x02 + X or 0x03 + X) - } - else { - const X = buffer.slice(45, 78); - hd = fromPublicKeyLocal(X, chainCode, network, depth, index, parentFingerprint); - } - return hd; +exports.assertNumber = assertNumber; +function isBytes(a) { + return (a instanceof Uint8Array || + (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')); } -exports.fromBase58 = fromBase58; -function fromPrivateKey(privateKey, chainCode, network) { - return fromPrivateKeyLocal(privateKey, chainCode, network); +/** + * @__NO_SIDE_EFFECTS__ + */ +function chain(...args) { + const id = (a) => a; + // Wrap call in closure so JIT can inline calls + const wrap = (a, b) => (c) => a(b(c)); + // Construct chain of args[-1].encode(args[-2].encode([...])) + const encode = args.map((x) => x.encode).reduceRight(wrap, id); + // Construct chain of args[0].decode(args[1].decode(...)) + const decode = args.map((x) => x.decode).reduce(wrap, id); + return { encode, decode }; } -exports.fromPrivateKey = fromPrivateKey; -function fromPrivateKeyLocal(privateKey, chainCode, network, depth, index, parentFingerprint) { - typeforce({ - privateKey: UINT256_TYPE, - chainCode: UINT256_TYPE, - }, { privateKey, chainCode }); - network = network || BITCOIN; - if (!ecc.isPrivate(privateKey)) - throw new TypeError('Private key not in range [1, n)'); - return new BIP32(privateKey, undefined, chainCode, network, depth, index, parentFingerprint); +/** + * Encodes integer radix representation to array of strings using alphabet and back + * @__NO_SIDE_EFFECTS__ + */ +function alphabet(alphabet) { + return { + encode: (digits) => { + if (!Array.isArray(digits) || (digits.length && typeof digits[0] !== 'number')) + throw new Error('alphabet.encode input should be an array of numbers'); + return digits.map((i) => { + assertNumber(i); + if (i < 0 || i >= alphabet.length) + throw new Error(`Digit index outside alphabet: ${i} (alphabet: ${alphabet.length})`); + return alphabet[i]; + }); + }, + decode: (input) => { + if (!Array.isArray(input) || (input.length && typeof input[0] !== 'string')) + throw new Error('alphabet.decode input should be array of strings'); + return input.map((letter) => { + if (typeof letter !== 'string') + throw new Error(`alphabet.decode: not string element=${letter}`); + const index = alphabet.indexOf(letter); + if (index === -1) + throw new Error(`Unknown letter: "${letter}". Allowed: ${alphabet}`); + return index; + }); + }, + }; } -function fromPublicKey(publicKey, chainCode, network) { - return fromPublicKeyLocal(publicKey, chainCode, network); +/** + * @__NO_SIDE_EFFECTS__ + */ +function join(separator = '') { + if (typeof separator !== 'string') + throw new Error('join separator should be string'); + return { + encode: (from) => { + if (!Array.isArray(from) || (from.length && typeof from[0] !== 'string')) + throw new Error('join.encode input should be array of strings'); + for (let i of from) + if (typeof i !== 'string') + throw new Error(`join.encode: non-string input=${i}`); + return from.join(separator); + }, + decode: (to) => { + if (typeof to !== 'string') + throw new Error('join.decode input should be string'); + return to.split(separator); + }, + }; } -exports.fromPublicKey = fromPublicKey; -function fromPublicKeyLocal(publicKey, chainCode, network, depth, index, parentFingerprint) { - typeforce({ - publicKey: typeforce.BufferN(33), - chainCode: UINT256_TYPE, - }, { publicKey, chainCode }); - network = network || BITCOIN; - // verify the X coordinate is a point on the curve - if (!ecc.isPoint(publicKey)) - throw new TypeError('Point is not on the curve'); - return new BIP32(undefined, publicKey, chainCode, network, depth, index, parentFingerprint); +/** + * Pad strings array so it has integer number of bits + * @__NO_SIDE_EFFECTS__ + */ +function padding(bits, chr = '=') { + assertNumber(bits); + if (typeof chr !== 'string') + throw new Error('padding chr should be string'); + return { + encode(data) { + if (!Array.isArray(data) || (data.length && typeof data[0] !== 'string')) + throw new Error('padding.encode input should be array of strings'); + for (let i of data) + if (typeof i !== 'string') + throw new Error(`padding.encode: non-string input=${i}`); + while ((data.length * bits) % 8) + data.push(chr); + return data; + }, + decode(input) { + if (!Array.isArray(input) || (input.length && typeof input[0] !== 'string')) + throw new Error('padding.encode input should be array of strings'); + for (let i of input) + if (typeof i !== 'string') + throw new Error(`padding.decode: non-string input=${i}`); + let end = input.length; + if ((end * bits) % 8) + throw new Error('Invalid padding: string should have whole number of bytes'); + for (; end > 0 && input[end - 1] === chr; end--) { + if (!(((end - 1) * bits) % 8)) + throw new Error('Invalid padding: string has too much padding'); + } + return input.slice(0, end); + }, + }; } -function fromSeed(seed, network) { - typeforce(typeforce.Buffer, seed); - if (seed.length < 16) - throw new TypeError('Seed should be at least 128 bits'); - if (seed.length > 64) - throw new TypeError('Seed should be at most 512 bits'); - network = network || BITCOIN; - const I = crypto.hmacSHA512(Buffer.from('Bitcoin seed', 'utf8'), seed); - const IL = I.slice(0, 32); - const IR = I.slice(32); - return fromPrivateKey(IL, IR, network); +/** + * @__NO_SIDE_EFFECTS__ + */ +function normalize(fn) { + if (typeof fn !== 'function') + throw new Error('normalize fn should be function'); + return { encode: (from) => from, decode: (to) => fn(to) }; } -exports.fromSeed = fromSeed; - -}).call(this,require("buffer").Buffer) -},{"./crypto":40,"bs58check":152,"buffer":155,"tiny-secp256k1":301,"typeforce":324,"wif":332}],40:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const createHash = require('create-hash'); -const createHmac = require('create-hmac'); -function hash160(buffer) { - const sha256Hash = createHash('sha256') - .update(buffer) - .digest(); - try { - return createHash('rmd160') - .update(sha256Hash) - .digest(); - } - catch (err) { - return createHash('ripemd160') - .update(sha256Hash) - .digest(); +/** + * Slow: O(n^2) time complexity + * @__NO_SIDE_EFFECTS__ + */ +function convertRadix(data, from, to) { + // base 1 is impossible + if (from < 2) + throw new Error(`convertRadix: wrong from=${from}, base cannot be less than 2`); + if (to < 2) + throw new Error(`convertRadix: wrong to=${to}, base cannot be less than 2`); + if (!Array.isArray(data)) + throw new Error('convertRadix: data should be array'); + if (!data.length) + return []; + let pos = 0; + const res = []; + const digits = Array.from(data); + digits.forEach((d) => { + assertNumber(d); + if (d < 0 || d >= from) + throw new Error(`Wrong integer: ${d}`); + }); + while (true) { + let carry = 0; + let done = true; + for (let i = pos; i < digits.length; i++) { + const digit = digits[i]; + const digitBase = from * carry + digit; + if (!Number.isSafeInteger(digitBase) || + (from * carry) / from !== carry || + digitBase - digit !== from * carry) { + throw new Error('convertRadix: carry overflow'); + } + carry = digitBase % to; + const rounded = Math.floor(digitBase / to); + digits[i] = rounded; + if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase) + throw new Error('convertRadix: carry overflow'); + if (!done) + continue; + else if (!rounded) + pos = i; + else + done = false; + } + res.push(carry); + if (done) + break; } + for (let i = 0; i < data.length - 1 && data[i] === 0; i++) + res.push(0); + return res.reverse(); } -exports.hash160 = hash160; -function hmacSHA512(key, data) { - return createHmac('sha512', key) - .update(data) - .digest(); +const gcd = /* @__NO_SIDE_EFFECTS__ */ (a, b) => (!b ? a : gcd(b, a % b)); +const radix2carry = /*@__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to)); +/** + * Implemented with numbers, because BigInt is 5x slower + * @__NO_SIDE_EFFECTS__ + */ +function convertRadix2(data, from, to, padding) { + if (!Array.isArray(data)) + throw new Error('convertRadix2: data should be array'); + if (from <= 0 || from > 32) + throw new Error(`convertRadix2: wrong from=${from}`); + if (to <= 0 || to > 32) + throw new Error(`convertRadix2: wrong to=${to}`); + if (radix2carry(from, to) > 32) { + throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`); + } + let carry = 0; + let pos = 0; // bitwise position in current element + const mask = 2 ** to - 1; + const res = []; + for (const n of data) { + assertNumber(n); + if (n >= 2 ** from) + throw new Error(`convertRadix2: invalid data word=${n} from=${from}`); + carry = (carry << from) | n; + if (pos + from > 32) + throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`); + pos += from; + for (; pos >= to; pos -= to) + res.push(((carry >> (pos - to)) & mask) >>> 0); + carry &= 2 ** pos - 1; // clean carry, otherwise it will cause overflow + } + carry = (carry << (to - pos)) & mask; + if (!padding && pos >= from) + throw new Error('Excess padding'); + if (!padding && carry) + throw new Error(`Non-zero padding: ${carry}`); + if (padding && pos > 0) + res.push(carry >>> 0); + return res; } -exports.hmacSHA512 = hmacSHA512; - -},{"create-hash":159,"create-hmac":161}],41:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var bip32_1 = require("./bip32"); -exports.fromSeed = bip32_1.fromSeed; -exports.fromBase58 = bip32_1.fromBase58; -exports.fromPublicKey = bip32_1.fromPublicKey; -exports.fromPrivateKey = bip32_1.fromPrivateKey; - -},{"./bip32":39}],42:[function(require,module,exports){ -var aes = require('browserify-aes') -var assert = require('assert') -var Buffer = require('safe-buffer').Buffer -var bs58check = require('bs58check') -var createHash = require('create-hash') -var scrypt = require('scryptsy') -var xor = require('buffer-xor/inplace') - -var ecurve = require('ecurve') -var curve = ecurve.getCurveByName('secp256k1') - -var BigInteger = require('bigi') - -// constants -var SCRYPT_PARAMS = { - N: 16384, // specified by BIP38 - r: 8, - p: 8 +/** + * @__NO_SIDE_EFFECTS__ + */ +function radix(num) { + assertNumber(num); + return { + encode: (bytes) => { + if (!isBytes(bytes)) + throw new Error('radix.encode input should be Uint8Array'); + return convertRadix(Array.from(bytes), 2 ** 8, num); + }, + decode: (digits) => { + if (!Array.isArray(digits) || (digits.length && typeof digits[0] !== 'number')) + throw new Error('radix.decode input should be array of numbers'); + return Uint8Array.from(convertRadix(digits, num, 2 ** 8)); + }, + }; } -var NULL = Buffer.alloc(0) - -function hash160 (buffer) { - var hash - try { - hash = createHash('rmd160') - } catch (e) { - hash = createHash('ripemd160') - } - return hash.update( - createHash('sha256').update(buffer).digest() - ).digest() +/** + * If both bases are power of same number (like `2**8 <-> 2**64`), + * there is a linear algorithm. For now we have implementation for power-of-two bases only. + * @__NO_SIDE_EFFECTS__ + */ +function radix2(bits, revPadding = false) { + assertNumber(bits); + if (bits <= 0 || bits > 32) + throw new Error('radix2: bits should be in (0..32]'); + if (radix2carry(8, bits) > 32 || radix2carry(bits, 8) > 32) + throw new Error('radix2: carry overflow'); + return { + encode: (bytes) => { + if (!isBytes(bytes)) + throw new Error('radix2.encode input should be Uint8Array'); + return convertRadix2(Array.from(bytes), 8, bits, !revPadding); + }, + decode: (digits) => { + if (!Array.isArray(digits) || (digits.length && typeof digits[0] !== 'number')) + throw new Error('radix2.decode input should be array of numbers'); + return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding)); + }, + }; } - -function hash256 (buffer) { - return createHash('sha256').update( - createHash('sha256').update(buffer).digest() - ).digest() +/** + * @__NO_SIDE_EFFECTS__ + */ +function unsafeWrapper(fn) { + if (typeof fn !== 'function') + throw new Error('unsafeWrapper fn should be function'); + return function (...args) { + try { + return fn.apply(null, args); + } + catch (e) { } + }; } - -function getAddress (d, compressed) { - var Q = curve.G.multiply(d).getEncoded(compressed) - var hash = hash160(Q) - var payload = Buffer.allocUnsafe(21) - payload.writeUInt8(0x00, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38 - hash.copy(payload, 1) - - return bs58check.encode(payload) +/** + * @__NO_SIDE_EFFECTS__ + */ +function checksum(len, fn) { + assertNumber(len); + if (typeof fn !== 'function') + throw new Error('checksum fn should be function'); + return { + encode(data) { + if (!isBytes(data)) + throw new Error('checksum.encode: input should be Uint8Array'); + const checksum = fn(data).slice(0, len); + const res = new Uint8Array(data.length + len); + res.set(data); + res.set(checksum, data.length); + return res; + }, + decode(data) { + if (!isBytes(data)) + throw new Error('checksum.decode: input should be Uint8Array'); + const payload = data.slice(0, -len); + const newChecksum = fn(payload).slice(0, len); + const oldChecksum = data.slice(-len); + for (let i = 0; i < len; i++) + if (newChecksum[i] !== oldChecksum[i]) + throw new Error('Invalid checksum'); + return payload; + }, + }; } +// prettier-ignore +exports.utils = { + alphabet, chain, checksum, convertRadix, convertRadix2, radix, radix2, join, padding, +}; +// RFC 4648 aka RFC 3548 +// --------------------- +exports.base16 = chain(radix2(4), alphabet('0123456789ABCDEF'), join('')); +exports.base32 = chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), padding(5), join('')); +exports.base32nopad = chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), join('')); +exports.base32hex = chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), padding(5), join('')); +exports.base32hexnopad = chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), join('')); +exports.base32crockford = chain(radix2(5), alphabet('0123456789ABCDEFGHJKMNPQRSTVWXYZ'), join(''), normalize((s) => s.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1'))); +exports.base64 = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'), padding(6), join('')); +exports.base64nopad = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'), join('')); +exports.base64url = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'), padding(6), join('')); +exports.base64urlnopad = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'), join('')); +// base58 code +// ----------- +const genBase58 = (abc) => chain(radix(58), alphabet(abc), join('')); +exports.base58 = genBase58('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'); +exports.base58flickr = genBase58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'); +exports.base58xrp = genBase58('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz'); +// xmr ver is done in 8-byte blocks (which equals 11 chars in decoding). Last (non-full) block padded with '1' to size in XMR_BLOCK_LEN. +// Block encoding significantly reduces quadratic complexity of base58. +// Data len (index) -> encoded block len +const XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11]; +exports.base58xmr = { + encode(data) { + let res = ''; + for (let i = 0; i < data.length; i += 8) { + const block = data.subarray(i, i + 8); + res += exports.base58.encode(block).padStart(XMR_BLOCK_LEN[block.length], '1'); + } + return res; + }, + decode(str) { + let res = []; + for (let i = 0; i < str.length; i += 11) { + const slice = str.slice(i, i + 11); + const blockLen = XMR_BLOCK_LEN.indexOf(slice.length); + const block = exports.base58.decode(slice); + for (let j = 0; j < block.length - blockLen; j++) { + if (block[j] !== 0) + throw new Error('base58xmr: wrong padding'); + } + res = res.concat(Array.from(block.slice(block.length - blockLen))); + } + return Uint8Array.from(res); + }, +}; +const createBase58check = (sha256) => chain(checksum(4, (data) => sha256(sha256(data))), exports.base58); +exports.createBase58check = createBase58check; +// legacy export, bad name +exports.base58check = exports.createBase58check; +const BECH_ALPHABET = /* @__PURE__ */ chain(alphabet('qpzry9x8gf2tvdw0s3jn54khce6mua7l'), join('')); +const POLYMOD_GENERATORS = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]; +/** + * @__NO_SIDE_EFFECTS__ + */ +function bech32Polymod(pre) { + const b = pre >> 25; + let chk = (pre & 0x1ffffff) << 5; + for (let i = 0; i < POLYMOD_GENERATORS.length; i++) { + if (((b >> i) & 1) === 1) + chk ^= POLYMOD_GENERATORS[i]; + } + return chk; +} +/** + * @__NO_SIDE_EFFECTS__ + */ +function bechChecksum(prefix, words, encodingConst = 1) { + const len = prefix.length; + let chk = 1; + for (let i = 0; i < len; i++) { + const c = prefix.charCodeAt(i); + if (c < 33 || c > 126) + throw new Error(`Invalid prefix (${prefix})`); + chk = bech32Polymod(chk) ^ (c >> 5); + } + chk = bech32Polymod(chk); + for (let i = 0; i < len; i++) + chk = bech32Polymod(chk) ^ (prefix.charCodeAt(i) & 0x1f); + for (let v of words) + chk = bech32Polymod(chk) ^ v; + for (let i = 0; i < 6; i++) + chk = bech32Polymod(chk); + chk ^= encodingConst; + return BECH_ALPHABET.encode(convertRadix2([chk % 2 ** 30], 30, 5, false)); +} +/** + * @__NO_SIDE_EFFECTS__ + */ +function genBech32(encoding) { + const ENCODING_CONST = encoding === 'bech32' ? 1 : 0x2bc830a3; + const _words = radix2(5); + const fromWords = _words.decode; + const toWords = _words.encode; + const fromWordsUnsafe = unsafeWrapper(fromWords); + function encode(prefix, words, limit = 90) { + if (typeof prefix !== 'string') + throw new Error(`bech32.encode prefix should be string, not ${typeof prefix}`); + if (!Array.isArray(words) || (words.length && typeof words[0] !== 'number')) + throw new Error(`bech32.encode words should be array of numbers, not ${typeof words}`); + if (prefix.length === 0) + throw new TypeError(`Invalid prefix length ${prefix.length}`); + const actualLength = prefix.length + 7 + words.length; + if (limit !== false && actualLength > limit) + throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`); + const lowered = prefix.toLowerCase(); + const sum = bechChecksum(lowered, words, ENCODING_CONST); + return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`; + } + function decode(str, limit = 90) { + if (typeof str !== 'string') + throw new Error(`bech32.decode input should be string, not ${typeof str}`); + if (str.length < 8 || (limit !== false && str.length > limit)) + throw new TypeError(`Wrong string length: ${str.length} (${str}). Expected (8..${limit})`); + // don't allow mixed case + const lowered = str.toLowerCase(); + if (str !== lowered && str !== str.toUpperCase()) + throw new Error(`String must be lowercase or uppercase`); + const sepIndex = lowered.lastIndexOf('1'); + if (sepIndex === 0 || sepIndex === -1) + throw new Error(`Letter "1" must be present between prefix and data only`); + const prefix = lowered.slice(0, sepIndex); + const data = lowered.slice(sepIndex + 1); + if (data.length < 6) + throw new Error('Data must be at least 6 characters long'); + const words = BECH_ALPHABET.decode(data).slice(0, -6); + const sum = bechChecksum(prefix, words, ENCODING_CONST); + if (!data.endsWith(sum)) + throw new Error(`Invalid checksum in ${str}: expected "${sum}"`); + return { prefix, words }; + } + const decodeUnsafe = unsafeWrapper(decode); + function decodeToBytes(str) { + const { prefix, words } = decode(str, false); + return { prefix, words, bytes: fromWords(words) }; + } + return { encode, decode, decodeToBytes, decodeUnsafe, fromWords, fromWordsUnsafe, toWords }; +} +exports.bech32 = genBech32('bech32'); +exports.bech32m = genBech32('bech32m'); +exports.utf8 = { + encode: (data) => new TextDecoder().decode(data), + decode: (str) => new TextEncoder().encode(str), +}; +exports.hex = chain(radix2(4), alphabet('0123456789abcdef'), join(''), normalize((s) => { + if (typeof s !== 'string' || s.length % 2) + throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`); + return s.toLowerCase(); +})); +// prettier-ignore +const CODERS = { + utf8: exports.utf8, hex: exports.hex, base16: exports.base16, base32: exports.base32, base64: exports.base64, base64url: exports.base64url, base58: exports.base58, base58xmr: exports.base58xmr +}; +const coderTypeError = 'Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr'; +const bytesToString = (type, bytes) => { + if (typeof type !== 'string' || !CODERS.hasOwnProperty(type)) + throw new TypeError(coderTypeError); + if (!isBytes(bytes)) + throw new TypeError('bytesToString() expects Uint8Array'); + return CODERS[type].encode(bytes); +}; +exports.bytesToString = bytesToString; +exports.str = exports.bytesToString; // as in python, but for bytes only +const stringToBytes = (type, str) => { + if (!CODERS.hasOwnProperty(type)) + throw new TypeError(coderTypeError); + if (typeof str !== 'string') + throw new TypeError('stringToBytes() expects string'); + return CODERS[type].decode(str); +}; +exports.stringToBytes = stringToBytes; +exports.bytes = exports.stringToBytes; + +},{}],94:[function(require,module,exports){ +const { xorBytes1x16, xorBytes4x16, uint8, uint32 } = require('./functions'); -function encryptRaw (buffer, compressed, passphrase, progressCallback, scryptParams) { - if (buffer.length !== 32) throw new Error('Invalid private key length') - scryptParams = scryptParams || SCRYPT_PARAMS - - var d = BigInteger.fromBuffer(buffer) - var address = getAddress(d, compressed) - var secret = Buffer.from(passphrase, 'utf8') - var salt = hash256(address).slice(0, 4) +const TE0 = [ + 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, + 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, + 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, + 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, + 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, + 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, + 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, + 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, + 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, + 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, + 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, + 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, + 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, + 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, + 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, + 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, + 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, + 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, + 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, + 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, + 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, + 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, + 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, + 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, + 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, + 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, + 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, + 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, + 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, + 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, + 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, + 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, + 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, + 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, + 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, + 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, + 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, + 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, + 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, + 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, + 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, + 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, + 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, + 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, + 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, + 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, + 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, + 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, + 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, + 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, + 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, + 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, + 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, + 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, + 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, + 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, + 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, + 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, + 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, + 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, + 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, + 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, + 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, + 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a, +]; - var N = scryptParams.N - var r = scryptParams.r - var p = scryptParams.p +const TE1 = [ + 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, + 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, + 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, + 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, + 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, + 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, + 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, + 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, + 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, + 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, + 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, + 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, + 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, + 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, + 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, + 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, + 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, + 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, + 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, + 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, + 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, + 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, + 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, + 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, + 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, + 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, + 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, + 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, + 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, + 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, + 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, + 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, + 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, + 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, + 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, + 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, + 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, + 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, + 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, + 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, + 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, + 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, + 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, + 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, + 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, + 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, + 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, + 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, + 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, + 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, + 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, + 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, + 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, + 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, + 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, + 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, + 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, + 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, + 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, + 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, + 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, + 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, + 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, + 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616, +]; - var scryptBuf = scrypt(secret, salt, N, r, p, 64, progressCallback) - var derivedHalf1 = scryptBuf.slice(0, 32) - var derivedHalf2 = scryptBuf.slice(32, 64) +const TE2 = [ + 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, + 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, + 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, + 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, + 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, + 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, + 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, + 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, + 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, + 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, + 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, + 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, + 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, + 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, + 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, + 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, + 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, + 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, + 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, + 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, + 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, + 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, + 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, + 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, + 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, + 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, + 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, + 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, + 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, + 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, + 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, + 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, + 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, + 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, + 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, + 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, + 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, + 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, + 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, + 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, + 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, + 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, + 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, + 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, + 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, + 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, + 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, + 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, + 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, + 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, + 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, + 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, + 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, + 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, + 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, + 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, + 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, + 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, + 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, + 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, + 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, + 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, + 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, + 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16, +]; - var xorBuf = xor(derivedHalf1, buffer) - var cipher = aes.createCipheriv('aes-256-ecb', derivedHalf2, NULL) - cipher.setAutoPadding(false) - cipher.end(xorBuf) +const TE3 = [ + 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, + 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, + 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, + 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, + 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, + 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, + 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, + 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, + 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, + 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, + 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, + 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, + 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, + 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, + 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, + 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, + 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, + 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, + 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, + 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, + 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, + 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, + 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, + 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, + 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, + 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, + 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, + 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, + 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, + 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, + 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, + 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, + 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, + 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, + 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, + 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, + 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, + 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, + 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, + 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, + 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, + 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, + 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, + 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, + 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, + 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, + 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, + 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, + 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, + 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, + 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, + 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, + 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, + 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, + 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, + 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, + 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, + 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, + 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, + 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, + 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, + 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, + 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, + 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c, +]; - var cipherText = cipher.read() +const AESRound = function(key) { - // 0x01 | 0x42 | flagByte | salt (4) | cipherText (32) - var result = Buffer.allocUnsafe(7 + 32) - result.writeUInt8(0x01, 0) - result.writeUInt8(0x42, 1) - result.writeUInt8(compressed ? 0xe0 : 0xc0, 2) - salt.copy(result, 3) - cipherText.copy(result, 7) + this.aes10Key = new Uint32Array(4 * 10); + this.aes4Key = new Uint32Array(4 * 4); - return result -} + const keys = new Uint32Array(12); + for (let i = 0; i < 12; i++) { + keys[i] = key.readUInt32BE(4 * i); + } -function encrypt (buffer, compressed, passphrase, progressCallback, scryptParams) { - return bs58check.encode(encryptRaw(buffer, compressed, passphrase, progressCallback, scryptParams)) -} + this.aes10Key.set(keys, 0); + this.aes10Key.set(keys, 12); + this.aes10Key.set(keys, 24); + this.aes10Key.set(keys.subarray(0, 4), 36); -// some of the techniques borrowed from: https://github.com/pointbiz/bitaddress.org -function decryptRaw (buffer, passphrase, progressCallback, scryptParams) { - // 39 bytes: 2 bytes prefix, 37 bytes payload - if (buffer.length !== 39) throw new Error('Invalid BIP38 data length') - if (buffer.readUInt8(0) !== 0x01) throw new Error('Invalid BIP38 prefix') - scryptParams = scryptParams || SCRYPT_PARAMS + this.aes4Key.set(keys.subarray(4, 8), 0); + this.aes4Key.set(keys.subarray(0, 4), 4); + this.aes4Key.set(keys.subarray(8, 12), 8); - // check if BIP38 EC multiply - var type = buffer.readUInt8(1) - if (type === 0x43) return decryptECMult(buffer, passphrase, progressCallback, scryptParams) - if (type !== 0x42) throw new Error('Invalid BIP38 type') + this.reset = function () { + this.aes10Key.fill(0); + this.aes4Key.fill(0); + }; - passphrase = Buffer.from(passphrase, 'utf8') + this.AES4 = function(j, i, l, src, dst) { + xorBytes4x16(j, i, l, src, dst); + this.rounds(dst, 4); + }; - var flagByte = buffer.readUInt8(2) - var compressed = flagByte === 0xe0 - if (!compressed && flagByte !== 0xc0) throw new Error('Invalid BIP38 compression flag') + this.AES10 = function (l, src, dst) { + xorBytes1x16(src, l, dst); + this.rounds(dst, 10); + }; - var N = scryptParams.N - var r = scryptParams.r - var p = scryptParams.p + this.rounds = function (block, rounds) { + const keys = rounds === 4 ? this.aes4Key : this.aes10Key; - var salt = buffer.slice(3, 7) - var scryptBuf = scrypt(passphrase, salt, N, r, p, 64, progressCallback) - var derivedHalf1 = scryptBuf.slice(0, 32) - var derivedHalf2 = scryptBuf.slice(32, 64) + let s0 = block.readUInt32BE(0); + let s1 = block.readUInt32BE(4); + let s2 = block.readUInt32BE(8); + let s3 = block.readUInt32BE(12); - var privKeyBuf = buffer.slice(7, 7 + 32) - var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, NULL) - decipher.setAutoPadding(false) - decipher.end(privKeyBuf) + // Always do MixColumns. + for (let r = 0; r < rounds; r++) { + let rkOff = r * 4; + const t0 = TE0[uint8(s0>>>24)] ^ + TE1[uint8(s1>>>16)] ^ + TE2[uint8(s2>>>8)] ^ + TE3[uint8(s3)] ^ + keys[rkOff+0]; - var plainText = decipher.read() - var privateKey = xor(derivedHalf1, plainText) + const t1 = TE0[uint8(s1>>>24)] ^ + TE1[uint8(s2>>>16)] ^ + TE2[uint8(s3>>>8)] ^ + TE3[uint8(s0)] ^ + keys[rkOff+1]; - // verify salt matches address - var d = BigInteger.fromBuffer(privateKey) - var address = getAddress(d, compressed) - var checksum = hash256(address).slice(0, 4) - assert.deepEqual(salt, checksum) + const t2 = TE0[uint8(s2>>>24)] ^ + TE1[uint8(s3>>>16)] ^ + TE2[uint8(s0>>>8)] ^ + TE3[uint8(s1)] ^ + keys[rkOff+2]; - return { - privateKey: privateKey, - compressed: compressed - } -} + const t3 = TE0[uint8(s3>>>24)] ^ + TE1[uint8(s0>>>16)] ^ + TE2[uint8(s1>>>8)] ^ + TE3[uint8(s2)] ^ + keys[rkOff+3]; -function decrypt (string, passphrase, progressCallback, scryptParams) { - return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams) -} + s0 = uint32(t0); + s1 = uint32(t1); + s2 = uint32(t2); + s3 = uint32(t3); + } -function decryptECMult (buffer, passphrase, progressCallback, scryptParams) { - passphrase = Buffer.from(passphrase, 'utf8') - buffer = buffer.slice(1) // FIXME: we can avoid this - scryptParams = scryptParams || SCRYPT_PARAMS + block.writeUInt32BE(s0, 0); + block.writeUInt32BE(s1, 4); + block.writeUInt32BE(s2, 8); + block.writeUInt32BE(s3, 12); + }; +}; - var flag = buffer.readUInt8(1) - var compressed = (flag & 0x20) !== 0 - var hasLotSeq = (flag & 0x04) !== 0 +module.exports = AESRound; - assert.equal((flag & 0x24), flag, 'Invalid private key.') +},{"./functions":97}],95:[function(require,module,exports){ +const AEZState = require('./aez_state'); +const { mkBlock } = require('./functions'); - var addressHash = buffer.slice(2, 6) - var ownerEntropy = buffer.slice(6, 14) - var ownerSalt +const VERSION = 'v5'; - // 4 bytes ownerSalt if 4 bytes lot/sequence - if (hasLotSeq) { - ownerSalt = ownerEntropy.slice(0, 4) +function encrypt(key, nonce, additionalData, tau, plaintext) { + let state = new AEZState(); + state.reset(); + state.init(key); + let delta = state.aezHash(nonce, additionalData, tau * 8); + let x = mkBlock(plaintext.length + tau); - // else, 8 bytes ownerSalt + if (!plaintext || plaintext.length === 0) { + state.aezPRF(delta, tau, x); } else { - ownerSalt = ownerEntropy + plaintext.copy(x); + state.encipher(delta, x, x); } - var encryptedPart1 = buffer.slice(14, 22) // First 8 bytes - var encryptedPart2 = buffer.slice(22, 38) // 16 bytes + return x; +} - var N = scryptParams.N - var r = scryptParams.r - var p = scryptParams.p - var preFactor = scrypt(passphrase, ownerSalt, N, r, p, 32, progressCallback) +function decrypt(key, nonce, additionalData, tau, ciphertext) { + let state = new AEZState(); + state.reset(); + state.init(key); + let delta = state.aezHash(nonce, additionalData, tau * 8); + let sum = 0; + let x = mkBlock(ciphertext.length); - var passFactor - if (hasLotSeq) { - var hashTarget = Buffer.concat([preFactor, ownerEntropy]) - passFactor = hash256(hashTarget) + if (ciphertext && ciphertext.length === tau) { + state.aezPRF(delta, tau, x); + for (let i = 0; i < tau; i++) { + sum |= x[i] ^ ciphertext[i]; + } + x = x.slice(0, ciphertext.length - tau); } else { - passFactor = preFactor + state.decipher(delta, ciphertext, x); + for (let i = 0; i < tau; i++) { + sum |= x[ciphertext.length - tau + i]; + } + if (sum === 0) { + x = x.slice(0, ciphertext.length - tau); + } } - var passInt = BigInteger.fromBuffer(passFactor) - var passPoint = curve.G.multiply(passInt).getEncoded(true) + if (sum !== 0) { + return null; + } - var seedBPass = scrypt(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64) - var derivedHalf1 = seedBPass.slice(0, 32) - var derivedHalf2 = seedBPass.slice(32, 64) + return x; +} - var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0)) - decipher.setAutoPadding(false) - decipher.end(encryptedPart2) +module.exports = { + VERSION, + encrypt, + decrypt, +}; - var decryptedPart2 = decipher.read() - var tmp = xor(decryptedPart2, derivedHalf1.slice(16, 32)) - var seedBPart2 = tmp.slice(8, 16) +},{"./aez_state":96,"./functions":97}],96:[function(require,module,exports){ +const { + BLOCK_SIZE, uint32, mkBlock, xorBytes1x16, xorBytes4x16, + extractKey, multBlock, doubleBlock, oneZeroPad, xorBytes +} = require('./functions'); +const AESRound = require('./aes_round'); +const Buffer = require('safe-buffer').Buffer; +const floor = Math.floor; - var decipher2 = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0)) - decipher2.setAutoPadding(false) - decipher2.write(encryptedPart1) // first 8 bytes - decipher2.end(tmp.slice(0, 8)) // last 8 bytes +const ZERO = mkBlock(); - var seedBPart1 = xor(decipher2.read(), derivedHalf1.slice(0, 16)) - var seedB = Buffer.concat([seedBPart1, seedBPart2], 24) - var factorB = BigInteger.fromBuffer(hash256(seedB)) +const AEZState = function () { - // d = passFactor * factorB (mod n) - var d = passInt.multiply(factorB).mod(curve.n) + this.I = [mkBlock(), mkBlock()]; + this.J = [mkBlock(), mkBlock(), mkBlock()]; + this.L = [ + mkBlock(), mkBlock(), mkBlock(), mkBlock(), + mkBlock(), mkBlock(), mkBlock(), mkBlock(), + ]; - return { - privateKey: d.toBuffer(32), - compressed: compressed - } -} + this.reset = function () { + this.I.forEach(buf => buf.fill(0)); + this.J.forEach(buf => buf.fill(0)); + this.L.forEach(buf => buf.fill(0)); -function verify (string) { - var decoded = bs58check.decodeUnsafe(string) - if (!decoded) return false + if (this.aes) { + this.aes.reset(); + } + }; - if (decoded.length !== 39) return false - if (decoded.readUInt8(0) !== 0x01) return false + this.init = function (key) { - var type = decoded.readUInt8(1) - var flag = decoded.readUInt8(2) + const extractedKey = extractKey(key); - // encrypted WIF - if (type === 0x42) { - if (flag !== 0xc0 && flag !== 0xe0) return false + extractedKey.slice(0, 16).copy(this.I[0]); + multBlock(2, this.I[0], this.I[1]); - // EC mult - } else if (type === 0x43) { - if ((flag & ~0x24)) return false - } else { - return false - } + extractedKey.slice(16, 32).copy(this.J[0]); + multBlock(2, this.J[0], this.J[1]); + multBlock(2, this.J[1], this.J[2]); - return true -} + extractedKey.slice(32, 48).copy(this.L[1]); + multBlock(2, this.L[1], this.L[2]); + xorBytes1x16(this.L[2], this.L[1], this.L[3]); + multBlock(2, this.L[2], this.L[4]); + xorBytes1x16(this.L[4], this.L[1], this.L[5]); + multBlock(2, this.L[3], this.L[6]); + xorBytes1x16(this.L[6], this.L[1], this.L[7]); -module.exports = { - decrypt: decrypt, - decryptECMult: decryptECMult, - decryptRaw: decryptRaw, - encrypt: encrypt, - encryptRaw: encryptRaw, - verify: verify -} + this.aes = new AESRound(extractedKey); + }; -},{"assert":21,"bigi":30,"browserify-aes":108,"bs58check":152,"buffer-xor/inplace":154,"create-hash":159,"ecurve":176,"safe-buffer":280,"scryptsy":283}],43:[function(require,module,exports){ -var Buffer = require('safe-buffer').Buffer -var createHash = require('create-hash') -var _pbkdf2 = require('pbkdf2') -var pbkdf2 = _pbkdf2.pbkdf2Sync -var pbkdf2Async = _pbkdf2.pbkdf2 -var randomBytes = require('randombytes') + this.aezHash = function (nonce, ad, tau) { + const [buf, sum, I, J] = [mkBlock(), mkBlock(), mkBlock(), mkBlock()]; -// use unorm until String.prototype.normalize gets better browser support -var unorm = require('unorm') + buf.writeInt32BE(uint32(tau), 12); + xorBytes1x16(this.J[0], this.J[1], J); + this.aes.AES4(J, this.I[1], this.L[1], buf, sum); -var CHINESE_SIMPLIFIED_WORDLIST = require('./wordlists/chinese_simplified.json') -var CHINESE_TRADITIONAL_WORDLIST = require('./wordlists/chinese_traditional.json') -var ENGLISH_WORDLIST = require('./wordlists/english.json') -var FRENCH_WORDLIST = require('./wordlists/french.json') -var ITALIAN_WORDLIST = require('./wordlists/italian.json') -var JAPANESE_WORDLIST = require('./wordlists/japanese.json') -var KOREAN_WORDLIST = require('./wordlists/korean.json') -var SPANISH_WORDLIST = require('./wordlists/spanish.json') -var DEFAULT_WORDLIST = ENGLISH_WORDLIST + const empty = !nonce || nonce.length === 0; + let n = nonce; + let nBytes = empty ? 0 : nonce.length; + this.I[1].copy(I); + for (let i = 1; nBytes >= BLOCK_SIZE; i++, nBytes -= BLOCK_SIZE) { + this.aes.AES4(this.J[2], I, this.L[i % 8], n.slice(0, BLOCK_SIZE), buf); + xorBytes1x16(sum, buf, sum); + n = n.slice(BLOCK_SIZE); + if (i % 8 === 0) { + doubleBlock(I); + } + } -var INVALID_MNEMONIC = 'Invalid mnemonic' -var INVALID_ENTROPY = 'Invalid entropy' -var INVALID_CHECKSUM = 'Invalid mnemonic checksum' + if (nBytes > 0 || empty) { + buf.fill(0); + if (!empty) { + n.copy(buf); + } + buf[nBytes] = 0x80; + this.aes.AES4(this.J[2], this.I[0], this.L[0], buf, buf); + xorBytes1x16(sum, buf, sum); + } -function lpad (str, padString, length) { - while (str.length < length) str = padString + str - return str -} + const self = this; + ad.forEach((p, k) => { + const empty = !p || p.length === 0; + let bytes = empty ? 0 : p.length; + self.I[1].copy(I); + multBlock(5 + k, self.J[0], J); + for (let i = 1; bytes >= BLOCK_SIZE; i++, bytes -= BLOCK_SIZE) { + self.aes.AES4(J, I, self.L[i % 8], p.slice(0, BLOCK_SIZE), buf); + xorBytes1x16(sum, buf, sum); + p = p.slice(BLOCK_SIZE); + if (i % 8 === 0) { + doubleBlock(I); + } + } + if (bytes > 0 || empty) { + buf.fill(0); + if (!empty) { + p.copy(buf); + } + buf[bytes] = 0x80; + self.aes.AES4(J, self.I[0], self.L[0], buf, buf); + xorBytes1x16(sum, buf, sum); + } + }); -function binaryToByte (bin) { - return parseInt(bin, 2) -} + return sum; + }; -function bytesToBinary (bytes) { - return bytes.map(function (x) { - return lpad(x.toString(2), '0', 8) - }).join('') -} + this.aezPRF = function (delta, tau, dst) { + const [buf, ctr] = [mkBlock(), mkBlock()]; -function deriveChecksumBits (entropyBuffer) { - var ENT = entropyBuffer.length * 8 - var CS = ENT / 32 - var hash = createHash('sha256').update(entropyBuffer).digest() + let off = 0; + while (tau >= BLOCK_SIZE) { + xorBytes1x16(delta, ctr, buf); + this.aes.AES10(this.L[3], buf, buf); + buf.copy(dst, off); - return bytesToBinary([].slice.call(hash)).slice(0, CS) -} + let i = 15; + while (true) { + ctr[i]++; + i--; + if (ctr[i + 1] !== 0) { + break; + } + } -function salt (password) { - return 'mnemonic' + (password || '') -} + tau -= BLOCK_SIZE; + off += BLOCK_SIZE; + } + if (tau > 0) { + xorBytes1x16(delta, ctr, buf); + this.aes.AES10(this.L[3], buf, buf); + buf.copy(dst, off); + } + }; -function mnemonicToSeed (mnemonic, password) { - var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8') - var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8') + this.encipher = function (delta, input, dst) { + if (!input || input.length === 0) { + return; + } - return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512') -} + if (input.length < 32) { + this.aezTiny(delta, input, 0, dst); + } else { + this.aezCore(delta, input, 0, dst); + } + }; -function mnemonicToSeedHex (mnemonic, password) { - return mnemonicToSeed(mnemonic, password).toString('hex') -} + this.decipher = function (delta, input, dst) { + if (!input || input.length === 0) { + return; + } -function mnemonicToSeedAsync (mnemonic, password) { - return new Promise(function (resolve, reject) { - try { - var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8') - var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8') - } catch (error) { - return reject(error) + if (input.length < 32) { + this.aezTiny(delta, input, 1, dst); + } else { + this.aezCore(delta, input, 1, dst); } + }; - pbkdf2Async(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512', function (err, data) { - if (err) return reject(err) - else return resolve(data) - }) - }) -} + this.aezTiny = function (delta, input, d, dst) { + const inBytes = input.length; + const buf = mkBlock(2 * BLOCK_SIZE); + const [L, R, tmp] = [mkBlock(), mkBlock(), mkBlock()]; + let mask = 0x00; + let pad = 0x80; + let rounds, i, j, step; -function mnemonicToSeedHexAsync (mnemonic, password) { - return mnemonicToSeedAsync(mnemonic, password) - .then(function (buf) { return buf.toString('hex') }) -} + i = 7; + if (inBytes === 1) { + rounds = 24; + } else if (inBytes === 2) { + rounds = 16; + } else if (inBytes < 16) { + rounds = 10; + } else { + i = 6; + rounds = 8; + } -function mnemonicToEntropy (mnemonic, wordlist) { - wordlist = wordlist || DEFAULT_WORDLIST + input.slice(0, (inBytes + 1) / 2).copy(L); + input.slice(inBytes / 2, (inBytes / 2) + ((inBytes + 1) / 2)).copy(R); + if (inBytes & 1 !== 0) { + for (let k = 0; k < (inBytes / 2); k++) { + R[k] = (R[k] << 4) | (R[k + 1] >> 4); + } + R[inBytes / 2] = R[inBytes / 2] << 4; + pad = 0x08; + mask = 0xf0; + } - var words = unorm.nfkd(mnemonic).split(' ') - if (words.length % 3 !== 0) throw new Error(INVALID_MNEMONIC) + if (d !== 0) { + if (inBytes < 16) { + input.slice(0, BLOCK_SIZE).copy(buf); + buf[0] |= 0x80; + xorBytes1x16(delta, buf, buf); + this.aes.AES4(ZERO, this.I[1], this.L[3], buf, tmp); + L[0] ^= (tmp[0] & 0x80); + } + j = rounds - 1; + step = -1; + } else { + j = 0; + step = 1; + } - // convert word indices to 11 bit binary strings - var bits = words.map(function (word) { - var index = wordlist.indexOf(word) - if (index === -1) throw new Error(INVALID_MNEMONIC) + for (let k = 0; k < rounds / 2; k++, j += step * 2) { + buf.fill(0, 0, BLOCK_SIZE); + R.slice(0, (inBytes + 1) / 2).copy(buf); + buf[floor(inBytes / 2)] = (buf[floor(inBytes / 2)] & mask) | pad; + xorBytes1x16(buf, delta, buf); + buf[15] ^= j; + this.aes.AES4(ZERO, this.I[1], this.L[i], buf, tmp); + xorBytes1x16(L, tmp, L); - return lpad(index.toString(2), '0', 11) - }).join('') + buf.fill(0, 0, BLOCK_SIZE); + L.slice(0, (inBytes + 1) / 2).copy(buf); + buf[floor(inBytes / 2)] = (buf[floor(inBytes / 2)] & mask) | pad; + xorBytes1x16(buf, delta, buf); + buf[15] ^= j + step; + this.aes.AES4(ZERO, this.I[1], this.L[i], buf, tmp); + xorBytes1x16(R, tmp, R); + } - // split the binary string into ENT/CS - var dividerIndex = Math.floor(bits.length / 33) * 32 - var entropyBits = bits.slice(0, dividerIndex) - var checksumBits = bits.slice(dividerIndex) + R.slice(0, floor(inBytes / 2)).copy(buf); + L.slice(0, floor((inBytes + 1) / 2)).copy(buf, floor(inBytes / 2)); + if (inBytes & 1 !== 0) { + for (let k = inBytes - 1; k > inBytes / 2; k--) { + buf[k] = (buf[k] >> 4) | (buf[k - 1] << 4); + } + buf[floor(inBytes / 2)] = (L[0] >> 4) | (R[floor(inBytes / 2)] & 0xf0); + } - // calculate the checksum and compare - var entropyBytes = entropyBits.match(/(.{1,8})/g).map(binaryToByte) - if (entropyBytes.length < 16) throw new Error(INVALID_ENTROPY) - if (entropyBytes.length > 32) throw new Error(INVALID_ENTROPY) - if (entropyBytes.length % 4 !== 0) throw new Error(INVALID_ENTROPY) + buf.slice(0, inBytes).copy(dst); + if (inBytes < 16 && d === 0) { + buf.fill(0, inBytes, BLOCK_SIZE); + buf[0] |= 0x80; + xorBytes1x16(delta, buf, buf); + this.aes.AES4(ZERO, this.I[1], this.L[3], buf, tmp); + dst[0] ^= tmp[0] & 0x80; + } + }; - var entropy = Buffer.from(entropyBytes) - var newChecksum = deriveChecksumBits(entropy) - if (newChecksum !== checksumBits) throw new Error(INVALID_CHECKSUM) + this.aezCore = function (delta, input, d, dst) { + const inBytes = input.length; + let fragBytes = inBytes % 32; - return entropy.toString('hex') -} + const initialBytes = inBytes - fragBytes - 32; + const [tmp, X, Y, S] = [mkBlock(), mkBlock(), mkBlock(), mkBlock()]; -function entropyToMnemonic (entropy, wordlist) { - if (!Buffer.isBuffer(entropy)) entropy = Buffer.from(entropy, 'hex') - wordlist = wordlist || DEFAULT_WORDLIST + const outOrig = dst; + const inOrig = input; - // 128 <= ENT <= 256 - if (entropy.length < 16) throw new TypeError(INVALID_ENTROPY) - if (entropy.length > 32) throw new TypeError(INVALID_ENTROPY) - if (entropy.length % 4 !== 0) throw new TypeError(INVALID_ENTROPY) + // Compute X and store intermediate results + if (inBytes >= 64) { + this.aezCorePass1(input, dst, X); + } - var entropyBits = bytesToBinary([].slice.call(entropy)) - var checksumBits = deriveChecksumBits(entropy) + // Finish X calculation + input = input.slice(initialBytes); + if (fragBytes >= BLOCK_SIZE) { + this.aes.AES4(ZERO, this.I[1], this.L[4], input, tmp); + xorBytes1x16(X, tmp, X); + oneZeroPad(input.slice(BLOCK_SIZE), fragBytes - BLOCK_SIZE, tmp); + this.aes.AES4(ZERO, this.I[1], this.L[5], tmp, tmp); + xorBytes1x16(X, tmp, X); + } else if (fragBytes > 0) { + oneZeroPad(input, fragBytes, tmp); + this.aes.AES4(ZERO, this.I[1], this.L[4], tmp, tmp); + xorBytes1x16(X, tmp, X); + } - var bits = entropyBits + checksumBits - var chunks = bits.match(/(.{1,11})/g) - var words = chunks.map(function (binary) { - var index = binaryToByte(binary) - return wordlist[index] - }) + // Calculate S + dst = outOrig.slice(inOrig.length - 32); + input = inOrig.slice(inOrig.length - 32); + this.aes.AES4(ZERO, this.I[1], this.L[(1 + d) % 8], input.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); + xorBytes4x16(X, input, delta, tmp, dst); + this.aes.AES10(this.L[(1 + d) % 8], dst, tmp); + xorBytes1x16(input.slice(BLOCK_SIZE), tmp, dst.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); + xorBytes1x16(dst, dst.slice(BLOCK_SIZE), S); - return wordlist === JAPANESE_WORDLIST ? words.join('\u3000') : words.join(' ') -} + // Pass 2 over intermediate values in dst[32..]. Final values written + dst = outOrig; + input = inOrig; + if (input.length >= 64) { + this.aezCorePass2(input, dst, Y, S); + } -function generateMnemonic (strength, rng, wordlist) { - strength = strength || 128 - if (strength % 32 !== 0) throw new TypeError(INVALID_ENTROPY) - rng = rng || randomBytes + // Finish Y calculation and finish encryption of fragment bytes + dst = dst.slice(initialBytes); + input = input.slice(initialBytes); + if (fragBytes >= BLOCK_SIZE) { + this.aes.AES10(this.L[4], S, tmp); + xorBytes1x16(input, tmp, dst); + this.aes.AES4(ZERO, this.I[1], this.L[4], dst, tmp); + xorBytes1x16(Y, tmp, Y); - return entropyToMnemonic(rng(strength / 8), wordlist) -} + dst = dst.slice(BLOCK_SIZE); + input = input.slice(BLOCK_SIZE); + fragBytes -= BLOCK_SIZE; -function validateMnemonic (mnemonic, wordlist) { - try { - mnemonicToEntropy(mnemonic, wordlist) - } catch (e) { - return false - } + this.aes.AES10(this.L[5], S, tmp); + xorBytes(input, tmp, tmp.slice(0, fragBytes)); + tmp.slice(0, fragBytes).copy(dst); + tmp.slice(fragBytes).fill(0); + tmp[fragBytes] = 0x80; + this.aes.AES4(ZERO, this.I[1], this.L[5], tmp, tmp); + xorBytes1x16(Y, tmp, Y); + } else if (fragBytes > 0) { + this.aes.AES10(this.L[4], S, tmp); + xorBytes(input, tmp, tmp.slice(0, fragBytes)); + tmp.slice(0, fragBytes).copy(dst); + tmp.slice(fragBytes).fill(0); + tmp[fragBytes] = 0x80; + this.aes.AES4(ZERO, this.I[1], this.L[4], tmp, tmp); + xorBytes1x16(Y, tmp, Y); + } - return true -} + // Finish encryption of last two blocks + dst = outOrig.slice(inOrig.length - 32); + this.aes.AES10(this.L[(2 - d) % 8], dst.slice(BLOCK_SIZE), tmp); + xorBytes1x16(dst, tmp, dst); + this.aes.AES4(ZERO, this.I[1], this.L[(2 - d) % 8], dst, tmp); + xorBytes4x16(tmp, dst.slice(BLOCK_SIZE), delta, Y, dst.slice(BLOCK_SIZE)); + dst.slice(0, BLOCK_SIZE).copy(tmp); + dst.slice(BLOCK_SIZE).copy(dst.slice(0, BLOCK_SIZE)); + tmp.copy(dst.slice(BLOCK_SIZE)); + }; -module.exports = { - mnemonicToSeed: mnemonicToSeed, - mnemonicToSeedAsync: mnemonicToSeedAsync, - mnemonicToSeedHex: mnemonicToSeedHex, - mnemonicToSeedHexAsync: mnemonicToSeedHexAsync, - mnemonicToEntropy: mnemonicToEntropy, - entropyToMnemonic: entropyToMnemonic, - generateMnemonic: generateMnemonic, - validateMnemonic: validateMnemonic, - wordlists: { - EN: ENGLISH_WORDLIST, - JA: JAPANESE_WORDLIST, + this.aezCorePass1 = function (input, output, X) { + const [tmp, I] = [mkBlock(), mkBlock()]; - chinese_simplified: CHINESE_SIMPLIFIED_WORDLIST, - chinese_traditional: CHINESE_TRADITIONAL_WORDLIST, - english: ENGLISH_WORDLIST, - french: FRENCH_WORDLIST, - italian: ITALIAN_WORDLIST, - japanese: JAPANESE_WORDLIST, - korean: KOREAN_WORDLIST, - spanish: SPANISH_WORDLIST - } -} + this.I[1].copy(I); + for (let i = 1, inBytes = input.length; inBytes >= 64; i++, inBytes -= 32) { + this.aes.AES4(this.J[0], I, this.L[i % 8], input.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); + xorBytes1x16(input, tmp, output); -},{"./wordlists/chinese_simplified.json":44,"./wordlists/chinese_traditional.json":45,"./wordlists/english.json":46,"./wordlists/french.json":47,"./wordlists/italian.json":48,"./wordlists/japanese.json":49,"./wordlists/korean.json":50,"./wordlists/spanish.json":51,"create-hash":159,"pbkdf2":246,"randombytes":262,"safe-buffer":280,"unorm":326}],44:[function(require,module,exports){ -module.exports=[ - "的", + this.aes.AES4(ZERO, this.I[0], this.L[0], output, tmp); + xorBytes1x16(input.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); + xorBytes1x16(output.slice(BLOCK_SIZE), X, X); + + input = input.slice(32); + output = output.slice(32); + if (i % 8 === 0) { + doubleBlock(I); + } + } + }; + + this.aezCorePass2 = function (input, output, Y, S) { + const [tmp, I] = [mkBlock(), mkBlock()]; + + this.I[1].copy(I); + for (let i = 1, inBytes = input.length; inBytes >= 64; i++, inBytes -= 32) { + this.aes.AES4(this.J[1], I, this.L[i % 8], S, tmp); + xorBytes1x16(output, tmp, output); + xorBytes1x16(output.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); + xorBytes1x16(output, Y, Y); + + this.aes.AES4(ZERO, this.I[0], this.L[0], output.slice(BLOCK_SIZE, BLOCK_SIZE * 2), tmp); + xorBytes1x16(output, tmp, output); + + this.aes.AES4(this.J[0], I, this.L[i % 8], output, tmp); + xorBytes1x16(output.slice(BLOCK_SIZE), tmp, output.slice(BLOCK_SIZE, BLOCK_SIZE * 2)); + + output.copy(tmp); + output.slice(BLOCK_SIZE).copy(output.slice(0, BLOCK_SIZE)); + tmp.copy(output.slice(BLOCK_SIZE)); + + input = input.slice(32); + output = output.slice(32); + if (i % 8 === 0) { + doubleBlock(I); + } + } + }; +}; + +module.exports = AEZState; + +},{"./aes_round":94,"./functions":97,"safe-buffer":463}],97:[function(require,module,exports){ +const Buffer = require('safe-buffer').Buffer; +const blake = require('blakejs'); + +const BLOCK_SIZE = 16; +const EXTRACTED_KEY_SIZE = 3 * 16; + +function mkBlock(size) { + return Buffer.alloc((size === undefined ? BLOCK_SIZE : size), 0); +} + +function xorBytes1x16(a, b, dst) { + for (let i = 0; i < BLOCK_SIZE; i++) { + dst[i] = a[i] ^ b[i]; + } +} + +function xorBytes4x16(a, b, c, d, dst) { + for (let i = 0; i < BLOCK_SIZE; i++) { + dst[i] = a[i] ^ b[i] ^ c[i] ^ d[i]; + } +} + +function xorBytes(a, b, dst) { + if (a.length < dst.length || b.length < dst.length) { + throw new Error('aez: xorBytes: len'); + } + for (let i = 0; i < dst.length; i++) { + dst[i] = a[i] ^ b[i] + } +} + +function uint32(i) { + return i >>> 0; +} + +function uint8(i) { + return 0x000000ff & i; +} + +function extractKey(k) { + if (k && k.length && k.length === EXTRACTED_KEY_SIZE) { + return k; + } else { + const context = blake.blake2bInit(EXTRACTED_KEY_SIZE); + blake.blake2bUpdate(context, k); + return Buffer.from(blake.blake2bFinal(context)); + } +} + +function multBlock(x, src, dst) { + const [t, r] = [mkBlock(), mkBlock()]; + + src.copy(t); + + while (x !== 0) { + if (x & 1 !== 0) { + xorBytes1x16(r, t, r); + } + doubleBlock(t); + x >>= 1 + } + + r.copy(dst); +} + +function doubleBlock(p) { + const tmp = p[0]; + for (let i = 0; i < 15; i++) { + p[i] = (p[i] << 1) | (p[i + 1] >> 7); + } + p[15] = (p[15] << 1) ^ ((tmp >> 7) ? 135 : 0); +} + +function oneZeroPad(src, size, dst) { + dst.fill(0); + src.slice(0, size).copy(dst); + dst[size] = 0x80; +} + +module.exports = { + BLOCK_SIZE, + EXTRACTED_KEY_SIZE, + mkBlock, + xorBytes1x16, + xorBytes4x16, + xorBytes, + uint32, + uint8, + extractKey, + multBlock, + doubleBlock, + oneZeroPad, +}; + +},{"blakejs":196,"safe-buffer":463}],98:[function(require,module,exports){ +const aez = require('./aez'); + +module.exports = { + VERSION: aez.VERSION, + encrypt: aez.encrypt, + decrypt: aez.decrypt, +}; + +},{"./aez":95}],99:[function(require,module,exports){ +'use strict'; + +const asn1 = exports; + +asn1.bignum = require('bn.js'); + +asn1.define = require('./asn1/api').define; +asn1.base = require('./asn1/base'); +asn1.constants = require('./asn1/constants'); +asn1.decoders = require('./asn1/decoders'); +asn1.encoders = require('./asn1/encoders'); + +},{"./asn1/api":100,"./asn1/base":102,"./asn1/constants":106,"./asn1/decoders":108,"./asn1/encoders":111,"bn.js":198}],100:[function(require,module,exports){ +'use strict'; + +const encoders = require('./encoders'); +const decoders = require('./decoders'); +const inherits = require('inherits'); + +const api = exports; + +api.define = function define(name, body) { + return new Entity(name, body); +}; + +function Entity(name, body) { + this.name = name; + this.body = body; + + this.decoders = {}; + this.encoders = {}; +} + +Entity.prototype._createNamed = function createNamed(Base) { + const name = this.name; + + function Generated(entity) { + this._initNamed(entity, name); + } + inherits(Generated, Base); + Generated.prototype._initNamed = function _initNamed(entity, name) { + Base.call(this, entity, name); + }; + + return new Generated(this); +}; + +Entity.prototype._getDecoder = function _getDecoder(enc) { + enc = enc || 'der'; + // Lazily create decoder + if (!this.decoders.hasOwnProperty(enc)) + this.decoders[enc] = this._createNamed(decoders[enc]); + return this.decoders[enc]; +}; + +Entity.prototype.decode = function decode(data, enc, options) { + return this._getDecoder(enc).decode(data, options); +}; + +Entity.prototype._getEncoder = function _getEncoder(enc) { + enc = enc || 'der'; + // Lazily create encoder + if (!this.encoders.hasOwnProperty(enc)) + this.encoders[enc] = this._createNamed(encoders[enc]); + return this.encoders[enc]; +}; + +Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) { + return this._getEncoder(enc).encode(data, reporter); +}; + +},{"./decoders":108,"./encoders":111,"inherits":349}],101:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); +const Reporter = require('../base/reporter').Reporter; +const Buffer = require('safer-buffer').Buffer; + +function DecoderBuffer(base, options) { + Reporter.call(this, options); + if (!Buffer.isBuffer(base)) { + this.error('Input not Buffer'); + return; + } + + this.base = base; + this.offset = 0; + this.length = base.length; +} +inherits(DecoderBuffer, Reporter); +exports.DecoderBuffer = DecoderBuffer; + +DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) { + if (data instanceof DecoderBuffer) { + return true; + } + + // Or accept compatible API + const isCompatible = typeof data === 'object' && + Buffer.isBuffer(data.base) && + data.constructor.name === 'DecoderBuffer' && + typeof data.offset === 'number' && + typeof data.length === 'number' && + typeof data.save === 'function' && + typeof data.restore === 'function' && + typeof data.isEmpty === 'function' && + typeof data.readUInt8 === 'function' && + typeof data.skip === 'function' && + typeof data.raw === 'function'; + + return isCompatible; +}; + +DecoderBuffer.prototype.save = function save() { + return { offset: this.offset, reporter: Reporter.prototype.save.call(this) }; +}; + +DecoderBuffer.prototype.restore = function restore(save) { + // Return skipped data + const res = new DecoderBuffer(this.base); + res.offset = save.offset; + res.length = this.offset; + + this.offset = save.offset; + Reporter.prototype.restore.call(this, save.reporter); + + return res; +}; + +DecoderBuffer.prototype.isEmpty = function isEmpty() { + return this.offset === this.length; +}; + +DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) { + if (this.offset + 1 <= this.length) + return this.base.readUInt8(this.offset++, true); + else + return this.error(fail || 'DecoderBuffer overrun'); +}; + +DecoderBuffer.prototype.skip = function skip(bytes, fail) { + if (!(this.offset + bytes <= this.length)) + return this.error(fail || 'DecoderBuffer overrun'); + + const res = new DecoderBuffer(this.base); + + // Share reporter state + res._reporterState = this._reporterState; + + res.offset = this.offset; + res.length = this.offset + bytes; + this.offset += bytes; + return res; +}; + +DecoderBuffer.prototype.raw = function raw(save) { + return this.base.slice(save ? save.offset : this.offset, this.length); +}; + +function EncoderBuffer(value, reporter) { + if (Array.isArray(value)) { + this.length = 0; + this.value = value.map(function(item) { + if (!EncoderBuffer.isEncoderBuffer(item)) + item = new EncoderBuffer(item, reporter); + this.length += item.length; + return item; + }, this); + } else if (typeof value === 'number') { + if (!(0 <= value && value <= 0xff)) + return reporter.error('non-byte EncoderBuffer value'); + this.value = value; + this.length = 1; + } else if (typeof value === 'string') { + this.value = value; + this.length = Buffer.byteLength(value); + } else if (Buffer.isBuffer(value)) { + this.value = value; + this.length = value.length; + } else { + return reporter.error('Unsupported type: ' + typeof value); + } +} +exports.EncoderBuffer = EncoderBuffer; + +EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) { + if (data instanceof EncoderBuffer) { + return true; + } + + // Or accept compatible API + const isCompatible = typeof data === 'object' && + data.constructor.name === 'EncoderBuffer' && + typeof data.length === 'number' && + typeof data.join === 'function'; + + return isCompatible; +}; + +EncoderBuffer.prototype.join = function join(out, offset) { + if (!out) + out = Buffer.alloc(this.length); + if (!offset) + offset = 0; + + if (this.length === 0) + return out; + + if (Array.isArray(this.value)) { + this.value.forEach(function(item) { + item.join(out, offset); + offset += item.length; + }); + } else { + if (typeof this.value === 'number') + out[offset] = this.value; + else if (typeof this.value === 'string') + out.write(this.value, offset); + else if (Buffer.isBuffer(this.value)) + this.value.copy(out, offset); + offset += this.length; + } + + return out; +}; + +},{"../base/reporter":104,"inherits":349,"safer-buffer":464}],102:[function(require,module,exports){ +'use strict'; + +const base = exports; + +base.Reporter = require('./reporter').Reporter; +base.DecoderBuffer = require('./buffer').DecoderBuffer; +base.EncoderBuffer = require('./buffer').EncoderBuffer; +base.Node = require('./node'); + +},{"./buffer":101,"./node":103,"./reporter":104}],103:[function(require,module,exports){ +'use strict'; + +const Reporter = require('../base/reporter').Reporter; +const EncoderBuffer = require('../base/buffer').EncoderBuffer; +const DecoderBuffer = require('../base/buffer').DecoderBuffer; +const assert = require('minimalistic-assert'); + +// Supported tags +const tags = [ + 'seq', 'seqof', 'set', 'setof', 'objid', 'bool', + 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc', + 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str', + 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr' +]; + +// Public methods list +const methods = [ + 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', + 'any', 'contains' +].concat(tags); + +// Overrided methods list +const overrided = [ + '_peekTag', '_decodeTag', '_use', + '_decodeStr', '_decodeObjid', '_decodeTime', + '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', + + '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', + '_encodeNull', '_encodeInt', '_encodeBool' +]; + +function Node(enc, parent, name) { + const state = {}; + this._baseState = state; + + state.name = name; + state.enc = enc; + + state.parent = parent || null; + state.children = null; + + // State + state.tag = null; + state.args = null; + state.reverseArgs = null; + state.choice = null; + state.optional = false; + state.any = false; + state.obj = false; + state.use = null; + state.useDecoder = null; + state.key = null; + state['default'] = null; + state.explicit = null; + state.implicit = null; + state.contains = null; + + // Should create new instance on each method + if (!state.parent) { + state.children = []; + this._wrap(); + } +} +module.exports = Node; + +const stateProps = [ + 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', + 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', + 'implicit', 'contains' +]; + +Node.prototype.clone = function clone() { + const state = this._baseState; + const cstate = {}; + stateProps.forEach(function(prop) { + cstate[prop] = state[prop]; + }); + const res = new this.constructor(cstate.parent); + res._baseState = cstate; + return res; +}; + +Node.prototype._wrap = function wrap() { + const state = this._baseState; + methods.forEach(function(method) { + this[method] = function _wrappedMethod() { + const clone = new this.constructor(this); + state.children.push(clone); + return clone[method].apply(clone, arguments); + }; + }, this); +}; + +Node.prototype._init = function init(body) { + const state = this._baseState; + + assert(state.parent === null); + body.call(this); + + // Filter children + state.children = state.children.filter(function(child) { + return child._baseState.parent === this; + }, this); + assert.equal(state.children.length, 1, 'Root node can have only one child'); +}; + +Node.prototype._useArgs = function useArgs(args) { + const state = this._baseState; + + // Filter children and args + const children = args.filter(function(arg) { + return arg instanceof this.constructor; + }, this); + args = args.filter(function(arg) { + return !(arg instanceof this.constructor); + }, this); + + if (children.length !== 0) { + assert(state.children === null); + state.children = children; + + // Replace parent to maintain backward link + children.forEach(function(child) { + child._baseState.parent = this; + }, this); + } + if (args.length !== 0) { + assert(state.args === null); + state.args = args; + state.reverseArgs = args.map(function(arg) { + if (typeof arg !== 'object' || arg.constructor !== Object) + return arg; + + const res = {}; + Object.keys(arg).forEach(function(key) { + if (key == (key | 0)) + key |= 0; + const value = arg[key]; + res[value] = key; + }); + return res; + }); + } +}; + +// +// Overrided methods +// + +overrided.forEach(function(method) { + Node.prototype[method] = function _overrided() { + const state = this._baseState; + throw new Error(method + ' not implemented for encoding: ' + state.enc); + }; +}); + +// +// Public methods +// + +tags.forEach(function(tag) { + Node.prototype[tag] = function _tagMethod() { + const state = this._baseState; + const args = Array.prototype.slice.call(arguments); + + assert(state.tag === null); + state.tag = tag; + + this._useArgs(args); + + return this; + }; +}); + +Node.prototype.use = function use(item) { + assert(item); + const state = this._baseState; + + assert(state.use === null); + state.use = item; + + return this; +}; + +Node.prototype.optional = function optional() { + const state = this._baseState; + + state.optional = true; + + return this; +}; + +Node.prototype.def = function def(val) { + const state = this._baseState; + + assert(state['default'] === null); + state['default'] = val; + state.optional = true; + + return this; +}; + +Node.prototype.explicit = function explicit(num) { + const state = this._baseState; + + assert(state.explicit === null && state.implicit === null); + state.explicit = num; + + return this; +}; + +Node.prototype.implicit = function implicit(num) { + const state = this._baseState; + + assert(state.explicit === null && state.implicit === null); + state.implicit = num; + + return this; +}; + +Node.prototype.obj = function obj() { + const state = this._baseState; + const args = Array.prototype.slice.call(arguments); + + state.obj = true; + + if (args.length !== 0) + this._useArgs(args); + + return this; +}; + +Node.prototype.key = function key(newKey) { + const state = this._baseState; + + assert(state.key === null); + state.key = newKey; + + return this; +}; + +Node.prototype.any = function any() { + const state = this._baseState; + + state.any = true; + + return this; +}; + +Node.prototype.choice = function choice(obj) { + const state = this._baseState; + + assert(state.choice === null); + state.choice = obj; + this._useArgs(Object.keys(obj).map(function(key) { + return obj[key]; + })); + + return this; +}; + +Node.prototype.contains = function contains(item) { + const state = this._baseState; + + assert(state.use === null); + state.contains = item; + + return this; +}; + +// +// Decoding +// + +Node.prototype._decode = function decode(input, options) { + const state = this._baseState; + + // Decode root node + if (state.parent === null) + return input.wrapResult(state.children[0]._decode(input, options)); + + let result = state['default']; + let present = true; + + let prevKey = null; + if (state.key !== null) + prevKey = input.enterKey(state.key); + + // Check if tag is there + if (state.optional) { + let tag = null; + if (state.explicit !== null) + tag = state.explicit; + else if (state.implicit !== null) + tag = state.implicit; + else if (state.tag !== null) + tag = state.tag; + + if (tag === null && !state.any) { + // Trial and Error + const save = input.save(); + try { + if (state.choice === null) + this._decodeGeneric(state.tag, input, options); + else + this._decodeChoice(input, options); + present = true; + } catch (e) { + present = false; + } + input.restore(save); + } else { + present = this._peekTag(input, tag, state.any); + + if (input.isError(present)) + return present; + } + } + + // Push object on stack + let prevObj; + if (state.obj && present) + prevObj = input.enterObject(); + + if (present) { + // Unwrap explicit values + if (state.explicit !== null) { + const explicit = this._decodeTag(input, state.explicit); + if (input.isError(explicit)) + return explicit; + input = explicit; + } + + const start = input.offset; + + // Unwrap implicit and normal values + if (state.use === null && state.choice === null) { + let save; + if (state.any) + save = input.save(); + const body = this._decodeTag( + input, + state.implicit !== null ? state.implicit : state.tag, + state.any + ); + if (input.isError(body)) + return body; + + if (state.any) + result = input.raw(save); + else + input = body; + } + + if (options && options.track && state.tag !== null) + options.track(input.path(), start, input.length, 'tagged'); + + if (options && options.track && state.tag !== null) + options.track(input.path(), input.offset, input.length, 'content'); + + // Select proper method for tag + if (state.any) { + // no-op + } else if (state.choice === null) { + result = this._decodeGeneric(state.tag, input, options); + } else { + result = this._decodeChoice(input, options); + } + + if (input.isError(result)) + return result; + + // Decode children + if (!state.any && state.choice === null && state.children !== null) { + state.children.forEach(function decodeChildren(child) { + // NOTE: We are ignoring errors here, to let parser continue with other + // parts of encoded data + child._decode(input, options); + }); + } + + // Decode contained/encoded by schema, only in bit or octet strings + if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) { + const data = new DecoderBuffer(result); + result = this._getUse(state.contains, input._reporterState.obj) + ._decode(data, options); + } + } + + // Pop object + if (state.obj && present) + result = input.leaveObject(prevObj); + + // Set key + if (state.key !== null && (result !== null || present === true)) + input.leaveKey(prevKey, state.key, result); + else if (prevKey !== null) + input.exitKey(prevKey); + + return result; +}; + +Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) { + const state = this._baseState; + + if (tag === 'seq' || tag === 'set') + return null; + if (tag === 'seqof' || tag === 'setof') + return this._decodeList(input, tag, state.args[0], options); + else if (/str$/.test(tag)) + return this._decodeStr(input, tag, options); + else if (tag === 'objid' && state.args) + return this._decodeObjid(input, state.args[0], state.args[1], options); + else if (tag === 'objid') + return this._decodeObjid(input, null, null, options); + else if (tag === 'gentime' || tag === 'utctime') + return this._decodeTime(input, tag, options); + else if (tag === 'null_') + return this._decodeNull(input, options); + else if (tag === 'bool') + return this._decodeBool(input, options); + else if (tag === 'objDesc') + return this._decodeStr(input, tag, options); + else if (tag === 'int' || tag === 'enum') + return this._decodeInt(input, state.args && state.args[0], options); + + if (state.use !== null) { + return this._getUse(state.use, input._reporterState.obj) + ._decode(input, options); + } else { + return input.error('unknown tag: ' + tag); + } +}; + +Node.prototype._getUse = function _getUse(entity, obj) { + + const state = this._baseState; + // Create altered use decoder if implicit is set + state.useDecoder = this._use(entity, obj); + assert(state.useDecoder._baseState.parent === null); + state.useDecoder = state.useDecoder._baseState.children[0]; + if (state.implicit !== state.useDecoder._baseState.implicit) { + state.useDecoder = state.useDecoder.clone(); + state.useDecoder._baseState.implicit = state.implicit; + } + return state.useDecoder; +}; + +Node.prototype._decodeChoice = function decodeChoice(input, options) { + const state = this._baseState; + let result = null; + let match = false; + + Object.keys(state.choice).some(function(key) { + const save = input.save(); + const node = state.choice[key]; + try { + const value = node._decode(input, options); + if (input.isError(value)) + return false; + + result = { type: key, value: value }; + match = true; + } catch (e) { + input.restore(save); + return false; + } + return true; + }, this); + + if (!match) + return input.error('Choice not matched'); + + return result; +}; + +// +// Encoding +// + +Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) { + return new EncoderBuffer(data, this.reporter); +}; + +Node.prototype._encode = function encode(data, reporter, parent) { + const state = this._baseState; + if (state['default'] !== null && state['default'] === data) + return; + + const result = this._encodeValue(data, reporter, parent); + if (result === undefined) + return; + + if (this._skipDefault(result, reporter, parent)) + return; + + return result; +}; + +Node.prototype._encodeValue = function encode(data, reporter, parent) { + const state = this._baseState; + + // Decode root node + if (state.parent === null) + return state.children[0]._encode(data, reporter || new Reporter()); + + let result = null; + + // Set reporter to share it with a child class + this.reporter = reporter; + + // Check if data is there + if (state.optional && data === undefined) { + if (state['default'] !== null) + data = state['default']; + else + return; + } + + // Encode children first + let content = null; + let primitive = false; + if (state.any) { + // Anything that was given is translated to buffer + result = this._createEncoderBuffer(data); + } else if (state.choice) { + result = this._encodeChoice(data, reporter); + } else if (state.contains) { + content = this._getUse(state.contains, parent)._encode(data, reporter); + primitive = true; + } else if (state.children) { + content = state.children.map(function(child) { + if (child._baseState.tag === 'null_') + return child._encode(null, reporter, data); + + if (child._baseState.key === null) + return reporter.error('Child should have a key'); + const prevKey = reporter.enterKey(child._baseState.key); + + if (typeof data !== 'object') + return reporter.error('Child expected, but input is not object'); + + const res = child._encode(data[child._baseState.key], reporter, data); + reporter.leaveKey(prevKey); + + return res; + }, this).filter(function(child) { + return child; + }); + content = this._createEncoderBuffer(content); + } else { + if (state.tag === 'seqof' || state.tag === 'setof') { + // TODO(indutny): this should be thrown on DSL level + if (!(state.args && state.args.length === 1)) + return reporter.error('Too many args for : ' + state.tag); + + if (!Array.isArray(data)) + return reporter.error('seqof/setof, but data is not Array'); + + const child = this.clone(); + child._baseState.implicit = null; + content = this._createEncoderBuffer(data.map(function(item) { + const state = this._baseState; + + return this._getUse(state.args[0], data)._encode(item, reporter); + }, child)); + } else if (state.use !== null) { + result = this._getUse(state.use, parent)._encode(data, reporter); + } else { + content = this._encodePrimitive(state.tag, data); + primitive = true; + } + } + + // Encode data itself + if (!state.any && state.choice === null) { + const tag = state.implicit !== null ? state.implicit : state.tag; + const cls = state.implicit === null ? 'universal' : 'context'; + + if (tag === null) { + if (state.use === null) + reporter.error('Tag could be omitted only for .use()'); + } else { + if (state.use === null) + result = this._encodeComposite(tag, primitive, cls, content); + } + } + + // Wrap in explicit + if (state.explicit !== null) + result = this._encodeComposite(state.explicit, false, 'context', result); + + return result; +}; + +Node.prototype._encodeChoice = function encodeChoice(data, reporter) { + const state = this._baseState; + + const node = state.choice[data.type]; + if (!node) { + assert( + false, + data.type + ' not found in ' + + JSON.stringify(Object.keys(state.choice))); + } + return node._encode(data.value, reporter); +}; + +Node.prototype._encodePrimitive = function encodePrimitive(tag, data) { + const state = this._baseState; + + if (/str$/.test(tag)) + return this._encodeStr(data, tag); + else if (tag === 'objid' && state.args) + return this._encodeObjid(data, state.reverseArgs[0], state.args[1]); + else if (tag === 'objid') + return this._encodeObjid(data, null, null); + else if (tag === 'gentime' || tag === 'utctime') + return this._encodeTime(data, tag); + else if (tag === 'null_') + return this._encodeNull(); + else if (tag === 'int' || tag === 'enum') + return this._encodeInt(data, state.args && state.reverseArgs[0]); + else if (tag === 'bool') + return this._encodeBool(data); + else if (tag === 'objDesc') + return this._encodeStr(data, tag); + else + throw new Error('Unsupported tag: ' + tag); +}; + +Node.prototype._isNumstr = function isNumstr(str) { + return /^[0-9 ]*$/.test(str); +}; + +Node.prototype._isPrintstr = function isPrintstr(str) { + return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str); +}; + +},{"../base/buffer":101,"../base/reporter":104,"minimalistic-assert":436}],104:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); + +function Reporter(options) { + this._reporterState = { + obj: null, + path: [], + options: options || {}, + errors: [] + }; +} +exports.Reporter = Reporter; + +Reporter.prototype.isError = function isError(obj) { + return obj instanceof ReporterError; +}; + +Reporter.prototype.save = function save() { + const state = this._reporterState; + + return { obj: state.obj, pathLen: state.path.length }; +}; + +Reporter.prototype.restore = function restore(data) { + const state = this._reporterState; + + state.obj = data.obj; + state.path = state.path.slice(0, data.pathLen); +}; + +Reporter.prototype.enterKey = function enterKey(key) { + return this._reporterState.path.push(key); +}; + +Reporter.prototype.exitKey = function exitKey(index) { + const state = this._reporterState; + + state.path = state.path.slice(0, index - 1); +}; + +Reporter.prototype.leaveKey = function leaveKey(index, key, value) { + const state = this._reporterState; + + this.exitKey(index); + if (state.obj !== null) + state.obj[key] = value; +}; + +Reporter.prototype.path = function path() { + return this._reporterState.path.join('/'); +}; + +Reporter.prototype.enterObject = function enterObject() { + const state = this._reporterState; + + const prev = state.obj; + state.obj = {}; + return prev; +}; + +Reporter.prototype.leaveObject = function leaveObject(prev) { + const state = this._reporterState; + + const now = state.obj; + state.obj = prev; + return now; +}; + +Reporter.prototype.error = function error(msg) { + let err; + const state = this._reporterState; + + const inherited = msg instanceof ReporterError; + if (inherited) { + err = msg; + } else { + err = new ReporterError(state.path.map(function(elem) { + return '[' + JSON.stringify(elem) + ']'; + }).join(''), msg.message || msg, msg.stack); + } + + if (!state.options.partial) + throw err; + + if (!inherited) + state.errors.push(err); + + return err; +}; + +Reporter.prototype.wrapResult = function wrapResult(result) { + const state = this._reporterState; + if (!state.options.partial) + return result; + + return { + result: this.isError(result) ? null : result, + errors: state.errors + }; +}; + +function ReporterError(path, msg) { + this.path = path; + this.rethrow(msg); +} +inherits(ReporterError, Error); + +ReporterError.prototype.rethrow = function rethrow(msg) { + this.message = msg + ' at: ' + (this.path || '(shallow)'); + if (Error.captureStackTrace) + Error.captureStackTrace(this, ReporterError); + + if (!this.stack) { + try { + // IE only adds stack when thrown + throw new Error(this.message); + } catch (e) { + this.stack = e.stack; + } + } + return this; +}; + +},{"inherits":349}],105:[function(require,module,exports){ +'use strict'; + +// Helper +function reverse(map) { + const res = {}; + + Object.keys(map).forEach(function(key) { + // Convert key to integer if it is stringified + if ((key | 0) == key) + key = key | 0; + + const value = map[key]; + res[value] = key; + }); + + return res; +} + +exports.tagClass = { + 0: 'universal', + 1: 'application', + 2: 'context', + 3: 'private' +}; +exports.tagClassByName = reverse(exports.tagClass); + +exports.tag = { + 0x00: 'end', + 0x01: 'bool', + 0x02: 'int', + 0x03: 'bitstr', + 0x04: 'octstr', + 0x05: 'null_', + 0x06: 'objid', + 0x07: 'objDesc', + 0x08: 'external', + 0x09: 'real', + 0x0a: 'enum', + 0x0b: 'embed', + 0x0c: 'utf8str', + 0x0d: 'relativeOid', + 0x10: 'seq', + 0x11: 'set', + 0x12: 'numstr', + 0x13: 'printstr', + 0x14: 't61str', + 0x15: 'videostr', + 0x16: 'ia5str', + 0x17: 'utctime', + 0x18: 'gentime', + 0x19: 'graphstr', + 0x1a: 'iso646str', + 0x1b: 'genstr', + 0x1c: 'unistr', + 0x1d: 'charstr', + 0x1e: 'bmpstr' +}; +exports.tagByName = reverse(exports.tag); + +},{}],106:[function(require,module,exports){ +'use strict'; + +const constants = exports; + +// Helper +constants._reverse = function reverse(map) { + const res = {}; + + Object.keys(map).forEach(function(key) { + // Convert key to integer if it is stringified + if ((key | 0) == key) + key = key | 0; + + const value = map[key]; + res[value] = key; + }); + + return res; +}; + +constants.der = require('./der'); + +},{"./der":105}],107:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); + +const bignum = require('bn.js'); +const DecoderBuffer = require('../base/buffer').DecoderBuffer; +const Node = require('../base/node'); + +// Import DER constants +const der = require('../constants/der'); + +function DERDecoder(entity) { + this.enc = 'der'; + this.name = entity.name; + this.entity = entity; + + // Construct base tree + this.tree = new DERNode(); + this.tree._init(entity.body); +} +module.exports = DERDecoder; + +DERDecoder.prototype.decode = function decode(data, options) { + if (!DecoderBuffer.isDecoderBuffer(data)) { + data = new DecoderBuffer(data, options); + } + + return this.tree._decode(data, options); +}; + +// Tree methods + +function DERNode(parent) { + Node.call(this, 'der', parent); +} +inherits(DERNode, Node); + +DERNode.prototype._peekTag = function peekTag(buffer, tag, any) { + if (buffer.isEmpty()) + return false; + + const state = buffer.save(); + const decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"'); + if (buffer.isError(decodedTag)) + return decodedTag; + + buffer.restore(state); + + return decodedTag.tag === tag || decodedTag.tagStr === tag || + (decodedTag.tagStr + 'of') === tag || any; +}; + +DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) { + const decodedTag = derDecodeTag(buffer, + 'Failed to decode tag of "' + tag + '"'); + if (buffer.isError(decodedTag)) + return decodedTag; + + let len = derDecodeLen(buffer, + decodedTag.primitive, + 'Failed to get length of "' + tag + '"'); + + // Failure + if (buffer.isError(len)) + return len; + + if (!any && + decodedTag.tag !== tag && + decodedTag.tagStr !== tag && + decodedTag.tagStr + 'of' !== tag) { + return buffer.error('Failed to match tag: "' + tag + '"'); + } + + if (decodedTag.primitive || len !== null) + return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); + + // Indefinite length... find END tag + const state = buffer.save(); + const res = this._skipUntilEnd( + buffer, + 'Failed to skip indefinite length body: "' + this.tag + '"'); + if (buffer.isError(res)) + return res; + + len = buffer.offset - state.offset; + buffer.restore(state); + return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); +}; + +DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) { + for (;;) { + const tag = derDecodeTag(buffer, fail); + if (buffer.isError(tag)) + return tag; + const len = derDecodeLen(buffer, tag.primitive, fail); + if (buffer.isError(len)) + return len; + + let res; + if (tag.primitive || len !== null) + res = buffer.skip(len); + else + res = this._skipUntilEnd(buffer, fail); + + // Failure + if (buffer.isError(res)) + return res; + + if (tag.tagStr === 'end') + break; + } +}; + +DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, + options) { + const result = []; + while (!buffer.isEmpty()) { + const possibleEnd = this._peekTag(buffer, 'end'); + if (buffer.isError(possibleEnd)) + return possibleEnd; + + const res = decoder.decode(buffer, 'der', options); + if (buffer.isError(res) && possibleEnd) + break; + result.push(res); + } + return result; +}; + +DERNode.prototype._decodeStr = function decodeStr(buffer, tag) { + if (tag === 'bitstr') { + const unused = buffer.readUInt8(); + if (buffer.isError(unused)) + return unused; + return { unused: unused, data: buffer.raw() }; + } else if (tag === 'bmpstr') { + const raw = buffer.raw(); + if (raw.length % 2 === 1) + return buffer.error('Decoding of string type: bmpstr length mismatch'); + + let str = ''; + for (let i = 0; i < raw.length / 2; i++) { + str += String.fromCharCode(raw.readUInt16BE(i * 2)); + } + return str; + } else if (tag === 'numstr') { + const numstr = buffer.raw().toString('ascii'); + if (!this._isNumstr(numstr)) { + return buffer.error('Decoding of string type: ' + + 'numstr unsupported characters'); + } + return numstr; + } else if (tag === 'octstr') { + return buffer.raw(); + } else if (tag === 'objDesc') { + return buffer.raw(); + } else if (tag === 'printstr') { + const printstr = buffer.raw().toString('ascii'); + if (!this._isPrintstr(printstr)) { + return buffer.error('Decoding of string type: ' + + 'printstr unsupported characters'); + } + return printstr; + } else if (/str$/.test(tag)) { + return buffer.raw().toString(); + } else { + return buffer.error('Decoding of string type: ' + tag + ' unsupported'); + } +}; + +DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) { + let result; + const identifiers = []; + let ident = 0; + let subident = 0; + while (!buffer.isEmpty()) { + subident = buffer.readUInt8(); + ident <<= 7; + ident |= subident & 0x7f; + if ((subident & 0x80) === 0) { + identifiers.push(ident); + ident = 0; + } + } + if (subident & 0x80) + identifiers.push(ident); + + const first = (identifiers[0] / 40) | 0; + const second = identifiers[0] % 40; + + if (relative) + result = identifiers; + else + result = [first, second].concat(identifiers.slice(1)); + + if (values) { + let tmp = values[result.join(' ')]; + if (tmp === undefined) + tmp = values[result.join('.')]; + if (tmp !== undefined) + result = tmp; + } + + return result; +}; + +DERNode.prototype._decodeTime = function decodeTime(buffer, tag) { + const str = buffer.raw().toString(); + + let year; + let mon; + let day; + let hour; + let min; + let sec; + if (tag === 'gentime') { + year = str.slice(0, 4) | 0; + mon = str.slice(4, 6) | 0; + day = str.slice(6, 8) | 0; + hour = str.slice(8, 10) | 0; + min = str.slice(10, 12) | 0; + sec = str.slice(12, 14) | 0; + } else if (tag === 'utctime') { + year = str.slice(0, 2) | 0; + mon = str.slice(2, 4) | 0; + day = str.slice(4, 6) | 0; + hour = str.slice(6, 8) | 0; + min = str.slice(8, 10) | 0; + sec = str.slice(10, 12) | 0; + if (year < 70) + year = 2000 + year; + else + year = 1900 + year; + } else { + return buffer.error('Decoding ' + tag + ' time is not supported yet'); + } + + return Date.UTC(year, mon - 1, day, hour, min, sec, 0); +}; + +DERNode.prototype._decodeNull = function decodeNull() { + return null; +}; + +DERNode.prototype._decodeBool = function decodeBool(buffer) { + const res = buffer.readUInt8(); + if (buffer.isError(res)) + return res; + else + return res !== 0; +}; + +DERNode.prototype._decodeInt = function decodeInt(buffer, values) { + // Bigint, return as it is (assume big endian) + const raw = buffer.raw(); + let res = new bignum(raw); + + if (values) + res = values[res.toString(10)] || res; + + return res; +}; + +DERNode.prototype._use = function use(entity, obj) { + if (typeof entity === 'function') + entity = entity(obj); + return entity._getDecoder('der').tree; +}; + +// Utility methods + +function derDecodeTag(buf, fail) { + let tag = buf.readUInt8(fail); + if (buf.isError(tag)) + return tag; + + const cls = der.tagClass[tag >> 6]; + const primitive = (tag & 0x20) === 0; + + // Multi-octet tag - load + if ((tag & 0x1f) === 0x1f) { + let oct = tag; + tag = 0; + while ((oct & 0x80) === 0x80) { + oct = buf.readUInt8(fail); + if (buf.isError(oct)) + return oct; + + tag <<= 7; + tag |= oct & 0x7f; + } + } else { + tag &= 0x1f; + } + const tagStr = der.tag[tag]; + + return { + cls: cls, + primitive: primitive, + tag: tag, + tagStr: tagStr + }; +} + +function derDecodeLen(buf, primitive, fail) { + let len = buf.readUInt8(fail); + if (buf.isError(len)) + return len; + + // Indefinite form + if (!primitive && len === 0x80) + return null; + + // Definite form + if ((len & 0x80) === 0) { + // Short form + return len; + } + + // Long form + const num = len & 0x7f; + if (num > 4) + return buf.error('length octect is too long'); + + len = 0; + for (let i = 0; i < num; i++) { + len <<= 8; + const j = buf.readUInt8(fail); + if (buf.isError(j)) + return j; + len |= j; + } + + return len; +} + +},{"../base/buffer":101,"../base/node":103,"../constants/der":105,"bn.js":198,"inherits":349}],108:[function(require,module,exports){ +'use strict'; + +const decoders = exports; + +decoders.der = require('./der'); +decoders.pem = require('./pem'); + +},{"./der":107,"./pem":109}],109:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); +const Buffer = require('safer-buffer').Buffer; + +const DERDecoder = require('./der'); + +function PEMDecoder(entity) { + DERDecoder.call(this, entity); + this.enc = 'pem'; +} +inherits(PEMDecoder, DERDecoder); +module.exports = PEMDecoder; + +PEMDecoder.prototype.decode = function decode(data, options) { + const lines = data.toString().split(/[\r\n]+/g); + + const label = options.label.toUpperCase(); + + const re = /^-----(BEGIN|END) ([^-]+)-----$/; + let start = -1; + let end = -1; + for (let i = 0; i < lines.length; i++) { + const match = lines[i].match(re); + if (match === null) + continue; + + if (match[2] !== label) + continue; + + if (start === -1) { + if (match[1] !== 'BEGIN') + break; + start = i; + } else { + if (match[1] !== 'END') + break; + end = i; + break; + } + } + if (start === -1 || end === -1) + throw new Error('PEM section not found for: ' + label); + + const base64 = lines.slice(start + 1, end).join(''); + // Remove excessive symbols + base64.replace(/[^a-z0-9+/=]+/gi, ''); + + const input = Buffer.from(base64, 'base64'); + return DERDecoder.prototype.decode.call(this, input, options); +}; + +},{"./der":107,"inherits":349,"safer-buffer":464}],110:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); +const Buffer = require('safer-buffer').Buffer; +const Node = require('../base/node'); + +// Import DER constants +const der = require('../constants/der'); + +function DEREncoder(entity) { + this.enc = 'der'; + this.name = entity.name; + this.entity = entity; + + // Construct base tree + this.tree = new DERNode(); + this.tree._init(entity.body); +} +module.exports = DEREncoder; + +DEREncoder.prototype.encode = function encode(data, reporter) { + return this.tree._encode(data, reporter).join(); +}; + +// Tree methods + +function DERNode(parent) { + Node.call(this, 'der', parent); +} +inherits(DERNode, Node); + +DERNode.prototype._encodeComposite = function encodeComposite(tag, + primitive, + cls, + content) { + const encodedTag = encodeTag(tag, primitive, cls, this.reporter); + + // Short form + if (content.length < 0x80) { + const header = Buffer.alloc(2); + header[0] = encodedTag; + header[1] = content.length; + return this._createEncoderBuffer([ header, content ]); + } + + // Long form + // Count octets required to store length + let lenOctets = 1; + for (let i = content.length; i >= 0x100; i >>= 8) + lenOctets++; + + const header = Buffer.alloc(1 + 1 + lenOctets); + header[0] = encodedTag; + header[1] = 0x80 | lenOctets; + + for (let i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) + header[i] = j & 0xff; + + return this._createEncoderBuffer([ header, content ]); +}; + +DERNode.prototype._encodeStr = function encodeStr(str, tag) { + if (tag === 'bitstr') { + return this._createEncoderBuffer([ str.unused | 0, str.data ]); + } else if (tag === 'bmpstr') { + const buf = Buffer.alloc(str.length * 2); + for (let i = 0; i < str.length; i++) { + buf.writeUInt16BE(str.charCodeAt(i), i * 2); + } + return this._createEncoderBuffer(buf); + } else if (tag === 'numstr') { + if (!this._isNumstr(str)) { + return this.reporter.error('Encoding of string type: numstr supports ' + + 'only digits and space'); + } + return this._createEncoderBuffer(str); + } else if (tag === 'printstr') { + if (!this._isPrintstr(str)) { + return this.reporter.error('Encoding of string type: printstr supports ' + + 'only latin upper and lower case letters, ' + + 'digits, space, apostrophe, left and rigth ' + + 'parenthesis, plus sign, comma, hyphen, ' + + 'dot, slash, colon, equal sign, ' + + 'question mark'); + } + return this._createEncoderBuffer(str); + } else if (/str$/.test(tag)) { + return this._createEncoderBuffer(str); + } else if (tag === 'objDesc') { + return this._createEncoderBuffer(str); + } else { + return this.reporter.error('Encoding of string type: ' + tag + + ' unsupported'); + } +}; + +DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) { + if (typeof id === 'string') { + if (!values) + return this.reporter.error('string objid given, but no values map found'); + if (!values.hasOwnProperty(id)) + return this.reporter.error('objid not found in values map'); + id = values[id].split(/[\s.]+/g); + for (let i = 0; i < id.length; i++) + id[i] |= 0; + } else if (Array.isArray(id)) { + id = id.slice(); + for (let i = 0; i < id.length; i++) + id[i] |= 0; + } + + if (!Array.isArray(id)) { + return this.reporter.error('objid() should be either array or string, ' + + 'got: ' + JSON.stringify(id)); + } + + if (!relative) { + if (id[1] >= 40) + return this.reporter.error('Second objid identifier OOB'); + id.splice(0, 2, id[0] * 40 + id[1]); + } + + // Count number of octets + let size = 0; + for (let i = 0; i < id.length; i++) { + let ident = id[i]; + for (size++; ident >= 0x80; ident >>= 7) + size++; + } + + const objid = Buffer.alloc(size); + let offset = objid.length - 1; + for (let i = id.length - 1; i >= 0; i--) { + let ident = id[i]; + objid[offset--] = ident & 0x7f; + while ((ident >>= 7) > 0) + objid[offset--] = 0x80 | (ident & 0x7f); + } + + return this._createEncoderBuffer(objid); +}; + +function two(num) { + if (num < 10) + return '0' + num; + else + return num; +} + +DERNode.prototype._encodeTime = function encodeTime(time, tag) { + let str; + const date = new Date(time); + + if (tag === 'gentime') { + str = [ + two(date.getUTCFullYear()), + two(date.getUTCMonth() + 1), + two(date.getUTCDate()), + two(date.getUTCHours()), + two(date.getUTCMinutes()), + two(date.getUTCSeconds()), + 'Z' + ].join(''); + } else if (tag === 'utctime') { + str = [ + two(date.getUTCFullYear() % 100), + two(date.getUTCMonth() + 1), + two(date.getUTCDate()), + two(date.getUTCHours()), + two(date.getUTCMinutes()), + two(date.getUTCSeconds()), + 'Z' + ].join(''); + } else { + this.reporter.error('Encoding ' + tag + ' time is not supported yet'); + } + + return this._encodeStr(str, 'octstr'); +}; + +DERNode.prototype._encodeNull = function encodeNull() { + return this._createEncoderBuffer(''); +}; + +DERNode.prototype._encodeInt = function encodeInt(num, values) { + if (typeof num === 'string') { + if (!values) + return this.reporter.error('String int or enum given, but no values map'); + if (!values.hasOwnProperty(num)) { + return this.reporter.error('Values map doesn\'t contain: ' + + JSON.stringify(num)); + } + num = values[num]; + } + + // Bignum, assume big endian + if (typeof num !== 'number' && !Buffer.isBuffer(num)) { + const numArray = num.toArray(); + if (!num.sign && numArray[0] & 0x80) { + numArray.unshift(0); + } + num = Buffer.from(numArray); + } + + if (Buffer.isBuffer(num)) { + let size = num.length; + if (num.length === 0) + size++; + + const out = Buffer.alloc(size); + num.copy(out); + if (num.length === 0) + out[0] = 0; + return this._createEncoderBuffer(out); + } + + if (num < 0x80) + return this._createEncoderBuffer(num); + + if (num < 0x100) + return this._createEncoderBuffer([0, num]); + + let size = 1; + for (let i = num; i >= 0x100; i >>= 8) + size++; + + const out = new Array(size); + for (let i = out.length - 1; i >= 0; i--) { + out[i] = num & 0xff; + num >>= 8; + } + if(out[0] & 0x80) { + out.unshift(0); + } + + return this._createEncoderBuffer(Buffer.from(out)); +}; + +DERNode.prototype._encodeBool = function encodeBool(value) { + return this._createEncoderBuffer(value ? 0xff : 0); +}; + +DERNode.prototype._use = function use(entity, obj) { + if (typeof entity === 'function') + entity = entity(obj); + return entity._getEncoder('der').tree; +}; + +DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) { + const state = this._baseState; + let i; + if (state['default'] === null) + return false; + + const data = dataBuffer.join(); + if (state.defaultBuffer === undefined) + state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join(); + + if (data.length !== state.defaultBuffer.length) + return false; + + for (i=0; i < data.length; i++) + if (data[i] !== state.defaultBuffer[i]) + return false; + + return true; +}; + +// Utility methods + +function encodeTag(tag, primitive, cls, reporter) { + let res; + + if (tag === 'seqof') + tag = 'seq'; + else if (tag === 'setof') + tag = 'set'; + + if (der.tagByName.hasOwnProperty(tag)) + res = der.tagByName[tag]; + else if (typeof tag === 'number' && (tag | 0) === tag) + res = tag; + else + return reporter.error('Unknown tag: ' + tag); + + if (res >= 0x1f) + return reporter.error('Multi-octet tag encoding unsupported'); + + if (!primitive) + res |= 0x20; + + res |= (der.tagClassByName[cls || 'universal'] << 6); + + return res; +} + +},{"../base/node":103,"../constants/der":105,"inherits":349,"safer-buffer":464}],111:[function(require,module,exports){ +'use strict'; + +const encoders = exports; + +encoders.der = require('./der'); +encoders.pem = require('./pem'); + +},{"./der":110,"./pem":112}],112:[function(require,module,exports){ +'use strict'; + +const inherits = require('inherits'); + +const DEREncoder = require('./der'); + +function PEMEncoder(entity) { + DEREncoder.call(this, entity); + this.enc = 'pem'; +} +inherits(PEMEncoder, DEREncoder); +module.exports = PEMEncoder; + +PEMEncoder.prototype.encode = function encode(data, options) { + const buf = DEREncoder.prototype.encode.call(this, data); + + const p = buf.toString('base64'); + const out = [ '-----BEGIN ' + options.label + '-----' ]; + for (let i = 0; i < p.length; i += 64) + out.push(p.slice(i, i + 64)); + out.push('-----END ' + options.label + '-----'); + return out.join('\n'); +}; + +},{"./der":110,"inherits":349}],113:[function(require,module,exports){ +(function (global){(function (){ +'use strict'; + +var objectAssign = require('object-assign'); + +// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js +// original notice: + +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +function compare(a, b) { + if (a === b) { + return 0; + } + + var x = a.length; + var y = b.length; + + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } + + if (x < y) { + return -1; + } + if (y < x) { + return 1; + } + return 0; +} +function isBuffer(b) { + if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { + return global.Buffer.isBuffer(b); + } + return !!(b != null && b._isBuffer); +} + +// based on node assert, original notice: +// NB: The URL to the CommonJS spec is kept just for tradition. +// node-assert has evolved a lot since then, both in API and behavior. + +// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 +// +// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! +// +// Originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the 'Software'), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +var util = require('util/'); +var hasOwn = Object.prototype.hasOwnProperty; +var pSlice = Array.prototype.slice; +var functionsHaveNames = (function () { + return function foo() {}.name === 'foo'; +}()); +function pToString (obj) { + return Object.prototype.toString.call(obj); +} +function isView(arrbuf) { + if (isBuffer(arrbuf)) { + return false; + } + if (typeof global.ArrayBuffer !== 'function') { + return false; + } + if (typeof ArrayBuffer.isView === 'function') { + return ArrayBuffer.isView(arrbuf); + } + if (!arrbuf) { + return false; + } + if (arrbuf instanceof DataView) { + return true; + } + if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { + return true; + } + return false; +} +// 1. The assert module provides functions that throw +// AssertionError's when particular conditions are not met. The +// assert module must conform to the following interface. + +var assert = module.exports = ok; + +// 2. The AssertionError is defined in assert. +// new assert.AssertionError({ message: message, +// actual: actual, +// expected: expected }) + +var regex = /\s*function\s+([^\(\s]*)\s*/; +// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js +function getName(func) { + if (!util.isFunction(func)) { + return; + } + if (functionsHaveNames) { + return func.name; + } + var str = func.toString(); + var match = str.match(regex); + return match && match[1]; +} +assert.AssertionError = function AssertionError(options) { + this.name = 'AssertionError'; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + if (options.message) { + this.message = options.message; + this.generatedMessage = false; + } else { + this.message = getMessage(this); + this.generatedMessage = true; + } + var stackStartFunction = options.stackStartFunction || fail; + if (Error.captureStackTrace) { + Error.captureStackTrace(this, stackStartFunction); + } else { + // non v8 browsers so we can have a stacktrace + var err = new Error(); + if (err.stack) { + var out = err.stack; + + // try to strip useless frames + var fn_name = getName(stackStartFunction); + var idx = out.indexOf('\n' + fn_name); + if (idx >= 0) { + // once we have located the function frame + // we need to strip out everything before it (and its line) + var next_line = out.indexOf('\n', idx + 1); + out = out.substring(next_line + 1); + } + + this.stack = out; + } + } +}; + +// assert.AssertionError instanceof Error +util.inherits(assert.AssertionError, Error); + +function truncate(s, n) { + if (typeof s === 'string') { + return s.length < n ? s : s.slice(0, n); + } else { + return s; + } +} +function inspect(something) { + if (functionsHaveNames || !util.isFunction(something)) { + return util.inspect(something); + } + var rawname = getName(something); + var name = rawname ? ': ' + rawname : ''; + return '[Function' + name + ']'; +} +function getMessage(self) { + return truncate(inspect(self.actual), 128) + ' ' + + self.operator + ' ' + + truncate(inspect(self.expected), 128); +} + +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. + +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. + +function fail(actual, expected, message, operator, stackStartFunction) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator, + stackStartFunction: stackStartFunction + }); +} + +// EXTENSION! allows for well behaved errors defined elsewhere. +assert.fail = fail; + +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, !!guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. + +function ok(value, message) { + if (!value) fail(value, true, message, '==', assert.ok); +} +assert.ok = ok; + +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); + +assert.equal = function equal(actual, expected, message) { + if (actual != expected) fail(actual, expected, message, '==', assert.equal); +}; + +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); + +assert.notEqual = function notEqual(actual, expected, message) { + if (actual == expected) { + fail(actual, expected, message, '!=', assert.notEqual); + } +}; + +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); + +assert.deepEqual = function deepEqual(actual, expected, message) { + if (!_deepEqual(actual, expected, false)) { + fail(actual, expected, message, 'deepEqual', assert.deepEqual); + } +}; + +assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { + if (!_deepEqual(actual, expected, true)) { + fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); + } +}; + +function _deepEqual(actual, expected, strict, memos) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + } else if (isBuffer(actual) && isBuffer(expected)) { + return compare(actual, expected) === 0; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (util.isDate(actual) && util.isDate(expected)) { + return actual.getTime() === expected.getTime(); + + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (util.isRegExp(actual) && util.isRegExp(expected)) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + + // 7.4. Other pairs that do not both pass typeof value == 'object', + // equivalence is determined by ==. + } else if ((actual === null || typeof actual !== 'object') && + (expected === null || typeof expected !== 'object')) { + return strict ? actual === expected : actual == expected; + + // If both values are instances of typed arrays, wrap their underlying + // ArrayBuffers in a Buffer each to increase performance + // This optimization requires the arrays to have the same type as checked by + // Object.prototype.toString (aka pToString). Never perform binary + // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their + // bit patterns are not identical. + } else if (isView(actual) && isView(expected) && + pToString(actual) === pToString(expected) && + !(actual instanceof Float32Array || + actual instanceof Float64Array)) { + return compare(new Uint8Array(actual.buffer), + new Uint8Array(expected.buffer)) === 0; + + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + } else if (isBuffer(actual) !== isBuffer(expected)) { + return false; + } else { + memos = memos || {actual: [], expected: []}; + + var actualIndex = memos.actual.indexOf(actual); + if (actualIndex !== -1) { + if (actualIndex === memos.expected.indexOf(expected)) { + return true; + } + } + + memos.actual.push(actual); + memos.expected.push(expected); + + return objEquiv(actual, expected, strict, memos); + } +} + +function isArguments(object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; +} + +function objEquiv(a, b, strict, actualVisitedObjects) { + if (a === null || a === undefined || b === null || b === undefined) + return false; + // if one is a primitive, the other must be same + if (util.isPrimitive(a) || util.isPrimitive(b)) + return a === b; + if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) + return false; + var aIsArgs = isArguments(a); + var bIsArgs = isArguments(b); + if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) + return false; + if (aIsArgs) { + a = pSlice.call(a); + b = pSlice.call(b); + return _deepEqual(a, b, strict); + } + var ka = objectKeys(a); + var kb = objectKeys(b); + var key, i; + // having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length !== kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] !== kb[i]) + return false; + } + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) + return false; + } + return true; +} + +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); + +assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (_deepEqual(actual, expected, false)) { + fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); + } +}; + +assert.notDeepStrictEqual = notDeepStrictEqual; +function notDeepStrictEqual(actual, expected, message) { + if (_deepEqual(actual, expected, true)) { + fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); + } +} + + +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); + +assert.strictEqual = function strictEqual(actual, expected, message) { + if (actual !== expected) { + fail(actual, expected, message, '===', assert.strictEqual); + } +}; + +// 10. The strict non-equality assertion tests for strict inequality, as +// determined by !==. assert.notStrictEqual(actual, expected, message_opt); + +assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (actual === expected) { + fail(actual, expected, message, '!==', assert.notStrictEqual); + } +}; + +function expectedException(actual, expected) { + if (!actual || !expected) { + return false; + } + + if (Object.prototype.toString.call(expected) == '[object RegExp]') { + return expected.test(actual); + } + + try { + if (actual instanceof expected) { + return true; + } + } catch (e) { + // Ignore. The instanceof check doesn't work for arrow functions. + } + + if (Error.isPrototypeOf(expected)) { + return false; + } + + return expected.call({}, actual) === true; +} + +function _tryBlock(block) { + var error; + try { + block(); + } catch (e) { + error = e; + } + return error; +} + +function _throws(shouldThrow, block, expected, message) { + var actual; + + if (typeof block !== 'function') { + throw new TypeError('"block" argument must be a function'); + } + + if (typeof expected === 'string') { + message = expected; + expected = null; + } + + actual = _tryBlock(block); + + message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + + (message ? ' ' + message : '.'); + + if (shouldThrow && !actual) { + fail(actual, expected, 'Missing expected exception' + message); + } + + var userProvidedMessage = typeof message === 'string'; + var isUnwantedException = !shouldThrow && util.isError(actual); + var isUnexpectedException = !shouldThrow && actual && !expected; + + if ((isUnwantedException && + userProvidedMessage && + expectedException(actual, expected)) || + isUnexpectedException) { + fail(actual, expected, 'Got unwanted exception' + message); + } + + if ((shouldThrow && actual && expected && + !expectedException(actual, expected)) || (!shouldThrow && actual)) { + throw actual; + } +} + +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); + +assert.throws = function(block, /*optional*/error, /*optional*/message) { + _throws(true, block, error, message); +}; + +// EXTENSION! This is annoying to write outside this module. +assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { + _throws(false, block, error, message); +}; + +assert.ifError = function(err) { if (err) throw err; }; + +// Expose a strict only variant of assert +function strict(value, message) { + if (!value) fail(value, true, message, '==', strict); +} +assert.strict = objectAssign(strict, assert, { + equal: assert.strictEqual, + deepEqual: assert.deepStrictEqual, + notEqual: assert.notStrictEqual, + notDeepEqual: assert.notDeepStrictEqual +}); +assert.strict.strict = assert.strict; + +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + if (hasOwn.call(obj, key)) keys.push(key); + } + return keys; +}; + +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"object-assign":438,"util/":116}],114:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + +},{}],115:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} +},{}],116:[function(require,module,exports){ +(function (process,global){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; + + +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; + + +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; + + +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; + +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; + + +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} + + +function stylizeNoColor(str, styleType) { + return str; +} + + +function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; +} + + +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + + var base = '', array = false, braces = ['{', '}']; + + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + + ctx.seen.push(value); + + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + + ctx.seen.pop(); + + return reduceToSingleString(output, base, braces); +} + + +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} + + +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} + + +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} + + +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + + return name + ': ' + str; +} + + +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } + + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} + + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = require('./support/isBuffer'); + +function objectToString(o) { + return Object.prototype.toString.call(o); +} + + +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} + + +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} + + +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; + + +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = require('inherits'); + +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":115,"_process":451,"inherits":114}],117:[function(require,module,exports){ +(function (global){(function (){ +'use strict'; + +var possibleNames = require('possible-typed-array-names'); + +var g = typeof globalThis === 'undefined' ? global : globalThis; + +/** @type {import('.')} */ +module.exports = function availableTypedArrays() { + var /** @type {ReturnType} */ out = []; + for (var i = 0; i < possibleNames.length; i++) { + if (typeof g[possibleNames[i]] === 'function') { + // @ts-expect-error + out[out.length] = possibleNames[i]; + } + } + return out; +}; + +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"possible-typed-array-names":450}],118:[function(require,module,exports){ +'use strict' +// base-x encoding / decoding +// Copyright (c) 2018 base-x contributors +// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp) +// Distributed under the MIT software license, see the accompanying +// file LICENSE or http://www.opensource.org/licenses/mit-license.php. +// @ts-ignore +var _Buffer = require('safe-buffer').Buffer +function base (ALPHABET) { + if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') } + var BASE_MAP = new Uint8Array(256) + for (var j = 0; j < BASE_MAP.length; j++) { + BASE_MAP[j] = 255 + } + for (var i = 0; i < ALPHABET.length; i++) { + var x = ALPHABET.charAt(i) + var xc = x.charCodeAt(0) + if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') } + BASE_MAP[xc] = i + } + var BASE = ALPHABET.length + var LEADER = ALPHABET.charAt(0) + var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up + var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up + function encode (source) { + if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source) } + if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') } + if (source.length === 0) { return '' } + // Skip & count leading zeroes. + var zeroes = 0 + var length = 0 + var pbegin = 0 + var pend = source.length + while (pbegin !== pend && source[pbegin] === 0) { + pbegin++ + zeroes++ + } + // Allocate enough space in big-endian base58 representation. + var size = ((pend - pbegin) * iFACTOR + 1) >>> 0 + var b58 = new Uint8Array(size) + // Process the bytes. + while (pbegin !== pend) { + var carry = source[pbegin] + // Apply "b58 = b58 * 256 + ch". + var i = 0 + for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) { + carry += (256 * b58[it1]) >>> 0 + b58[it1] = (carry % BASE) >>> 0 + carry = (carry / BASE) >>> 0 + } + if (carry !== 0) { throw new Error('Non-zero carry') } + length = i + pbegin++ + } + // Skip leading zeroes in base58 result. + var it2 = size - length + while (it2 !== size && b58[it2] === 0) { + it2++ + } + // Translate the result into a string. + var str = LEADER.repeat(zeroes) + for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) } + return str + } + function decodeUnsafe (source) { + if (typeof source !== 'string') { throw new TypeError('Expected String') } + if (source.length === 0) { return _Buffer.alloc(0) } + var psz = 0 + // Skip leading spaces. + if (source[psz] === ' ') { return } + // Skip and count leading '1's. + var zeroes = 0 + var length = 0 + while (source[psz] === LEADER) { + zeroes++ + psz++ + } + // Allocate enough space in big-endian base256 representation. + var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up. + var b256 = new Uint8Array(size) + // Process the characters. + while (source[psz]) { + // Decode character + var carry = BASE_MAP[source.charCodeAt(psz)] + // Invalid character + if (carry === 255) { return } + var i = 0 + for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) { + carry += (BASE * b256[it3]) >>> 0 + b256[it3] = (carry % 256) >>> 0 + carry = (carry / 256) >>> 0 + } + if (carry !== 0) { throw new Error('Non-zero carry') } + length = i + psz++ + } + // Skip trailing spaces. + if (source[psz] === ' ') { return } + // Skip leading zeroes in b256. + var it4 = size - length + while (it4 !== size && b256[it4] === 0) { + it4++ + } + var vch = _Buffer.allocUnsafe(zeroes + (size - it4)) + vch.fill(0x00, 0, zeroes) + var j = zeroes + while (it4 !== size) { + vch[j++] = b256[it4++] + } + return vch + } + function decode (string) { + var buffer = decodeUnsafe(string) + if (buffer) { return buffer } + throw new Error('Non-base' + BASE + ' character') + } + return { + encode: encode, + decodeUnsafe: decodeUnsafe, + decode: decode + } +} +module.exports = base + +},{"safe-buffer":463}],119:[function(require,module,exports){ +'use strict' + +exports.byteLength = byteLength +exports.toByteArray = toByteArray +exports.fromByteArray = fromByteArray + +var lookup = [] +var revLookup = [] +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array + +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' +for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i] + revLookup[code.charCodeAt(i)] = i +} + +// Support decoding URL-safe base64 strings, as Node.js does. +// See: https://en.wikipedia.org/wiki/Base64#URL_applications +revLookup['-'.charCodeAt(0)] = 62 +revLookup['_'.charCodeAt(0)] = 63 + +function getLens (b64) { + var len = b64.length + + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('=') + if (validLen === -1) validLen = len + + var placeHoldersLen = validLen === len + ? 0 + : 4 - (validLen % 4) + + return [validLen, placeHoldersLen] +} + +// base64 is 4/3 + up to two characters of the original data +function byteLength (b64) { + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} + +function _byteLength (b64, validLen, placeHoldersLen) { + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen +} + +function toByteArray (b64) { + var tmp + var lens = getLens(b64) + var validLen = lens[0] + var placeHoldersLen = lens[1] + + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) + + var curByte = 0 + + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 + ? validLen - 4 + : validLen + + var i + for (i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)] + arr[curByte++] = (tmp >> 16) & 0xFF + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } + + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[curByte++] = tmp & 0xFF + } + + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[curByte++] = (tmp >> 8) & 0xFF + arr[curByte++] = tmp & 0xFF + } + + return arr +} + +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + + lookup[num >> 12 & 0x3F] + + lookup[num >> 6 & 0x3F] + + lookup[num & 0x3F] +} + +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = + ((uint8[i] << 16) & 0xFF0000) + + ((uint8[i + 1] << 8) & 0xFF00) + + (uint8[i + 2] & 0xFF) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} + +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk( + uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) + )) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + parts.push( + lookup[tmp >> 2] + + lookup[(tmp << 4) & 0x3F] + + '==' + ) + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1] + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3F] + + lookup[(tmp << 2) & 0x3F] + + '=' + ) + } + + return parts.join('') +} + +},{}],120:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.bech32m = exports.bech32 = void 0; +const ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'; +const ALPHABET_MAP = {}; +for (let z = 0; z < ALPHABET.length; z++) { + const x = ALPHABET.charAt(z); + ALPHABET_MAP[x] = z; +} +function polymodStep(pre) { + const b = pre >> 25; + return (((pre & 0x1ffffff) << 5) ^ + (-((b >> 0) & 1) & 0x3b6a57b2) ^ + (-((b >> 1) & 1) & 0x26508e6d) ^ + (-((b >> 2) & 1) & 0x1ea119fa) ^ + (-((b >> 3) & 1) & 0x3d4233dd) ^ + (-((b >> 4) & 1) & 0x2a1462b3)); +} +function prefixChk(prefix) { + let chk = 1; + for (let i = 0; i < prefix.length; ++i) { + const c = prefix.charCodeAt(i); + if (c < 33 || c > 126) + return 'Invalid prefix (' + prefix + ')'; + chk = polymodStep(chk) ^ (c >> 5); + } + chk = polymodStep(chk); + for (let i = 0; i < prefix.length; ++i) { + const v = prefix.charCodeAt(i); + chk = polymodStep(chk) ^ (v & 0x1f); + } + return chk; +} +function convert(data, inBits, outBits, pad) { + let value = 0; + let bits = 0; + const maxV = (1 << outBits) - 1; + const result = []; + for (let i = 0; i < data.length; ++i) { + value = (value << inBits) | data[i]; + bits += inBits; + while (bits >= outBits) { + bits -= outBits; + result.push((value >> bits) & maxV); + } + } + if (pad) { + if (bits > 0) { + result.push((value << (outBits - bits)) & maxV); + } + } + else { + if (bits >= inBits) + return 'Excess padding'; + if ((value << (outBits - bits)) & maxV) + return 'Non-zero padding'; + } + return result; +} +function toWords(bytes) { + return convert(bytes, 8, 5, true); +} +function fromWordsUnsafe(words) { + const res = convert(words, 5, 8, false); + if (Array.isArray(res)) + return res; +} +function fromWords(words) { + const res = convert(words, 5, 8, false); + if (Array.isArray(res)) + return res; + throw new Error(res); +} +function getLibraryFromEncoding(encoding) { + let ENCODING_CONST; + if (encoding === 'bech32') { + ENCODING_CONST = 1; + } + else { + ENCODING_CONST = 0x2bc830a3; + } + function encode(prefix, words, LIMIT) { + LIMIT = LIMIT || 90; + if (prefix.length + 7 + words.length > LIMIT) + throw new TypeError('Exceeds length limit'); + prefix = prefix.toLowerCase(); + // determine chk mod + let chk = prefixChk(prefix); + if (typeof chk === 'string') + throw new Error(chk); + let result = prefix + '1'; + for (let i = 0; i < words.length; ++i) { + const x = words[i]; + if (x >> 5 !== 0) + throw new Error('Non 5-bit word'); + chk = polymodStep(chk) ^ x; + result += ALPHABET.charAt(x); + } + for (let i = 0; i < 6; ++i) { + chk = polymodStep(chk); + } + chk ^= ENCODING_CONST; + for (let i = 0; i < 6; ++i) { + const v = (chk >> ((5 - i) * 5)) & 0x1f; + result += ALPHABET.charAt(v); + } + return result; + } + function __decode(str, LIMIT) { + LIMIT = LIMIT || 90; + if (str.length < 8) + return str + ' too short'; + if (str.length > LIMIT) + return 'Exceeds length limit'; + // don't allow mixed case + const lowered = str.toLowerCase(); + const uppered = str.toUpperCase(); + if (str !== lowered && str !== uppered) + return 'Mixed-case string ' + str; + str = lowered; + const split = str.lastIndexOf('1'); + if (split === -1) + return 'No separator character for ' + str; + if (split === 0) + return 'Missing prefix for ' + str; + const prefix = str.slice(0, split); + const wordChars = str.slice(split + 1); + if (wordChars.length < 6) + return 'Data too short'; + let chk = prefixChk(prefix); + if (typeof chk === 'string') + return chk; + const words = []; + for (let i = 0; i < wordChars.length; ++i) { + const c = wordChars.charAt(i); + const v = ALPHABET_MAP[c]; + if (v === undefined) + return 'Unknown character ' + c; + chk = polymodStep(chk) ^ v; + // not in the checksum? + if (i + 6 >= wordChars.length) + continue; + words.push(v); + } + if (chk !== ENCODING_CONST) + return 'Invalid checksum for ' + str; + return { prefix, words }; + } + function decodeUnsafe(str, LIMIT) { + const res = __decode(str, LIMIT); + if (typeof res === 'object') + return res; + } + function decode(str, LIMIT) { + const res = __decode(str, LIMIT); + if (typeof res === 'object') + return res; + throw new Error(res); + } + return { + decodeUnsafe, + decode, + encode, + toWords, + fromWordsUnsafe, + fromWords, + }; +} +exports.bech32 = getLibraryFromEncoding('bech32'); +exports.bech32m = getLibraryFromEncoding('bech32m'); + +},{}],121:[function(require,module,exports){ +// (public) Constructor +function BigInteger(a, b, c) { + if (!(this instanceof BigInteger)) + return new BigInteger(a, b, c) + + if (a != null) { + if ("number" == typeof a) this.fromNumber(a, b, c) + else if (b == null && "string" != typeof a) this.fromString(a, 256) + else this.fromString(a, b) + } +} + +var proto = BigInteger.prototype + +// duck-typed isBigInteger +proto.__bigi = require('../package.json').version +BigInteger.isBigInteger = function (obj, check_ver) { + return obj && obj.__bigi && (!check_ver || obj.__bigi === proto.__bigi) +} + +// Bits per digit +var dbits + +// am: Compute w_j += (x*this_i), propagate carries, +// c is initial carry, returns final carry. +// c < 3*dvalue, x < 2*dvalue, this_i < dvalue +// We need to select the fastest one that works in this environment. + +// am1: use a single mult and divide to get the high bits, +// max digit bits should be 26 because +// max internal value = 2*dvalue^2-2*dvalue (< 2^53) +function am1(i, x, w, j, c, n) { + while (--n >= 0) { + var v = x * this[i++] + w[j] + c + c = Math.floor(v / 0x4000000) + w[j++] = v & 0x3ffffff + } + return c +} +// am2 avoids a big mult-and-extract completely. +// Max digit bits should be <= 30 because we do bitwise ops +// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) +function am2(i, x, w, j, c, n) { + var xl = x & 0x7fff, + xh = x >> 15 + while (--n >= 0) { + var l = this[i] & 0x7fff + var h = this[i++] >> 15 + var m = xh * l + h * xl + l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff) + c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30) + w[j++] = l & 0x3fffffff + } + return c +} +// Alternately, set max digit bits to 28 since some +// browsers slow down when dealing with 32-bit numbers. +function am3(i, x, w, j, c, n) { + var xl = x & 0x3fff, + xh = x >> 14 + while (--n >= 0) { + var l = this[i] & 0x3fff + var h = this[i++] >> 14 + var m = xh * l + h * xl + l = xl * l + ((m & 0x3fff) << 14) + w[j] + c + c = (l >> 28) + (m >> 14) + xh * h + w[j++] = l & 0xfffffff + } + return c +} + +// wtf? +BigInteger.prototype.am = am1 +dbits = 26 + +BigInteger.prototype.DB = dbits +BigInteger.prototype.DM = ((1 << dbits) - 1) +var DV = BigInteger.prototype.DV = (1 << dbits) + +var BI_FP = 52 +BigInteger.prototype.FV = Math.pow(2, BI_FP) +BigInteger.prototype.F1 = BI_FP - dbits +BigInteger.prototype.F2 = 2 * dbits - BI_FP + +// Digit conversions +var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz" +var BI_RC = new Array() +var rr, vv +rr = "0".charCodeAt(0) +for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv +rr = "a".charCodeAt(0) +for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv +rr = "A".charCodeAt(0) +for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv + +function int2char(n) { + return BI_RM.charAt(n) +} + +function intAt(s, i) { + var c = BI_RC[s.charCodeAt(i)] + return (c == null) ? -1 : c +} + +// (protected) copy this to r +function bnpCopyTo(r) { + for (var i = this.t - 1; i >= 0; --i) r[i] = this[i] + r.t = this.t + r.s = this.s +} + +// (protected) set from integer value x, -DV <= x < DV +function bnpFromInt(x) { + this.t = 1 + this.s = (x < 0) ? -1 : 0 + if (x > 0) this[0] = x + else if (x < -1) this[0] = x + DV + else this.t = 0 +} + +// return bigint initialized to value +function nbv(i) { + var r = new BigInteger() + r.fromInt(i) + return r +} + +// (protected) set from string and radix +function bnpFromString(s, b) { + var self = this + + var k + if (b == 16) k = 4 + else if (b == 8) k = 3 + else if (b == 256) k = 8; // byte array + else if (b == 2) k = 1 + else if (b == 32) k = 5 + else if (b == 4) k = 2 + else { + self.fromRadix(s, b) + return + } + self.t = 0 + self.s = 0 + var i = s.length, + mi = false, + sh = 0 + while (--i >= 0) { + var x = (k == 8) ? s[i] & 0xff : intAt(s, i) + if (x < 0) { + if (s.charAt(i) == "-") mi = true + continue + } + mi = false + if (sh == 0) + self[self.t++] = x + else if (sh + k > self.DB) { + self[self.t - 1] |= (x & ((1 << (self.DB - sh)) - 1)) << sh + self[self.t++] = (x >> (self.DB - sh)) + } else + self[self.t - 1] |= x << sh + sh += k + if (sh >= self.DB) sh -= self.DB + } + if (k == 8 && (s[0] & 0x80) != 0) { + self.s = -1 + if (sh > 0) self[self.t - 1] |= ((1 << (self.DB - sh)) - 1) << sh + } + self.clamp() + if (mi) BigInteger.ZERO.subTo(self, self) +} + +// (protected) clamp off excess high words +function bnpClamp() { + var c = this.s & this.DM + while (this.t > 0 && this[this.t - 1] == c)--this.t +} + +// (public) return string representation in given radix +function bnToString(b) { + var self = this + if (self.s < 0) return "-" + self.negate() + .toString(b) + var k + if (b == 16) k = 4 + else if (b == 8) k = 3 + else if (b == 2) k = 1 + else if (b == 32) k = 5 + else if (b == 4) k = 2 + else return self.toRadix(b) + var km = (1 << k) - 1, + d, m = false, + r = "", + i = self.t + var p = self.DB - (i * self.DB) % k + if (i-- > 0) { + if (p < self.DB && (d = self[i] >> p) > 0) { + m = true + r = int2char(d) + } + while (i >= 0) { + if (p < k) { + d = (self[i] & ((1 << p) - 1)) << (k - p) + d |= self[--i] >> (p += self.DB - k) + } else { + d = (self[i] >> (p -= k)) & km + if (p <= 0) { + p += self.DB + --i + } + } + if (d > 0) m = true + if (m) r += int2char(d) + } + } + return m ? r : "0" +} + +// (public) -this +function bnNegate() { + var r = new BigInteger() + BigInteger.ZERO.subTo(this, r) + return r +} + +// (public) |this| +function bnAbs() { + return (this.s < 0) ? this.negate() : this +} + +// (public) return + if this > a, - if this < a, 0 if equal +function bnCompareTo(a) { + var r = this.s - a.s + if (r != 0) return r + var i = this.t + r = i - a.t + if (r != 0) return (this.s < 0) ? -r : r + while (--i >= 0) + if ((r = this[i] - a[i]) != 0) return r + return 0 +} + +// returns bit length of the integer x +function nbits(x) { + var r = 1, + t + if ((t = x >>> 16) != 0) { + x = t + r += 16 + } + if ((t = x >> 8) != 0) { + x = t + r += 8 + } + if ((t = x >> 4) != 0) { + x = t + r += 4 + } + if ((t = x >> 2) != 0) { + x = t + r += 2 + } + if ((t = x >> 1) != 0) { + x = t + r += 1 + } + return r +} + +// (public) return the number of bits in "this" +function bnBitLength() { + if (this.t <= 0) return 0 + return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM)) +} + +// (public) return the number of bytes in "this" +function bnByteLength() { + return this.bitLength() >> 3 +} + +// (protected) r = this << n*DB +function bnpDLShiftTo(n, r) { + var i + for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i] + for (i = n - 1; i >= 0; --i) r[i] = 0 + r.t = this.t + n + r.s = this.s +} + +// (protected) r = this >> n*DB +function bnpDRShiftTo(n, r) { + for (var i = n; i < this.t; ++i) r[i - n] = this[i] + r.t = Math.max(this.t - n, 0) + r.s = this.s +} + +// (protected) r = this << n +function bnpLShiftTo(n, r) { + var self = this + var bs = n % self.DB + var cbs = self.DB - bs + var bm = (1 << cbs) - 1 + var ds = Math.floor(n / self.DB), + c = (self.s << bs) & self.DM, + i + for (i = self.t - 1; i >= 0; --i) { + r[i + ds + 1] = (self[i] >> cbs) | c + c = (self[i] & bm) << bs + } + for (i = ds - 1; i >= 0; --i) r[i] = 0 + r[ds] = c + r.t = self.t + ds + 1 + r.s = self.s + r.clamp() +} + +// (protected) r = this >> n +function bnpRShiftTo(n, r) { + var self = this + r.s = self.s + var ds = Math.floor(n / self.DB) + if (ds >= self.t) { + r.t = 0 + return + } + var bs = n % self.DB + var cbs = self.DB - bs + var bm = (1 << bs) - 1 + r[0] = self[ds] >> bs + for (var i = ds + 1; i < self.t; ++i) { + r[i - ds - 1] |= (self[i] & bm) << cbs + r[i - ds] = self[i] >> bs + } + if (bs > 0) r[self.t - ds - 1] |= (self.s & bm) << cbs + r.t = self.t - ds + r.clamp() +} + +// (protected) r = this - a +function bnpSubTo(a, r) { + var self = this + var i = 0, + c = 0, + m = Math.min(a.t, self.t) + while (i < m) { + c += self[i] - a[i] + r[i++] = c & self.DM + c >>= self.DB + } + if (a.t < self.t) { + c -= a.s + while (i < self.t) { + c += self[i] + r[i++] = c & self.DM + c >>= self.DB + } + c += self.s + } else { + c += self.s + while (i < a.t) { + c -= a[i] + r[i++] = c & self.DM + c >>= self.DB + } + c -= a.s + } + r.s = (c < 0) ? -1 : 0 + if (c < -1) r[i++] = self.DV + c + else if (c > 0) r[i++] = c + r.t = i + r.clamp() +} + +// (protected) r = this * a, r != this,a (HAC 14.12) +// "this" should be the larger one if appropriate. +function bnpMultiplyTo(a, r) { + var x = this.abs(), + y = a.abs() + var i = x.t + r.t = i + y.t + while (--i >= 0) r[i] = 0 + for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t) + r.s = 0 + r.clamp() + if (this.s != a.s) BigInteger.ZERO.subTo(r, r) +} + +// (protected) r = this^2, r != this (HAC 14.16) +function bnpSquareTo(r) { + var x = this.abs() + var i = r.t = 2 * x.t + while (--i >= 0) r[i] = 0 + for (i = 0; i < x.t - 1; ++i) { + var c = x.am(i, x[i], r, 2 * i, 0, 1) + if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { + r[i + x.t] -= x.DV + r[i + x.t + 1] = 1 + } + } + if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1) + r.s = 0 + r.clamp() +} + +// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) +// r != q, this != m. q or r may be null. +function bnpDivRemTo(m, q, r) { + var self = this + var pm = m.abs() + if (pm.t <= 0) return + var pt = self.abs() + if (pt.t < pm.t) { + if (q != null) q.fromInt(0) + if (r != null) self.copyTo(r) + return + } + if (r == null) r = new BigInteger() + var y = new BigInteger(), + ts = self.s, + ms = m.s + var nsh = self.DB - nbits(pm[pm.t - 1]); // normalize modulus + if (nsh > 0) { + pm.lShiftTo(nsh, y) + pt.lShiftTo(nsh, r) + } else { + pm.copyTo(y) + pt.copyTo(r) + } + var ys = y.t + var y0 = y[ys - 1] + if (y0 == 0) return + var yt = y0 * (1 << self.F1) + ((ys > 1) ? y[ys - 2] >> self.F2 : 0) + var d1 = self.FV / yt, + d2 = (1 << self.F1) / yt, + e = 1 << self.F2 + var i = r.t, + j = i - ys, + t = (q == null) ? new BigInteger() : q + y.dlShiftTo(j, t) + if (r.compareTo(t) >= 0) { + r[r.t++] = 1 + r.subTo(t, r) + } + BigInteger.ONE.dlShiftTo(ys, t) + t.subTo(y, y); // "negative" y so we can replace sub with am later + while (y.t < ys) y[y.t++] = 0 + while (--j >= 0) { + // Estimate quotient digit + var qd = (r[--i] == y0) ? self.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2) + if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out + y.dlShiftTo(j, t) + r.subTo(t, r) + while (r[i] < --qd) r.subTo(t, r) + } + } + if (q != null) { + r.drShiftTo(ys, q) + if (ts != ms) BigInteger.ZERO.subTo(q, q) + } + r.t = ys + r.clamp() + if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder + if (ts < 0) BigInteger.ZERO.subTo(r, r) +} + +// (public) this mod a +function bnMod(a) { + var r = new BigInteger() + this.abs() + .divRemTo(a, null, r) + if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r) + return r +} + +// Modular reduction using "classic" algorithm +function Classic(m) { + this.m = m +} + +function cConvert(x) { + if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m) + else return x +} + +function cRevert(x) { + return x +} + +function cReduce(x) { + x.divRemTo(this.m, null, x) +} + +function cMulTo(x, y, r) { + x.multiplyTo(y, r) + this.reduce(r) +} + +function cSqrTo(x, r) { + x.squareTo(r) + this.reduce(r) +} + +Classic.prototype.convert = cConvert +Classic.prototype.revert = cRevert +Classic.prototype.reduce = cReduce +Classic.prototype.mulTo = cMulTo +Classic.prototype.sqrTo = cSqrTo + +// (protected) return "-1/this % 2^DB"; useful for Mont. reduction +// justification: +// xy == 1 (mod m) +// xy = 1+km +// xy(2-xy) = (1+km)(1-km) +// x[y(2-xy)] = 1-k^2m^2 +// x[y(2-xy)] == 1 (mod m^2) +// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 +// should reduce x and y(2-xy) by m^2 at each step to keep size bounded. +// JS multiply "overflows" differently from C/C++, so care is needed here. +function bnpInvDigit() { + if (this.t < 1) return 0 + var x = this[0] + if ((x & 1) == 0) return 0 + var y = x & 3; // y == 1/x mod 2^2 + y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 + y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 + y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16 + // last step - calculate inverse mod DV directly + // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints + y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits + // we really want the negative inverse, and -DV < y < DV + return (y > 0) ? this.DV - y : -y +} + +// Montgomery reduction +function Montgomery(m) { + this.m = m + this.mp = m.invDigit() + this.mpl = this.mp & 0x7fff + this.mph = this.mp >> 15 + this.um = (1 << (m.DB - 15)) - 1 + this.mt2 = 2 * m.t +} + +// xR mod m +function montConvert(x) { + var r = new BigInteger() + x.abs() + .dlShiftTo(this.m.t, r) + r.divRemTo(this.m, null, r) + if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r) + return r +} + +// x/R mod m +function montRevert(x) { + var r = new BigInteger() + x.copyTo(r) + this.reduce(r) + return r +} + +// x = x/R mod m (HAC 14.32) +function montReduce(x) { + while (x.t <= this.mt2) // pad x so am has enough room later + x[x.t++] = 0 + for (var i = 0; i < this.m.t; ++i) { + // faster way of calculating u0 = x[i]*mp mod DV + var j = x[i] & 0x7fff + var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM + // use am to combine the multiply-shift-add into one call + j = i + this.m.t + x[j] += this.m.am(0, u0, x, i, 0, this.m.t) + // propagate carry + while (x[j] >= x.DV) { + x[j] -= x.DV + x[++j]++ + } + } + x.clamp() + x.drShiftTo(this.m.t, x) + if (x.compareTo(this.m) >= 0) x.subTo(this.m, x) +} + +// r = "x^2/R mod m"; x != r +function montSqrTo(x, r) { + x.squareTo(r) + this.reduce(r) +} + +// r = "xy/R mod m"; x,y != r +function montMulTo(x, y, r) { + x.multiplyTo(y, r) + this.reduce(r) +} + +Montgomery.prototype.convert = montConvert +Montgomery.prototype.revert = montRevert +Montgomery.prototype.reduce = montReduce +Montgomery.prototype.mulTo = montMulTo +Montgomery.prototype.sqrTo = montSqrTo + +// (protected) true iff this is even +function bnpIsEven() { + return ((this.t > 0) ? (this[0] & 1) : this.s) == 0 +} + +// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) +function bnpExp(e, z) { + if (e > 0xffffffff || e < 1) return BigInteger.ONE + var r = new BigInteger(), + r2 = new BigInteger(), + g = z.convert(this), + i = nbits(e) - 1 + g.copyTo(r) + while (--i >= 0) { + z.sqrTo(r, r2) + if ((e & (1 << i)) > 0) z.mulTo(r2, g, r) + else { + var t = r + r = r2 + r2 = t + } + } + return z.revert(r) +} + +// (public) this^e % m, 0 <= e < 2^32 +function bnModPowInt(e, m) { + var z + if (e < 256 || m.isEven()) z = new Classic(m) + else z = new Montgomery(m) + return this.exp(e, z) +} + +// protected +proto.copyTo = bnpCopyTo +proto.fromInt = bnpFromInt +proto.fromString = bnpFromString +proto.clamp = bnpClamp +proto.dlShiftTo = bnpDLShiftTo +proto.drShiftTo = bnpDRShiftTo +proto.lShiftTo = bnpLShiftTo +proto.rShiftTo = bnpRShiftTo +proto.subTo = bnpSubTo +proto.multiplyTo = bnpMultiplyTo +proto.squareTo = bnpSquareTo +proto.divRemTo = bnpDivRemTo +proto.invDigit = bnpInvDigit +proto.isEven = bnpIsEven +proto.exp = bnpExp + +// public +proto.toString = bnToString +proto.negate = bnNegate +proto.abs = bnAbs +proto.compareTo = bnCompareTo +proto.bitLength = bnBitLength +proto.byteLength = bnByteLength +proto.mod = bnMod +proto.modPowInt = bnModPowInt + +// (public) +function bnClone() { + var r = new BigInteger() + this.copyTo(r) + return r +} + +// (public) return value as integer +function bnIntValue() { + if (this.s < 0) { + if (this.t == 1) return this[0] - this.DV + else if (this.t == 0) return -1 + } else if (this.t == 1) return this[0] + else if (this.t == 0) return 0 + // assumes 16 < DB < 32 + return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0] +} + +// (public) return value as byte +function bnByteValue() { + return (this.t == 0) ? this.s : (this[0] << 24) >> 24 +} + +// (public) return value as short (assumes DB>=16) +function bnShortValue() { + return (this.t == 0) ? this.s : (this[0] << 16) >> 16 +} + +// (protected) return x s.t. r^x < DV +function bnpChunkSize(r) { + return Math.floor(Math.LN2 * this.DB / Math.log(r)) +} + +// (public) 0 if this == 0, 1 if this > 0 +function bnSigNum() { + if (this.s < 0) return -1 + else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0 + else return 1 +} + +// (protected) convert to radix string +function bnpToRadix(b) { + if (b == null) b = 10 + if (this.signum() == 0 || b < 2 || b > 36) return "0" + var cs = this.chunkSize(b) + var a = Math.pow(b, cs) + var d = nbv(a), + y = new BigInteger(), + z = new BigInteger(), + r = "" + this.divRemTo(d, y, z) + while (y.signum() > 0) { + r = (a + z.intValue()) + .toString(b) + .substr(1) + r + y.divRemTo(d, y, z) + } + return z.intValue() + .toString(b) + r +} + +// (protected) convert from radix string +function bnpFromRadix(s, b) { + var self = this + self.fromInt(0) + if (b == null) b = 10 + var cs = self.chunkSize(b) + var d = Math.pow(b, cs), + mi = false, + j = 0, + w = 0 + for (var i = 0; i < s.length; ++i) { + var x = intAt(s, i) + if (x < 0) { + if (s.charAt(i) == "-" && self.signum() == 0) mi = true + continue + } + w = b * w + x + if (++j >= cs) { + self.dMultiply(d) + self.dAddOffset(w, 0) + j = 0 + w = 0 + } + } + if (j > 0) { + self.dMultiply(Math.pow(b, j)) + self.dAddOffset(w, 0) + } + if (mi) BigInteger.ZERO.subTo(self, self) +} + +// (protected) alternate constructor +function bnpFromNumber(a, b, c) { + var self = this + if ("number" == typeof b) { + // new BigInteger(int,int,RNG) + if (a < 2) self.fromInt(1) + else { + self.fromNumber(a, c) + if (!self.testBit(a - 1)) // force MSB set + self.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, self) + if (self.isEven()) self.dAddOffset(1, 0); // force odd + while (!self.isProbablePrime(b)) { + self.dAddOffset(2, 0) + if (self.bitLength() > a) self.subTo(BigInteger.ONE.shiftLeft(a - 1), self) + } + } + } else { + // new BigInteger(int,RNG) + var x = new Array(), + t = a & 7 + x.length = (a >> 3) + 1 + b.nextBytes(x) + if (t > 0) x[0] &= ((1 << t) - 1) + else x[0] = 0 + self.fromString(x, 256) + } +} + +// (public) convert to bigendian byte array +function bnToByteArray() { + var self = this + var i = self.t, + r = new Array() + r[0] = self.s + var p = self.DB - (i * self.DB) % 8, + d, k = 0 + if (i-- > 0) { + if (p < self.DB && (d = self[i] >> p) != (self.s & self.DM) >> p) + r[k++] = d | (self.s << (self.DB - p)) + while (i >= 0) { + if (p < 8) { + d = (self[i] & ((1 << p) - 1)) << (8 - p) + d |= self[--i] >> (p += self.DB - 8) + } else { + d = (self[i] >> (p -= 8)) & 0xff + if (p <= 0) { + p += self.DB + --i + } + } + if ((d & 0x80) != 0) d |= -256 + if (k === 0 && (self.s & 0x80) != (d & 0x80))++k + if (k > 0 || d != self.s) r[k++] = d + } + } + return r +} + +function bnEquals(a) { + return (this.compareTo(a) == 0) +} + +function bnMin(a) { + return (this.compareTo(a) < 0) ? this : a +} + +function bnMax(a) { + return (this.compareTo(a) > 0) ? this : a +} + +// (protected) r = this op a (bitwise) +function bnpBitwiseTo(a, op, r) { + var self = this + var i, f, m = Math.min(a.t, self.t) + for (i = 0; i < m; ++i) r[i] = op(self[i], a[i]) + if (a.t < self.t) { + f = a.s & self.DM + for (i = m; i < self.t; ++i) r[i] = op(self[i], f) + r.t = self.t + } else { + f = self.s & self.DM + for (i = m; i < a.t; ++i) r[i] = op(f, a[i]) + r.t = a.t + } + r.s = op(self.s, a.s) + r.clamp() +} + +// (public) this & a +function op_and(x, y) { + return x & y +} + +function bnAnd(a) { + var r = new BigInteger() + this.bitwiseTo(a, op_and, r) + return r +} + +// (public) this | a +function op_or(x, y) { + return x | y +} + +function bnOr(a) { + var r = new BigInteger() + this.bitwiseTo(a, op_or, r) + return r +} + +// (public) this ^ a +function op_xor(x, y) { + return x ^ y +} + +function bnXor(a) { + var r = new BigInteger() + this.bitwiseTo(a, op_xor, r) + return r +} + +// (public) this & ~a +function op_andnot(x, y) { + return x & ~y +} + +function bnAndNot(a) { + var r = new BigInteger() + this.bitwiseTo(a, op_andnot, r) + return r +} + +// (public) ~this +function bnNot() { + var r = new BigInteger() + for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i] + r.t = this.t + r.s = ~this.s + return r +} + +// (public) this << n +function bnShiftLeft(n) { + var r = new BigInteger() + if (n < 0) this.rShiftTo(-n, r) + else this.lShiftTo(n, r) + return r +} + +// (public) this >> n +function bnShiftRight(n) { + var r = new BigInteger() + if (n < 0) this.lShiftTo(-n, r) + else this.rShiftTo(n, r) + return r +} + +// return index of lowest 1-bit in x, x < 2^31 +function lbit(x) { + if (x == 0) return -1 + var r = 0 + if ((x & 0xffff) == 0) { + x >>= 16 + r += 16 + } + if ((x & 0xff) == 0) { + x >>= 8 + r += 8 + } + if ((x & 0xf) == 0) { + x >>= 4 + r += 4 + } + if ((x & 3) == 0) { + x >>= 2 + r += 2 + } + if ((x & 1) == 0)++r + return r +} + +// (public) returns index of lowest 1-bit (or -1 if none) +function bnGetLowestSetBit() { + for (var i = 0; i < this.t; ++i) + if (this[i] != 0) return i * this.DB + lbit(this[i]) + if (this.s < 0) return this.t * this.DB + return -1 +} + +// return number of 1 bits in x +function cbit(x) { + var r = 0 + while (x != 0) { + x &= x - 1 + ++r + } + return r +} + +// (public) return number of set bits +function bnBitCount() { + var r = 0, + x = this.s & this.DM + for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x) + return r +} + +// (public) true iff nth bit is set +function bnTestBit(n) { + var j = Math.floor(n / this.DB) + if (j >= this.t) return (this.s != 0) + return ((this[j] & (1 << (n % this.DB))) != 0) +} + +// (protected) this op (1<>= self.DB + } + if (a.t < self.t) { + c += a.s + while (i < self.t) { + c += self[i] + r[i++] = c & self.DM + c >>= self.DB + } + c += self.s + } else { + c += self.s + while (i < a.t) { + c += a[i] + r[i++] = c & self.DM + c >>= self.DB + } + c += a.s + } + r.s = (c < 0) ? -1 : 0 + if (c > 0) r[i++] = c + else if (c < -1) r[i++] = self.DV + c + r.t = i + r.clamp() +} + +// (public) this + a +function bnAdd(a) { + var r = new BigInteger() + this.addTo(a, r) + return r +} + +// (public) this - a +function bnSubtract(a) { + var r = new BigInteger() + this.subTo(a, r) + return r +} + +// (public) this * a +function bnMultiply(a) { + var r = new BigInteger() + this.multiplyTo(a, r) + return r +} + +// (public) this^2 +function bnSquare() { + var r = new BigInteger() + this.squareTo(r) + return r +} + +// (public) this / a +function bnDivide(a) { + var r = new BigInteger() + this.divRemTo(a, r, null) + return r +} + +// (public) this % a +function bnRemainder(a) { + var r = new BigInteger() + this.divRemTo(a, null, r) + return r +} + +// (public) [this/a,this%a] +function bnDivideAndRemainder(a) { + var q = new BigInteger(), + r = new BigInteger() + this.divRemTo(a, q, r) + return new Array(q, r) +} + +// (protected) this *= n, this >= 0, 1 < n < DV +function bnpDMultiply(n) { + this[this.t] = this.am(0, n - 1, this, 0, 0, this.t) + ++this.t + this.clamp() +} + +// (protected) this += n << w words, this >= 0 +function bnpDAddOffset(n, w) { + if (n == 0) return + while (this.t <= w) this[this.t++] = 0 + this[w] += n + while (this[w] >= this.DV) { + this[w] -= this.DV + if (++w >= this.t) this[this.t++] = 0 + ++this[w] + } +} + +// A "null" reducer +function NullExp() {} + +function nNop(x) { + return x +} + +function nMulTo(x, y, r) { + x.multiplyTo(y, r) +} + +function nSqrTo(x, r) { + x.squareTo(r) +} + +NullExp.prototype.convert = nNop +NullExp.prototype.revert = nNop +NullExp.prototype.mulTo = nMulTo +NullExp.prototype.sqrTo = nSqrTo + +// (public) this^e +function bnPow(e) { + return this.exp(e, new NullExp()) +} + +// (protected) r = lower n words of "this * a", a.t <= n +// "this" should be the larger one if appropriate. +function bnpMultiplyLowerTo(a, n, r) { + var i = Math.min(this.t + a.t, n) + r.s = 0; // assumes a,this >= 0 + r.t = i + while (i > 0) r[--i] = 0 + var j + for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t) + for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i) + r.clamp() +} + +// (protected) r = "this * a" without lower n words, n > 0 +// "this" should be the larger one if appropriate. +function bnpMultiplyUpperTo(a, n, r) { + --n + var i = r.t = this.t + a.t - n + r.s = 0; // assumes a,this >= 0 + while (--i >= 0) r[i] = 0 + for (i = Math.max(n - this.t, 0); i < a.t; ++i) + r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n) + r.clamp() + r.drShiftTo(1, r) +} + +// Barrett modular reduction +function Barrett(m) { + // setup Barrett + this.r2 = new BigInteger() + this.q3 = new BigInteger() + BigInteger.ONE.dlShiftTo(2 * m.t, this.r2) + this.mu = this.r2.divide(m) + this.m = m +} + +function barrettConvert(x) { + if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m) + else if (x.compareTo(this.m) < 0) return x + else { + var r = new BigInteger() + x.copyTo(r) + this.reduce(r) + return r + } +} + +function barrettRevert(x) { + return x +} + +// x = x mod m (HAC 14.42) +function barrettReduce(x) { + var self = this + x.drShiftTo(self.m.t - 1, self.r2) + if (x.t > self.m.t + 1) { + x.t = self.m.t + 1 + x.clamp() + } + self.mu.multiplyUpperTo(self.r2, self.m.t + 1, self.q3) + self.m.multiplyLowerTo(self.q3, self.m.t + 1, self.r2) + while (x.compareTo(self.r2) < 0) x.dAddOffset(1, self.m.t + 1) + x.subTo(self.r2, x) + while (x.compareTo(self.m) >= 0) x.subTo(self.m, x) +} + +// r = x^2 mod m; x != r +function barrettSqrTo(x, r) { + x.squareTo(r) + this.reduce(r) +} + +// r = x*y mod m; x,y != r +function barrettMulTo(x, y, r) { + x.multiplyTo(y, r) + this.reduce(r) +} + +Barrett.prototype.convert = barrettConvert +Barrett.prototype.revert = barrettRevert +Barrett.prototype.reduce = barrettReduce +Barrett.prototype.mulTo = barrettMulTo +Barrett.prototype.sqrTo = barrettSqrTo + +// (public) this^e % m (HAC 14.85) +function bnModPow(e, m) { + var i = e.bitLength(), + k, r = nbv(1), + z + if (i <= 0) return r + else if (i < 18) k = 1 + else if (i < 48) k = 3 + else if (i < 144) k = 4 + else if (i < 768) k = 5 + else k = 6 + if (i < 8) + z = new Classic(m) + else if (m.isEven()) + z = new Barrett(m) + else + z = new Montgomery(m) + + // precomputation + var g = new Array(), + n = 3, + k1 = k - 1, + km = (1 << k) - 1 + g[1] = z.convert(this) + if (k > 1) { + var g2 = new BigInteger() + z.sqrTo(g[1], g2) + while (n <= km) { + g[n] = new BigInteger() + z.mulTo(g2, g[n - 2], g[n]) + n += 2 + } + } + + var j = e.t - 1, + w, is1 = true, + r2 = new BigInteger(), + t + i = nbits(e[j]) - 1 + while (j >= 0) { + if (i >= k1) w = (e[j] >> (i - k1)) & km + else { + w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i) + if (j > 0) w |= e[j - 1] >> (this.DB + i - k1) + } + + n = k + while ((w & 1) == 0) { + w >>= 1 + --n + } + if ((i -= n) < 0) { + i += this.DB + --j + } + if (is1) { // ret == 1, don't bother squaring or multiplying it + g[w].copyTo(r) + is1 = false + } else { + while (n > 1) { + z.sqrTo(r, r2) + z.sqrTo(r2, r) + n -= 2 + } + if (n > 0) z.sqrTo(r, r2) + else { + t = r + r = r2 + r2 = t + } + z.mulTo(r2, g[w], r) + } + + while (j >= 0 && (e[j] & (1 << i)) == 0) { + z.sqrTo(r, r2) + t = r + r = r2 + r2 = t + if (--i < 0) { + i = this.DB - 1 + --j + } + } + } + return z.revert(r) +} + +// (public) gcd(this,a) (HAC 14.54) +function bnGCD(a) { + var x = (this.s < 0) ? this.negate() : this.clone() + var y = (a.s < 0) ? a.negate() : a.clone() + if (x.compareTo(y) < 0) { + var t = x + x = y + y = t + } + var i = x.getLowestSetBit(), + g = y.getLowestSetBit() + if (g < 0) return x + if (i < g) g = i + if (g > 0) { + x.rShiftTo(g, x) + y.rShiftTo(g, y) + } + while (x.signum() > 0) { + if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x) + if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y) + if (x.compareTo(y) >= 0) { + x.subTo(y, x) + x.rShiftTo(1, x) + } else { + y.subTo(x, y) + y.rShiftTo(1, y) + } + } + if (g > 0) y.lShiftTo(g, y) + return y +} + +// (protected) this % n, n < 2^26 +function bnpModInt(n) { + if (n <= 0) return 0 + var d = this.DV % n, + r = (this.s < 0) ? n - 1 : 0 + if (this.t > 0) + if (d == 0) r = this[0] % n + else + for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n + return r +} + +// (public) 1/this % m (HAC 14.61) +function bnModInverse(m) { + var ac = m.isEven() + if (this.signum() === 0) throw new Error('division by zero') + if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO + var u = m.clone(), + v = this.clone() + var a = nbv(1), + b = nbv(0), + c = nbv(0), + d = nbv(1) + while (u.signum() != 0) { + while (u.isEven()) { + u.rShiftTo(1, u) + if (ac) { + if (!a.isEven() || !b.isEven()) { + a.addTo(this, a) + b.subTo(m, b) + } + a.rShiftTo(1, a) + } else if (!b.isEven()) b.subTo(m, b) + b.rShiftTo(1, b) + } + while (v.isEven()) { + v.rShiftTo(1, v) + if (ac) { + if (!c.isEven() || !d.isEven()) { + c.addTo(this, c) + d.subTo(m, d) + } + c.rShiftTo(1, c) + } else if (!d.isEven()) d.subTo(m, d) + d.rShiftTo(1, d) + } + if (u.compareTo(v) >= 0) { + u.subTo(v, u) + if (ac) a.subTo(c, a) + b.subTo(d, b) + } else { + v.subTo(u, v) + if (ac) c.subTo(a, c) + d.subTo(b, d) + } + } + if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO + while (d.compareTo(m) >= 0) d.subTo(m, d) + while (d.signum() < 0) d.addTo(m, d) + return d +} + +var lowprimes = [ + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, + 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, + 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, + 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, + 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, + 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, + 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, + 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, + 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, + 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, + 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 +] + +var lplim = (1 << 26) / lowprimes[lowprimes.length - 1] + +// (public) test primality with certainty >= 1-.5^t +function bnIsProbablePrime(t) { + var i, x = this.abs() + if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) { + for (i = 0; i < lowprimes.length; ++i) + if (x[0] == lowprimes[i]) return true + return false + } + if (x.isEven()) return false + i = 1 + while (i < lowprimes.length) { + var m = lowprimes[i], + j = i + 1 + while (j < lowprimes.length && m < lplim) m *= lowprimes[j++] + m = x.modInt(m) + while (i < j) if (m % lowprimes[i++] == 0) return false + } + return x.millerRabin(t) +} + +// (protected) true if probably prime (HAC 4.24, Miller-Rabin) +function bnpMillerRabin(t) { + var n1 = this.subtract(BigInteger.ONE) + var k = n1.getLowestSetBit() + if (k <= 0) return false + var r = n1.shiftRight(k) + t = (t + 1) >> 1 + if (t > lowprimes.length) t = lowprimes.length + var a = new BigInteger(null) + var j, bases = [] + for (var i = 0; i < t; ++i) { + for (;;) { + j = lowprimes[Math.floor(Math.random() * lowprimes.length)] + if (bases.indexOf(j) == -1) break + } + bases.push(j) + a.fromInt(j) + var y = a.modPow(r, this) + if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { + var j = 1 + while (j++ < k && y.compareTo(n1) != 0) { + y = y.modPowInt(2, this) + if (y.compareTo(BigInteger.ONE) == 0) return false + } + if (y.compareTo(n1) != 0) return false + } + } + return true +} + +// protected +proto.chunkSize = bnpChunkSize +proto.toRadix = bnpToRadix +proto.fromRadix = bnpFromRadix +proto.fromNumber = bnpFromNumber +proto.bitwiseTo = bnpBitwiseTo +proto.changeBit = bnpChangeBit +proto.addTo = bnpAddTo +proto.dMultiply = bnpDMultiply +proto.dAddOffset = bnpDAddOffset +proto.multiplyLowerTo = bnpMultiplyLowerTo +proto.multiplyUpperTo = bnpMultiplyUpperTo +proto.modInt = bnpModInt +proto.millerRabin = bnpMillerRabin + +// public +proto.clone = bnClone +proto.intValue = bnIntValue +proto.byteValue = bnByteValue +proto.shortValue = bnShortValue +proto.signum = bnSigNum +proto.toByteArray = bnToByteArray +proto.equals = bnEquals +proto.min = bnMin +proto.max = bnMax +proto.and = bnAnd +proto.or = bnOr +proto.xor = bnXor +proto.andNot = bnAndNot +proto.not = bnNot +proto.shiftLeft = bnShiftLeft +proto.shiftRight = bnShiftRight +proto.getLowestSetBit = bnGetLowestSetBit +proto.bitCount = bnBitCount +proto.testBit = bnTestBit +proto.setBit = bnSetBit +proto.clearBit = bnClearBit +proto.flipBit = bnFlipBit +proto.add = bnAdd +proto.subtract = bnSubtract +proto.multiply = bnMultiply +proto.divide = bnDivide +proto.remainder = bnRemainder +proto.divideAndRemainder = bnDivideAndRemainder +proto.modPow = bnModPow +proto.modInverse = bnModInverse +proto.pow = bnPow +proto.gcd = bnGCD +proto.isProbablePrime = bnIsProbablePrime + +// JSBN-specific extension +proto.square = bnSquare + +// constants +BigInteger.ZERO = nbv(0) +BigInteger.ONE = nbv(1) +BigInteger.valueOf = nbv + +module.exports = BigInteger + +},{"../package.json":124}],122:[function(require,module,exports){ +(function (Buffer){(function (){ +// FIXME: Kind of a weird way to throw exceptions, consider removing +var assert = require('assert') +var BigInteger = require('./bigi') + +/** + * Turns a byte array into a big integer. + * + * This function will interpret a byte array as a big integer in big + * endian notation. + */ +BigInteger.fromByteArrayUnsigned = function(byteArray) { + // BigInteger expects a DER integer conformant byte array + if (byteArray[0] & 0x80) { + return new BigInteger([0].concat(byteArray)) + } + + return new BigInteger(byteArray) +} + +/** + * Returns a byte array representation of the big integer. + * + * This returns the absolute of the contained value in big endian + * form. A value of zero results in an empty array. + */ +BigInteger.prototype.toByteArrayUnsigned = function() { + var byteArray = this.toByteArray() + return byteArray[0] === 0 ? byteArray.slice(1) : byteArray +} + +BigInteger.fromDERInteger = function(byteArray) { + return new BigInteger(byteArray) +} + +/* + * Converts BigInteger to a DER integer representation. + * + * The format for this value uses the most significant bit as a sign + * bit. If the most significant bit is already set and the integer is + * positive, a 0x00 is prepended. + * + * Examples: + * + * 0 => 0x00 + * 1 => 0x01 + * -1 => 0xff + * 127 => 0x7f + * -127 => 0x81 + * 128 => 0x0080 + * -128 => 0x80 + * 255 => 0x00ff + * -255 => 0xff01 + * 16300 => 0x3fac + * -16300 => 0xc054 + * 62300 => 0x00f35c + * -62300 => 0xff0ca4 +*/ +BigInteger.prototype.toDERInteger = BigInteger.prototype.toByteArray + +BigInteger.fromBuffer = function(buffer) { + // BigInteger expects a DER integer conformant byte array + if (buffer[0] & 0x80) { + var byteArray = Array.prototype.slice.call(buffer) + + return new BigInteger([0].concat(byteArray)) + } + + return new BigInteger(buffer) +} + +BigInteger.fromHex = function(hex) { + if (hex === '') return BigInteger.ZERO + + assert.equal(hex, hex.match(/^[A-Fa-f0-9]+/), 'Invalid hex string') + assert.equal(hex.length % 2, 0, 'Incomplete hex') + return new BigInteger(hex, 16) +} + +BigInteger.prototype.toBuffer = function(size) { + var byteArray = this.toByteArrayUnsigned() + var zeros = [] + + var padding = size - byteArray.length + while (zeros.length < padding) zeros.push(0) + + return new Buffer(zeros.concat(byteArray)) +} + +BigInteger.prototype.toHex = function(size) { + return this.toBuffer(size).toString('hex') +} + +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bigi":121,"assert":113,"buffer":249}],123:[function(require,module,exports){ +var BigInteger = require('./bigi') + +//addons +require('./convert') + +module.exports = BigInteger +},{"./bigi":121,"./convert":122}],124:[function(require,module,exports){ +module.exports={ + "name": "bigi", + "version": "1.4.2", + "description": "Big integers.", + "keywords": [ + "cryptography", + "math", + "bitcoin", + "arbitrary", + "precision", + "arithmetic", + "big", + "integer", + "int", + "number", + "biginteger", + "bigint", + "bignumber", + "decimal", + "float" + ], + "devDependencies": { + "coveralls": "^2.11.2", + "istanbul": "^0.3.5", + "jshint": "^2.5.1", + "mocha": "^2.1.0", + "mochify": "^2.1.0" + }, + "repository": { + "url": "https://github.com/cryptocoinjs/bigi", + "type": "git" + }, + "main": "./lib/index.js", + "scripts": { + "browser-test": "./node_modules/.bin/mochify --wd -R spec", + "test": "./node_modules/.bin/_mocha -- test/*.js", + "jshint": "./node_modules/.bin/jshint --config jshint.json lib/*.js ; true", + "unit": "./node_modules/.bin/mocha", + "coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js", + "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info" + }, + "dependencies": {}, + "testling": { + "files": "test/*.js", + "harness": "mocha", + "browsers": [ + "ie/9..latest", + "firefox/latest", + "chrome/latest", + "safari/6.0..latest", + "iphone/6.0..latest", + "android-browser/4.2..latest" + ] + } +} + +},{}],125:[function(require,module,exports){ +const BigInteger = require('bigi'); +const Buffer = require('safe-buffer').Buffer; +const ecurve = require('ecurve'); +const curve = ecurve.getCurveByName('secp256k1'); + +const one = BigInteger.ONE; +const n = curve.n; +const p = curve.p; + +function checkBuffer(name, buf, len, idx) { + const idxStr = (idx !== undefined ? '[' + idx + ']' : ''); + if (!Buffer.isBuffer(buf)) { + throw new Error(name + idxStr + ' must be a Buffer'); + } + if (buf.length !== len) { + throw new Error(name + idxStr + ' must be ' + len + ' bytes long'); + } +} + +function checkArray(name, arr) { + if (!arr || !arr.length) { + throw new Error(name + ' must be an array with one or more elements'); + } +} + +function checkPubKeyArr(pubKeys) { + checkArray('pubKeys', pubKeys); + for (let i = 0; i < pubKeys.length; i++) { + checkBuffer('pubKey', pubKeys[i], 32, i); + } +} + +function checkMessageArr(messages) { + checkArray('messages', messages); + for (let i = 0; i < messages.length; i++) { + checkBuffer('message', messages[i], 32, i); + } +} + +function checkSignatureArr(signatures) { + checkArray('signatures', signatures); + for (let i = 0; i < signatures.length; i++) { + checkBuffer('signature', signatures[i], 64, i); + } +} + +function checkNonceArr(nonces) { + checkArray('nonces', nonces); + for (let i = 0; i < nonces.length; i++) { + checkBuffer('nonce', nonces[i], 32, i); + } +} + +function checkPrivateKey(privateKey, idx) { + const idxStr = (idx !== undefined ? '[' + idx + ']' : ''); + if (!BigInteger.isBigInteger(privateKey) && !(typeof privateKey == 'string')) { + throw new Error('privateKey' + idxStr + ' must be a BigInteger or valid hex string'); + } + + if (typeof(privateKey) == 'string') { + if (privateKey.match(/[^a-f^A-F^0-9]+/)) { + throw new Error('privateKey must be a BigInteger or valid hex string'); + } + + checkRange('privateKey', BigInteger.fromHex(privateKey)); + return + } + + checkRange('privateKey', privateKey); +} + +function checkSignParams(privateKey, message) { + checkPrivateKey(privateKey); + checkBuffer('message', message, 32); +} + +function checkVerifyParams(pubKey, message, signature) { + checkBuffer('pubKey', pubKey, 32); + checkBuffer('message', message, 32); + checkBuffer('signature', signature, 64); +} + +function checkBatchVerifyParams(pubKeys, messages, signatures) { + checkPubKeyArr(pubKeys); + checkMessageArr(messages); + checkSignatureArr(signatures); + if (pubKeys.length !== messages.length || messages.length !== signatures.length) { + throw new Error('all parameters must be an array with the same length') + } +} + +function checkSessionParams(sessionId, privateKey, message, pubKeyCombined, ell) { + checkSignParams(privateKey, message); + checkBuffer('sessionId', sessionId, 32); + checkBuffer('pubKeyCombined', pubKeyCombined, 32); + checkBuffer('ell', ell, 32); +} + +function checkRange(name, scalar) { + if (scalar.compareTo(one) < 0 || scalar.compareTo(n.subtract(one)) > 0) { + throw new Error(name + ' must be an integer in the range 1..n-1') + } +} + +function checkSignatureInput(r, s) { + if (r.compareTo(p) >= 0) { + throw new Error('r is larger than or equal to field size'); + } + if (s.compareTo(n) >= 0) { + throw new Error('s is larger than or equal to curve order'); + } +} + +function checkPointExists(pubKeyEven, P) { + if (P.curve.isInfinity(P)) { + throw new Error('point is at infinity'); + } + const pEven = P.affineY.isEven(); + if (pubKeyEven !== pEven) { + throw new Error('point does not exist'); + } +} + +function checkAux(aux) { + if (aux.length !== 32) { + throw new Error('aux must be 32 bytes'); + } +} + +module.exports = { + checkSessionParams, + checkSignParams, + checkVerifyParams, + checkBatchVerifyParams, + checkRange, + checkSignatureInput, + checkPointExists, + checkPubKeyArr, + checkArray, + checkNonceArr, + checkAux, +}; + +},{"bigi":123,"ecurve":277,"safe-buffer":463}],126:[function(require,module,exports){ +const BigInteger = require('bigi'); +const Buffer = require('safe-buffer').Buffer; +const sha256 = require('js-sha256'); + +function bufferToInt(buffer) { + return BigInteger.fromBuffer(buffer); +} + +function intToBuffer(bigInteger) { + return bigInteger.toBuffer(32); +} + +function hash(buffer) { + return Buffer.from(sha256.create().update(buffer).array()); +} + +module.exports = { + bufferToInt, + intToBuffer, + hash, +}; + +},{"bigi":123,"js-sha256":355,"safe-buffer":463}],127:[function(require,module,exports){ +const schnorr = require('./schnorr'); +schnorr.check = require('./check'); +schnorr.convert = require('./convert'); +schnorr.math = require('./math'); +schnorr.muSig = require('./mu-sig'); +schnorr.taproot = require('./taproot'); + +module.exports = schnorr; + +},{"./check":125,"./convert":126,"./math":128,"./mu-sig":129,"./schnorr":130,"./taproot":131}],128:[function(require,module,exports){ +const BigInteger = require('bigi'); +const Buffer = require('safe-buffer').Buffer; +const ecurve = require('ecurve'); +const randomBytes = require('randombytes'); +const curve = ecurve.getCurveByName('secp256k1'); +const check = require('./check'); +const convert = require('./convert'); + +const concat = Buffer.concat; +const G = curve.G; +const p = curve.p; +const n = curve.n; +const zero = BigInteger.ZERO; +const one = BigInteger.ONE; +const two = BigInteger.valueOf(2); +const three = BigInteger.valueOf(3); +const four = BigInteger.valueOf(4); +const seven = BigInteger.valueOf(7); + +function deterministicGetK0(privateKey, publicKey, message) { + check.checkSignParams(privateKey, message); + + const h = taggedHash('BIP0340/nonce', concat([convert.intToBuffer(privateKey), publicKey, message])); + const i = convert.bufferToInt(h); + return i.mod(n); +} + +function isEven(pubKey) { + return pubKey.affineY.mod(two).equals(zero); +} + +function getEvenKey(pubKey, privateKey) { + if (isEven(pubKey)) { + return privateKey.clone(); + } + + return n.subtract(privateKey); +} + +function getE(Rx, Px, m) { + const hash = taggedHash('BIP0340/challenge', concat([Rx, Px, m])); + return convert.bufferToInt(hash).mod(n); +} + +function getR(s, e, P) { + const sG = G.multiply(s); + const eP = P.multiply(e); + return sG.add(eP.negate()); +} + +function taggedHash(tag, msg) { + const tagHash = convert.hash(tag); + return convert.hash(concat([tagHash, tagHash, Buffer.from(msg)])); +} + +function liftX(Px) { + const x = convert.bufferToInt(Px); + + const c = x.pow(three).add(seven).mod(p); + const y = c.modPow(p.add(one).divide(four), p); + if (c.compareTo(y.modPow(two, p)) !== 0) { + throw new Error('c is not equal to y^2'); + } + let P = ecurve.Point.fromAffine(curve, x, y); + if (!isEven(P)) { + P = ecurve.Point.fromAffine(curve, x, p.subtract(y)); + } + + check.checkPointExists(true, P); + return P; +} + +function randomA() { + let a = null; + for (; ;) { + a = convert.bufferToInt(Buffer.from(randomBytes(32))); + try { + check.checkRange('a', a); + return a; + } catch (e) { + // out of range, generate another one + } + } +} + +module.exports = { + deterministicGetK0, + isEven, + getEvenKey, + getE, + getR, + taggedHash, + liftX, + randomA, +}; + +},{"./check":125,"./convert":126,"bigi":123,"ecurve":277,"randombytes":460,"safe-buffer":463}],129:[function(require,module,exports){ +const Buffer = require('safe-buffer').Buffer; +const ecurve = require('ecurve'); +const curve = ecurve.getCurveByName('secp256k1'); +const math = require('./math'); +const check = require('./check'); +const convert = require('./convert'); + +const concat = Buffer.concat; +const G = curve.G; +const n = curve.n; +const MUSIG_TAG = convert.hash(Buffer.from('MuSig coefficient')); + +// Computes ell = SHA256(pubKeys[0], ..., pubKeys[pubKeys.length-1]) with +// pubKeys serialized in compressed form. +function computeEll(pubKeys) { + check.checkPubKeyArr(pubKeys); + return convert.hash(concat(pubKeys)) +} + +function computeCoefficient(ell, idx) { + const idxBuf = Buffer.alloc(4); + idxBuf.writeUInt32LE(idx); + const data = concat([MUSIG_TAG, MUSIG_TAG, ell, idxBuf]); + return convert.bufferToInt(convert.hash(data)).mod(n); +} + +function pubKeyCombine(pubKeys, pubKeyHash) { + const ell = pubKeyHash || computeEll(pubKeys); + let X = null; + for (let i = 0; i < pubKeys.length; i++) { + const Xi = math.liftX(pubKeys[i]); + const coefficient = computeCoefficient(ell, i); + const summand = Xi.multiply(coefficient); + if (X === null) { + X = summand; + } else { + X = X.add(summand); + } + } + return X; +} + +function sessionInitialize(sessionId, privateKey, message, pubKeyCombined, pkParity, ell, idx) { + check.checkSessionParams(sessionId, privateKey, message, pubKeyCombined, ell); + + const session = { + sessionId, + message, + pubKeyCombined, + pkParity, + ell, + idx, + }; + + const coefficient = computeCoefficient(ell, idx); + session.secretKey = privateKey.multiply(coefficient).mod(n); + session.ownKeyParity = math.isEven(G.multiply(privateKey)); + if (session.pkParity !== session.ownKeyParity) { + session.secretKey = n.subtract(session.secretKey); + } + + const nonceData = concat([sessionId, message, session.pubKeyCombined, convert.intToBuffer(privateKey)]); + session.secretNonce = convert.bufferToInt(convert.hash(nonceData)); + check.checkRange('secretNonce', session.secretNonce); + const R = G.multiply(session.secretNonce); + session.nonce = convert.intToBuffer(R.affineX); + session.nonceParity = math.isEven(R); + session.commitment = convert.hash(session.nonce); + return session; +} + +function sessionNonceCombine(session, nonces) { + check.checkNonceArr(nonces); + let R = math.liftX(nonces[0]); + for (let i = 1; i < nonces.length; i++) { + R = R.add(math.liftX(nonces[i])); + } + session.combinedNonceParity = math.isEven(R); + return convert.intToBuffer(R.affineX); +} + +function partialSign(session, message, nonceCombined, pubKeyCombined) { + const e = math.getE(nonceCombined, pubKeyCombined, message); + const sk = session.secretKey; + let k = session.secretNonce; + if (session.nonceParity !== session.combinedNonceParity) { + k = n.subtract(k); + } + return sk.multiply(e).add(k).mod(n); +} + +function partialSigVerify(session, partialSig, nonceCombined, idx, pubKey, nonce) { + let e = math.getE(nonceCombined, session.pubKeyCombined, session.message); + const coefficient = computeCoefficient(session.ell, idx); + const Pj = math.liftX(pubKey); + const Ri = math.liftX(nonce); + + if (!session.pkParity) { + e = n.subtract(e); + } + + let RP = math.getR(partialSig, e.multiply(coefficient).mod(n), Pj); + if (session.combinedNonceParity) { + RP = RP.negate(); + } + const sum = RP.add(Ri); + if (!sum.curve.isInfinity(sum)) { + throw new Error('partial signature verification failed'); + } +} + +function partialSigCombine(nonceCombined, partialSigs) { + const R = math.liftX(nonceCombined); + check.checkArray('partialSigs', partialSigs); + const Rx = convert.intToBuffer(R.affineX); + let s = partialSigs[0]; + for (let i = 1; i < partialSigs.length; i++) { + s = s.add(partialSigs[i]).mod(n); + } + return concat([Rx, convert.intToBuffer(s)]); +} + +module.exports = { + computeEll, + computeCoefficient, + pubKeyCombine, + sessionInitialize, + sessionNonceCombine, + partialSign, + partialSigVerify, + partialSigCombine, +}; + +},{"./check":125,"./convert":126,"./math":128,"ecurve":277,"safe-buffer":463}],130:[function(require,module,exports){ +const BigInteger = require('bigi'); +const Buffer = require('safe-buffer').Buffer; +const ecurve = require('ecurve'); +const curve = ecurve.getCurveByName('secp256k1'); +const math = require('./math'); +const check = require('./check'); +const convert = require('./convert'); + +const concat = Buffer.concat; +const G = curve.G; +const p = curve.p; +const n = curve.n; +const zero = BigInteger.ZERO; + +function sign(privateKey, message, aux) { + // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#signing + check.checkSignParams(privateKey, message); + privateKey = typeof (privateKey) == 'string' ? BigInteger.fromHex(privateKey) : privateKey; + + const P = G.multiply(privateKey); + const Px = convert.intToBuffer(P.affineX); + + const d = math.getEvenKey(P, privateKey); + let kPrime + if (aux) { + check.checkAux(aux); + + const t = convert.intToBuffer(d.xor(convert.bufferToInt(math.taggedHash('BIP0340/aux', aux)))); + const rand = math.taggedHash('BIP0340/nonce', concat([t, Px, message])) + kPrime = convert.bufferToInt(rand).mod(n); + } else { + kPrime = math.deterministicGetK0(d, Px, message); + } + + if (kPrime.signum() === 0) { + throw new Error('kPrime is zero'); + } + + const R = G.multiply(kPrime); + const k = math.getEvenKey(R, kPrime); + const Rx = convert.intToBuffer(R.affineX); + const e = math.getE(Rx, Px, message); + return concat([Rx, convert.intToBuffer(k.add(e.multiply(d)).mod(n))]); +} + +function verify(pubKey, message, signature) { + check.checkVerifyParams(pubKey, message, signature); + + // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#verification + const P = math.liftX(pubKey); + const Px = convert.intToBuffer(P.affineX); + const r = convert.bufferToInt(signature.slice(0, 32)); + const s = convert.bufferToInt(signature.slice(32, 64)); + check.checkSignatureInput(r, s); + const e = math.getE(convert.intToBuffer(r), Px, message); + const R = math.getR(s, e, P); + if (R.curve.isInfinity(R) || !math.isEven(R) || !R.affineX.equals(r)) { + throw new Error('signature verification failed'); + } +} + +function batchVerify(pubKeys, messages, signatures) { + check.checkBatchVerifyParams(pubKeys, messages, signatures); + + // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#Batch_Verification + let leftSide = zero; + let rightSide = null; + for (let i = 0; i < pubKeys.length; i++) { + const P = math.liftX(pubKeys[i]); + const Px = convert.intToBuffer(P.affineX); + const r = convert.bufferToInt(signatures[i].slice(0, 32)); + const s = convert.bufferToInt(signatures[i].slice(32, 64)); + check.checkSignatureInput(r, s); + const e = math.getE(convert.intToBuffer(r), Px, messages[i]); + const R = math.liftX(signatures[i].slice(0, 32)); + + if (i === 0) { + leftSide = leftSide.add(s); + rightSide = R; + rightSide = rightSide.add(P.multiply(e)); + } else { + const a = math.randomA(); + leftSide = leftSide.add(a.multiply(s)); + rightSide = rightSide.add(R.multiply(a)); + rightSide = rightSide.add(P.multiply(a.multiply(e))); + } + } + + if (!G.multiply(leftSide).equals(rightSide)) { + throw new Error('signature verification failed'); + } +} + +module.exports = { + sign, + verify, + batchVerify, +}; + +},{"./check":125,"./convert":126,"./math":128,"bigi":123,"ecurve":277,"safe-buffer":463}],131:[function(require,module,exports){ +const Buffer = require('safe-buffer').Buffer; +const ecurve = require('ecurve'); +const curve = ecurve.getCurveByName('secp256k1'); +const math = require('./math'); +const convert = require('./convert'); + +const concat = Buffer.concat; +const G = curve.G; + +function taprootConstruct(pubKey, merkleRoot) { + // If the spending conditions do not require a script path, the output key should commit to an unspendable script path + // instead of having no script path. This can be achieved by computing the output key point as + // Q = P + int(hashTapTweak(bytes(P)))G. + // https://en.bitcoin.it/wiki/BIP_0341#cite_note-22 + if (!merkleRoot || merkleRoot.length === 0) { + merkleRoot = Buffer.alloc(0, 0); + } + const Px = convert.intToBuffer(pubKey.affineX); + const P = math.liftX(Px); + const tweak = convert.bufferToInt(math.taggedHash('TapTweak', concat([Px, merkleRoot]))); + const Q = P.add(G.multiply(tweak)); + return convert.intToBuffer(Q.affineX); +} + +module.exports = { + taprootConstruct, +}; + +},{"./convert":126,"./math":128,"ecurve":277,"safe-buffer":463}],132:[function(require,module,exports){ +/* + * Bitcoin BIP32 path helpers + * (C) 2016 Alex Beregszaszi + */ + +const HARDENED = 0x80000000 + +var BIPPath = function (path) { + if (!Array.isArray(path)) { + throw new Error('Input must be an Array') + } + if (path.length === 0) { + throw new Error('Path must contain at least one level') + } + for (var i = 0; i < path.length; i++) { + if (typeof path[i] !== 'number') { + throw new Error('Path element is not a number') + } + } + this.path = path +} + +BIPPath.validatePathArray = function (path) { + try { + BIPPath.fromPathArray(path) + return true + } catch (e) { + return false + } +} + +BIPPath.validateString = function (text, reqRoot) { + try { + BIPPath.fromString(text, reqRoot) + return true + } catch (e) { + return false + } +} + +BIPPath.fromPathArray = function (path) { + return new BIPPath(path) +} + +BIPPath.fromString = function (text, reqRoot) { + // skip the root + if (/^m\//i.test(text)) { + text = text.slice(2) + } else if (reqRoot) { + throw new Error('Root element is required') + } + + var path = text.split('/') + var ret = new Array(path.length) + for (var i = 0; i < path.length; i++) { + var tmp = /(\d+)([hH\']?)/.exec(path[i]) + if (tmp === null) { + throw new Error('Invalid input') + } + ret[i] = parseInt(tmp[1], 10) + + if (ret[i] >= HARDENED) { + throw new Error('Invalid child index') + } + + if (tmp[2] === 'h' || tmp[2] === 'H' || tmp[2] === '\'') { + ret[i] += HARDENED + } else if (tmp[2].length != 0) { + throw new Error('Invalid modifier') + } + } + return new BIPPath(ret) +} + +BIPPath.prototype.toPathArray = function () { + return this.path +} + +BIPPath.prototype.toString = function (noRoot, oldStyle) { + var ret = new Array(this.path.length) + for (var i = 0; i < this.path.length; i++) { + var tmp = this.path[i] + if (tmp & HARDENED) { + ret[i] = (tmp & ~HARDENED) + (oldStyle ? 'h' : '\'') + } else { + ret[i] = tmp + } + } + return (noRoot ? '' : 'm/') + ret.join('/') +} + +BIPPath.prototype.inspect = function () { + return 'BIPPath <' + this.toString() + '>' +} + +module.exports = BIPPath + +},{}],133:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const crypto = require("./crypto"); +const bs58check = require('bs58check'); +const ecc = require('tiny-secp256k1'); +const typeforce = require('typeforce'); +const wif = require('wif'); +const UINT256_TYPE = typeforce.BufferN(32); +const NETWORK_TYPE = typeforce.compile({ + wif: typeforce.UInt8, + bip32: { + public: typeforce.UInt32, + private: typeforce.UInt32, + }, +}); +const BITCOIN = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'bc', + bip32: { + public: 0x0488b21e, + private: 0x0488ade4, + }, + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80, +}; +const HIGHEST_BIT = 0x80000000; +const UINT31_MAX = Math.pow(2, 31) - 1; +function BIP32Path(value) { + return (typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null); +} +function UInt31(value) { + return typeforce.UInt32(value) && value <= UINT31_MAX; +} +class BIP32 { + constructor(__D, __Q, chainCode, network, __DEPTH = 0, __INDEX = 0, __PARENT_FINGERPRINT = 0x00000000) { + this.__D = __D; + this.__Q = __Q; + this.chainCode = chainCode; + this.network = network; + this.__DEPTH = __DEPTH; + this.__INDEX = __INDEX; + this.__PARENT_FINGERPRINT = __PARENT_FINGERPRINT; + typeforce(NETWORK_TYPE, network); + this.lowR = false; + } + get depth() { + return this.__DEPTH; + } + get index() { + return this.__INDEX; + } + get parentFingerprint() { + return this.__PARENT_FINGERPRINT; + } + get publicKey() { + if (this.__Q === undefined) + this.__Q = ecc.pointFromScalar(this.__D, true); + return this.__Q; + } + get privateKey() { + return this.__D; + } + get identifier() { + return crypto.hash160(this.publicKey); + } + get fingerprint() { + return this.identifier.slice(0, 4); + } + get compressed() { + return true; + } + // Private === not neutered + // Public === neutered + isNeutered() { + return this.__D === undefined; + } + neutered() { + return fromPublicKeyLocal(this.publicKey, this.chainCode, this.network, this.depth, this.index, this.parentFingerprint); + } + toBase58() { + const network = this.network; + const version = !this.isNeutered() + ? network.bip32.private + : network.bip32.public; + const buffer = Buffer.allocUnsafe(78); + // 4 bytes: version bytes + buffer.writeUInt32BE(version, 0); + // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, .... + buffer.writeUInt8(this.depth, 4); + // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) + buffer.writeUInt32BE(this.parentFingerprint, 5); + // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. + // This is encoded in big endian. (0x00000000 if master key) + buffer.writeUInt32BE(this.index, 9); + // 32 bytes: the chain code + this.chainCode.copy(buffer, 13); + // 33 bytes: the public key or private key data + if (!this.isNeutered()) { + // 0x00 + k for private keys + buffer.writeUInt8(0, 45); + this.privateKey.copy(buffer, 46); + // 33 bytes: the public key + } + else { + // X9.62 encoding for public keys + this.publicKey.copy(buffer, 45); + } + return bs58check.encode(buffer); + } + toWIF() { + if (!this.privateKey) + throw new TypeError('Missing private key'); + return wif.encode(this.network.wif, this.privateKey, true); + } + // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions + derive(index) { + typeforce(typeforce.UInt32, index); + const isHardened = index >= HIGHEST_BIT; + const data = Buffer.allocUnsafe(37); + // Hardened child + if (isHardened) { + if (this.isNeutered()) + throw new TypeError('Missing private key for hardened child key'); + // data = 0x00 || ser256(kpar) || ser32(index) + data[0] = 0x00; + this.privateKey.copy(data, 1); + data.writeUInt32BE(index, 33); + // Normal child + } + else { + // data = serP(point(kpar)) || ser32(index) + // = serP(Kpar) || ser32(index) + this.publicKey.copy(data, 0); + data.writeUInt32BE(index, 33); + } + const I = crypto.hmacSHA512(this.chainCode, data); + const IL = I.slice(0, 32); + const IR = I.slice(32); + // if parse256(IL) >= n, proceed with the next value for i + if (!ecc.isPrivate(IL)) + return this.derive(index + 1); + // Private parent key -> private child key + let hd; + if (!this.isNeutered()) { + // ki = parse256(IL) + kpar (mod n) + const ki = ecc.privateAdd(this.privateKey, IL); + // In case ki == 0, proceed with the next value for i + if (ki == null) + return this.derive(index + 1); + hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); + // Public parent key -> public child key + } + else { + // Ki = point(parse256(IL)) + Kpar + // = G*IL + Kpar + const Ki = ecc.pointAddScalar(this.publicKey, IL, true); + // In case Ki is the point at infinity, proceed with the next value for i + if (Ki === null) + return this.derive(index + 1); + hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0)); + } + return hd; + } + deriveHardened(index) { + typeforce(UInt31, index); + // Only derives hardened private keys by default + return this.derive(index + HIGHEST_BIT); + } + derivePath(path) { + typeforce(BIP32Path, path); + let splitPath = path.split('/'); + if (splitPath[0] === 'm') { + if (this.parentFingerprint) + throw new TypeError('Expected master, got child'); + splitPath = splitPath.slice(1); + } + return splitPath.reduce((prevHd, indexStr) => { + let index; + if (indexStr.slice(-1) === `'`) { + index = parseInt(indexStr.slice(0, -1), 10); + return prevHd.deriveHardened(index); + } + else { + index = parseInt(indexStr, 10); + return prevHd.derive(index); + } + }, this); + } + sign(hash, lowR) { + if (!this.privateKey) + throw new Error('Missing private key'); + if (lowR === undefined) + lowR = this.lowR; + if (lowR === false) { + return ecc.sign(hash, this.privateKey); + } + else { + let sig = ecc.sign(hash, this.privateKey); + const extraData = Buffer.alloc(32, 0); + let counter = 0; + // if first try is lowR, skip the loop + // for second try and on, add extra entropy counting up + while (sig[0] > 0x7f) { + counter++; + extraData.writeUIntLE(counter, 0, 6); + sig = ecc.signWithEntropy(hash, this.privateKey, extraData); + } + return sig; + } + } + verify(hash, signature) { + return ecc.verify(hash, this.publicKey, signature); + } +} +function fromBase58(inString, network) { + const buffer = bs58check.decode(inString); + if (buffer.length !== 78) + throw new TypeError('Invalid buffer length'); + network = network || BITCOIN; + // 4 bytes: version bytes + const version = buffer.readUInt32BE(0); + if (version !== network.bip32.private && version !== network.bip32.public) + throw new TypeError('Invalid network version'); + // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ... + const depth = buffer[4]; + // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key) + const parentFingerprint = buffer.readUInt32BE(5); + if (depth === 0) { + if (parentFingerprint !== 0x00000000) + throw new TypeError('Invalid parent fingerprint'); + } + // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized. + // This is encoded in MSB order. (0x00000000 if master key) + const index = buffer.readUInt32BE(9); + if (depth === 0 && index !== 0) + throw new TypeError('Invalid index'); + // 32 bytes: the chain code + const chainCode = buffer.slice(13, 45); + let hd; + // 33 bytes: private key data (0x00 + k) + if (version === network.bip32.private) { + if (buffer.readUInt8(45) !== 0x00) + throw new TypeError('Invalid private key'); + const k = buffer.slice(46, 78); + hd = fromPrivateKeyLocal(k, chainCode, network, depth, index, parentFingerprint); + // 33 bytes: public key data (0x02 + X or 0x03 + X) + } + else { + const X = buffer.slice(45, 78); + hd = fromPublicKeyLocal(X, chainCode, network, depth, index, parentFingerprint); + } + return hd; +} +exports.fromBase58 = fromBase58; +function fromPrivateKey(privateKey, chainCode, network) { + return fromPrivateKeyLocal(privateKey, chainCode, network); +} +exports.fromPrivateKey = fromPrivateKey; +function fromPrivateKeyLocal(privateKey, chainCode, network, depth, index, parentFingerprint) { + typeforce({ + privateKey: UINT256_TYPE, + chainCode: UINT256_TYPE, + }, { privateKey, chainCode }); + network = network || BITCOIN; + if (!ecc.isPrivate(privateKey)) + throw new TypeError('Private key not in range [1, n)'); + return new BIP32(privateKey, undefined, chainCode, network, depth, index, parentFingerprint); +} +function fromPublicKey(publicKey, chainCode, network) { + return fromPublicKeyLocal(publicKey, chainCode, network); +} +exports.fromPublicKey = fromPublicKey; +function fromPublicKeyLocal(publicKey, chainCode, network, depth, index, parentFingerprint) { + typeforce({ + publicKey: typeforce.BufferN(33), + chainCode: UINT256_TYPE, + }, { publicKey, chainCode }); + network = network || BITCOIN; + // verify the X coordinate is a point on the curve + if (!ecc.isPoint(publicKey)) + throw new TypeError('Point is not on the curve'); + return new BIP32(undefined, publicKey, chainCode, network, depth, index, parentFingerprint); +} +function fromSeed(seed, network) { + typeforce(typeforce.Buffer, seed); + if (seed.length < 16) + throw new TypeError('Seed should be at least 128 bits'); + if (seed.length > 64) + throw new TypeError('Seed should be at most 512 bits'); + network = network || BITCOIN; + const I = crypto.hmacSHA512(Buffer.from('Bitcoin seed', 'utf8'), seed); + const IL = I.slice(0, 32); + const IR = I.slice(32); + return fromPrivateKey(IL, IR, network); +} +exports.fromSeed = fromSeed; + +}).call(this)}).call(this,require("buffer").Buffer) +},{"./crypto":134,"bs58check":246,"buffer":249,"tiny-secp256k1":498,"typeforce":521,"wif":530}],134:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const createHash = require('create-hash'); +const createHmac = require('create-hmac'); +function hash160(buffer) { + const sha256Hash = createHash('sha256') + .update(buffer) + .digest(); + try { + return createHash('rmd160') + .update(sha256Hash) + .digest(); + } + catch (err) { + return createHash('ripemd160') + .update(sha256Hash) + .digest(); + } +} +exports.hash160 = hash160; +function hmacSHA512(key, data) { + return createHmac('sha512', key) + .update(data) + .digest(); +} +exports.hmacSHA512 = hmacSHA512; + +},{"create-hash":254,"create-hmac":256}],135:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var bip32_1 = require("./bip32"); +exports.fromSeed = bip32_1.fromSeed; +exports.fromBase58 = bip32_1.fromBase58; +exports.fromPublicKey = bip32_1.fromPublicKey; +exports.fromPrivateKey = bip32_1.fromPrivateKey; + +},{"./bip32":133}],136:[function(require,module,exports){ +var aes = require('browserify-aes') +var assert = require('assert') +var Buffer = require('safe-buffer').Buffer +var bs58check = require('bs58check') +var createHash = require('create-hash') +var scrypt = require('scryptsy') +var xor = require('buffer-xor/inplace') + +var ecurve = require('ecurve') +var curve = ecurve.getCurveByName('secp256k1') + +var BigInteger = require('bigi') + +// constants +var SCRYPT_PARAMS = { + N: 16384, // specified by BIP38 + r: 8, + p: 8 +} +var NULL = Buffer.alloc(0) + +function hash160 (buffer) { + var hash + try { + hash = createHash('rmd160') + } catch (e) { + hash = createHash('ripemd160') + } + return hash.update( + createHash('sha256').update(buffer).digest() + ).digest() +} + +function hash256 (buffer) { + return createHash('sha256').update( + createHash('sha256').update(buffer).digest() + ).digest() +} + +function getAddress (d, compressed) { + var Q = curve.G.multiply(d).getEncoded(compressed) + var hash = hash160(Q) + var payload = Buffer.allocUnsafe(21) + payload.writeUInt8(0x00, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38 + hash.copy(payload, 1) + + return bs58check.encode(payload) +} + +function encryptRaw (buffer, compressed, passphrase, progressCallback, scryptParams) { + if (buffer.length !== 32) throw new Error('Invalid private key length') + scryptParams = scryptParams || SCRYPT_PARAMS + + var d = BigInteger.fromBuffer(buffer) + var address = getAddress(d, compressed) + var secret = Buffer.from(passphrase, 'utf8') + var salt = hash256(address).slice(0, 4) + + var N = scryptParams.N + var r = scryptParams.r + var p = scryptParams.p + + var scryptBuf = scrypt(secret, salt, N, r, p, 64, progressCallback) + var derivedHalf1 = scryptBuf.slice(0, 32) + var derivedHalf2 = scryptBuf.slice(32, 64) + + var xorBuf = xor(derivedHalf1, buffer) + var cipher = aes.createCipheriv('aes-256-ecb', derivedHalf2, NULL) + cipher.setAutoPadding(false) + cipher.end(xorBuf) + + var cipherText = cipher.read() + + // 0x01 | 0x42 | flagByte | salt (4) | cipherText (32) + var result = Buffer.allocUnsafe(7 + 32) + result.writeUInt8(0x01, 0) + result.writeUInt8(0x42, 1) + result.writeUInt8(compressed ? 0xe0 : 0xc0, 2) + salt.copy(result, 3) + cipherText.copy(result, 7) + + return result +} + +function encrypt (buffer, compressed, passphrase, progressCallback, scryptParams) { + return bs58check.encode(encryptRaw(buffer, compressed, passphrase, progressCallback, scryptParams)) +} + +// some of the techniques borrowed from: https://github.com/pointbiz/bitaddress.org +function decryptRaw (buffer, passphrase, progressCallback, scryptParams) { + // 39 bytes: 2 bytes prefix, 37 bytes payload + if (buffer.length !== 39) throw new Error('Invalid BIP38 data length') + if (buffer.readUInt8(0) !== 0x01) throw new Error('Invalid BIP38 prefix') + scryptParams = scryptParams || SCRYPT_PARAMS + + // check if BIP38 EC multiply + var type = buffer.readUInt8(1) + if (type === 0x43) return decryptECMult(buffer, passphrase, progressCallback, scryptParams) + if (type !== 0x42) throw new Error('Invalid BIP38 type') + + passphrase = Buffer.from(passphrase, 'utf8') + + var flagByte = buffer.readUInt8(2) + var compressed = flagByte === 0xe0 + if (!compressed && flagByte !== 0xc0) throw new Error('Invalid BIP38 compression flag') + + var N = scryptParams.N + var r = scryptParams.r + var p = scryptParams.p + + var salt = buffer.slice(3, 7) + var scryptBuf = scrypt(passphrase, salt, N, r, p, 64, progressCallback) + var derivedHalf1 = scryptBuf.slice(0, 32) + var derivedHalf2 = scryptBuf.slice(32, 64) + + var privKeyBuf = buffer.slice(7, 7 + 32) + var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, NULL) + decipher.setAutoPadding(false) + decipher.end(privKeyBuf) + + var plainText = decipher.read() + var privateKey = xor(derivedHalf1, plainText) + + // verify salt matches address + var d = BigInteger.fromBuffer(privateKey) + var address = getAddress(d, compressed) + var checksum = hash256(address).slice(0, 4) + assert.deepEqual(salt, checksum) + + return { + privateKey: privateKey, + compressed: compressed + } +} + +function decrypt (string, passphrase, progressCallback, scryptParams) { + return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams) +} + +function decryptECMult (buffer, passphrase, progressCallback, scryptParams) { + passphrase = Buffer.from(passphrase, 'utf8') + buffer = buffer.slice(1) // FIXME: we can avoid this + scryptParams = scryptParams || SCRYPT_PARAMS + + var flag = buffer.readUInt8(1) + var compressed = (flag & 0x20) !== 0 + var hasLotSeq = (flag & 0x04) !== 0 + + assert.equal((flag & 0x24), flag, 'Invalid private key.') + + var addressHash = buffer.slice(2, 6) + var ownerEntropy = buffer.slice(6, 14) + var ownerSalt + + // 4 bytes ownerSalt if 4 bytes lot/sequence + if (hasLotSeq) { + ownerSalt = ownerEntropy.slice(0, 4) + + // else, 8 bytes ownerSalt + } else { + ownerSalt = ownerEntropy + } + + var encryptedPart1 = buffer.slice(14, 22) // First 8 bytes + var encryptedPart2 = buffer.slice(22, 38) // 16 bytes + + var N = scryptParams.N + var r = scryptParams.r + var p = scryptParams.p + var preFactor = scrypt(passphrase, ownerSalt, N, r, p, 32, progressCallback) + + var passFactor + if (hasLotSeq) { + var hashTarget = Buffer.concat([preFactor, ownerEntropy]) + passFactor = hash256(hashTarget) + } else { + passFactor = preFactor + } + + var passInt = BigInteger.fromBuffer(passFactor) + var passPoint = curve.G.multiply(passInt).getEncoded(true) + + var seedBPass = scrypt(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64) + var derivedHalf1 = seedBPass.slice(0, 32) + var derivedHalf2 = seedBPass.slice(32, 64) + + var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0)) + decipher.setAutoPadding(false) + decipher.end(encryptedPart2) + + var decryptedPart2 = decipher.read() + var tmp = xor(decryptedPart2, derivedHalf1.slice(16, 32)) + var seedBPart2 = tmp.slice(8, 16) + + var decipher2 = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0)) + decipher2.setAutoPadding(false) + decipher2.write(encryptedPart1) // first 8 bytes + decipher2.end(tmp.slice(0, 8)) // last 8 bytes + + var seedBPart1 = xor(decipher2.read(), derivedHalf1.slice(0, 16)) + var seedB = Buffer.concat([seedBPart1, seedBPart2], 24) + var factorB = BigInteger.fromBuffer(hash256(seedB)) + + // d = passFactor * factorB (mod n) + var d = passInt.multiply(factorB).mod(curve.n) + + return { + privateKey: d.toBuffer(32), + compressed: compressed + } +} + +function verify (string) { + var decoded = bs58check.decodeUnsafe(string) + if (!decoded) return false + + if (decoded.length !== 39) return false + if (decoded.readUInt8(0) !== 0x01) return false + + var type = decoded.readUInt8(1) + var flag = decoded.readUInt8(2) + + // encrypted WIF + if (type === 0x42) { + if (flag !== 0xc0 && flag !== 0xe0) return false + + // EC mult + } else if (type === 0x43) { + if ((flag & ~0x24)) return false + } else { + return false + } + + return true +} + +module.exports = { + decrypt: decrypt, + decryptECMult: decryptECMult, + decryptRaw: decryptRaw, + encrypt: encrypt, + encryptRaw: encryptRaw, + verify: verify +} + +},{"assert":113,"bigi":123,"browserify-aes":203,"bs58check":246,"buffer-xor/inplace":248,"create-hash":254,"ecurve":277,"safe-buffer":463,"scryptsy":466}],137:[function(require,module,exports){ +var Buffer = require('safe-buffer').Buffer +var createHash = require('create-hash') +var _pbkdf2 = require('pbkdf2') +var pbkdf2 = _pbkdf2.pbkdf2Sync +var pbkdf2Async = _pbkdf2.pbkdf2 +var randomBytes = require('randombytes') + +// use unorm until String.prototype.normalize gets better browser support +var unorm = require('unorm') + +var CHINESE_SIMPLIFIED_WORDLIST = require('./wordlists/chinese_simplified.json') +var CHINESE_TRADITIONAL_WORDLIST = require('./wordlists/chinese_traditional.json') +var ENGLISH_WORDLIST = require('./wordlists/english.json') +var FRENCH_WORDLIST = require('./wordlists/french.json') +var ITALIAN_WORDLIST = require('./wordlists/italian.json') +var JAPANESE_WORDLIST = require('./wordlists/japanese.json') +var KOREAN_WORDLIST = require('./wordlists/korean.json') +var SPANISH_WORDLIST = require('./wordlists/spanish.json') +var DEFAULT_WORDLIST = ENGLISH_WORDLIST + +var INVALID_MNEMONIC = 'Invalid mnemonic' +var INVALID_ENTROPY = 'Invalid entropy' +var INVALID_CHECKSUM = 'Invalid mnemonic checksum' + +function lpad (str, padString, length) { + while (str.length < length) str = padString + str + return str +} + +function binaryToByte (bin) { + return parseInt(bin, 2) +} + +function bytesToBinary (bytes) { + return bytes.map(function (x) { + return lpad(x.toString(2), '0', 8) + }).join('') +} + +function deriveChecksumBits (entropyBuffer) { + var ENT = entropyBuffer.length * 8 + var CS = ENT / 32 + var hash = createHash('sha256').update(entropyBuffer).digest() + + return bytesToBinary([].slice.call(hash)).slice(0, CS) +} + +function salt (password) { + return 'mnemonic' + (password || '') +} + +function mnemonicToSeed (mnemonic, password) { + var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8') + var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8') + + return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512') +} + +function mnemonicToSeedHex (mnemonic, password) { + return mnemonicToSeed(mnemonic, password).toString('hex') +} + +function mnemonicToSeedAsync (mnemonic, password) { + return new Promise(function (resolve, reject) { + try { + var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8') + var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8') + } catch (error) { + return reject(error) + } + + pbkdf2Async(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512', function (err, data) { + if (err) return reject(err) + else return resolve(data) + }) + }) +} + +function mnemonicToSeedHexAsync (mnemonic, password) { + return mnemonicToSeedAsync(mnemonic, password) + .then(function (buf) { return buf.toString('hex') }) +} + +function mnemonicToEntropy (mnemonic, wordlist) { + wordlist = wordlist || DEFAULT_WORDLIST + + var words = unorm.nfkd(mnemonic).split(' ') + if (words.length % 3 !== 0) throw new Error(INVALID_MNEMONIC) + + // convert word indices to 11 bit binary strings + var bits = words.map(function (word) { + var index = wordlist.indexOf(word) + if (index === -1) throw new Error(INVALID_MNEMONIC) + + return lpad(index.toString(2), '0', 11) + }).join('') + + // split the binary string into ENT/CS + var dividerIndex = Math.floor(bits.length / 33) * 32 + var entropyBits = bits.slice(0, dividerIndex) + var checksumBits = bits.slice(dividerIndex) + + // calculate the checksum and compare + var entropyBytes = entropyBits.match(/(.{1,8})/g).map(binaryToByte) + if (entropyBytes.length < 16) throw new Error(INVALID_ENTROPY) + if (entropyBytes.length > 32) throw new Error(INVALID_ENTROPY) + if (entropyBytes.length % 4 !== 0) throw new Error(INVALID_ENTROPY) + + var entropy = Buffer.from(entropyBytes) + var newChecksum = deriveChecksumBits(entropy) + if (newChecksum !== checksumBits) throw new Error(INVALID_CHECKSUM) + + return entropy.toString('hex') +} + +function entropyToMnemonic (entropy, wordlist) { + if (!Buffer.isBuffer(entropy)) entropy = Buffer.from(entropy, 'hex') + wordlist = wordlist || DEFAULT_WORDLIST + + // 128 <= ENT <= 256 + if (entropy.length < 16) throw new TypeError(INVALID_ENTROPY) + if (entropy.length > 32) throw new TypeError(INVALID_ENTROPY) + if (entropy.length % 4 !== 0) throw new TypeError(INVALID_ENTROPY) + + var entropyBits = bytesToBinary([].slice.call(entropy)) + var checksumBits = deriveChecksumBits(entropy) + + var bits = entropyBits + checksumBits + var chunks = bits.match(/(.{1,11})/g) + var words = chunks.map(function (binary) { + var index = binaryToByte(binary) + return wordlist[index] + }) + + return wordlist === JAPANESE_WORDLIST ? words.join('\u3000') : words.join(' ') +} + +function generateMnemonic (strength, rng, wordlist) { + strength = strength || 128 + if (strength % 32 !== 0) throw new TypeError(INVALID_ENTROPY) + rng = rng || randomBytes + + return entropyToMnemonic(rng(strength / 8), wordlist) +} + +function validateMnemonic (mnemonic, wordlist) { + try { + mnemonicToEntropy(mnemonic, wordlist) + } catch (e) { + return false + } + + return true +} + +module.exports = { + mnemonicToSeed: mnemonicToSeed, + mnemonicToSeedAsync: mnemonicToSeedAsync, + mnemonicToSeedHex: mnemonicToSeedHex, + mnemonicToSeedHexAsync: mnemonicToSeedHexAsync, + mnemonicToEntropy: mnemonicToEntropy, + entropyToMnemonic: entropyToMnemonic, + generateMnemonic: generateMnemonic, + validateMnemonic: validateMnemonic, + wordlists: { + EN: ENGLISH_WORDLIST, + JA: JAPANESE_WORDLIST, + + chinese_simplified: CHINESE_SIMPLIFIED_WORDLIST, + chinese_traditional: CHINESE_TRADITIONAL_WORDLIST, + english: ENGLISH_WORDLIST, + french: FRENCH_WORDLIST, + italian: ITALIAN_WORDLIST, + japanese: JAPANESE_WORDLIST, + korean: KOREAN_WORDLIST, + spanish: SPANISH_WORDLIST + } +} + +},{"./wordlists/chinese_simplified.json":138,"./wordlists/chinese_traditional.json":139,"./wordlists/english.json":140,"./wordlists/french.json":141,"./wordlists/italian.json":142,"./wordlists/japanese.json":143,"./wordlists/korean.json":144,"./wordlists/spanish.json":145,"create-hash":254,"pbkdf2":444,"randombytes":460,"safe-buffer":463,"unorm":523}],138:[function(require,module,exports){ +module.exports=[ + "的", "一", "是", "在", @@ -9367,7 +25625,7 @@ module.exports=[ "歇" ] -},{}],45:[function(require,module,exports){ +},{}],139:[function(require,module,exports){ module.exports=[ "的", "一", @@ -11419,7 +27677,7 @@ module.exports=[ "歇" ] -},{}],46:[function(require,module,exports){ +},{}],140:[function(require,module,exports){ module.exports=[ "abandon", "ability", @@ -13471,7 +29729,7 @@ module.exports=[ "zoo" ] -},{}],47:[function(require,module,exports){ +},{}],141:[function(require,module,exports){ module.exports=[ "abaisser", "abandon", @@ -15523,7 +31781,7 @@ module.exports=[ "zoologie" ] -},{}],48:[function(require,module,exports){ +},{}],142:[function(require,module,exports){ module.exports=[ "abaco", "abbaglio", @@ -17575,7 +33833,7 @@ module.exports=[ "zuppa" ] -},{}],49:[function(require,module,exports){ +},{}],143:[function(require,module,exports){ module.exports=[ "あいこくしん", "あいさつ", @@ -19627,7 +35885,7 @@ module.exports=[ "われる" ] -},{}],50:[function(require,module,exports){ +},{}],144:[function(require,module,exports){ module.exports=[ "가격", "가끔", @@ -21679,7 +37937,7 @@ module.exports=[ "힘껏" ] -},{}],51:[function(require,module,exports){ +},{}],145:[function(require,module,exports){ module.exports=[ "ábaco", "abdomen", @@ -23731,7 +39989,7 @@ module.exports=[ "zurdo" ] -},{}],52:[function(require,module,exports){ +},{}],146:[function(require,module,exports){ // Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] // NOTE: SIGHASH byte ignored AND restricted, truncate before use @@ -23846,7 +40104,53 @@ module.exports = { encode: encode } -},{"safe-buffer":280}],53:[function(require,module,exports){ +},{"safe-buffer":463}],147:[function(require,module,exports){ +// see https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki#compatibility + +const SEQUENCE_FINAL = 0xffffffff +const SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31) +const SEQUENCE_LOCKTIME_GRANULARITY = 9 +const SEQUENCE_LOCKTIME_MASK = 0x0000ffff +const SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22) + +const BLOCKS_MAX = SEQUENCE_LOCKTIME_MASK +const SECONDS_MOD = 1 << SEQUENCE_LOCKTIME_GRANULARITY +const SECONDS_MAX = SEQUENCE_LOCKTIME_MASK << SEQUENCE_LOCKTIME_GRANULARITY + +function decode (sequence) { + if (sequence & SEQUENCE_LOCKTIME_DISABLE_FLAG) return {} + if (sequence & SEQUENCE_LOCKTIME_TYPE_FLAG) { + return { + seconds: (sequence & SEQUENCE_LOCKTIME_MASK) << SEQUENCE_LOCKTIME_GRANULARITY + } + } + + return { + blocks: sequence & SEQUENCE_LOCKTIME_MASK + } +} + +function encode ({ blocks, seconds }) { + if (blocks !== undefined && seconds !== undefined) throw new TypeError('Cannot encode blocks AND seconds') + if (blocks === undefined && seconds === undefined) return SEQUENCE_FINAL // neither? assume final + + if (seconds !== undefined) { + if (!Number.isFinite(seconds)) throw new TypeError('Expected Number seconds') + if (seconds > SECONDS_MAX) throw new TypeError('Expected Number seconds <= ' + SECONDS_MAX) + if (seconds % SECONDS_MOD !== 0) throw new TypeError('Expected Number seconds as a multiple of ' + SECONDS_MOD) + + return SEQUENCE_LOCKTIME_TYPE_FLAG | (seconds >> SEQUENCE_LOCKTIME_GRANULARITY) + } + + if (!Number.isFinite(blocks)) throw new TypeError('Expected Number blocks') + if (blocks > SEQUENCE_LOCKTIME_MASK) throw new TypeError('Expected Number blocks <= ' + BLOCKS_MAX) + + return blocks +} + +module.exports = { decode, encode } + +},{}],148:[function(require,module,exports){ module.exports={ "OP_FALSE": 0, "OP_0": 0, @@ -23981,7 +40285,7 @@ module.exports={ "OP_INVALIDOPCODE": 255 } -},{}],54:[function(require,module,exports){ +},{}],149:[function(require,module,exports){ var OPS = require('./index.json') var map = {} @@ -23992,7 +40296,7 @@ for (var op in OPS) { module.exports = map -},{"./index.json":53}],55:[function(require,module,exports){ +},{"./index.json":148}],150:[function(require,module,exports){ 'use strict' var ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l' @@ -24176,8 +40480,8 @@ module.exports = { fromWords: fromWords } -},{}],56:[function(require,module,exports){ -(function (Buffer){ +},{}],151:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const networks = require('./networks'); @@ -24270,9 +40574,9 @@ function toOutputScript(address, network) { } exports.toOutputScript = toOutputScript; -}).call(this,require("buffer").Buffer) -},{"./networks":62,"./payments":64,"./script":72,"./types":98,"bech32":55,"bs58check":152,"buffer":155,"typeforce":324}],57:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./networks":157,"./payments":159,"./script":167,"./types":193,"bech32":150,"bs58check":246,"buffer":249,"typeforce":521}],152:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bufferutils_1 = require('./bufferutils'); @@ -24490,9 +40794,9 @@ function anyTxHasWitness(transactions) { ); } -}).call(this,require("buffer").Buffer) -},{"./bufferutils":58,"./crypto":60,"./transaction":96,"./types":98,"buffer":155,"merkle-lib/fastRoot":236,"typeforce":324,"varuint-bitcoin":331}],58:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bufferutils":153,"./crypto":155,"./transaction":191,"./types":193,"buffer":249,"merkle-lib/fastRoot":434,"typeforce":521,"varuint-bitcoin":528}],153:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const types = require('./types'); @@ -24637,8 +40941,8 @@ class BufferReader { } exports.BufferReader = BufferReader; -}).call(this,require("buffer").Buffer) -},{"./types":98,"buffer":155,"typeforce":324,"varuint-bitcoin":331}],59:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./types":193,"buffer":249,"typeforce":521,"varuint-bitcoin":528}],154:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const script_1 = require('./script'); @@ -24699,7 +41003,7 @@ function classifyWitness(script, allowIncomplete) { } exports.witness = classifyWitness; -},{"./script":72,"./templates/multisig":75,"./templates/nulldata":78,"./templates/pubkey":79,"./templates/pubkeyhash":82,"./templates/scripthash":85,"./templates/witnesscommitment":88,"./templates/witnesspubkeyhash":90,"./templates/witnessscripthash":93}],60:[function(require,module,exports){ +},{"./script":167,"./templates/multisig":170,"./templates/nulldata":173,"./templates/pubkey":174,"./templates/pubkeyhash":177,"./templates/scripthash":180,"./templates/witnesscommitment":183,"./templates/witnesspubkeyhash":185,"./templates/witnessscripthash":188}],155:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const createHash = require('create-hash'); @@ -24736,8 +41040,8 @@ function hash256(buffer) { } exports.hash256 = hash256; -},{"create-hash":159}],61:[function(require,module,exports){ -(function (Buffer){ +},{"create-hash":254}],156:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const NETWORKS = require('./networks'); @@ -24846,8 +41150,8 @@ function makeRandom(options) { } exports.makeRandom = makeRandom; -}).call(this,require("buffer").Buffer) -},{"./networks":62,"./types":98,"buffer":155,"randombytes":262,"tiny-secp256k1":301,"typeforce":324,"wif":332}],62:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./networks":157,"./types":193,"buffer":249,"randombytes":460,"tiny-secp256k1":498,"typeforce":521,"wif":530}],157:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.bitcoin = { @@ -24884,7 +41188,7 @@ exports.testnet = { wif: 0xef, }; -},{}],63:[function(require,module,exports){ +},{}],158:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const networks_1 = require('../networks'); @@ -24935,7 +41239,7 @@ function p2data(a, opts) { } exports.p2data = p2data; -},{"../networks":62,"../script":72,"./lazy":65,"typeforce":324}],64:[function(require,module,exports){ +},{"../networks":157,"../script":167,"./lazy":160,"typeforce":521}],159:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const embed_1 = require('./embed'); @@ -24955,7 +41259,7 @@ exports.p2wsh = p2wsh_1.p2wsh; // TODO // witness commitment -},{"./embed":63,"./p2ms":66,"./p2pk":67,"./p2pkh":68,"./p2sh":69,"./p2wpkh":70,"./p2wsh":71}],65:[function(require,module,exports){ +},{"./embed":158,"./p2ms":161,"./p2pk":162,"./p2pkh":163,"./p2sh":164,"./p2wpkh":165,"./p2wsh":166}],160:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function prop(object, name, f) { @@ -24988,7 +41292,7 @@ function value(f) { } exports.value = value; -},{}],66:[function(require,module,exports){ +},{}],161:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const networks_1 = require('../networks'); @@ -25135,7 +41439,7 @@ function p2ms(a, opts) { } exports.p2ms = p2ms; -},{"../networks":62,"../script":72,"./lazy":65,"tiny-secp256k1":301,"typeforce":324}],67:[function(require,module,exports){ +},{"../networks":157,"../script":167,"./lazy":160,"tiny-secp256k1":498,"typeforce":521}],162:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const networks_1 = require('../networks'); @@ -25209,8 +41513,8 @@ function p2pk(a, opts) { } exports.p2pk = p2pk; -},{"../networks":62,"../script":72,"./lazy":65,"tiny-secp256k1":301,"typeforce":324}],68:[function(require,module,exports){ -(function (Buffer){ +},{"../networks":157,"../script":167,"./lazy":160,"tiny-secp256k1":498,"typeforce":521}],163:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bcrypto = require('../crypto'); @@ -25344,9 +41648,9 @@ function p2pkh(a, opts) { } exports.p2pkh = p2pkh; -}).call(this,require("buffer").Buffer) -},{"../crypto":60,"../networks":62,"../script":72,"./lazy":65,"bs58check":152,"buffer":155,"tiny-secp256k1":301,"typeforce":324}],69:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":155,"../networks":157,"../script":167,"./lazy":160,"bs58check":246,"buffer":249,"tiny-secp256k1":498,"typeforce":521}],164:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bcrypto = require('../crypto'); @@ -25531,9 +41835,9 @@ function p2sh(a, opts) { } exports.p2sh = p2sh; -}).call(this,require("buffer").Buffer) -},{"../crypto":60,"../networks":62,"../script":72,"./lazy":65,"bs58check":152,"buffer":155,"typeforce":324}],70:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":155,"../networks":157,"../script":167,"./lazy":160,"bs58check":246,"buffer":249,"typeforce":521}],165:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bcrypto = require('../crypto'); @@ -25665,9 +41969,9 @@ function p2wpkh(a, opts) { } exports.p2wpkh = p2wpkh; -}).call(this,require("buffer").Buffer) -},{"../crypto":60,"../networks":62,"../script":72,"./lazy":65,"bech32":55,"buffer":155,"tiny-secp256k1":301,"typeforce":324}],71:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":155,"../networks":157,"../script":167,"./lazy":160,"bech32":150,"buffer":249,"tiny-secp256k1":498,"typeforce":521}],166:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bcrypto = require('../crypto'); @@ -25876,9 +42180,9 @@ function p2wsh(a, opts) { } exports.p2wsh = p2wsh; -}).call(this,require("buffer").Buffer) -},{"../crypto":60,"../networks":62,"../script":72,"./lazy":65,"bech32":55,"buffer":155,"tiny-secp256k1":301,"typeforce":324}],72:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../crypto":155,"../networks":157,"../script":167,"./lazy":160,"bech32":150,"buffer":249,"tiny-secp256k1":498,"typeforce":521}],167:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const scriptNumber = require('./script_number'); @@ -26057,9 +42361,9 @@ exports.isCanonicalScriptSignature = isCanonicalScriptSignature; exports.number = scriptNumber; exports.signature = scriptSignature; -}).call(this,require("buffer").Buffer) -},{"./script_number":73,"./script_signature":74,"./types":98,"bip66":52,"bitcoin-ops":53,"bitcoin-ops/map":54,"buffer":155,"pushdata-bitcoin":260,"tiny-secp256k1":301,"typeforce":324}],73:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./script_number":168,"./script_signature":169,"./types":193,"bip66":146,"bitcoin-ops":148,"bitcoin-ops/map":149,"buffer":249,"pushdata-bitcoin":458,"tiny-secp256k1":498,"typeforce":521}],168:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function decode(buffer, maxLength, minimal) { @@ -26122,9 +42426,9 @@ function encode(_number) { } exports.encode = encode; -}).call(this,require("buffer").Buffer) -},{"buffer":155}],74:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],169:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const types = require('./types'); @@ -26178,8 +42482,8 @@ function encode(signature, hashType) { } exports.encode = encode; -}).call(this,require("buffer").Buffer) -},{"./types":98,"bip66":52,"buffer":155,"typeforce":324}],75:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./types":193,"bip66":146,"buffer":249,"typeforce":521}],170:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const input = require('./input'); @@ -26187,7 +42491,7 @@ exports.input = input; const output = require('./output'); exports.output = output; -},{"./input":76,"./output":77}],76:[function(require,module,exports){ +},{"./input":171,"./output":172}],171:[function(require,module,exports){ 'use strict'; // OP_0 [signatures ...] Object.defineProperty(exports, '__esModule', { value: true }); @@ -26212,7 +42516,7 @@ check.toJSON = () => { return 'multisig input'; }; -},{"../../script":72}],77:[function(require,module,exports){ +},{"../../script":167}],172:[function(require,module,exports){ 'use strict'; // m [pubKeys ...] n OP_CHECKMULTISIG Object.defineProperty(exports, '__esModule', { value: true }); @@ -26241,7 +42545,7 @@ check.toJSON = () => { return 'multi-sig output'; }; -},{"../../script":72,"../../types":98}],78:[function(require,module,exports){ +},{"../../script":167,"../../types":193}],173:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); // OP_RETURN {data} @@ -26258,9 +42562,9 @@ check.toJSON = () => { const output = { check }; exports.output = output; -},{"../script":72}],79:[function(require,module,exports){ -arguments[4][75][0].apply(exports,arguments) -},{"./input":80,"./output":81,"dup":75}],80:[function(require,module,exports){ +},{"../script":167}],174:[function(require,module,exports){ +arguments[4][170][0].apply(exports,arguments) +},{"./input":175,"./output":176,"dup":170}],175:[function(require,module,exports){ 'use strict'; // {signature} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26274,7 +42578,7 @@ check.toJSON = () => { return 'pubKey input'; }; -},{"../../script":72}],81:[function(require,module,exports){ +},{"../../script":167}],176:[function(require,module,exports){ 'use strict'; // {pubKey} OP_CHECKSIG Object.defineProperty(exports, '__esModule', { value: true }); @@ -26293,9 +42597,9 @@ check.toJSON = () => { return 'pubKey output'; }; -},{"../../script":72}],82:[function(require,module,exports){ -arguments[4][75][0].apply(exports,arguments) -},{"./input":83,"./output":84,"dup":75}],83:[function(require,module,exports){ +},{"../../script":167}],177:[function(require,module,exports){ +arguments[4][170][0].apply(exports,arguments) +},{"./input":178,"./output":179,"dup":170}],178:[function(require,module,exports){ 'use strict'; // {signature} {pubKey} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26313,7 +42617,7 @@ check.toJSON = () => { return 'pubKeyHash input'; }; -},{"../../script":72}],84:[function(require,module,exports){ +},{"../../script":167}],179:[function(require,module,exports){ 'use strict'; // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG Object.defineProperty(exports, '__esModule', { value: true }); @@ -26335,10 +42639,10 @@ check.toJSON = () => { return 'pubKeyHash output'; }; -},{"../../script":72}],85:[function(require,module,exports){ -arguments[4][75][0].apply(exports,arguments) -},{"./input":86,"./output":87,"dup":75}],86:[function(require,module,exports){ -(function (Buffer){ +},{"../../script":167}],180:[function(require,module,exports){ +arguments[4][170][0].apply(exports,arguments) +},{"./input":181,"./output":182,"dup":170}],181:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; // {serialized scriptPubKey script} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26390,8 +42694,8 @@ check.toJSON = () => { return 'scriptHash input'; }; -}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) -},{"../../../../is-buffer/index.js":231,"../../script":72,"../multisig":75,"../pubkey":79,"../pubkeyhash":82,"../witnesspubkeyhash/output":92,"../witnessscripthash/output":95}],87:[function(require,module,exports){ +}).call(this)}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) +},{"../../../../is-buffer/index.js":351,"../../script":167,"../multisig":170,"../pubkey":174,"../pubkeyhash":177,"../witnesspubkeyhash/output":187,"../witnessscripthash/output":190}],182:[function(require,module,exports){ 'use strict'; // OP_HASH160 {scriptHash} OP_EQUAL Object.defineProperty(exports, '__esModule', { value: true }); @@ -26411,14 +42715,14 @@ check.toJSON = () => { return 'scriptHash output'; }; -},{"../../script":72}],88:[function(require,module,exports){ +},{"../../script":167}],183:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const output = require('./output'); exports.output = output; -},{"./output":89}],89:[function(require,module,exports){ -(function (Buffer){ +},{"./output":184}],184:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; // OP_RETURN {aa21a9ed} {commitment} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26454,10 +42758,10 @@ function decode(buffer) { } exports.decode = decode; -}).call(this,require("buffer").Buffer) -},{"../../script":72,"../../types":98,"buffer":155,"typeforce":324}],90:[function(require,module,exports){ -arguments[4][75][0].apply(exports,arguments) -},{"./input":91,"./output":92,"dup":75}],91:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"../../script":167,"../../types":193,"buffer":249,"typeforce":521}],185:[function(require,module,exports){ +arguments[4][170][0].apply(exports,arguments) +},{"./input":186,"./output":187,"dup":170}],186:[function(require,module,exports){ 'use strict'; // {signature} {pubKey} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26478,7 +42782,7 @@ check.toJSON = () => { return 'witnessPubKeyHash input'; }; -},{"../../script":72}],92:[function(require,module,exports){ +},{"../../script":167}],187:[function(require,module,exports){ 'use strict'; // OP_0 {pubKeyHash} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26497,10 +42801,10 @@ check.toJSON = () => { return 'Witness pubKeyHash output'; }; -},{"../../script":72}],93:[function(require,module,exports){ -arguments[4][75][0].apply(exports,arguments) -},{"./input":94,"./output":95,"dup":75}],94:[function(require,module,exports){ -(function (Buffer){ +},{"../../script":167}],188:[function(require,module,exports){ +arguments[4][170][0].apply(exports,arguments) +},{"./input":189,"./output":190,"dup":170}],189:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; // {serialized scriptPubKey script} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26541,8 +42845,8 @@ check.toJSON = () => { return 'witnessScriptHash input'; }; -}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) -},{"../../../../is-buffer/index.js":231,"../../script":72,"../multisig":75,"../pubkey":79,"../pubkeyhash":82,"typeforce":324}],95:[function(require,module,exports){ +}).call(this)}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")}) +},{"../../../../is-buffer/index.js":351,"../../script":167,"../multisig":170,"../pubkey":174,"../pubkeyhash":177,"typeforce":521}],190:[function(require,module,exports){ 'use strict'; // OP_0 {scriptHash} Object.defineProperty(exports, '__esModule', { value: true }); @@ -26561,8 +42865,8 @@ check.toJSON = () => { return 'Witness scriptHash output'; }; -},{"../../script":72}],96:[function(require,module,exports){ -(function (Buffer){ +},{"../../script":167}],191:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bufferutils_1 = require('./bufferutils'); @@ -26966,9 +43270,9 @@ Transaction.ADVANCED_TRANSACTION_MARKER = 0x00; Transaction.ADVANCED_TRANSACTION_FLAG = 0x01; exports.Transaction = Transaction; -}).call(this,require("buffer").Buffer) -},{"./bufferutils":58,"./crypto":60,"./script":72,"./types":98,"buffer":155,"typeforce":324,"varuint-bitcoin":331}],97:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bufferutils":153,"./crypto":155,"./script":167,"./types":193,"buffer":249,"typeforce":521,"varuint-bitcoin":528}],192:[function(require,module,exports){ +(function (Buffer){(function (){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const baddress = require('./address'); @@ -28035,8 +44339,8 @@ function getSigningData( }; } -}).call(this,require("buffer").Buffer) -},{"./address":56,"./bufferutils":58,"./classify":59,"./crypto":60,"./ecpair":61,"./networks":62,"./payments":64,"./script":72,"./transaction":96,"./types":98,"buffer":155,"typeforce":324}],98:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./address":151,"./bufferutils":153,"./classify":154,"./crypto":155,"./ecpair":156,"./networks":157,"./payments":159,"./script":167,"./transaction":191,"./types":193,"buffer":249,"typeforce":521}],193:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const typeforce = require('typeforce'); @@ -28096,7 +44400,7 @@ exports.BufferN = typeforce.BufferN; exports.Null = typeforce.Null; exports.oneOf = typeforce.oneOf; -},{"typeforce":324}],99:[function(require,module,exports){ +},{"typeforce":521}],194:[function(require,module,exports){ // Blake2B in pure Javascript // Adapted from the reference implementation in RFC7693 // Ported to Javascript by DC - https://github.com/dcposch @@ -28371,7 +44675,7 @@ module.exports = { blake2bFinal: blake2bFinal } -},{"./util":102}],100:[function(require,module,exports){ +},{"./util":197}],195:[function(require,module,exports){ // BLAKE2s hash function in pure Javascript // Adapted from the reference implementation in RFC7693 // Ported to Javascript by DC - https://github.com/dcposch @@ -28563,7 +44867,7 @@ module.exports = { blake2sFinal: blake2sFinal } -},{"./util":102}],101:[function(require,module,exports){ +},{"./util":197}],196:[function(require,module,exports){ var b2b = require('./blake2b') var b2s = require('./blake2s') @@ -28580,8 +44884,8 @@ module.exports = { blake2sFinal: b2s.blake2sFinal } -},{"./blake2b":99,"./blake2s":100}],102:[function(require,module,exports){ -(function (Buffer){ +},{"./blake2b":194,"./blake2s":195}],197:[function(require,module,exports){ +(function (Buffer){(function (){ var ERROR_MSG_INPUT = 'Input must be an string, Buffer or Uint8Array' // For convenience, let people hash a string, not just a Uint8Array @@ -28664,8 +44968,8 @@ module.exports = { testSpeed: testSpeed } -}).call(this,require("buffer").Buffer) -},{"buffer":155}],103:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],198:[function(require,module,exports){ (function (module, exports) { 'use strict'; @@ -32100,7 +48404,7 @@ module.exports = { }; })(typeof module === 'undefined' || module, this); -},{"buffer":105}],104:[function(require,module,exports){ +},{"buffer":200}],199:[function(require,module,exports){ var r; module.exports = function rand(len) { @@ -32167,9 +48471,9 @@ if (typeof self === 'object') { } } -},{"crypto":105}],105:[function(require,module,exports){ +},{"crypto":200}],200:[function(require,module,exports){ -},{}],106:[function(require,module,exports){ +},{}],201:[function(require,module,exports){ // based on the aes implimentation in triple sec // https://github.com/keybase/triplesec // which is in turn based on the one from crypto-js @@ -32399,7 +48703,7 @@ AES.prototype.scrub = function () { module.exports.AES = AES -},{"safe-buffer":280}],107:[function(require,module,exports){ +},{"safe-buffer":463}],202:[function(require,module,exports){ var aes = require('./aes') var Buffer = require('safe-buffer').Buffer var Transform = require('cipher-base') @@ -32518,7 +48822,7 @@ StreamCipher.prototype.setAAD = function setAAD (buf) { module.exports = StreamCipher -},{"./aes":106,"./ghash":111,"./incr32":112,"buffer-xor":153,"cipher-base":156,"inherits":230,"safe-buffer":280}],108:[function(require,module,exports){ +},{"./aes":201,"./ghash":206,"./incr32":207,"buffer-xor":247,"cipher-base":252,"inherits":349,"safe-buffer":463}],203:[function(require,module,exports){ var ciphers = require('./encrypter') var deciphers = require('./decrypter') var modes = require('./modes/list.json') @@ -32533,7 +48837,7 @@ exports.createDecipher = exports.Decipher = deciphers.createDecipher exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv exports.listCiphers = exports.getCiphers = getCiphers -},{"./decrypter":109,"./encrypter":110,"./modes/list.json":120}],109:[function(require,module,exports){ +},{"./decrypter":204,"./encrypter":205,"./modes/list.json":215}],204:[function(require,module,exports){ var AuthCipher = require('./authCipher') var Buffer = require('safe-buffer').Buffer var MODES = require('./modes') @@ -32659,7 +48963,7 @@ function createDecipher (suite, password) { exports.createDecipher = createDecipher exports.createDecipheriv = createDecipheriv -},{"./aes":106,"./authCipher":107,"./modes":119,"./streamCipher":122,"cipher-base":156,"evp_bytestokey":196,"inherits":230,"safe-buffer":280}],110:[function(require,module,exports){ +},{"./aes":201,"./authCipher":202,"./modes":214,"./streamCipher":217,"cipher-base":252,"evp_bytestokey":305,"inherits":349,"safe-buffer":463}],205:[function(require,module,exports){ var MODES = require('./modes') var AuthCipher = require('./authCipher') var Buffer = require('safe-buffer').Buffer @@ -32775,7 +49079,7 @@ function createCipher (suite, password) { exports.createCipheriv = createCipheriv exports.createCipher = createCipher -},{"./aes":106,"./authCipher":107,"./modes":119,"./streamCipher":122,"cipher-base":156,"evp_bytestokey":196,"inherits":230,"safe-buffer":280}],111:[function(require,module,exports){ +},{"./aes":201,"./authCipher":202,"./modes":214,"./streamCipher":217,"cipher-base":252,"evp_bytestokey":305,"inherits":349,"safe-buffer":463}],206:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer var ZEROES = Buffer.alloc(16, 0) @@ -32866,7 +49170,7 @@ GHASH.prototype.final = function (abl, bl) { module.exports = GHASH -},{"safe-buffer":280}],112:[function(require,module,exports){ +},{"safe-buffer":463}],207:[function(require,module,exports){ function incr32 (iv) { var len = iv.length var item @@ -32883,7 +49187,7 @@ function incr32 (iv) { } module.exports = incr32 -},{}],113:[function(require,module,exports){ +},{}],208:[function(require,module,exports){ var xor = require('buffer-xor') exports.encrypt = function (self, block) { @@ -32902,7 +49206,7 @@ exports.decrypt = function (self, block) { return xor(out, pad) } -},{"buffer-xor":153}],114:[function(require,module,exports){ +},{"buffer-xor":247}],209:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer var xor = require('buffer-xor') @@ -32937,7 +49241,7 @@ exports.encrypt = function (self, data, decrypt) { return out } -},{"buffer-xor":153,"safe-buffer":280}],115:[function(require,module,exports){ +},{"buffer-xor":247,"safe-buffer":463}],210:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer function encryptByte (self, byteParam, decrypt) { @@ -32981,7 +49285,7 @@ exports.encrypt = function (self, chunk, decrypt) { return out } -},{"safe-buffer":280}],116:[function(require,module,exports){ +},{"safe-buffer":463}],211:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer function encryptByte (self, byteParam, decrypt) { @@ -33008,7 +49312,7 @@ exports.encrypt = function (self, chunk, decrypt) { return out } -},{"safe-buffer":280}],117:[function(require,module,exports){ +},{"safe-buffer":463}],212:[function(require,module,exports){ var xor = require('buffer-xor') var Buffer = require('safe-buffer').Buffer var incr32 = require('../incr32') @@ -33040,7 +49344,7 @@ exports.encrypt = function (self, chunk) { return xor(chunk, pad) } -},{"../incr32":112,"buffer-xor":153,"safe-buffer":280}],118:[function(require,module,exports){ +},{"../incr32":207,"buffer-xor":247,"safe-buffer":463}],213:[function(require,module,exports){ exports.encrypt = function (self, block) { return self._cipher.encryptBlock(block) } @@ -33049,7 +49353,7 @@ exports.decrypt = function (self, block) { return self._cipher.decryptBlock(block) } -},{}],119:[function(require,module,exports){ +},{}],214:[function(require,module,exports){ var modeModules = { ECB: require('./ecb'), CBC: require('./cbc'), @@ -33069,7 +49373,7 @@ for (var key in modes) { module.exports = modes -},{"./cbc":113,"./cfb":114,"./cfb1":115,"./cfb8":116,"./ctr":117,"./ecb":118,"./list.json":120,"./ofb":121}],120:[function(require,module,exports){ +},{"./cbc":208,"./cfb":209,"./cfb1":210,"./cfb8":211,"./ctr":212,"./ecb":213,"./list.json":215,"./ofb":216}],215:[function(require,module,exports){ module.exports={ "aes-128-ecb": { "cipher": "AES", @@ -33262,8 +49566,8 @@ module.exports={ } } -},{}],121:[function(require,module,exports){ -(function (Buffer){ +},{}],216:[function(require,module,exports){ +(function (Buffer){(function (){ var xor = require('buffer-xor') function getBlock (self) { @@ -33281,8 +49585,8 @@ exports.encrypt = function (self, chunk) { return xor(chunk, pad) } -}).call(this,require("buffer").Buffer) -},{"buffer":155,"buffer-xor":153}],122:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249,"buffer-xor":247}],217:[function(require,module,exports){ var aes = require('./aes') var Buffer = require('safe-buffer').Buffer var Transform = require('cipher-base') @@ -33311,7 +49615,7 @@ StreamCipher.prototype._final = function () { module.exports = StreamCipher -},{"./aes":106,"cipher-base":156,"inherits":230,"safe-buffer":280}],123:[function(require,module,exports){ +},{"./aes":201,"cipher-base":252,"inherits":349,"safe-buffer":463}],218:[function(require,module,exports){ var DES = require('browserify-des') var aes = require('browserify-aes/browser') var aesModes = require('browserify-aes/modes') @@ -33380,7 +49684,7 @@ exports.createDecipher = exports.Decipher = createDecipher exports.createDecipheriv = exports.Decipheriv = createDecipheriv exports.listCiphers = exports.getCiphers = getCiphers -},{"browserify-aes/browser":108,"browserify-aes/modes":119,"browserify-des":124,"browserify-des/modes":125,"evp_bytestokey":196}],124:[function(require,module,exports){ +},{"browserify-aes/browser":203,"browserify-aes/modes":214,"browserify-des":219,"browserify-des/modes":220,"evp_bytestokey":305}],219:[function(require,module,exports){ var CipherBase = require('cipher-base') var des = require('des.js') var inherits = require('inherits') @@ -33432,7 +49736,7 @@ DES.prototype._final = function () { return Buffer.from(this._des.final()) } -},{"cipher-base":156,"des.js":164,"inherits":230,"safe-buffer":280}],125:[function(require,module,exports){ +},{"cipher-base":252,"des.js":260,"inherits":349,"safe-buffer":463}],220:[function(require,module,exports){ exports['des-ecb'] = { key: 8, iv: 0 @@ -33458,8 +49762,8 @@ exports['des-ede'] = { iv: 0 } -},{}],126:[function(require,module,exports){ -(function (Buffer){ +},{}],221:[function(require,module,exports){ +(function (Buffer){(function (){ var bn = require('bn.js'); var randomBytes = require('randombytes'); module.exports = crt; @@ -33501,11 +49805,11 @@ function getr(priv) { return r; } -}).call(this,require("buffer").Buffer) -},{"bn.js":103,"buffer":155,"randombytes":262}],127:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"bn.js":198,"buffer":249,"randombytes":460}],222:[function(require,module,exports){ module.exports = require('./browser/algorithms.json') -},{"./browser/algorithms.json":128}],128:[function(require,module,exports){ +},{"./browser/algorithms.json":223}],223:[function(require,module,exports){ module.exports={ "sha224WithRSAEncryption": { "sign": "rsa", @@ -33659,7 +49963,7 @@ module.exports={ } } -},{}],129:[function(require,module,exports){ +},{}],224:[function(require,module,exports){ module.exports={ "1.3.132.0.10": "secp256k1", "1.3.132.0.33": "p224", @@ -33669,7 +49973,7 @@ module.exports={ "1.3.132.0.35": "p521" } -},{}],130:[function(require,module,exports){ +},{}],225:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer var createHash = require('create-hash') var stream = require('readable-stream') @@ -33763,7 +50067,7 @@ module.exports = { createVerify: createVerify } -},{"./algorithms.json":128,"./sign":131,"./verify":132,"create-hash":159,"inherits":230,"readable-stream":148,"safe-buffer":280}],131:[function(require,module,exports){ +},{"./algorithms.json":223,"./sign":226,"./verify":227,"create-hash":254,"inherits":349,"readable-stream":243,"safe-buffer":463}],226:[function(require,module,exports){ // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js var Buffer = require('safe-buffer').Buffer var createHmac = require('create-hmac') @@ -33908,7 +50212,7 @@ module.exports = sign module.exports.getKey = getKey module.exports.makeKey = makeKey -},{"./curves.json":129,"bn.js":133,"browserify-rsa":126,"create-hmac":161,"elliptic":179,"parse-asn1":245,"safe-buffer":280}],132:[function(require,module,exports){ +},{"./curves.json":224,"bn.js":228,"browserify-rsa":221,"create-hmac":256,"elliptic":280,"parse-asn1":443,"safe-buffer":463}],227:[function(require,module,exports){ // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js var Buffer = require('safe-buffer').Buffer var BN = require('bn.js') @@ -33994,7 +50298,7 @@ function checkValue (b, q) { module.exports = verify -},{"./curves.json":129,"bn.js":133,"elliptic":179,"parse-asn1":245,"safe-buffer":280}],133:[function(require,module,exports){ +},{"./curves.json":224,"bn.js":228,"elliptic":280,"parse-asn1":443,"safe-buffer":463}],228:[function(require,module,exports){ (function (module, exports) { 'use strict'; @@ -37536,7 +53840,7 @@ module.exports = verify }; })(typeof module === 'undefined' || module, this); -},{"buffer":105}],134:[function(require,module,exports){ +},{"buffer":200}],229:[function(require,module,exports){ 'use strict'; function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } @@ -37665,8 +53969,8 @@ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) { createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event'); module.exports.codes = codes; -},{}],135:[function(require,module,exports){ -(function (process){ +},{}],230:[function(require,module,exports){ +(function (process){(function (){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -37806,8 +54110,8 @@ Object.defineProperty(Duplex.prototype, 'destroyed', { this._writableState.destroyed = value; } }); -}).call(this,require('_process')) -},{"./_stream_readable":137,"./_stream_writable":139,"_process":253,"inherits":230}],136:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"./_stream_readable":232,"./_stream_writable":234,"_process":451,"inherits":349}],231:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -37847,8 +54151,8 @@ function PassThrough(options) { PassThrough.prototype._transform = function (chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":138,"inherits":230}],137:[function(require,module,exports){ -(function (process,global){ +},{"./_stream_transform":233,"inherits":349}],232:[function(require,module,exports){ +(function (process,global){(function (){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -38973,8 +55277,8 @@ function indexOf(xs, x) { return -1; } -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../errors":134,"./_stream_duplex":135,"./internal/streams/async_iterator":140,"./internal/streams/buffer_list":141,"./internal/streams/destroy":142,"./internal/streams/from":144,"./internal/streams/state":146,"./internal/streams/stream":147,"_process":253,"buffer":155,"events":195,"inherits":230,"string_decoder/":149,"util":105}],138:[function(require,module,exports){ +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../errors":229,"./_stream_duplex":230,"./internal/streams/async_iterator":235,"./internal/streams/buffer_list":236,"./internal/streams/destroy":237,"./internal/streams/from":239,"./internal/streams/state":241,"./internal/streams/stream":242,"_process":451,"buffer":249,"events":304,"inherits":349,"string_decoder/":496,"util":200}],233:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -39176,8 +55480,8 @@ function done(stream, er, data) { if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING(); return stream.push(null); } -},{"../errors":134,"./_stream_duplex":135,"inherits":230}],139:[function(require,module,exports){ -(function (process,global){ +},{"../errors":229,"./_stream_duplex":230,"inherits":349}],234:[function(require,module,exports){ +(function (process,global){(function (){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -39875,9 +56179,9 @@ Writable.prototype._undestroy = destroyImpl.undestroy; Writable.prototype._destroy = function (err, cb) { cb(err); }; -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"../errors":134,"./_stream_duplex":135,"./internal/streams/destroy":142,"./internal/streams/state":146,"./internal/streams/stream":147,"_process":253,"buffer":155,"inherits":230,"util-deprecate":327}],140:[function(require,module,exports){ -(function (process){ +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../errors":229,"./_stream_duplex":230,"./internal/streams/destroy":237,"./internal/streams/state":241,"./internal/streams/stream":242,"_process":451,"buffer":249,"inherits":349,"util-deprecate":524}],235:[function(require,module,exports){ +(function (process){(function (){ 'use strict'; var _Object$setPrototypeO; @@ -40085,8 +56389,8 @@ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterat }; module.exports = createReadableStreamAsyncIterator; -}).call(this,require('_process')) -},{"./end-of-stream":143,"_process":253}],141:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"./end-of-stream":238,"_process":451}],236:[function(require,module,exports){ 'use strict'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } @@ -40297,8 +56601,8 @@ function () { return BufferList; }(); -},{"buffer":155,"util":105}],142:[function(require,module,exports){ -(function (process){ +},{"buffer":249,"util":200}],237:[function(require,module,exports){ +(function (process){(function (){ 'use strict'; // undocumented cb() API, needed for core, not for public API function destroy(err, cb) { @@ -40404,8 +56708,8 @@ module.exports = { undestroy: undestroy, errorOrDestroy: errorOrDestroy }; -}).call(this,require('_process')) -},{"_process":253}],143:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"_process":451}],238:[function(require,module,exports){ // Ported from https://github.com/mafintosh/end-of-stream with // permission from the author, Mathias Buus (@mafintosh). 'use strict'; @@ -40510,12 +56814,12 @@ function eos(stream, opts, callback) { } module.exports = eos; -},{"../../../errors":134}],144:[function(require,module,exports){ +},{"../../../errors":229}],239:[function(require,module,exports){ module.exports = function () { throw new Error('Readable.from is not available in the browser') }; -},{}],145:[function(require,module,exports){ +},{}],240:[function(require,module,exports){ // Ported from https://github.com/mafintosh/pump with // permission from the author, Mathias Buus (@mafintosh). 'use strict'; @@ -40613,7 +56917,7 @@ function pipeline() { } module.exports = pipeline; -},{"../../../errors":134,"./end-of-stream":143}],146:[function(require,module,exports){ +},{"../../../errors":229,"./end-of-stream":238}],241:[function(require,module,exports){ 'use strict'; var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; @@ -40641,10 +56945,10 @@ function getHighWaterMark(state, options, duplexKey, isDuplex) { module.exports = { getHighWaterMark: getHighWaterMark }; -},{"../../../errors":134}],147:[function(require,module,exports){ +},{"../../../errors":229}],242:[function(require,module,exports){ module.exports = require('events').EventEmitter; -},{"events":195}],148:[function(require,module,exports){ +},{"events":304}],243:[function(require,module,exports){ exports = module.exports = require('./lib/_stream_readable.js'); exports.Stream = exports; exports.Readable = exports; @@ -40655,310 +56959,13 @@ exports.PassThrough = require('./lib/_stream_passthrough.js'); exports.finished = require('./lib/internal/streams/end-of-stream.js'); exports.pipeline = require('./lib/internal/streams/pipeline.js'); -},{"./lib/_stream_duplex.js":135,"./lib/_stream_passthrough.js":136,"./lib/_stream_readable.js":137,"./lib/_stream_transform.js":138,"./lib/_stream_writable.js":139,"./lib/internal/streams/end-of-stream.js":143,"./lib/internal/streams/pipeline.js":145}],149:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -/**/ - -var Buffer = require('safe-buffer').Buffer; -/**/ - -var isEncoding = Buffer.isEncoding || function (encoding) { - encoding = '' + encoding; - switch (encoding && encoding.toLowerCase()) { - case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw': - return true; - default: - return false; - } -}; - -function _normalizeEncoding(enc) { - if (!enc) return 'utf8'; - var retried; - while (true) { - switch (enc) { - case 'utf8': - case 'utf-8': - return 'utf8'; - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return 'utf16le'; - case 'latin1': - case 'binary': - return 'latin1'; - case 'base64': - case 'ascii': - case 'hex': - return enc; - default: - if (retried) return; // undefined - enc = ('' + enc).toLowerCase(); - retried = true; - } - } -}; - -// Do not cache `Buffer.isEncoding` when checking encoding names as some -// modules monkey-patch it to support additional encodings -function normalizeEncoding(enc) { - var nenc = _normalizeEncoding(enc); - if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc); - return nenc || enc; -} - -// StringDecoder provides an interface for efficiently splitting a series of -// buffers into a series of JS strings without breaking apart multi-byte -// characters. -exports.StringDecoder = StringDecoder; -function StringDecoder(encoding) { - this.encoding = normalizeEncoding(encoding); - var nb; - switch (this.encoding) { - case 'utf16le': - this.text = utf16Text; - this.end = utf16End; - nb = 4; - break; - case 'utf8': - this.fillLast = utf8FillLast; - nb = 4; - break; - case 'base64': - this.text = base64Text; - this.end = base64End; - nb = 3; - break; - default: - this.write = simpleWrite; - this.end = simpleEnd; - return; - } - this.lastNeed = 0; - this.lastTotal = 0; - this.lastChar = Buffer.allocUnsafe(nb); -} - -StringDecoder.prototype.write = function (buf) { - if (buf.length === 0) return ''; - var r; - var i; - if (this.lastNeed) { - r = this.fillLast(buf); - if (r === undefined) return ''; - i = this.lastNeed; - this.lastNeed = 0; - } else { - i = 0; - } - if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i); - return r || ''; -}; - -StringDecoder.prototype.end = utf8End; - -// Returns only complete characters in a Buffer -StringDecoder.prototype.text = utf8Text; - -// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer -StringDecoder.prototype.fillLast = function (buf) { - if (this.lastNeed <= buf.length) { - buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); - return this.lastChar.toString(this.encoding, 0, this.lastTotal); - } - buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length); - this.lastNeed -= buf.length; -}; - -// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a -// continuation byte. If an invalid byte is detected, -2 is returned. -function utf8CheckByte(byte) { - if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4; - return byte >> 6 === 0x02 ? -1 : -2; -} - -// Checks at most 3 bytes at the end of a Buffer in order to detect an -// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4) -// needed to complete the UTF-8 character (if applicable) are returned. -function utf8CheckIncomplete(self, buf, i) { - var j = buf.length - 1; - if (j < i) return 0; - var nb = utf8CheckByte(buf[j]); - if (nb >= 0) { - if (nb > 0) self.lastNeed = nb - 1; - return nb; - } - if (--j < i || nb === -2) return 0; - nb = utf8CheckByte(buf[j]); - if (nb >= 0) { - if (nb > 0) self.lastNeed = nb - 2; - return nb; - } - if (--j < i || nb === -2) return 0; - nb = utf8CheckByte(buf[j]); - if (nb >= 0) { - if (nb > 0) { - if (nb === 2) nb = 0;else self.lastNeed = nb - 3; - } - return nb; - } - return 0; -} - -// Validates as many continuation bytes for a multi-byte UTF-8 character as -// needed or are available. If we see a non-continuation byte where we expect -// one, we "replace" the validated continuation bytes we've seen so far with -// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding -// behavior. The continuation byte check is included three times in the case -// where all of the continuation bytes for a character exist in the same buffer. -// It is also done this way as a slight performance increase instead of using a -// loop. -function utf8CheckExtraBytes(self, buf, p) { - if ((buf[0] & 0xC0) !== 0x80) { - self.lastNeed = 0; - return '\ufffd'; - } - if (self.lastNeed > 1 && buf.length > 1) { - if ((buf[1] & 0xC0) !== 0x80) { - self.lastNeed = 1; - return '\ufffd'; - } - if (self.lastNeed > 2 && buf.length > 2) { - if ((buf[2] & 0xC0) !== 0x80) { - self.lastNeed = 2; - return '\ufffd'; - } - } - } -} - -// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer. -function utf8FillLast(buf) { - var p = this.lastTotal - this.lastNeed; - var r = utf8CheckExtraBytes(this, buf, p); - if (r !== undefined) return r; - if (this.lastNeed <= buf.length) { - buf.copy(this.lastChar, p, 0, this.lastNeed); - return this.lastChar.toString(this.encoding, 0, this.lastTotal); - } - buf.copy(this.lastChar, p, 0, buf.length); - this.lastNeed -= buf.length; -} - -// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a -// partial character, the character's bytes are buffered until the required -// number of bytes are available. -function utf8Text(buf, i) { - var total = utf8CheckIncomplete(this, buf, i); - if (!this.lastNeed) return buf.toString('utf8', i); - this.lastTotal = total; - var end = buf.length - (total - this.lastNeed); - buf.copy(this.lastChar, 0, end); - return buf.toString('utf8', i, end); -} - -// For UTF-8, a replacement character is added when ending on a partial -// character. -function utf8End(buf) { - var r = buf && buf.length ? this.write(buf) : ''; - if (this.lastNeed) return r + '\ufffd'; - return r; -} - -// UTF-16LE typically needs two bytes per character, but even if we have an even -// number of bytes available, we need to check if we end on a leading/high -// surrogate. In that case, we need to wait for the next two bytes in order to -// decode the last character properly. -function utf16Text(buf, i) { - if ((buf.length - i) % 2 === 0) { - var r = buf.toString('utf16le', i); - if (r) { - var c = r.charCodeAt(r.length - 1); - if (c >= 0xD800 && c <= 0xDBFF) { - this.lastNeed = 2; - this.lastTotal = 4; - this.lastChar[0] = buf[buf.length - 2]; - this.lastChar[1] = buf[buf.length - 1]; - return r.slice(0, -1); - } - } - return r; - } - this.lastNeed = 1; - this.lastTotal = 2; - this.lastChar[0] = buf[buf.length - 1]; - return buf.toString('utf16le', i, buf.length - 1); -} - -// For UTF-16LE we do not explicitly append special replacement characters if we -// end on a partial character, we simply let v8 handle that. -function utf16End(buf) { - var r = buf && buf.length ? this.write(buf) : ''; - if (this.lastNeed) { - var end = this.lastTotal - this.lastNeed; - return r + this.lastChar.toString('utf16le', 0, end); - } - return r; -} - -function base64Text(buf, i) { - var n = (buf.length - i) % 3; - if (n === 0) return buf.toString('base64', i); - this.lastNeed = 3 - n; - this.lastTotal = 3; - if (n === 1) { - this.lastChar[0] = buf[buf.length - 1]; - } else { - this.lastChar[0] = buf[buf.length - 2]; - this.lastChar[1] = buf[buf.length - 1]; - } - return buf.toString('base64', i, buf.length - n); -} - -function base64End(buf) { - var r = buf && buf.length ? this.write(buf) : ''; - if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed); - return r; -} - -// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex) -function simpleWrite(buf) { - return buf.toString(this.encoding); -} - -function simpleEnd(buf) { - return buf && buf.length ? this.write(buf) : ''; -} -},{"safe-buffer":280}],150:[function(require,module,exports){ +},{"./lib/_stream_duplex.js":230,"./lib/_stream_passthrough.js":231,"./lib/_stream_readable.js":232,"./lib/_stream_transform.js":233,"./lib/_stream_writable.js":234,"./lib/internal/streams/end-of-stream.js":238,"./lib/internal/streams/pipeline.js":240}],244:[function(require,module,exports){ var basex = require('base-x') var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' module.exports = basex(ALPHABET) -},{"base-x":25}],151:[function(require,module,exports){ +},{"base-x":118}],245:[function(require,module,exports){ 'use strict' var base58 = require('bs58') @@ -41010,7 +57017,7 @@ module.exports = function (checksumFn) { } } -},{"bs58":150,"safe-buffer":280}],152:[function(require,module,exports){ +},{"bs58":244,"safe-buffer":463}],246:[function(require,module,exports){ 'use strict' var createHash = require('create-hash') @@ -41024,8 +57031,8 @@ function sha256x2 (buffer) { module.exports = bs58checkBase(sha256x2) -},{"./base":151,"create-hash":159}],153:[function(require,module,exports){ -(function (Buffer){ +},{"./base":245,"create-hash":254}],247:[function(require,module,exports){ +(function (Buffer){(function (){ module.exports = function xor (a, b) { var length = Math.min(a.length, b.length) var buffer = new Buffer(length) @@ -41037,8 +57044,8 @@ module.exports = function xor (a, b) { return buffer } -}).call(this,require("buffer").Buffer) -},{"buffer":155}],154:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],248:[function(require,module,exports){ module.exports = function xorInplace (a, b) { var length = Math.min(a.length, b.length) @@ -41049,8 +57056,8 @@ module.exports = function xorInplace (a, b) { return a.slice(0, length) } -},{}],155:[function(require,module,exports){ -(function (Buffer){ +},{}],249:[function(require,module,exports){ +(function (Buffer){(function (){ /*! * The buffer module from node.js, for the browser. * @@ -41063,10 +57070,6 @@ module.exports = function xorInplace (a, b) { var base64 = require('base64-js') var ieee754 = require('ieee754') -var customInspectSymbol = - (typeof Symbol === 'function' && typeof Symbol.for === 'function') - ? Symbol.for('nodejs.util.inspect.custom') - : null exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer @@ -41103,9 +57106,7 @@ function typedArraySupport () { // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) - var proto = { foo: function () { return 42 } } - Object.setPrototypeOf(proto, Uint8Array.prototype) - Object.setPrototypeOf(arr, proto) + arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } return arr.foo() === 42 } catch (e) { return false @@ -41134,7 +57135,7 @@ function createBuffer (length) { } // Return an augmented `Uint8Array` instance var buf = new Uint8Array(length) - Object.setPrototypeOf(buf, Buffer.prototype) + buf.__proto__ = Buffer.prototype return buf } @@ -41161,6 +57162,17 @@ function Buffer (arg, encodingOrOffset, length) { return from(arg, encodingOrOffset, length) } +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species != null && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) +} + Buffer.poolSize = 8192 // not used by this implementation function from (value, encodingOrOffset, length) { @@ -41173,7 +57185,7 @@ function from (value, encodingOrOffset, length) { } if (value == null) { - throw new TypeError( + throw TypeError( 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + (typeof value) ) @@ -41184,12 +57196,6 @@ function from (value, encodingOrOffset, length) { return fromArrayBuffer(value, encodingOrOffset, length) } - if (typeof SharedArrayBuffer !== 'undefined' && - (isInstance(value, SharedArrayBuffer) || - (value && isInstance(value.buffer, SharedArrayBuffer)))) { - return fromArrayBuffer(value, encodingOrOffset, length) - } - if (typeof value === 'number') { throw new TypeError( 'The "value" argument must not be of type number. Received type number' @@ -41231,8 +57237,8 @@ Buffer.from = function (value, encodingOrOffset, length) { // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: // https://github.com/feross/buffer/pull/148 -Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype) -Object.setPrototypeOf(Buffer, Uint8Array) +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array function assertSize (size) { if (typeof size !== 'number') { @@ -41336,8 +57342,7 @@ function fromArrayBuffer (array, byteOffset, length) { } // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(buf, Buffer.prototype) - + buf.__proto__ = Buffer.prototype return buf } @@ -41659,9 +57664,6 @@ Buffer.prototype.inspect = function inspect () { if (this.length > max) str += ' ... ' return '' } -if (customInspectSymbol) { - Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect -} Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { if (isInstance(target, Uint8Array)) { @@ -41787,7 +57789,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) } } - return arrayIndexOf(buffer, [val], byteOffset, encoding, dir) + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) } throw new TypeError('val must be string, number or Buffer') @@ -42116,7 +58118,7 @@ function hexSlice (buf, start, end) { var out = '' for (var i = start; i < end; ++i) { - out += hexSliceLookupTable[buf[i]] + out += toHex(buf[i]) } return out } @@ -42153,8 +58155,7 @@ Buffer.prototype.slice = function slice (start, end) { var newBuf = this.subarray(start, end) // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(newBuf, Buffer.prototype) - + newBuf.__proto__ = Buffer.prototype return newBuf } @@ -42643,8 +58644,6 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } } else if (typeof val === 'number') { val = val & 255 - } else if (typeof val === 'boolean') { - val = Number(val) } // Invalid ranges are not set to a default, so can range check early. @@ -42702,6 +58701,11 @@ function base64clean (str) { return str } +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) +} + function utf8ToBytes (string, units) { units = units || Infinity var codePoint @@ -42832,22 +58836,62 @@ function numberIsNaN (obj) { return obj !== obj // eslint-disable-line no-self-compare } -// Create lookup table for `toString('hex')` -// See: https://github.com/feross/buffer/issues/219 -var hexSliceLookupTable = (function () { - var alphabet = '0123456789abcdef' - var table = new Array(256) - for (var i = 0; i < 16; ++i) { - var i16 = i * 16 - for (var j = 0; j < 16; ++j) { - table[i16 + j] = alphabet[i] + alphabet[j] - } - } - return table -})() +}).call(this)}).call(this,require("buffer").Buffer) +},{"base64-js":119,"buffer":249,"ieee754":348}],250:[function(require,module,exports){ +'use strict'; + +var GetIntrinsic = require('get-intrinsic'); + +var callBind = require('./'); + +var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf')); + +module.exports = function callBoundIntrinsic(name, allowMissing) { + var intrinsic = GetIntrinsic(name, !!allowMissing); + if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) { + return callBind(intrinsic); + } + return intrinsic; +}; + +},{"./":251,"get-intrinsic":310}],251:[function(require,module,exports){ +'use strict'; + +var bind = require('function-bind'); +var GetIntrinsic = require('get-intrinsic'); +var setFunctionLength = require('set-function-length'); + +var $TypeError = require('es-errors/type'); +var $apply = GetIntrinsic('%Function.prototype.apply%'); +var $call = GetIntrinsic('%Function.prototype.call%'); +var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); + +var $defineProperty = require('es-define-property'); +var $max = GetIntrinsic('%Math.max%'); -}).call(this,require("buffer").Buffer) -},{"base64-js":26,"buffer":155,"ieee754":229}],156:[function(require,module,exports){ +module.exports = function callBind(originalFunction) { + if (typeof originalFunction !== 'function') { + throw new $TypeError('a function is required'); + } + var func = $reflectApply(bind, $call, arguments); + return setFunctionLength( + func, + 1 + $max(0, originalFunction.length - (arguments.length - 1)), + true + ); +}; + +var applyBind = function applyBind() { + return $reflectApply(bind, $apply, arguments); +}; + +if ($defineProperty) { + $defineProperty(module.exports, 'apply', { value: applyBind }); +} else { + module.exports.apply = applyBind; +} + +},{"es-define-property":296,"es-errors/type":302,"function-bind":309,"get-intrinsic":310,"set-function-length":471}],252:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer var Transform = require('stream').Transform var StringDecoder = require('string_decoder').StringDecoder @@ -42948,119 +58992,8 @@ CipherBase.prototype._toString = function (value, enc, fin) { module.exports = CipherBase -},{"inherits":230,"safe-buffer":280,"stream":297,"string_decoder":298}],157:[function(require,module,exports){ -(function (Buffer){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// NOTE: These type checking functions intentionally don't use `instanceof` -// because it is fragile and can be easily faked with `Object.create()`. - -function isArray(arg) { - if (Array.isArray) { - return Array.isArray(arg); - } - return objectToString(arg) === '[object Array]'; -} -exports.isArray = isArray; - -function isBoolean(arg) { - return typeof arg === 'boolean'; -} -exports.isBoolean = isBoolean; - -function isNull(arg) { - return arg === null; -} -exports.isNull = isNull; - -function isNullOrUndefined(arg) { - return arg == null; -} -exports.isNullOrUndefined = isNullOrUndefined; - -function isNumber(arg) { - return typeof arg === 'number'; -} -exports.isNumber = isNumber; - -function isString(arg) { - return typeof arg === 'string'; -} -exports.isString = isString; - -function isSymbol(arg) { - return typeof arg === 'symbol'; -} -exports.isSymbol = isSymbol; - -function isUndefined(arg) { - return arg === void 0; -} -exports.isUndefined = isUndefined; - -function isRegExp(re) { - return objectToString(re) === '[object RegExp]'; -} -exports.isRegExp = isRegExp; - -function isObject(arg) { - return typeof arg === 'object' && arg !== null; -} -exports.isObject = isObject; - -function isDate(d) { - return objectToString(d) === '[object Date]'; -} -exports.isDate = isDate; - -function isError(e) { - return (objectToString(e) === '[object Error]' || e instanceof Error); -} -exports.isError = isError; - -function isFunction(arg) { - return typeof arg === 'function'; -} -exports.isFunction = isFunction; - -function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; -} -exports.isPrimitive = isPrimitive; - -exports.isBuffer = Buffer.isBuffer; - -function objectToString(o) { - return Object.prototype.toString.call(o); -} - -}).call(this,{"isBuffer":require("../../is-buffer/index.js")}) -},{"../../is-buffer/index.js":231}],158:[function(require,module,exports){ -(function (Buffer){ +},{"inherits":349,"safe-buffer":463,"stream":481,"string_decoder":496}],253:[function(require,module,exports){ +(function (Buffer){(function (){ var elliptic = require('elliptic') var BN = require('bn.js') @@ -43186,8 +59119,8 @@ function formatReturnValue (bn, enc, len) { } } -}).call(this,require("buffer").Buffer) -},{"bn.js":103,"buffer":155,"elliptic":179}],159:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"bn.js":198,"buffer":249,"elliptic":280}],254:[function(require,module,exports){ 'use strict' var inherits = require('inherits') var MD5 = require('md5.js') @@ -43219,14 +59152,14 @@ module.exports = function createHash (alg) { return new Hash(sha(alg)) } -},{"cipher-base":156,"inherits":230,"md5.js":235,"ripemd160":279,"sha.js":289}],160:[function(require,module,exports){ +},{"cipher-base":252,"inherits":349,"md5.js":433,"ripemd160":462,"sha.js":473}],255:[function(require,module,exports){ var MD5 = require('md5.js') module.exports = function (buffer) { return new MD5().update(buffer).digest() } -},{"md5.js":235}],161:[function(require,module,exports){ +},{"md5.js":433}],256:[function(require,module,exports){ 'use strict' var inherits = require('inherits') var Legacy = require('./legacy') @@ -43290,7 +59223,7 @@ module.exports = function createHmac (alg, key) { return new Hmac(alg, key) } -},{"./legacy":162,"cipher-base":156,"create-hash/md5":160,"inherits":230,"ripemd160":279,"safe-buffer":280,"sha.js":289}],162:[function(require,module,exports){ +},{"./legacy":257,"cipher-base":252,"create-hash/md5":255,"inherits":349,"ripemd160":462,"safe-buffer":463,"sha.js":473}],257:[function(require,module,exports){ 'use strict' var inherits = require('inherits') var Buffer = require('safe-buffer').Buffer @@ -43338,7 +59271,7 @@ Hmac.prototype._final = function () { } module.exports = Hmac -},{"cipher-base":156,"inherits":230,"safe-buffer":280}],163:[function(require,module,exports){ +},{"cipher-base":252,"inherits":349,"safe-buffer":463}],258:[function(require,module,exports){ 'use strict' exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes') @@ -43437,7 +59370,65 @@ exports.constants = { 'POINT_CONVERSION_HYBRID': 6 } -},{"browserify-cipher":123,"browserify-sign":130,"browserify-sign/algos":127,"create-ecdh":158,"create-hash":159,"create-hmac":161,"diffie-hellman":170,"pbkdf2":246,"public-encrypt":254,"randombytes":262,"randomfill":263}],164:[function(require,module,exports){ +},{"browserify-cipher":218,"browserify-sign":225,"browserify-sign/algos":222,"create-ecdh":253,"create-hash":254,"create-hmac":256,"diffie-hellman":266,"pbkdf2":444,"public-encrypt":452,"randombytes":460,"randomfill":461}],259:[function(require,module,exports){ +'use strict'; + +var $defineProperty = require('es-define-property'); + +var $SyntaxError = require('es-errors/syntax'); +var $TypeError = require('es-errors/type'); + +var gopd = require('gopd'); + +/** @type {import('.')} */ +module.exports = function defineDataProperty( + obj, + property, + value +) { + if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { + throw new $TypeError('`obj` must be an object or a function`'); + } + if (typeof property !== 'string' && typeof property !== 'symbol') { + throw new $TypeError('`property` must be a string or a symbol`'); + } + if (arguments.length > 3 && typeof arguments[3] !== 'boolean' && arguments[3] !== null) { + throw new $TypeError('`nonEnumerable`, if provided, must be a boolean or null'); + } + if (arguments.length > 4 && typeof arguments[4] !== 'boolean' && arguments[4] !== null) { + throw new $TypeError('`nonWritable`, if provided, must be a boolean or null'); + } + if (arguments.length > 5 && typeof arguments[5] !== 'boolean' && arguments[5] !== null) { + throw new $TypeError('`nonConfigurable`, if provided, must be a boolean or null'); + } + if (arguments.length > 6 && typeof arguments[6] !== 'boolean') { + throw new $TypeError('`loose`, if provided, must be a boolean'); + } + + var nonEnumerable = arguments.length > 3 ? arguments[3] : null; + var nonWritable = arguments.length > 4 ? arguments[4] : null; + var nonConfigurable = arguments.length > 5 ? arguments[5] : null; + var loose = arguments.length > 6 ? arguments[6] : false; + + /* @type {false | TypedPropertyDescriptor} */ + var desc = !!gopd && gopd(obj, property); + + if ($defineProperty) { + $defineProperty(obj, property, { + configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable, + enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable, + value: value, + writable: nonWritable === null && desc ? desc.writable : !nonWritable + }); + } else if (loose || (!nonEnumerable && !nonWritable && !nonConfigurable)) { + // must fall back to [[Set]], and was not explicitly asked to make non-enumerable, non-writable, or non-configurable + obj[property] = value; // eslint-disable-line no-param-reassign + } else { + throw new $SyntaxError('This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.'); + } +}; + +},{"es-define-property":296,"es-errors/syntax":301,"es-errors/type":302,"gopd":312}],260:[function(require,module,exports){ 'use strict'; exports.utils = require('./des/utils'); @@ -43446,7 +59437,7 @@ exports.DES = require('./des/des'); exports.CBC = require('./des/cbc'); exports.EDE = require('./des/ede'); -},{"./des/cbc":165,"./des/cipher":166,"./des/des":167,"./des/ede":168,"./des/utils":169}],165:[function(require,module,exports){ +},{"./des/cbc":261,"./des/cipher":262,"./des/des":263,"./des/ede":264,"./des/utils":265}],261:[function(require,module,exports){ 'use strict'; var assert = require('minimalistic-assert'); @@ -43513,7 +59504,7 @@ proto._update = function _update(inp, inOff, out, outOff) { } }; -},{"inherits":230,"minimalistic-assert":238}],166:[function(require,module,exports){ +},{"inherits":349,"minimalistic-assert":436}],262:[function(require,module,exports){ 'use strict'; var assert = require('minimalistic-assert'); @@ -43656,7 +59647,7 @@ Cipher.prototype._finalDecrypt = function _finalDecrypt() { return this._unpad(out); }; -},{"minimalistic-assert":238}],167:[function(require,module,exports){ +},{"minimalistic-assert":436}],263:[function(require,module,exports){ 'use strict'; var assert = require('minimalistic-assert'); @@ -43800,7 +59791,7 @@ DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { utils.rip(l, r, out, off); }; -},{"./cipher":166,"./utils":169,"inherits":230,"minimalistic-assert":238}],168:[function(require,module,exports){ +},{"./cipher":262,"./utils":265,"inherits":349,"minimalistic-assert":436}],264:[function(require,module,exports){ 'use strict'; var assert = require('minimalistic-assert'); @@ -43856,7 +59847,7 @@ EDE.prototype._update = function _update(inp, inOff, out, outOff) { EDE.prototype._pad = DES.prototype._pad; EDE.prototype._unpad = DES.prototype._unpad; -},{"./cipher":166,"./des":167,"inherits":230,"minimalistic-assert":238}],169:[function(require,module,exports){ +},{"./cipher":262,"./des":263,"inherits":349,"minimalistic-assert":436}],265:[function(require,module,exports){ 'use strict'; exports.readUInt32BE = function readUInt32BE(bytes, off) { @@ -44114,8 +60105,8 @@ exports.padSplit = function padSplit(num, size, group) { return out.join(' '); }; -},{}],170:[function(require,module,exports){ -(function (Buffer){ +},{}],266:[function(require,module,exports){ +(function (Buffer){(function (){ var generatePrime = require('./lib/generatePrime') var primes = require('./lib/primes.json') @@ -44159,9 +60150,9 @@ function createDiffieHellman (prime, enc, generator, genc) { exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman -}).call(this,require("buffer").Buffer) -},{"./lib/dh":171,"./lib/generatePrime":172,"./lib/primes.json":173,"buffer":155}],171:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./lib/dh":267,"./lib/generatePrime":268,"./lib/primes.json":269,"buffer":249}],267:[function(require,module,exports){ +(function (Buffer){(function (){ var BN = require('bn.js'); var MillerRabin = require('miller-rabin'); var millerRabin = new MillerRabin(); @@ -44327,8 +60318,8 @@ function formatReturnValue(bn, enc) { } } -}).call(this,require("buffer").Buffer) -},{"./generatePrime":172,"bn.js":103,"buffer":155,"miller-rabin":237,"randombytes":262}],172:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./generatePrime":268,"bn.js":198,"buffer":249,"miller-rabin":435,"randombytes":460}],268:[function(require,module,exports){ var randomBytes = require('randombytes'); module.exports = findPrime; findPrime.simpleSieve = simpleSieve; @@ -44435,7 +60426,7 @@ function findPrime(bits, gen) { } -},{"bn.js":103,"miller-rabin":237,"randombytes":262}],173:[function(require,module,exports){ +},{"bn.js":198,"miller-rabin":435,"randombytes":460}],269:[function(require,module,exports){ module.exports={ "modp1": { "gen": "02", @@ -44470,7 +60461,503 @@ module.exports={ "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff" } } -},{}],174:[function(require,module,exports){ +},{}],270:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.ECPairFactory = exports.networks = void 0; +const networks = require('./networks'); +exports.networks = networks; +const types = require('./types'); +const randomBytes = require('randombytes'); +const wif = require('wif'); +const testecc_1 = require('./testecc'); +const isOptions = types.typeforce.maybe( + types.typeforce.compile({ + compressed: types.maybe(types.Boolean), + network: types.maybe(types.Network), + }), +); +const toXOnly = (pubKey) => + pubKey.length === 32 ? pubKey : pubKey.slice(1, 33); +function ECPairFactory(ecc) { + (0, testecc_1.testEcc)(ecc); + function isPoint(maybePoint) { + return ecc.isPoint(maybePoint); + } + function fromPrivateKey(buffer, options) { + types.typeforce(types.Buffer256bit, buffer); + if (!ecc.isPrivate(buffer)) + throw new TypeError('Private key not in range [1, n)'); + types.typeforce(isOptions, options); + return new ECPair(buffer, undefined, options); + } + function fromPublicKey(buffer, options) { + types.typeforce(ecc.isPoint, buffer); + types.typeforce(isOptions, options); + return new ECPair(undefined, buffer, options); + } + function fromWIF(wifString, network) { + const decoded = wif.decode(wifString); + const version = decoded.version; + // list of networks? + if (types.Array(network)) { + network = network + .filter((x) => { + return version === x.wif; + }) + .pop(); + if (!network) throw new Error('Unknown network version'); + // otherwise, assume a network object (or default to bitcoin) + } else { + network = network || networks.bitcoin; + if (version !== network.wif) throw new Error('Invalid network version'); + } + return fromPrivateKey(decoded.privateKey, { + compressed: decoded.compressed, + network: network, + }); + } + function makeRandom(options) { + types.typeforce(isOptions, options); + if (options === undefined) options = {}; + const rng = options.rng || randomBytes; + let d; + do { + d = rng(32); + types.typeforce(types.Buffer256bit, d); + } while (!ecc.isPrivate(d)); + return fromPrivateKey(d, options); + } + class ECPair { + __D; + __Q; + compressed; + network; + lowR; + constructor(__D, __Q, options) { + this.__D = __D; + this.__Q = __Q; + this.lowR = false; + if (options === undefined) options = {}; + this.compressed = + options.compressed === undefined ? true : options.compressed; + this.network = options.network || networks.bitcoin; + if (__Q !== undefined) + this.__Q = Buffer.from(ecc.pointCompress(__Q, this.compressed)); + } + get privateKey() { + return this.__D; + } + get publicKey() { + if (!this.__Q) { + // It is not possible for both `__Q` and `__D` to be `undefined` at the same time. + // The factory methods guard for this. + const p = ecc.pointFromScalar(this.__D, this.compressed); + // It is not possible for `p` to be null. + // `fromPrivateKey()` checks that `__D` is a valid scalar. + this.__Q = Buffer.from(p); + } + return this.__Q; + } + toWIF() { + if (!this.__D) throw new Error('Missing private key'); + return wif.encode(this.network.wif, this.__D, this.compressed); + } + tweak(t) { + if (this.privateKey) return this.tweakFromPrivateKey(t); + return this.tweakFromPublicKey(t); + } + sign(hash, lowR) { + if (!this.__D) throw new Error('Missing private key'); + if (lowR === undefined) lowR = this.lowR; + if (lowR === false) { + return Buffer.from(ecc.sign(hash, this.__D)); + } else { + let sig = ecc.sign(hash, this.__D); + const extraData = Buffer.alloc(32, 0); + let counter = 0; + // if first try is lowR, skip the loop + // for second try and on, add extra entropy counting up + while (sig[0] > 0x7f) { + counter++; + extraData.writeUIntLE(counter, 0, 6); + sig = ecc.sign(hash, this.__D, extraData); + } + return Buffer.from(sig); + } + } + signSchnorr(hash) { + if (!this.privateKey) throw new Error('Missing private key'); + if (!ecc.signSchnorr) + throw new Error('signSchnorr not supported by ecc library'); + return Buffer.from(ecc.signSchnorr(hash, this.privateKey)); + } + verify(hash, signature) { + return ecc.verify(hash, this.publicKey, signature); + } + verifySchnorr(hash, signature) { + if (!ecc.verifySchnorr) + throw new Error('verifySchnorr not supported by ecc library'); + return ecc.verifySchnorr(hash, this.publicKey.subarray(1, 33), signature); + } + tweakFromPublicKey(t) { + const xOnlyPubKey = toXOnly(this.publicKey); + const tweakedPublicKey = ecc.xOnlyPointAddTweak(xOnlyPubKey, t); + if (!tweakedPublicKey || tweakedPublicKey.xOnlyPubkey === null) + throw new Error('Cannot tweak public key!'); + const parityByte = Buffer.from([ + tweakedPublicKey.parity === 0 ? 0x02 : 0x03, + ]); + return fromPublicKey( + Buffer.concat([parityByte, tweakedPublicKey.xOnlyPubkey]), + { network: this.network, compressed: this.compressed }, + ); + } + tweakFromPrivateKey(t) { + const hasOddY = + this.publicKey[0] === 3 || + (this.publicKey[0] === 4 && (this.publicKey[64] & 1) === 1); + const privateKey = hasOddY + ? ecc.privateNegate(this.privateKey) + : this.privateKey; + const tweakedPrivateKey = ecc.privateAdd(privateKey, t); + if (!tweakedPrivateKey) throw new Error('Invalid tweaked private key!'); + return fromPrivateKey(Buffer.from(tweakedPrivateKey), { + network: this.network, + compressed: this.compressed, + }); + } + } + return { + isPoint, + fromPrivateKey, + fromPublicKey, + fromWIF, + makeRandom, + }; +} +exports.ECPairFactory = ECPairFactory; + +}).call(this)}).call(this,require("buffer").Buffer) +},{"./networks":272,"./testecc":273,"./types":274,"buffer":249,"randombytes":460,"wif":530}],271:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.networks = exports.ECPairFactory = exports.default = void 0; +var ecpair_1 = require('./ecpair'); +Object.defineProperty(exports, 'default', { + enumerable: true, + get: function () { + return ecpair_1.ECPairFactory; + }, +}); +Object.defineProperty(exports, 'ECPairFactory', { + enumerable: true, + get: function () { + return ecpair_1.ECPairFactory; + }, +}); +Object.defineProperty(exports, 'networks', { + enumerable: true, + get: function () { + return ecpair_1.networks; + }, +}); + +},{"./ecpair":270}],272:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.testnet = exports.bitcoin = void 0; +exports.bitcoin = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'bc', + bip32: { + public: 0x0488b21e, + private: 0x0488ade4, + }, + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80, +}; +exports.testnet = { + messagePrefix: '\x18Bitcoin Signed Message:\n', + bech32: 'tb', + bip32: { + public: 0x043587cf, + private: 0x04358394, + }, + pubKeyHash: 0x6f, + scriptHash: 0xc4, + wif: 0xef, +}; + +},{}],273:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.testEcc = void 0; +const h = (hex) => Buffer.from(hex, 'hex'); +function testEcc(ecc) { + assert( + ecc.isPoint( + h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + ), + ); + assert( + !ecc.isPoint( + h('030000000000000000000000000000000000000000000000000000000000000005'), + ), + ); + assert( + ecc.isPrivate( + h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + ), + ); + // order - 1 + assert( + ecc.isPrivate( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'), + ), + ); + // 0 + assert( + !ecc.isPrivate( + h('0000000000000000000000000000000000000000000000000000000000000000'), + ), + ); + // order + assert( + !ecc.isPrivate( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'), + ), + ); + // order + 1 + assert( + !ecc.isPrivate( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142'), + ), + ); + // 1 + 0 == 1 + assert( + Buffer.from( + ecc.privateAdd( + h('0000000000000000000000000000000000000000000000000000000000000001'), + h('0000000000000000000000000000000000000000000000000000000000000000'), + ), + ).equals( + h('0000000000000000000000000000000000000000000000000000000000000001'), + ), + ); + // -3 + 3 == 0 + assert( + ecc.privateAdd( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e'), + h('0000000000000000000000000000000000000000000000000000000000000003'), + ) === null, + ); + assert( + Buffer.from( + ecc.privateAdd( + h('e211078564db65c3ce7704f08262b1f38f1ef412ad15b5ac2d76657a63b2c500'), + h('b51fbb69051255d1becbd683de5848242a89c229348dd72896a87ada94ae8665'), + ), + ).equals( + h('9730c2ee69edbb958d42db7460bafa18fef9d955325aec99044c81c8282b0a24'), + ), + ); + assert( + Buffer.from( + ecc.privateNegate( + h('0000000000000000000000000000000000000000000000000000000000000001'), + ), + ).equals( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'), + ), + ); + assert( + Buffer.from( + ecc.privateNegate( + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e'), + ), + ).equals( + h('0000000000000000000000000000000000000000000000000000000000000003'), + ), + ); + assert( + Buffer.from( + ecc.privateNegate( + h('b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af'), + ), + ).equals( + h('4eede1bf775995d70a494f0a7bb6bc11e0b8cccd41cce8009ab1132c8b0a3792'), + ), + ); + assert( + Buffer.from( + ecc.pointCompress( + h( + '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', + ), + true, + ), + ).equals( + h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + ), + ); + assert( + Buffer.from( + ecc.pointCompress( + h( + '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', + ), + false, + ), + ).equals( + h( + '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', + ), + ), + ); + assert( + Buffer.from( + ecc.pointCompress( + h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + true, + ), + ).equals( + h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + ), + ); + assert( + Buffer.from( + ecc.pointCompress( + h('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + false, + ), + ).equals( + h( + '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', + ), + ), + ); + assert( + Buffer.from( + ecc.pointFromScalar( + h('b1121e4088a66a28f5b6b0f5844943ecd9f610196d7bb83b25214b60452c09af'), + ), + ).equals( + h('02b07ba9dca9523b7ef4bd97703d43d20399eb698e194704791a25ce77a400df99'), + ), + ); + assert( + ecc.xOnlyPointAddTweak( + h('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'), + ) === null, + ); + let xOnlyRes = ecc.xOnlyPointAddTweak( + h('1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b'), + h('a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac'), + ); + assert( + Buffer.from(xOnlyRes.xOnlyPubkey).equals( + h('e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf'), + ) && xOnlyRes.parity === 1, + ); + xOnlyRes = ecc.xOnlyPointAddTweak( + h('2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991'), + h('823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47'), + ); + assert( + Buffer.from(xOnlyRes.xOnlyPubkey).equals( + h('9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c'), + ) && xOnlyRes.parity === 0, + ); + assert( + Buffer.from( + ecc.sign( + h('5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed'), + h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140'), + ), + ).equals( + h( + '54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5', + ), + ), + ); + assert( + ecc.verify( + h('5e9f0a0d593efdcf78ac923bc3313e4e7d408d574354ee2b3288c0da9fbba6ed'), + h('0379be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), + h( + '54c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed07082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5', + ), + ), + ); + if (ecc.signSchnorr) { + assert( + Buffer.from( + ecc.signSchnorr( + h('7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c'), + h('c90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b14e5c9'), + h('c87aa53824b4d7ae2eb035a2b5bbbccc080e76cdc6d1692c4b0b62d798e6d906'), + ), + ).equals( + h( + '5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7', + ), + ), + ); + } + if (ecc.verifySchnorr) { + assert( + ecc.verifySchnorr( + h('7e2d58d8b3bcdf1abadec7829054f90dda9805aab56c77333024b9d0a508b75c'), + h('dd308afec5777e13121fa72b9cc1b7cc0139715309b086c960e18fd969774eb8'), + h( + '5831aaeed7b44bb74e5eab94ba9d4294c49bcf2a60728d8b4c200f50dd313c1bab745879a5ad954a72c45a91c3a51d3c7adea98d82f8481e0e1e03674a6f3fb7', + ), + ), + ); + } +} +exports.testEcc = testEcc; +function assert(bool) { + if (!bool) throw new Error('ecc library invalid'); +} + +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],274:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.maybe = + exports.Boolean = + exports.Array = + exports.Buffer256bit = + exports.Network = + exports.typeforce = + void 0; +exports.typeforce = require('typeforce'); +// exposed, external API +exports.Network = exports.typeforce.compile({ + messagePrefix: exports.typeforce.oneOf( + exports.typeforce.Buffer, + exports.typeforce.String, + ), + bip32: { + public: exports.typeforce.UInt32, + private: exports.typeforce.UInt32, + }, + pubKeyHash: exports.typeforce.UInt8, + scriptHash: exports.typeforce.UInt8, + wif: exports.typeforce.UInt8, +}); +exports.Buffer256bit = exports.typeforce.BufferN(32); +exports.Array = exports.typeforce.Array; +exports.Boolean = exports.typeforce.Boolean; // tslint:disable-line variable-name +exports.maybe = exports.typeforce.maybe; + +},{"typeforce":521}],275:[function(require,module,exports){ var assert = require('assert') var BigInteger = require('bigi') @@ -44549,7 +61036,7 @@ Curve.prototype.validate = function (Q) { module.exports = Curve -},{"./point":178,"assert":21,"bigi":30}],175:[function(require,module,exports){ +},{"./point":279,"assert":113,"bigi":123}],276:[function(require,module,exports){ module.exports={ "secp128r1": { "p": "fffffffdffffffffffffffffffffffff", @@ -44616,7 +61103,7 @@ module.exports={ } } -},{}],176:[function(require,module,exports){ +},{}],277:[function(require,module,exports){ var Point = require('./point') var Curve = require('./curve') @@ -44628,7 +61115,7 @@ module.exports = { getCurveByName: getCurveByName } -},{"./curve":174,"./names":177,"./point":178}],177:[function(require,module,exports){ +},{"./curve":275,"./names":278,"./point":279}],278:[function(require,module,exports){ var BigInteger = require('bigi') var curves = require('./curves.json') @@ -44651,7 +61138,7 @@ function getCurveByName (name) { module.exports = getCurveByName -},{"./curve":174,"./curves.json":175,"bigi":30}],178:[function(require,module,exports){ +},{"./curve":275,"./curves.json":276,"bigi":123}],279:[function(require,module,exports){ var assert = require('assert') var Buffer = require('safe-buffer').Buffer var BigInteger = require('bigi') @@ -44897,7 +61384,7 @@ Point.prototype.toString = function () { module.exports = Point -},{"assert":21,"bigi":30,"safe-buffer":280}],179:[function(require,module,exports){ +},{"assert":113,"bigi":123,"safe-buffer":463}],280:[function(require,module,exports){ 'use strict'; var elliptic = exports; @@ -44912,7 +61399,7 @@ elliptic.curves = require('./elliptic/curves'); elliptic.ec = require('./elliptic/ec'); elliptic.eddsa = require('./elliptic/eddsa'); -},{"../package.json":194,"./elliptic/curve":182,"./elliptic/curves":185,"./elliptic/ec":186,"./elliptic/eddsa":189,"./elliptic/utils":193,"brorand":104}],180:[function(require,module,exports){ +},{"../package.json":295,"./elliptic/curve":283,"./elliptic/curves":286,"./elliptic/ec":287,"./elliptic/eddsa":290,"./elliptic/utils":294,"brorand":199}],281:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -45290,7 +61777,7 @@ BasePoint.prototype.dblp = function dblp(k) { return r; }; -},{"../utils":193,"bn.js":103}],181:[function(require,module,exports){ +},{"../utils":294,"bn.js":198}],282:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -45724,7 +62211,7 @@ Point.prototype.eqXToP = function eqXToP(x) { Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; -},{"../utils":193,"./base":180,"bn.js":103,"inherits":230}],182:[function(require,module,exports){ +},{"../utils":294,"./base":281,"bn.js":198,"inherits":349}],283:[function(require,module,exports){ 'use strict'; var curve = exports; @@ -45734,7 +62221,7 @@ curve.short = require('./short'); curve.mont = require('./mont'); curve.edwards = require('./edwards'); -},{"./base":180,"./edwards":181,"./mont":183,"./short":184}],183:[function(require,module,exports){ +},{"./base":281,"./edwards":282,"./mont":284,"./short":285}],284:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -45914,7 +62401,7 @@ Point.prototype.getX = function getX() { return this.x.fromRed(); }; -},{"../utils":193,"./base":180,"bn.js":103,"inherits":230}],184:[function(require,module,exports){ +},{"../utils":294,"./base":281,"bn.js":198,"inherits":349}],285:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -46853,7 +63340,7 @@ JPoint.prototype.isInfinity = function isInfinity() { return this.z.cmpn(0) === 0; }; -},{"../utils":193,"./base":180,"bn.js":103,"inherits":230}],185:[function(require,module,exports){ +},{"../utils":294,"./base":281,"bn.js":198,"inherits":349}],286:[function(require,module,exports){ 'use strict'; var curves = exports; @@ -47061,7 +63548,7 @@ defineCurve('secp256k1', { ] }); -},{"./curve":182,"./precomputed/secp256k1":192,"./utils":193,"hash.js":216}],186:[function(require,module,exports){ +},{"./curve":283,"./precomputed/secp256k1":293,"./utils":294,"hash.js":334}],287:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -47304,7 +63791,7 @@ EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { throw new Error('Unable to find valid recovery factor'); }; -},{"../curves":185,"../utils":193,"./key":187,"./signature":188,"bn.js":103,"brorand":104,"hmac-drbg":228}],187:[function(require,module,exports){ +},{"../curves":286,"../utils":294,"./key":288,"./signature":289,"bn.js":198,"brorand":199,"hmac-drbg":347}],288:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -47424,7 +63911,7 @@ KeyPair.prototype.inspect = function inspect() { ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; }; -},{"../utils":193,"bn.js":103}],188:[function(require,module,exports){ +},{"../utils":294,"bn.js":198}],289:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -47592,7 +64079,7 @@ Signature.prototype.toDER = function toDER(enc) { return utils.encode(res, enc); }; -},{"../utils":193,"bn.js":103}],189:[function(require,module,exports){ +},{"../utils":294,"bn.js":198}],290:[function(require,module,exports){ 'use strict'; var hash = require('hash.js'); @@ -47712,7 +64199,7 @@ EDDSA.prototype.isPoint = function isPoint(val) { return val instanceof this.pointClass; }; -},{"../curves":185,"../utils":193,"./key":190,"./signature":191,"hash.js":216}],190:[function(require,module,exports){ +},{"../curves":286,"../utils":294,"./key":291,"./signature":292,"hash.js":334}],291:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -47809,7 +64296,7 @@ KeyPair.prototype.getPublic = function getPublic(enc) { module.exports = KeyPair; -},{"../utils":193}],191:[function(require,module,exports){ +},{"../utils":294}],292:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -47876,7 +64363,7 @@ Signature.prototype.toHex = function toHex() { module.exports = Signature; -},{"../utils":193,"bn.js":103}],192:[function(require,module,exports){ +},{"../utils":294,"bn.js":198}],293:[function(require,module,exports){ module.exports = { doubles: { step: 4, @@ -48658,7 +65145,7 @@ module.exports = { } }; -},{}],193:[function(require,module,exports){ +},{}],294:[function(require,module,exports){ 'use strict'; var utils = exports; @@ -48779,7 +65266,7 @@ function intFromLE(bytes) { utils.intFromLE = intFromLE; -},{"bn.js":103,"minimalistic-assert":238,"minimalistic-crypto-utils":239}],194:[function(require,module,exports){ +},{"bn.js":198,"minimalistic-assert":436,"minimalistic-crypto-utils":437}],295:[function(require,module,exports){ module.exports={ "name": "elliptic", "version": "6.5.3", @@ -48839,7 +65326,67 @@ module.exports={ } } -},{}],195:[function(require,module,exports){ +},{}],296:[function(require,module,exports){ +'use strict'; + +var GetIntrinsic = require('get-intrinsic'); + +/** @type {import('.')} */ +var $defineProperty = GetIntrinsic('%Object.defineProperty%', true) || false; +if ($defineProperty) { + try { + $defineProperty({}, 'a', { value: 1 }); + } catch (e) { + // IE 8 has a broken defineProperty + $defineProperty = false; + } +} + +module.exports = $defineProperty; + +},{"get-intrinsic":310}],297:[function(require,module,exports){ +'use strict'; + +/** @type {import('./eval')} */ +module.exports = EvalError; + +},{}],298:[function(require,module,exports){ +'use strict'; + +/** @type {import('.')} */ +module.exports = Error; + +},{}],299:[function(require,module,exports){ +'use strict'; + +/** @type {import('./range')} */ +module.exports = RangeError; + +},{}],300:[function(require,module,exports){ +'use strict'; + +/** @type {import('./ref')} */ +module.exports = ReferenceError; + +},{}],301:[function(require,module,exports){ +'use strict'; + +/** @type {import('./syntax')} */ +module.exports = SyntaxError; + +},{}],302:[function(require,module,exports){ +'use strict'; + +/** @type {import('./type')} */ +module.exports = TypeError; + +},{}],303:[function(require,module,exports){ +'use strict'; + +/** @type {import('./uri')} */ +module.exports = URIError; + +},{}],304:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -48861,289 +65408,484 @@ module.exports={ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +'use strict'; + +var R = typeof Reflect === 'object' ? Reflect : null +var ReflectApply = R && typeof R.apply === 'function' + ? R.apply + : function ReflectApply(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + } + +var ReflectOwnKeys +if (R && typeof R.ownKeys === 'function') { + ReflectOwnKeys = R.ownKeys +} else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target) + .concat(Object.getOwnPropertySymbols(target)); + }; +} else { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target); + }; +} + +function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); +} + +var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) { + return value !== value; +} + function EventEmitter() { - this._events = this._events || {}; - this._maxListeners = this._maxListeners || undefined; + EventEmitter.init.call(this); } module.exports = EventEmitter; +module.exports.once = once; // Backwards-compat with node 0.10.x EventEmitter.EventEmitter = EventEmitter; EventEmitter.prototype._events = undefined; +EventEmitter.prototype._eventsCount = 0; EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are // added to it. This is a useful default which helps finding memory leaks. -EventEmitter.defaultMaxListeners = 10; +var defaultMaxListeners = 10; + +function checkListener(listener) { + if (typeof listener !== 'function') { + throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); + } +} + +Object.defineProperty(EventEmitter, 'defaultMaxListeners', { + enumerable: true, + get: function() { + return defaultMaxListeners; + }, + set: function(arg) { + if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.'); + } + defaultMaxListeners = arg; + } +}); + +EventEmitter.init = function() { + + if (this._events === undefined || + this._events === Object.getPrototypeOf(this)._events) { + this._events = Object.create(null); + this._eventsCount = 0; + } + + this._maxListeners = this._maxListeners || undefined; +}; // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. -EventEmitter.prototype.setMaxListeners = function(n) { - if (!isNumber(n) || n < 0 || isNaN(n)) - throw TypeError('n must be a positive number'); +EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) { + throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.'); + } this._maxListeners = n; return this; }; -EventEmitter.prototype.emit = function(type) { - var er, handler, len, args, i, listeners; +function _getMaxListeners(that) { + if (that._maxListeners === undefined) + return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); +}; + +EventEmitter.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = (type === 'error'); - if (!this._events) - this._events = {}; + var events = this._events; + if (events !== undefined) + doError = (doError && events.error === undefined); + else if (!doError) + return false; // If there is no 'error' event listener then throw. - if (type === 'error') { - if (!this._events.error || - (isObject(this._events.error) && !this._events.error.length)) { - er = arguments[1]; - if (er instanceof Error) { - throw er; // Unhandled 'error' event - } else { - // At least give some kind of context to the user - var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); - err.context = er; - throw err; - } + if (doError) { + var er; + if (args.length > 0) + er = args[0]; + if (er instanceof Error) { + // Note: The comments on the `throw` lines are intentional, they show + // up in Node's output if this results in an unhandled exception. + throw er; // Unhandled 'error' event } + // At least give some kind of context to the user + var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : '')); + err.context = er; + throw err; // Unhandled 'error' event } - handler = this._events[type]; + var handler = events[type]; - if (isUndefined(handler)) + if (handler === undefined) return false; - if (isFunction(handler)) { - switch (arguments.length) { - // fast cases - case 1: - handler.call(this); - break; - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - // slower - default: - args = Array.prototype.slice.call(arguments, 1); - handler.apply(this, args); - } - } else if (isObject(handler)) { - args = Array.prototype.slice.call(arguments, 1); - listeners = handler.slice(); - len = listeners.length; - for (i = 0; i < len; i++) - listeners[i].apply(this, args); + if (typeof handler === 'function') { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) + ReflectApply(listeners[i], this, args); } return true; }; -EventEmitter.prototype.addListener = function(type, listener) { +function _addListener(target, type, listener, prepend) { var m; + var events; + var existing; - if (!isFunction(listener)) - throw TypeError('listener must be a function'); + checkListener(listener); - if (!this._events) - this._events = {}; + events = target._events; + if (events === undefined) { + events = target._events = Object.create(null); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener !== undefined) { + target.emit('newListener', type, + listener.listener ? listener.listener : listener); - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (this._events.newListener) - this.emit('newListener', type, - isFunction(listener.listener) ? - listener.listener : listener); + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; + } + existing = events[type]; + } - if (!this._events[type]) + if (existing === undefined) { // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - else if (isObject(this._events[type])) - // If we've already got an array, just append. - this._events[type].push(listener); - else - // Adding the second element, need to change to array. - this._events[type] = [this._events[type], listener]; - - // Check for listener leak - if (isObject(this._events[type]) && !this._events[type].warned) { - if (!isUndefined(this._maxListeners)) { - m = this._maxListeners; + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === 'function') { + // Adding the second element, need to change to array. + existing = events[type] = + prepend ? [listener, existing] : [existing, listener]; + // If we've already got an array, just append. + } else if (prepend) { + existing.unshift(listener); } else { - m = EventEmitter.defaultMaxListeners; - } - - if (m && m > 0 && this._events[type].length > m) { - this._events[type].warned = true; - console.error('(node) warning: possible EventEmitter memory ' + - 'leak detected. %d listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.', - this._events[type].length); - if (typeof console.trace === 'function') { - // not supported in IE 10 - console.trace(); - } + existing.push(listener); + } + + // Check for listener leak + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + // No error code for this since it is a Warning + // eslint-disable-next-line no-restricted-syntax + var w = new Error('Possible EventEmitter memory leak detected. ' + + existing.length + ' ' + String(type) + ' listeners ' + + 'added. Use emitter.setMaxListeners() to ' + + 'increase limit'); + w.name = 'MaxListenersExceededWarning'; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); } } - return this; + return target; +} + +EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; -EventEmitter.prototype.once = function(type, listener) { - if (!isFunction(listener)) - throw TypeError('listener must be a function'); - - var fired = false; - - function g() { - this.removeListener(type, g); +EventEmitter.prototype.prependListener = + function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; - if (!fired) { - fired = true; - listener.apply(this, arguments); - } +function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) + return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); } +} - g.listener = listener; - this.on(type, g); +function _onceWrap(target, type, listener) { + var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; +} +EventEmitter.prototype.once = function once(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); return this; }; -// emits a 'removeListener' event iff the listener was removed -EventEmitter.prototype.removeListener = function(type, listener) { - var list, position, length, i; +EventEmitter.prototype.prependOnceListener = + function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + +// Emits a 'removeListener' event if and only if the listener was removed. +EventEmitter.prototype.removeListener = + function removeListener(type, listener) { + var list, events, position, i, originalListener; + + checkListener(listener); + + events = this._events; + if (events === undefined) + return this; + + list = events[type]; + if (list === undefined) + return this; + + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) + this._events = Object.create(null); + else { + delete events[type]; + if (events.removeListener) + this.emit('removeListener', type, list.listener || listener); + } + } else if (typeof list !== 'function') { + position = -1; + + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + + if (position < 0) + return this; + + if (position === 0) + list.shift(); + else { + spliceOne(list, position); + } + + if (list.length === 1) + events[type] = list[0]; + + if (events.removeListener !== undefined) + this.emit('removeListener', type, originalListener || listener); + } + + return this; + }; + +EventEmitter.prototype.off = EventEmitter.prototype.removeListener; + +EventEmitter.prototype.removeAllListeners = + function removeAllListeners(type) { + var listeners, events, i; + + events = this._events; + if (events === undefined) + return this; + + // not listening for removeListener, no need to emit + if (events.removeListener === undefined) { + if (arguments.length === 0) { + this._events = Object.create(null); + this._eventsCount = 0; + } else if (events[type] !== undefined) { + if (--this._eventsCount === 0) + this._events = Object.create(null); + else + delete events[type]; + } + return this; + } - if (!isFunction(listener)) - throw TypeError('listener must be a function'); + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = Object.keys(events); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = Object.create(null); + this._eventsCount = 0; + return this; + } - if (!this._events || !this._events[type]) - return this; + listeners = events[type]; - list = this._events[type]; - length = list.length; - position = -1; - - if (list === listener || - (isFunction(list.listener) && list.listener === listener)) { - delete this._events[type]; - if (this._events.removeListener) - this.emit('removeListener', type, listener); - - } else if (isObject(list)) { - for (i = length; i-- > 0;) { - if (list[i] === listener || - (list[i].listener && list[i].listener === listener)) { - position = i; - break; + if (typeof listeners === 'function') { + this.removeListener(type, listeners); + } else if (listeners !== undefined) { + // LIFO order + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } } - } - if (position < 0) return this; + }; - if (list.length === 1) { - list.length = 0; - delete this._events[type]; - } else { - list.splice(position, 1); - } - - if (this._events.removeListener) - this.emit('removeListener', type, listener); - } +function _listeners(target, type, unwrap) { + var events = target._events; - return this; -}; + if (events === undefined) + return []; -EventEmitter.prototype.removeAllListeners = function(type) { - var key, listeners; + var evlistener = events[type]; + if (evlistener === undefined) + return []; - if (!this._events) - return this; + if (typeof evlistener === 'function') + return unwrap ? [evlistener.listener || evlistener] : [evlistener]; - // not listening for removeListener, no need to emit - if (!this._events.removeListener) { - if (arguments.length === 0) - this._events = {}; - else if (this._events[type]) - delete this._events[type]; - return this; - } + return unwrap ? + unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); +} - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - for (key in this._events) { - if (key === 'removeListener') continue; - this.removeAllListeners(key); - } - this.removeAllListeners('removeListener'); - this._events = {}; - return this; - } +EventEmitter.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); +}; - listeners = this._events[type]; +EventEmitter.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); +}; - if (isFunction(listeners)) { - this.removeListener(type, listeners); - } else if (listeners) { - // LIFO order - while (listeners.length) - this.removeListener(type, listeners[listeners.length - 1]); +EventEmitter.listenerCount = function(emitter, type) { + if (typeof emitter.listenerCount === 'function') { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); } - delete this._events[type]; - - return this; }; -EventEmitter.prototype.listeners = function(type) { - var ret; - if (!this._events || !this._events[type]) - ret = []; - else if (isFunction(this._events[type])) - ret = [this._events[type]]; - else - ret = this._events[type].slice(); - return ret; -}; +EventEmitter.prototype.listenerCount = listenerCount; +function listenerCount(type) { + var events = this._events; -EventEmitter.prototype.listenerCount = function(type) { - if (this._events) { - var evlistener = this._events[type]; + if (events !== undefined) { + var evlistener = events[type]; - if (isFunction(evlistener)) + if (typeof evlistener === 'function') { return 1; - else if (evlistener) + } else if (evlistener !== undefined) { return evlistener.length; + } } + return 0; -}; +} -EventEmitter.listenerCount = function(emitter, type) { - return emitter.listenerCount(type); +EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; }; -function isFunction(arg) { - return typeof arg === 'function'; +function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) + copy[i] = arr[i]; + return copy; } -function isNumber(arg) { - return typeof arg === 'number'; +function spliceOne(list, index) { + for (; index + 1 < list.length; index++) + list[index] = list[index + 1]; + list.pop(); } -function isObject(arg) { - return typeof arg === 'object' && arg !== null; +function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; } -function isUndefined(arg) { - return arg === void 0; +function once(emitter, name) { + return new Promise(function (resolve, reject) { + function errorListener(err) { + emitter.removeListener(name, resolver); + reject(err); + } + + function resolver() { + if (typeof emitter.removeListener === 'function') { + emitter.removeListener('error', errorListener); + } + resolve([].slice.call(arguments)); + }; + + eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); + if (name !== 'error') { + addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); + } + }); +} + +function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === 'function') { + eventTargetAgnosticAddListener(emitter, 'error', handler, flags); + } } -},{}],196:[function(require,module,exports){ +function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === 'function') { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === 'function') { + // EventTarget does not have `error` event semantics like Node + // EventEmitters, we do not listen for `error` events here. + emitter.addEventListener(name, function wrapListener(arg) { + // IE does not have builtin `{ once: true }` support so we + // have to do it manually. + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); + } +} + +},{}],305:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer var MD5 = require('md5.js') @@ -49190,8 +65932,8 @@ function EVP_BytesToKey (password, salt, keyBits, ivLen) { module.exports = EVP_BytesToKey -},{"md5.js":235,"safe-buffer":280}],197:[function(require,module,exports){ -(function (Buffer){ +},{"md5.js":433,"safe-buffer":463}],306:[function(require,module,exports){ +(function (Buffer){(function (){ /** * This code is a manual javascript translation of c code generated by * pycrc 0.7.1 (http://www.tty1.net/pycrc/). Command line used: @@ -49278,9 +66020,527 @@ module.exports = { calculate: calculate }; -}).call(this,require("buffer").Buffer) -},{"buffer":155}],198:[function(require,module,exports){ -(function (global,Buffer){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],307:[function(require,module,exports){ +'use strict'; + +var isCallable = require('is-callable'); + +var toStr = Object.prototype.toString; +var hasOwnProperty = Object.prototype.hasOwnProperty; + +var forEachArray = function forEachArray(array, iterator, receiver) { + for (var i = 0, len = array.length; i < len; i++) { + if (hasOwnProperty.call(array, i)) { + if (receiver == null) { + iterator(array[i], i, array); + } else { + iterator.call(receiver, array[i], i, array); + } + } + } +}; + +var forEachString = function forEachString(string, iterator, receiver) { + for (var i = 0, len = string.length; i < len; i++) { + // no such thing as a sparse string. + if (receiver == null) { + iterator(string.charAt(i), i, string); + } else { + iterator.call(receiver, string.charAt(i), i, string); + } + } +}; + +var forEachObject = function forEachObject(object, iterator, receiver) { + for (var k in object) { + if (hasOwnProperty.call(object, k)) { + if (receiver == null) { + iterator(object[k], k, object); + } else { + iterator.call(receiver, object[k], k, object); + } + } + } +}; + +var forEach = function forEach(list, iterator, thisArg) { + if (!isCallable(iterator)) { + throw new TypeError('iterator must be a function'); + } + + var receiver; + if (arguments.length >= 3) { + receiver = thisArg; + } + + if (toStr.call(list) === '[object Array]') { + forEachArray(list, iterator, receiver); + } else if (typeof list === 'string') { + forEachString(list, iterator, receiver); + } else { + forEachObject(list, iterator, receiver); + } +}; + +module.exports = forEach; + +},{"is-callable":352}],308:[function(require,module,exports){ +'use strict'; + +/* eslint no-invalid-this: 1 */ + +var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; +var toStr = Object.prototype.toString; +var max = Math.max; +var funcType = '[object Function]'; + +var concatty = function concatty(a, b) { + var arr = []; + + for (var i = 0; i < a.length; i += 1) { + arr[i] = a[i]; + } + for (var j = 0; j < b.length; j += 1) { + arr[j + a.length] = b[j]; + } + + return arr; +}; + +var slicy = function slicy(arrLike, offset) { + var arr = []; + for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) { + arr[j] = arrLike[i]; + } + return arr; +}; + +var joiny = function (arr, joiner) { + var str = ''; + for (var i = 0; i < arr.length; i += 1) { + str += arr[i]; + if (i + 1 < arr.length) { + str += joiner; + } + } + return str; +}; + +module.exports = function bind(that) { + var target = this; + if (typeof target !== 'function' || toStr.apply(target) !== funcType) { + throw new TypeError(ERROR_MESSAGE + target); + } + var args = slicy(arguments, 1); + + var bound; + var binder = function () { + if (this instanceof bound) { + var result = target.apply( + this, + concatty(args, arguments) + ); + if (Object(result) === result) { + return result; + } + return this; + } + return target.apply( + that, + concatty(args, arguments) + ); + + }; + + var boundLength = max(0, target.length - args.length); + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + boundArgs[i] = '$' + i; + } + + bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder); + + if (target.prototype) { + var Empty = function Empty() {}; + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + Empty.prototype = null; + } + + return bound; +}; + +},{}],309:[function(require,module,exports){ +'use strict'; + +var implementation = require('./implementation'); + +module.exports = Function.prototype.bind || implementation; + +},{"./implementation":308}],310:[function(require,module,exports){ +'use strict'; + +var undefined; + +var $Error = require('es-errors'); +var $EvalError = require('es-errors/eval'); +var $RangeError = require('es-errors/range'); +var $ReferenceError = require('es-errors/ref'); +var $SyntaxError = require('es-errors/syntax'); +var $TypeError = require('es-errors/type'); +var $URIError = require('es-errors/uri'); + +var $Function = Function; + +// eslint-disable-next-line consistent-return +var getEvalledConstructor = function (expressionSyntax) { + try { + return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); + } catch (e) {} +}; + +var $gOPD = Object.getOwnPropertyDescriptor; +if ($gOPD) { + try { + $gOPD({}, ''); + } catch (e) { + $gOPD = null; // this is IE 8, which has a broken gOPD + } +} + +var throwTypeError = function () { + throw new $TypeError(); +}; +var ThrowTypeError = $gOPD + ? (function () { + try { + // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties + arguments.callee; // IE 8 does not throw here + return throwTypeError; + } catch (calleeThrows) { + try { + // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') + return $gOPD(arguments, 'callee').get; + } catch (gOPDthrows) { + return throwTypeError; + } + } + }()) + : throwTypeError; + +var hasSymbols = require('has-symbols')(); +var hasProto = require('has-proto')(); + +var getProto = Object.getPrototypeOf || ( + hasProto + ? function (x) { return x.__proto__; } // eslint-disable-line no-proto + : null +); + +var needsEval = {}; + +var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined : getProto(Uint8Array); + +var INTRINSICS = { + __proto__: null, + '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, + '%Array%': Array, + '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, + '%ArrayIteratorPrototype%': hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined, + '%AsyncFromSyncIteratorPrototype%': undefined, + '%AsyncFunction%': needsEval, + '%AsyncGenerator%': needsEval, + '%AsyncGeneratorFunction%': needsEval, + '%AsyncIteratorPrototype%': needsEval, + '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, + '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, + '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array, + '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array, + '%Boolean%': Boolean, + '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, + '%Date%': Date, + '%decodeURI%': decodeURI, + '%decodeURIComponent%': decodeURIComponent, + '%encodeURI%': encodeURI, + '%encodeURIComponent%': encodeURIComponent, + '%Error%': $Error, + '%eval%': eval, // eslint-disable-line no-eval + '%EvalError%': $EvalError, + '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, + '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, + '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, + '%Function%': $Function, + '%GeneratorFunction%': needsEval, + '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, + '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, + '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, + '%isFinite%': isFinite, + '%isNaN%': isNaN, + '%IteratorPrototype%': hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined, + '%JSON%': typeof JSON === 'object' ? JSON : undefined, + '%Map%': typeof Map === 'undefined' ? undefined : Map, + '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Map()[Symbol.iterator]()), + '%Math%': Math, + '%Number%': Number, + '%Object%': Object, + '%parseFloat%': parseFloat, + '%parseInt%': parseInt, + '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, + '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, + '%RangeError%': $RangeError, + '%ReferenceError%': $ReferenceError, + '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, + '%RegExp%': RegExp, + '%Set%': typeof Set === 'undefined' ? undefined : Set, + '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Set()[Symbol.iterator]()), + '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, + '%String%': String, + '%StringIteratorPrototype%': hasSymbols && getProto ? getProto(''[Symbol.iterator]()) : undefined, + '%Symbol%': hasSymbols ? Symbol : undefined, + '%SyntaxError%': $SyntaxError, + '%ThrowTypeError%': ThrowTypeError, + '%TypedArray%': TypedArray, + '%TypeError%': $TypeError, + '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, + '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, + '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, + '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, + '%URIError%': $URIError, + '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, + '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, + '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet +}; + +if (getProto) { + try { + null.error; // eslint-disable-line no-unused-expressions + } catch (e) { + // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 + var errorProto = getProto(getProto(e)); + INTRINSICS['%Error.prototype%'] = errorProto; + } +} + +var doEval = function doEval(name) { + var value; + if (name === '%AsyncFunction%') { + value = getEvalledConstructor('async function () {}'); + } else if (name === '%GeneratorFunction%') { + value = getEvalledConstructor('function* () {}'); + } else if (name === '%AsyncGeneratorFunction%') { + value = getEvalledConstructor('async function* () {}'); + } else if (name === '%AsyncGenerator%') { + var fn = doEval('%AsyncGeneratorFunction%'); + if (fn) { + value = fn.prototype; + } + } else if (name === '%AsyncIteratorPrototype%') { + var gen = doEval('%AsyncGenerator%'); + if (gen && getProto) { + value = getProto(gen.prototype); + } + } + + INTRINSICS[name] = value; + + return value; +}; + +var LEGACY_ALIASES = { + __proto__: null, + '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], + '%ArrayPrototype%': ['Array', 'prototype'], + '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], + '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], + '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], + '%ArrayProto_values%': ['Array', 'prototype', 'values'], + '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], + '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], + '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], + '%BooleanPrototype%': ['Boolean', 'prototype'], + '%DataViewPrototype%': ['DataView', 'prototype'], + '%DatePrototype%': ['Date', 'prototype'], + '%ErrorPrototype%': ['Error', 'prototype'], + '%EvalErrorPrototype%': ['EvalError', 'prototype'], + '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], + '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], + '%FunctionPrototype%': ['Function', 'prototype'], + '%Generator%': ['GeneratorFunction', 'prototype'], + '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], + '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], + '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], + '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], + '%JSONParse%': ['JSON', 'parse'], + '%JSONStringify%': ['JSON', 'stringify'], + '%MapPrototype%': ['Map', 'prototype'], + '%NumberPrototype%': ['Number', 'prototype'], + '%ObjectPrototype%': ['Object', 'prototype'], + '%ObjProto_toString%': ['Object', 'prototype', 'toString'], + '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], + '%PromisePrototype%': ['Promise', 'prototype'], + '%PromiseProto_then%': ['Promise', 'prototype', 'then'], + '%Promise_all%': ['Promise', 'all'], + '%Promise_reject%': ['Promise', 'reject'], + '%Promise_resolve%': ['Promise', 'resolve'], + '%RangeErrorPrototype%': ['RangeError', 'prototype'], + '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], + '%RegExpPrototype%': ['RegExp', 'prototype'], + '%SetPrototype%': ['Set', 'prototype'], + '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], + '%StringPrototype%': ['String', 'prototype'], + '%SymbolPrototype%': ['Symbol', 'prototype'], + '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], + '%TypedArrayPrototype%': ['TypedArray', 'prototype'], + '%TypeErrorPrototype%': ['TypeError', 'prototype'], + '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], + '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], + '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], + '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], + '%URIErrorPrototype%': ['URIError', 'prototype'], + '%WeakMapPrototype%': ['WeakMap', 'prototype'], + '%WeakSetPrototype%': ['WeakSet', 'prototype'] +}; + +var bind = require('function-bind'); +var hasOwn = require('hasown'); +var $concat = bind.call(Function.call, Array.prototype.concat); +var $spliceApply = bind.call(Function.apply, Array.prototype.splice); +var $replace = bind.call(Function.call, String.prototype.replace); +var $strSlice = bind.call(Function.call, String.prototype.slice); +var $exec = bind.call(Function.call, RegExp.prototype.exec); + +/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ +var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; +var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ +var stringToPath = function stringToPath(string) { + var first = $strSlice(string, 0, 1); + var last = $strSlice(string, -1); + if (first === '%' && last !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); + } else if (last === '%' && first !== '%') { + throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); + } + var result = []; + $replace(string, rePropName, function (match, number, quote, subString) { + result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; + }); + return result; +}; +/* end adaptation */ + +var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { + var intrinsicName = name; + var alias; + if (hasOwn(LEGACY_ALIASES, intrinsicName)) { + alias = LEGACY_ALIASES[intrinsicName]; + intrinsicName = '%' + alias[0] + '%'; + } + + if (hasOwn(INTRINSICS, intrinsicName)) { + var value = INTRINSICS[intrinsicName]; + if (value === needsEval) { + value = doEval(intrinsicName); + } + if (typeof value === 'undefined' && !allowMissing) { + throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); + } + + return { + alias: alias, + name: intrinsicName, + value: value + }; + } + + throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); +}; + +module.exports = function GetIntrinsic(name, allowMissing) { + if (typeof name !== 'string' || name.length === 0) { + throw new $TypeError('intrinsic name must be a non-empty string'); + } + if (arguments.length > 1 && typeof allowMissing !== 'boolean') { + throw new $TypeError('"allowMissing" argument must be a boolean'); + } + + if ($exec(/^%?[^%]*%?$/, name) === null) { + throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name'); + } + var parts = stringToPath(name); + var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; + + var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); + var intrinsicRealName = intrinsic.name; + var value = intrinsic.value; + var skipFurtherCaching = false; + + var alias = intrinsic.alias; + if (alias) { + intrinsicBaseName = alias[0]; + $spliceApply(parts, $concat([0, 1], alias)); + } + + for (var i = 1, isOwn = true; i < parts.length; i += 1) { + var part = parts[i]; + var first = $strSlice(part, 0, 1); + var last = $strSlice(part, -1); + if ( + ( + (first === '"' || first === "'" || first === '`') + || (last === '"' || last === "'" || last === '`') + ) + && first !== last + ) { + throw new $SyntaxError('property names with quotes must have matching quotes'); + } + if (part === 'constructor' || !isOwn) { + skipFurtherCaching = true; + } + + intrinsicBaseName += '.' + part; + intrinsicRealName = '%' + intrinsicBaseName + '%'; + + if (hasOwn(INTRINSICS, intrinsicRealName)) { + value = INTRINSICS[intrinsicRealName]; + } else if (value != null) { + if (!(part in value)) { + if (!allowMissing) { + throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.'); + } + return void undefined; + } + if ($gOPD && (i + 1) >= parts.length) { + var desc = $gOPD(value, part); + isOwn = !!desc; + + // By convention, when a data property is converted to an accessor + // property to emulate a data property that does not suffer from + // the override mistake, that accessor's getter is marked with + // an `originalValue` property. Here, when we detect this, we + // uphold the illusion by pretending to see that original data + // property, i.e., returning the value rather than the getter + // itself. + if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { + value = desc.get; + } else { + value = value[part]; + } + } else { + isOwn = hasOwn(value, part); + value = value[part]; + } + + if (isOwn && !skipFurtherCaching) { + INTRINSICS[intrinsicRealName] = value; + } + } + } + return value; +}; + +},{"es-errors":298,"es-errors/eval":297,"es-errors/range":299,"es-errors/ref":300,"es-errors/syntax":301,"es-errors/type":302,"es-errors/uri":303,"function-bind":309,"has-proto":314,"has-symbols":315,"hasown":346}],311:[function(require,module,exports){ +(function (global,Buffer){(function (){ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,b,c){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e= this._blockSize) { + for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++] + this._update() + this._blockOffset = 0 + } + while (offset < data.length) block[this._blockOffset++] = data[offset++] + + // update length + for (var j = 0, carry = data.length * 8; carry > 0; ++j) { + this._length[j] += carry + carry = (this._length[j] / 0x0100000000) | 0 + if (carry > 0) this._length[j] -= 0x0100000000 * carry + } + + return this +} + +HashBase.prototype._update = function () { + throw new Error('_update is not implemented') +} + +HashBase.prototype.digest = function (encoding) { + if (this._finalized) throw new Error('Digest already called') + this._finalized = true + + var digest = this._digest() + if (encoding !== undefined) digest = digest.toString(encoding) + + // reset state + this._block.fill(0) + this._blockOffset = 0 + for (var i = 0; i < 4; ++i) this._length[i] = 0 + + return digest +} + +HashBase.prototype._digest = function () { + throw new Error('_digest is not implemented') +} + +module.exports = HashBase + +},{"inherits":349,"readable-stream":333,"safe-buffer":463}],319:[function(require,module,exports){ +arguments[4][229][0].apply(exports,arguments) +},{"dup":229}],320:[function(require,module,exports){ +arguments[4][230][0].apply(exports,arguments) +},{"./_stream_readable":322,"./_stream_writable":324,"_process":451,"dup":230,"inherits":349}],321:[function(require,module,exports){ +arguments[4][231][0].apply(exports,arguments) +},{"./_stream_transform":323,"dup":231,"inherits":349}],322:[function(require,module,exports){ +arguments[4][232][0].apply(exports,arguments) +},{"../errors":319,"./_stream_duplex":320,"./internal/streams/async_iterator":325,"./internal/streams/buffer_list":326,"./internal/streams/destroy":327,"./internal/streams/from":329,"./internal/streams/state":331,"./internal/streams/stream":332,"_process":451,"buffer":249,"dup":232,"events":304,"inherits":349,"string_decoder/":496,"util":200}],323:[function(require,module,exports){ +arguments[4][233][0].apply(exports,arguments) +},{"../errors":319,"./_stream_duplex":320,"dup":233,"inherits":349}],324:[function(require,module,exports){ +arguments[4][234][0].apply(exports,arguments) +},{"../errors":319,"./_stream_duplex":320,"./internal/streams/destroy":327,"./internal/streams/state":331,"./internal/streams/stream":332,"_process":451,"buffer":249,"dup":234,"inherits":349,"util-deprecate":524}],325:[function(require,module,exports){ +arguments[4][235][0].apply(exports,arguments) +},{"./end-of-stream":328,"_process":451,"dup":235}],326:[function(require,module,exports){ +arguments[4][236][0].apply(exports,arguments) +},{"buffer":249,"dup":236,"util":200}],327:[function(require,module,exports){ +arguments[4][237][0].apply(exports,arguments) +},{"_process":451,"dup":237}],328:[function(require,module,exports){ +arguments[4][238][0].apply(exports,arguments) +},{"../../../errors":319,"dup":238}],329:[function(require,module,exports){ +arguments[4][239][0].apply(exports,arguments) +},{"dup":239}],330:[function(require,module,exports){ +arguments[4][240][0].apply(exports,arguments) +},{"../../../errors":319,"./end-of-stream":328,"dup":240}],331:[function(require,module,exports){ +arguments[4][241][0].apply(exports,arguments) +},{"../../../errors":319,"dup":241}],332:[function(require,module,exports){ +arguments[4][242][0].apply(exports,arguments) +},{"dup":242,"events":304}],333:[function(require,module,exports){ +arguments[4][243][0].apply(exports,arguments) +},{"./lib/_stream_duplex.js":320,"./lib/_stream_passthrough.js":321,"./lib/_stream_readable.js":322,"./lib/_stream_transform.js":323,"./lib/_stream_writable.js":324,"./lib/internal/streams/end-of-stream.js":328,"./lib/internal/streams/pipeline.js":330,"dup":243}],334:[function(require,module,exports){ +var hash = exports; + +hash.utils = require('./hash/utils'); +hash.common = require('./hash/common'); +hash.sha = require('./hash/sha'); +hash.ripemd = require('./hash/ripemd'); +hash.hmac = require('./hash/hmac'); + +// Proxy hash functions to the main object +hash.sha1 = hash.sha.sha1; +hash.sha256 = hash.sha.sha256; +hash.sha224 = hash.sha.sha224; +hash.sha384 = hash.sha.sha384; +hash.sha512 = hash.sha.sha512; +hash.ripemd160 = hash.ripemd.ripemd160; + +},{"./hash/common":335,"./hash/hmac":336,"./hash/ripemd":337,"./hash/sha":338,"./hash/utils":345}],335:[function(require,module,exports){ +'use strict'; + +var utils = require('./utils'); +var assert = require('minimalistic-assert'); + +function BlockHash() { + this.pending = null; + this.pendingTotal = 0; + this.blockSize = this.constructor.blockSize; + this.outSize = this.constructor.outSize; + this.hmacStrength = this.constructor.hmacStrength; + this.padLength = this.constructor.padLength / 8; + this.endian = 'big'; + + this._delta8 = this.blockSize / 8; + this._delta32 = this.blockSize / 32; +} +exports.BlockHash = BlockHash; + +BlockHash.prototype.update = function update(msg, enc) { + // Convert message to array, pad it, and join into 32bit blocks + msg = utils.toArray(msg, enc); + if (!this.pending) + this.pending = msg; + else + this.pending = this.pending.concat(msg); + this.pendingTotal += msg.length; + + // Enough data, try updating + if (this.pending.length >= this._delta8) { + msg = this.pending; + + // Process pending data in blocks + var r = msg.length % this._delta8; + this.pending = msg.slice(msg.length - r, msg.length); + if (this.pending.length === 0) + this.pending = null; + + msg = utils.join32(msg, 0, msg.length - r, this.endian); + for (var i = 0; i < msg.length; i += this._delta32) + this._update(msg, i, i + this._delta32); + } + + return this; +}; + +BlockHash.prototype.digest = function digest(enc) { + this.update(this._pad()); + assert(this.pending === null); + + return this._digest(enc); +}; + +BlockHash.prototype._pad = function pad() { + var len = this.pendingTotal; + var bytes = this._delta8; + var k = bytes - ((len + this.padLength) % bytes); + var res = new Array(k + this.padLength); + res[0] = 0x80; + for (var i = 1; i < k; i++) + res[i] = 0; + + // Append length + len <<= 3; + if (this.endian === 'big') { + for (var t = 8; t < this.padLength; t++) + res[i++] = 0; + + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = (len >>> 24) & 0xff; + res[i++] = (len >>> 16) & 0xff; + res[i++] = (len >>> 8) & 0xff; + res[i++] = len & 0xff; + } else { + res[i++] = len & 0xff; + res[i++] = (len >>> 8) & 0xff; + res[i++] = (len >>> 16) & 0xff; + res[i++] = (len >>> 24) & 0xff; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + + for (t = 8; t < this.padLength; t++) + res[i++] = 0; + } + + return res; +}; + +},{"./utils":345,"minimalistic-assert":436}],336:[function(require,module,exports){ +'use strict'; + +var utils = require('./utils'); +var assert = require('minimalistic-assert'); + +function Hmac(hash, key, enc) { + if (!(this instanceof Hmac)) + return new Hmac(hash, key, enc); + this.Hash = hash; + this.blockSize = hash.blockSize / 8; + this.outSize = hash.outSize / 8; + this.inner = null; + this.outer = null; + + this._init(utils.toArray(key, enc)); +} +module.exports = Hmac; + +Hmac.prototype._init = function init(key) { + // Shorten key, if needed + if (key.length > this.blockSize) + key = new this.Hash().update(key).digest(); + assert(key.length <= this.blockSize); + + // Add padding to key + for (var i = key.length; i < this.blockSize; i++) + key.push(0); + + for (i = 0; i < key.length; i++) + key[i] ^= 0x36; + this.inner = new this.Hash().update(key); + + // 0x36 ^ 0x5c = 0x6a + for (i = 0; i < key.length; i++) + key[i] ^= 0x6a; + this.outer = new this.Hash().update(key); +}; + +Hmac.prototype.update = function update(msg, enc) { + this.inner.update(msg, enc); + return this; +}; + +Hmac.prototype.digest = function digest(enc) { + this.outer.update(this.inner.digest()); + return this.outer.digest(enc); +}; + +},{"./utils":345,"minimalistic-assert":436}],337:[function(require,module,exports){ +'use strict'; + +var utils = require('./utils'); +var common = require('./common'); + +var rotl32 = utils.rotl32; +var sum32 = utils.sum32; +var sum32_3 = utils.sum32_3; +var sum32_4 = utils.sum32_4; +var BlockHash = common.BlockHash; + +function RIPEMD160() { + if (!(this instanceof RIPEMD160)) + return new RIPEMD160(); + + BlockHash.call(this); + + this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ]; + this.endian = 'little'; +} +utils.inherits(RIPEMD160, BlockHash); +exports.ripemd160 = RIPEMD160; + +RIPEMD160.blockSize = 512; +RIPEMD160.outSize = 160; +RIPEMD160.hmacStrength = 192; +RIPEMD160.padLength = 64; + +RIPEMD160.prototype._update = function update(msg, start) { + var A = this.h[0]; + var B = this.h[1]; + var C = this.h[2]; + var D = this.h[3]; + var E = this.h[4]; + var Ah = A; + var Bh = B; + var Ch = C; + var Dh = D; + var Eh = E; + for (var j = 0; j < 80; j++) { + var T = sum32( + rotl32( + sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), + s[j]), + E); + A = E; + E = D; + D = rotl32(C, 10); + C = B; + B = T; + T = sum32( + rotl32( + sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), + sh[j]), + Eh); + Ah = Eh; + Eh = Dh; + Dh = rotl32(Ch, 10); + Ch = Bh; + Bh = T; + } + T = sum32_3(this.h[1], C, Dh); + this.h[1] = sum32_3(this.h[2], D, Eh); + this.h[2] = sum32_3(this.h[3], E, Ah); + this.h[3] = sum32_3(this.h[4], A, Bh); + this.h[4] = sum32_3(this.h[0], B, Ch); + this.h[0] = T; +}; + +RIPEMD160.prototype._digest = function digest(enc) { + if (enc === 'hex') + return utils.toHex32(this.h, 'little'); + else + return utils.split32(this.h, 'little'); +}; + +function f(j, x, y, z) { + if (j <= 15) + return x ^ y ^ z; + else if (j <= 31) + return (x & y) | ((~x) & z); + else if (j <= 47) + return (x | (~y)) ^ z; + else if (j <= 63) + return (x & z) | (y & (~z)); + else + return x ^ (y | (~z)); +} + +function K(j) { + if (j <= 15) + return 0x00000000; + else if (j <= 31) + return 0x5a827999; + else if (j <= 47) + return 0x6ed9eba1; + else if (j <= 63) + return 0x8f1bbcdc; + else + return 0xa953fd4e; +} + +function Kh(j) { + if (j <= 15) + return 0x50a28be6; + else if (j <= 31) + return 0x5c4dd124; + else if (j <= 47) + return 0x6d703ef3; + else if (j <= 63) + return 0x7a6d76e9; + else + return 0x00000000; +} + +var r = [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 +]; + +var rh = [ + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 +]; + +var s = [ + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 +]; + +var sh = [ + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 +]; + +},{"./common":335,"./utils":345}],338:[function(require,module,exports){ +'use strict'; + +exports.sha1 = require('./sha/1'); +exports.sha224 = require('./sha/224'); +exports.sha256 = require('./sha/256'); +exports.sha384 = require('./sha/384'); +exports.sha512 = require('./sha/512'); + +},{"./sha/1":339,"./sha/224":340,"./sha/256":341,"./sha/384":342,"./sha/512":343}],339:[function(require,module,exports){ +'use strict'; + +var utils = require('../utils'); +var common = require('../common'); +var shaCommon = require('./common'); + +var rotl32 = utils.rotl32; +var sum32 = utils.sum32; +var sum32_5 = utils.sum32_5; +var ft_1 = shaCommon.ft_1; +var BlockHash = common.BlockHash; + +var sha1_K = [ + 0x5A827999, 0x6ED9EBA1, + 0x8F1BBCDC, 0xCA62C1D6 +]; + +function SHA1() { + if (!(this instanceof SHA1)) + return new SHA1(); + + BlockHash.call(this); + this.h = [ + 0x67452301, 0xefcdab89, 0x98badcfe, + 0x10325476, 0xc3d2e1f0 ]; + this.W = new Array(80); +} + +utils.inherits(SHA1, BlockHash); +module.exports = SHA1; + +SHA1.blockSize = 512; +SHA1.outSize = 160; +SHA1.hmacStrength = 80; +SHA1.padLength = 64; + +SHA1.prototype._update = function _update(msg, start) { + var W = this.W; + + for (var i = 0; i < 16; i++) + W[i] = msg[start + i]; + + for(; i < W.length; i++) + W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); + + var a = this.h[0]; + var b = this.h[1]; + var c = this.h[2]; + var d = this.h[3]; + var e = this.h[4]; + + for (i = 0; i < W.length; i++) { + var s = ~~(i / 20); + var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]); + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = t; + } + + this.h[0] = sum32(this.h[0], a); + this.h[1] = sum32(this.h[1], b); + this.h[2] = sum32(this.h[2], c); + this.h[3] = sum32(this.h[3], d); + this.h[4] = sum32(this.h[4], e); +}; + +SHA1.prototype._digest = function digest(enc) { + if (enc === 'hex') + return utils.toHex32(this.h, 'big'); + else + return utils.split32(this.h, 'big'); +}; + +},{"../common":335,"../utils":345,"./common":344}],340:[function(require,module,exports){ +'use strict'; + +var utils = require('../utils'); +var SHA256 = require('./256'); + +function SHA224() { + if (!(this instanceof SHA224)) + return new SHA224(); + + SHA256.call(this); + this.h = [ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ]; +} +utils.inherits(SHA224, SHA256); +module.exports = SHA224; + +SHA224.blockSize = 512; +SHA224.outSize = 224; +SHA224.hmacStrength = 192; +SHA224.padLength = 64; + +SHA224.prototype._digest = function digest(enc) { + // Just truncate output + if (enc === 'hex') + return utils.toHex32(this.h.slice(0, 7), 'big'); + else + return utils.split32(this.h.slice(0, 7), 'big'); +}; + + +},{"../utils":345,"./256":341}],341:[function(require,module,exports){ +'use strict'; + +var utils = require('../utils'); +var common = require('../common'); +var shaCommon = require('./common'); +var assert = require('minimalistic-assert'); + +var sum32 = utils.sum32; +var sum32_4 = utils.sum32_4; +var sum32_5 = utils.sum32_5; +var ch32 = shaCommon.ch32; +var maj32 = shaCommon.maj32; +var s0_256 = shaCommon.s0_256; +var s1_256 = shaCommon.s1_256; +var g0_256 = shaCommon.g0_256; +var g1_256 = shaCommon.g1_256; + +var BlockHash = common.BlockHash; + +var sha256_K = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +]; + +function SHA256() { + if (!(this instanceof SHA256)) + return new SHA256(); + + BlockHash.call(this); + this.h = [ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 + ]; + this.k = sha256_K; + this.W = new Array(64); +} +utils.inherits(SHA256, BlockHash); +module.exports = SHA256; + +SHA256.blockSize = 512; +SHA256.outSize = 256; +SHA256.hmacStrength = 192; +SHA256.padLength = 64; + +SHA256.prototype._update = function _update(msg, start) { + var W = this.W; + + for (var i = 0; i < 16; i++) + W[i] = msg[start + i]; + for (; i < W.length; i++) + W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]); + + var a = this.h[0]; + var b = this.h[1]; + var c = this.h[2]; + var d = this.h[3]; + var e = this.h[4]; + var f = this.h[5]; + var g = this.h[6]; + var h = this.h[7]; + + assert(this.k.length === W.length); + for (i = 0; i < W.length; i++) { + var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]); + var T2 = sum32(s0_256(a), maj32(a, b, c)); + h = g; + g = f; + f = e; + e = sum32(d, T1); + d = c; + c = b; + b = a; + a = sum32(T1, T2); + } + + this.h[0] = sum32(this.h[0], a); + this.h[1] = sum32(this.h[1], b); + this.h[2] = sum32(this.h[2], c); + this.h[3] = sum32(this.h[3], d); + this.h[4] = sum32(this.h[4], e); + this.h[5] = sum32(this.h[5], f); + this.h[6] = sum32(this.h[6], g); + this.h[7] = sum32(this.h[7], h); +}; + +SHA256.prototype._digest = function digest(enc) { + if (enc === 'hex') + return utils.toHex32(this.h, 'big'); + else + return utils.split32(this.h, 'big'); +}; + +},{"../common":335,"../utils":345,"./common":344,"minimalistic-assert":436}],342:[function(require,module,exports){ +'use strict'; + +var utils = require('../utils'); + +var SHA512 = require('./512'); + +function SHA384() { + if (!(this instanceof SHA384)) + return new SHA384(); + + SHA512.call(this); + this.h = [ + 0xcbbb9d5d, 0xc1059ed8, + 0x629a292a, 0x367cd507, + 0x9159015a, 0x3070dd17, + 0x152fecd8, 0xf70e5939, + 0x67332667, 0xffc00b31, + 0x8eb44a87, 0x68581511, + 0xdb0c2e0d, 0x64f98fa7, + 0x47b5481d, 0xbefa4fa4 ]; +} +utils.inherits(SHA384, SHA512); +module.exports = SHA384; + +SHA384.blockSize = 1024; +SHA384.outSize = 384; +SHA384.hmacStrength = 192; +SHA384.padLength = 128; + +SHA384.prototype._digest = function digest(enc) { + if (enc === 'hex') + return utils.toHex32(this.h.slice(0, 12), 'big'); + else + return utils.split32(this.h.slice(0, 12), 'big'); +}; + +},{"../utils":345,"./512":343}],343:[function(require,module,exports){ +'use strict'; + +var utils = require('../utils'); +var common = require('../common'); +var assert = require('minimalistic-assert'); + +var rotr64_hi = utils.rotr64_hi; +var rotr64_lo = utils.rotr64_lo; +var shr64_hi = utils.shr64_hi; +var shr64_lo = utils.shr64_lo; +var sum64 = utils.sum64; +var sum64_hi = utils.sum64_hi; +var sum64_lo = utils.sum64_lo; +var sum64_4_hi = utils.sum64_4_hi; +var sum64_4_lo = utils.sum64_4_lo; +var sum64_5_hi = utils.sum64_5_hi; +var sum64_5_lo = utils.sum64_5_lo; + +var BlockHash = common.BlockHash; + +var sha512_K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function SHA512() { + if (!(this instanceof SHA512)) + return new SHA512(); + + BlockHash.call(this); + this.h = [ + 0x6a09e667, 0xf3bcc908, + 0xbb67ae85, 0x84caa73b, + 0x3c6ef372, 0xfe94f82b, + 0xa54ff53a, 0x5f1d36f1, + 0x510e527f, 0xade682d1, + 0x9b05688c, 0x2b3e6c1f, + 0x1f83d9ab, 0xfb41bd6b, + 0x5be0cd19, 0x137e2179 ]; + this.k = sha512_K; + this.W = new Array(160); +} +utils.inherits(SHA512, BlockHash); +module.exports = SHA512; + +SHA512.blockSize = 1024; +SHA512.outSize = 512; +SHA512.hmacStrength = 192; +SHA512.padLength = 128; + +SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) { + var W = this.W; + + // 32 x 32bit words + for (var i = 0; i < 32; i++) + W[i] = msg[start + i]; + for (; i < W.length; i += 2) { + var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2 + var c0_lo = g1_512_lo(W[i - 4], W[i - 3]); + var c1_hi = W[i - 14]; // i - 7 + var c1_lo = W[i - 13]; + var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15 + var c2_lo = g0_512_lo(W[i - 30], W[i - 29]); + var c3_hi = W[i - 32]; // i - 16 + var c3_lo = W[i - 31]; + + W[i] = sum64_4_hi( + c0_hi, c0_lo, + c1_hi, c1_lo, + c2_hi, c2_lo, + c3_hi, c3_lo); + W[i + 1] = sum64_4_lo( + c0_hi, c0_lo, + c1_hi, c1_lo, + c2_hi, c2_lo, + c3_hi, c3_lo); + } +}; + +SHA512.prototype._update = function _update(msg, start) { + this._prepareBlock(msg, start); -function throwIfNotStringOrBuffer (val, prefix) { - if (!Buffer.isBuffer(val) && typeof val !== 'string') { - throw new TypeError(prefix + ' must be a string or a buffer') - } -} + var W = this.W; -function HashBase (blockSize) { - Transform.call(this) + var ah = this.h[0]; + var al = this.h[1]; + var bh = this.h[2]; + var bl = this.h[3]; + var ch = this.h[4]; + var cl = this.h[5]; + var dh = this.h[6]; + var dl = this.h[7]; + var eh = this.h[8]; + var el = this.h[9]; + var fh = this.h[10]; + var fl = this.h[11]; + var gh = this.h[12]; + var gl = this.h[13]; + var hh = this.h[14]; + var hl = this.h[15]; - this._block = Buffer.allocUnsafe(blockSize) - this._blockSize = blockSize - this._blockOffset = 0 - this._length = [0, 0, 0, 0] + assert(this.k.length === W.length); + for (var i = 0; i < W.length; i += 2) { + var c0_hi = hh; + var c0_lo = hl; + var c1_hi = s1_512_hi(eh, el); + var c1_lo = s1_512_lo(eh, el); + var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl); + var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl); + var c3_hi = this.k[i]; + var c3_lo = this.k[i + 1]; + var c4_hi = W[i]; + var c4_lo = W[i + 1]; - this._finalized = false -} + var T1_hi = sum64_5_hi( + c0_hi, c0_lo, + c1_hi, c1_lo, + c2_hi, c2_lo, + c3_hi, c3_lo, + c4_hi, c4_lo); + var T1_lo = sum64_5_lo( + c0_hi, c0_lo, + c1_hi, c1_lo, + c2_hi, c2_lo, + c3_hi, c3_lo, + c4_hi, c4_lo); -inherits(HashBase, Transform) + c0_hi = s0_512_hi(ah, al); + c0_lo = s0_512_lo(ah, al); + c1_hi = maj64_hi(ah, al, bh, bl, ch, cl); + c1_lo = maj64_lo(ah, al, bh, bl, ch, cl); -HashBase.prototype._transform = function (chunk, encoding, callback) { - var error = null - try { - this.update(chunk, encoding) - } catch (err) { - error = err + var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo); + var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo); + + hh = gh; + hl = gl; + + gh = fh; + gl = fl; + + fh = eh; + fl = el; + + eh = sum64_hi(dh, dl, T1_hi, T1_lo); + el = sum64_lo(dl, dl, T1_hi, T1_lo); + + dh = ch; + dl = cl; + + ch = bh; + cl = bl; + + bh = ah; + bl = al; + + ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo); + al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo); } - callback(error) + sum64(this.h, 0, ah, al); + sum64(this.h, 2, bh, bl); + sum64(this.h, 4, ch, cl); + sum64(this.h, 6, dh, dl); + sum64(this.h, 8, eh, el); + sum64(this.h, 10, fh, fl); + sum64(this.h, 12, gh, gl); + sum64(this.h, 14, hh, hl); +}; + +SHA512.prototype._digest = function digest(enc) { + if (enc === 'hex') + return utils.toHex32(this.h, 'big'); + else + return utils.split32(this.h, 'big'); +}; + +function ch64_hi(xh, xl, yh, yl, zh) { + var r = (xh & yh) ^ ((~xh) & zh); + if (r < 0) + r += 0x100000000; + return r; } -HashBase.prototype._flush = function (callback) { - var error = null - try { - this.push(this.digest()) - } catch (err) { - error = err - } +function ch64_lo(xh, xl, yh, yl, zh, zl) { + var r = (xl & yl) ^ ((~xl) & zl); + if (r < 0) + r += 0x100000000; + return r; +} - callback(error) +function maj64_hi(xh, xl, yh, yl, zh) { + var r = (xh & yh) ^ (xh & zh) ^ (yh & zh); + if (r < 0) + r += 0x100000000; + return r; } -HashBase.prototype.update = function (data, encoding) { - throwIfNotStringOrBuffer(data, 'Data') - if (this._finalized) throw new Error('Digest already called') - if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding) +function maj64_lo(xh, xl, yh, yl, zh, zl) { + var r = (xl & yl) ^ (xl & zl) ^ (yl & zl); + if (r < 0) + r += 0x100000000; + return r; +} - // consume data - var block = this._block - var offset = 0 - while (this._blockOffset + data.length - offset >= this._blockSize) { - for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++] - this._update() - this._blockOffset = 0 - } - while (offset < data.length) block[this._blockOffset++] = data[offset++] +function s0_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 28); + var c1_hi = rotr64_hi(xl, xh, 2); // 34 + var c2_hi = rotr64_hi(xl, xh, 7); // 39 - // update length - for (var j = 0, carry = data.length * 8; carry > 0; ++j) { - this._length[j] += carry - carry = (this._length[j] / 0x0100000000) | 0 - if (carry > 0) this._length[j] -= 0x0100000000 * carry - } + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) + r += 0x100000000; + return r; +} - return this +function s0_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 28); + var c1_lo = rotr64_lo(xl, xh, 2); // 34 + var c2_lo = rotr64_lo(xl, xh, 7); // 39 + + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) + r += 0x100000000; + return r; } -HashBase.prototype._update = function () { - throw new Error('_update is not implemented') +function s1_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 14); + var c1_hi = rotr64_hi(xh, xl, 18); + var c2_hi = rotr64_hi(xl, xh, 9); // 41 + + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) + r += 0x100000000; + return r; } -HashBase.prototype.digest = function (encoding) { - if (this._finalized) throw new Error('Digest already called') - this._finalized = true +function s1_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 14); + var c1_lo = rotr64_lo(xh, xl, 18); + var c2_lo = rotr64_lo(xl, xh, 9); // 41 - var digest = this._digest() - if (encoding !== undefined) digest = digest.toString(encoding) + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) + r += 0x100000000; + return r; +} - // reset state - this._block.fill(0) - this._blockOffset = 0 - for (var i = 0; i < 4; ++i) this._length[i] = 0 +function g0_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 1); + var c1_hi = rotr64_hi(xh, xl, 8); + var c2_hi = shr64_hi(xh, xl, 7); - return digest + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) + r += 0x100000000; + return r; } -HashBase.prototype._digest = function () { - throw new Error('_digest is not implemented') +function g0_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 1); + var c1_lo = rotr64_lo(xh, xl, 8); + var c2_lo = shr64_lo(xh, xl, 7); + + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) + r += 0x100000000; + return r; } -module.exports = HashBase +function g1_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 19); + var c1_hi = rotr64_hi(xl, xh, 29); // 61 + var c2_hi = shr64_hi(xh, xl, 6); -},{"inherits":230,"readable-stream":214,"safe-buffer":280}],200:[function(require,module,exports){ -arguments[4][134][0].apply(exports,arguments) -},{"dup":134}],201:[function(require,module,exports){ -arguments[4][135][0].apply(exports,arguments) -},{"./_stream_readable":203,"./_stream_writable":205,"_process":253,"dup":135,"inherits":230}],202:[function(require,module,exports){ -arguments[4][136][0].apply(exports,arguments) -},{"./_stream_transform":204,"dup":136,"inherits":230}],203:[function(require,module,exports){ -arguments[4][137][0].apply(exports,arguments) -},{"../errors":200,"./_stream_duplex":201,"./internal/streams/async_iterator":206,"./internal/streams/buffer_list":207,"./internal/streams/destroy":208,"./internal/streams/from":210,"./internal/streams/state":212,"./internal/streams/stream":213,"_process":253,"buffer":155,"dup":137,"events":195,"inherits":230,"string_decoder/":215,"util":105}],204:[function(require,module,exports){ -arguments[4][138][0].apply(exports,arguments) -},{"../errors":200,"./_stream_duplex":201,"dup":138,"inherits":230}],205:[function(require,module,exports){ -arguments[4][139][0].apply(exports,arguments) -},{"../errors":200,"./_stream_duplex":201,"./internal/streams/destroy":208,"./internal/streams/state":212,"./internal/streams/stream":213,"_process":253,"buffer":155,"dup":139,"inherits":230,"util-deprecate":327}],206:[function(require,module,exports){ -arguments[4][140][0].apply(exports,arguments) -},{"./end-of-stream":209,"_process":253,"dup":140}],207:[function(require,module,exports){ -arguments[4][141][0].apply(exports,arguments) -},{"buffer":155,"dup":141,"util":105}],208:[function(require,module,exports){ -arguments[4][142][0].apply(exports,arguments) -},{"_process":253,"dup":142}],209:[function(require,module,exports){ -arguments[4][143][0].apply(exports,arguments) -},{"../../../errors":200,"dup":143}],210:[function(require,module,exports){ -arguments[4][144][0].apply(exports,arguments) -},{"dup":144}],211:[function(require,module,exports){ -arguments[4][145][0].apply(exports,arguments) -},{"../../../errors":200,"./end-of-stream":209,"dup":145}],212:[function(require,module,exports){ -arguments[4][146][0].apply(exports,arguments) -},{"../../../errors":200,"dup":146}],213:[function(require,module,exports){ -arguments[4][147][0].apply(exports,arguments) -},{"dup":147,"events":195}],214:[function(require,module,exports){ -arguments[4][148][0].apply(exports,arguments) -},{"./lib/_stream_duplex.js":201,"./lib/_stream_passthrough.js":202,"./lib/_stream_readable.js":203,"./lib/_stream_transform.js":204,"./lib/_stream_writable.js":205,"./lib/internal/streams/end-of-stream.js":209,"./lib/internal/streams/pipeline.js":211,"dup":148}],215:[function(require,module,exports){ -arguments[4][149][0].apply(exports,arguments) -},{"dup":149,"safe-buffer":280}],216:[function(require,module,exports){ -var hash = exports; + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) + r += 0x100000000; + return r; +} -hash.utils = require('./hash/utils'); -hash.common = require('./hash/common'); -hash.sha = require('./hash/sha'); -hash.ripemd = require('./hash/ripemd'); -hash.hmac = require('./hash/hmac'); +function g1_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 19); + var c1_lo = rotr64_lo(xl, xh, 29); // 61 + var c2_lo = shr64_lo(xh, xl, 6); -// Proxy hash functions to the main object -hash.sha1 = hash.sha.sha1; -hash.sha256 = hash.sha.sha256; -hash.sha224 = hash.sha.sha224; -hash.sha384 = hash.sha.sha384; -hash.sha512 = hash.sha.sha512; -hash.ripemd160 = hash.ripemd.ripemd160; + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) + r += 0x100000000; + return r; +} -},{"./hash/common":217,"./hash/hmac":218,"./hash/ripemd":219,"./hash/sha":220,"./hash/utils":227}],217:[function(require,module,exports){ +},{"../common":335,"../utils":345,"minimalistic-assert":436}],344:[function(require,module,exports){ 'use strict'; -var utils = require('./utils'); -var assert = require('minimalistic-assert'); +var utils = require('../utils'); +var rotr32 = utils.rotr32; -function BlockHash() { - this.pending = null; - this.pendingTotal = 0; - this.blockSize = this.constructor.blockSize; - this.outSize = this.constructor.outSize; - this.hmacStrength = this.constructor.hmacStrength; - this.padLength = this.constructor.padLength / 8; - this.endian = 'big'; +function ft_1(s, x, y, z) { + if (s === 0) + return ch32(x, y, z); + if (s === 1 || s === 3) + return p32(x, y, z); + if (s === 2) + return maj32(x, y, z); +} +exports.ft_1 = ft_1; - this._delta8 = this.blockSize / 8; - this._delta32 = this.blockSize / 32; +function ch32(x, y, z) { + return (x & y) ^ ((~x) & z); } -exports.BlockHash = BlockHash; +exports.ch32 = ch32; -BlockHash.prototype.update = function update(msg, enc) { - // Convert message to array, pad it, and join into 32bit blocks - msg = utils.toArray(msg, enc); - if (!this.pending) - this.pending = msg; - else - this.pending = this.pending.concat(msg); - this.pendingTotal += msg.length; +function maj32(x, y, z) { + return (x & y) ^ (x & z) ^ (y & z); +} +exports.maj32 = maj32; - // Enough data, try updating - if (this.pending.length >= this._delta8) { - msg = this.pending; +function p32(x, y, z) { + return x ^ y ^ z; +} +exports.p32 = p32; - // Process pending data in blocks - var r = msg.length % this._delta8; - this.pending = msg.slice(msg.length - r, msg.length); - if (this.pending.length === 0) - this.pending = null; +function s0_256(x) { + return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); +} +exports.s0_256 = s0_256; - msg = utils.join32(msg, 0, msg.length - r, this.endian); - for (var i = 0; i < msg.length; i += this._delta32) - this._update(msg, i, i + this._delta32); - } +function s1_256(x) { + return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); +} +exports.s1_256 = s1_256; - return this; -}; +function g0_256(x) { + return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3); +} +exports.g0_256 = g0_256; -BlockHash.prototype.digest = function digest(enc) { - this.update(this._pad()); - assert(this.pending === null); +function g1_256(x) { + return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10); +} +exports.g1_256 = g1_256; - return this._digest(enc); -}; +},{"../utils":345}],345:[function(require,module,exports){ +'use strict'; -BlockHash.prototype._pad = function pad() { - var len = this.pendingTotal; - var bytes = this._delta8; - var k = bytes - ((len + this.padLength) % bytes); - var res = new Array(k + this.padLength); - res[0] = 0x80; - for (var i = 1; i < k; i++) - res[i] = 0; +var assert = require('minimalistic-assert'); +var inherits = require('inherits'); - // Append length - len <<= 3; - if (this.endian === 'big') { - for (var t = 8; t < this.padLength; t++) - res[i++] = 0; +exports.inherits = inherits; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = (len >>> 24) & 0xff; - res[i++] = (len >>> 16) & 0xff; - res[i++] = (len >>> 8) & 0xff; - res[i++] = len & 0xff; +function isSurrogatePair(msg, i) { + if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) { + return false; + } + if (i < 0 || i + 1 >= msg.length) { + return false; + } + return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00; +} + +function toArray(msg, enc) { + if (Array.isArray(msg)) + return msg.slice(); + if (!msg) + return []; + var res = []; + if (typeof msg === 'string') { + if (!enc) { + // Inspired by stringToUtf8ByteArray() in closure-library by Google + // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143 + // Apache License 2.0 + // https://github.com/google/closure-library/blob/master/LICENSE + var p = 0; + for (var i = 0; i < msg.length; i++) { + var c = msg.charCodeAt(i); + if (c < 128) { + res[p++] = c; + } else if (c < 2048) { + res[p++] = (c >> 6) | 192; + res[p++] = (c & 63) | 128; + } else if (isSurrogatePair(msg, i)) { + c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF); + res[p++] = (c >> 18) | 240; + res[p++] = ((c >> 12) & 63) | 128; + res[p++] = ((c >> 6) & 63) | 128; + res[p++] = (c & 63) | 128; + } else { + res[p++] = (c >> 12) | 224; + res[p++] = ((c >> 6) & 63) | 128; + res[p++] = (c & 63) | 128; + } + } + } else if (enc === 'hex') { + msg = msg.replace(/[^a-z0-9]+/ig, ''); + if (msg.length % 2 !== 0) + msg = '0' + msg; + for (i = 0; i < msg.length; i += 2) + res.push(parseInt(msg[i] + msg[i + 1], 16)); + } } else { - res[i++] = len & 0xff; - res[i++] = (len >>> 8) & 0xff; - res[i++] = (len >>> 16) & 0xff; - res[i++] = (len >>> 24) & 0xff; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; + for (i = 0; i < msg.length; i++) + res[i] = msg[i] | 0; + } + return res; +} +exports.toArray = toArray; - for (t = 8; t < this.padLength; t++) - res[i++] = 0; +function toHex(msg) { + var res = ''; + for (var i = 0; i < msg.length; i++) + res += zero2(msg[i].toString(16)); + return res; +} +exports.toHex = toHex; + +function htonl(w) { + var res = (w >>> 24) | + ((w >>> 8) & 0xff00) | + ((w << 8) & 0xff0000) | + ((w & 0xff) << 24); + return res >>> 0; +} +exports.htonl = htonl; + +function toHex32(msg, endian) { + var res = ''; + for (var i = 0; i < msg.length; i++) { + var w = msg[i]; + if (endian === 'little') + w = htonl(w); + res += zero8(w.toString(16)); + } + return res; +} +exports.toHex32 = toHex32; + +function zero2(word) { + if (word.length === 1) + return '0' + word; + else + return word; +} +exports.zero2 = zero2; + +function zero8(word) { + if (word.length === 7) + return '0' + word; + else if (word.length === 6) + return '00' + word; + else if (word.length === 5) + return '000' + word; + else if (word.length === 4) + return '0000' + word; + else if (word.length === 3) + return '00000' + word; + else if (word.length === 2) + return '000000' + word; + else if (word.length === 1) + return '0000000' + word; + else + return word; +} +exports.zero8 = zero8; + +function join32(msg, start, end, endian) { + var len = end - start; + assert(len % 4 === 0); + var res = new Array(len / 4); + for (var i = 0, k = start; i < res.length; i++, k += 4) { + var w; + if (endian === 'big') + w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3]; + else + w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k]; + res[i] = w >>> 0; + } + return res; +} +exports.join32 = join32; + +function split32(msg, endian) { + var res = new Array(msg.length * 4); + for (var i = 0, k = 0; i < msg.length; i++, k += 4) { + var m = msg[i]; + if (endian === 'big') { + res[k] = m >>> 24; + res[k + 1] = (m >>> 16) & 0xff; + res[k + 2] = (m >>> 8) & 0xff; + res[k + 3] = m & 0xff; + } else { + res[k + 3] = m >>> 24; + res[k + 2] = (m >>> 16) & 0xff; + res[k + 1] = (m >>> 8) & 0xff; + res[k] = m & 0xff; + } } - return res; -}; - -},{"./utils":227,"minimalistic-assert":238}],218:[function(require,module,exports){ -'use strict'; - -var utils = require('./utils'); -var assert = require('minimalistic-assert'); - -function Hmac(hash, key, enc) { - if (!(this instanceof Hmac)) - return new Hmac(hash, key, enc); - this.Hash = hash; - this.blockSize = hash.blockSize / 8; - this.outSize = hash.outSize / 8; - this.inner = null; - this.outer = null; +} +exports.split32 = split32; - this._init(utils.toArray(key, enc)); +function rotr32(w, b) { + return (w >>> b) | (w << (32 - b)); } -module.exports = Hmac; +exports.rotr32 = rotr32; -Hmac.prototype._init = function init(key) { - // Shorten key, if needed - if (key.length > this.blockSize) - key = new this.Hash().update(key).digest(); - assert(key.length <= this.blockSize); +function rotl32(w, b) { + return (w << b) | (w >>> (32 - b)); +} +exports.rotl32 = rotl32; - // Add padding to key - for (var i = key.length; i < this.blockSize; i++) - key.push(0); +function sum32(a, b) { + return (a + b) >>> 0; +} +exports.sum32 = sum32; - for (i = 0; i < key.length; i++) - key[i] ^= 0x36; - this.inner = new this.Hash().update(key); +function sum32_3(a, b, c) { + return (a + b + c) >>> 0; +} +exports.sum32_3 = sum32_3; - // 0x36 ^ 0x5c = 0x6a - for (i = 0; i < key.length; i++) - key[i] ^= 0x6a; - this.outer = new this.Hash().update(key); -}; +function sum32_4(a, b, c, d) { + return (a + b + c + d) >>> 0; +} +exports.sum32_4 = sum32_4; -Hmac.prototype.update = function update(msg, enc) { - this.inner.update(msg, enc); - return this; -}; +function sum32_5(a, b, c, d, e) { + return (a + b + c + d + e) >>> 0; +} +exports.sum32_5 = sum32_5; -Hmac.prototype.digest = function digest(enc) { - this.outer.update(this.inner.digest()); - return this.outer.digest(enc); -}; +function sum64(buf, pos, ah, al) { + var bh = buf[pos]; + var bl = buf[pos + 1]; -},{"./utils":227,"minimalistic-assert":238}],219:[function(require,module,exports){ -'use strict'; + var lo = (al + bl) >>> 0; + var hi = (lo < al ? 1 : 0) + ah + bh; + buf[pos] = hi >>> 0; + buf[pos + 1] = lo; +} +exports.sum64 = sum64; -var utils = require('./utils'); -var common = require('./common'); +function sum64_hi(ah, al, bh, bl) { + var lo = (al + bl) >>> 0; + var hi = (lo < al ? 1 : 0) + ah + bh; + return hi >>> 0; +} +exports.sum64_hi = sum64_hi; -var rotl32 = utils.rotl32; -var sum32 = utils.sum32; -var sum32_3 = utils.sum32_3; -var sum32_4 = utils.sum32_4; -var BlockHash = common.BlockHash; +function sum64_lo(ah, al, bh, bl) { + var lo = al + bl; + return lo >>> 0; +} +exports.sum64_lo = sum64_lo; -function RIPEMD160() { - if (!(this instanceof RIPEMD160)) - return new RIPEMD160(); +function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { + var carry = 0; + var lo = al; + lo = (lo + bl) >>> 0; + carry += lo < al ? 1 : 0; + lo = (lo + cl) >>> 0; + carry += lo < cl ? 1 : 0; + lo = (lo + dl) >>> 0; + carry += lo < dl ? 1 : 0; - BlockHash.call(this); + var hi = ah + bh + ch + dh + carry; + return hi >>> 0; +} +exports.sum64_4_hi = sum64_4_hi; - this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ]; - this.endian = 'little'; +function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { + var lo = al + bl + cl + dl; + return lo >>> 0; } -utils.inherits(RIPEMD160, BlockHash); -exports.ripemd160 = RIPEMD160; +exports.sum64_4_lo = sum64_4_lo; -RIPEMD160.blockSize = 512; -RIPEMD160.outSize = 160; -RIPEMD160.hmacStrength = 192; -RIPEMD160.padLength = 64; +function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { + var carry = 0; + var lo = al; + lo = (lo + bl) >>> 0; + carry += lo < al ? 1 : 0; + lo = (lo + cl) >>> 0; + carry += lo < cl ? 1 : 0; + lo = (lo + dl) >>> 0; + carry += lo < dl ? 1 : 0; + lo = (lo + el) >>> 0; + carry += lo < el ? 1 : 0; -RIPEMD160.prototype._update = function update(msg, start) { - var A = this.h[0]; - var B = this.h[1]; - var C = this.h[2]; - var D = this.h[3]; - var E = this.h[4]; - var Ah = A; - var Bh = B; - var Ch = C; - var Dh = D; - var Eh = E; - for (var j = 0; j < 80; j++) { - var T = sum32( - rotl32( - sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), - s[j]), - E); - A = E; - E = D; - D = rotl32(C, 10); - C = B; - B = T; - T = sum32( - rotl32( - sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), - sh[j]), - Eh); - Ah = Eh; - Eh = Dh; - Dh = rotl32(Ch, 10); - Ch = Bh; - Bh = T; - } - T = sum32_3(this.h[1], C, Dh); - this.h[1] = sum32_3(this.h[2], D, Eh); - this.h[2] = sum32_3(this.h[3], E, Ah); - this.h[3] = sum32_3(this.h[4], A, Bh); - this.h[4] = sum32_3(this.h[0], B, Ch); - this.h[0] = T; -}; + var hi = ah + bh + ch + dh + eh + carry; + return hi >>> 0; +} +exports.sum64_5_hi = sum64_5_hi; -RIPEMD160.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h, 'little'); - else - return utils.split32(this.h, 'little'); -}; +function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { + var lo = al + bl + cl + dl + el; -function f(j, x, y, z) { - if (j <= 15) - return x ^ y ^ z; - else if (j <= 31) - return (x & y) | ((~x) & z); - else if (j <= 47) - return (x | (~y)) ^ z; - else if (j <= 63) - return (x & z) | (y & (~z)); - else - return x ^ (y | (~z)); + return lo >>> 0; } +exports.sum64_5_lo = sum64_5_lo; -function K(j) { - if (j <= 15) - return 0x00000000; - else if (j <= 31) - return 0x5a827999; - else if (j <= 47) - return 0x6ed9eba1; - else if (j <= 63) - return 0x8f1bbcdc; - else - return 0xa953fd4e; +function rotr64_hi(ah, al, num) { + var r = (al << (32 - num)) | (ah >>> num); + return r >>> 0; } +exports.rotr64_hi = rotr64_hi; -function Kh(j) { - if (j <= 15) - return 0x50a28be6; - else if (j <= 31) - return 0x5c4dd124; - else if (j <= 47) - return 0x6d703ef3; - else if (j <= 63) - return 0x7a6d76e9; - else - return 0x00000000; +function rotr64_lo(ah, al, num) { + var r = (ah << (32 - num)) | (al >>> num); + return r >>> 0; } +exports.rotr64_lo = rotr64_lo; -var r = [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, - 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, - 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, - 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 -]; - -var rh = [ - 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, - 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, - 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, - 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, - 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 -]; - -var s = [ - 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, - 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, - 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, - 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, - 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 -]; +function shr64_hi(ah, al, num) { + return ah >>> num; +} +exports.shr64_hi = shr64_hi; -var sh = [ - 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, - 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, - 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, - 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, - 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 -]; +function shr64_lo(ah, al, num) { + var r = (ah << (32 - num)) | (al >>> num); + return r >>> 0; +} +exports.shr64_lo = shr64_lo; -},{"./common":217,"./utils":227}],220:[function(require,module,exports){ +},{"inherits":349,"minimalistic-assert":436}],346:[function(require,module,exports){ 'use strict'; -exports.sha1 = require('./sha/1'); -exports.sha224 = require('./sha/224'); -exports.sha256 = require('./sha/256'); -exports.sha384 = require('./sha/384'); -exports.sha512 = require('./sha/512'); +var call = Function.prototype.call; +var $hasOwn = Object.prototype.hasOwnProperty; +var bind = require('function-bind'); + +/** @type {import('.')} */ +module.exports = bind.call(call, $hasOwn); -},{"./sha/1":221,"./sha/224":222,"./sha/256":223,"./sha/384":224,"./sha/512":225}],221:[function(require,module,exports){ +},{"function-bind":309}],347:[function(require,module,exports){ 'use strict'; -var utils = require('../utils'); -var common = require('../common'); -var shaCommon = require('./common'); +var hash = require('hash.js'); +var utils = require('minimalistic-crypto-utils'); +var assert = require('minimalistic-assert'); -var rotl32 = utils.rotl32; -var sum32 = utils.sum32; -var sum32_5 = utils.sum32_5; -var ft_1 = shaCommon.ft_1; -var BlockHash = common.BlockHash; +function HmacDRBG(options) { + if (!(this instanceof HmacDRBG)) + return new HmacDRBG(options); + this.hash = options.hash; + this.predResist = !!options.predResist; -var sha1_K = [ - 0x5A827999, 0x6ED9EBA1, - 0x8F1BBCDC, 0xCA62C1D6 -]; + this.outLen = this.hash.outSize; + this.minEntropy = options.minEntropy || this.hash.hmacStrength; -function SHA1() { - if (!(this instanceof SHA1)) - return new SHA1(); + this._reseed = null; + this.reseedInterval = null; + this.K = null; + this.V = null; - BlockHash.call(this); - this.h = [ - 0x67452301, 0xefcdab89, 0x98badcfe, - 0x10325476, 0xc3d2e1f0 ]; - this.W = new Array(80); + var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex'); + var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex'); + var pers = utils.toArray(options.pers, options.persEnc || 'hex'); + assert(entropy.length >= (this.minEntropy / 8), + 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); + this._init(entropy, nonce, pers); } +module.exports = HmacDRBG; -utils.inherits(SHA1, BlockHash); -module.exports = SHA1; +HmacDRBG.prototype._init = function init(entropy, nonce, pers) { + var seed = entropy.concat(nonce).concat(pers); -SHA1.blockSize = 512; -SHA1.outSize = 160; -SHA1.hmacStrength = 80; -SHA1.padLength = 64; + this.K = new Array(this.outLen / 8); + this.V = new Array(this.outLen / 8); + for (var i = 0; i < this.V.length; i++) { + this.K[i] = 0x00; + this.V[i] = 0x01; + } -SHA1.prototype._update = function _update(msg, start) { - var W = this.W; + this._update(seed); + this._reseed = 1; + this.reseedInterval = 0x1000000000000; // 2^48 +}; - for (var i = 0; i < 16; i++) - W[i] = msg[start + i]; +HmacDRBG.prototype._hmac = function hmac() { + return new hash.hmac(this.hash, this.K); +}; - for(; i < W.length; i++) - W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); +HmacDRBG.prototype._update = function update(seed) { + var kmac = this._hmac() + .update(this.V) + .update([ 0x00 ]); + if (seed) + kmac = kmac.update(seed); + this.K = kmac.digest(); + this.V = this._hmac().update(this.V).digest(); + if (!seed) + return; - var a = this.h[0]; - var b = this.h[1]; - var c = this.h[2]; - var d = this.h[3]; - var e = this.h[4]; + this.K = this._hmac() + .update(this.V) + .update([ 0x01 ]) + .update(seed) + .digest(); + this.V = this._hmac().update(this.V).digest(); +}; - for (i = 0; i < W.length; i++) { - var s = ~~(i / 20); - var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]); - e = d; - d = c; - c = rotl32(b, 30); - b = a; - a = t; +HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { + // Optional entropy enc + if (typeof entropyEnc !== 'string') { + addEnc = add; + add = entropyEnc; + entropyEnc = null; } - this.h[0] = sum32(this.h[0], a); - this.h[1] = sum32(this.h[1], b); - this.h[2] = sum32(this.h[2], c); - this.h[3] = sum32(this.h[3], d); - this.h[4] = sum32(this.h[4], e); + entropy = utils.toArray(entropy, entropyEnc); + add = utils.toArray(add, addEnc); + + assert(entropy.length >= (this.minEntropy / 8), + 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); + + this._update(entropy.concat(add || [])); + this._reseed = 1; }; -SHA1.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h, 'big'); - else - return utils.split32(this.h, 'big'); +HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { + if (this._reseed > this.reseedInterval) + throw new Error('Reseed is required'); + + // Optional encoding + if (typeof enc !== 'string') { + addEnc = add; + add = enc; + enc = null; + } + + // Optional additional data + if (add) { + add = utils.toArray(add, addEnc || 'hex'); + this._update(add); + } + + var temp = []; + while (temp.length < len) { + this.V = this._hmac().update(this.V).digest(); + temp = temp.concat(this.V); + } + + var res = temp.slice(0, len); + this._update(add); + this._reseed++; + return utils.encode(res, enc); }; -},{"../common":217,"../utils":227,"./common":226}],222:[function(require,module,exports){ -'use strict'; +},{"hash.js":334,"minimalistic-assert":436,"minimalistic-crypto-utils":437}],348:[function(require,module,exports){ +exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = (nBytes * 8) - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] -var utils = require('../utils'); -var SHA256 = require('./256'); + i += d -function SHA224() { - if (!(this instanceof SHA224)) - return new SHA224(); + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1) + e >>= (-nBits) + nBits += mLen + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +} + +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + var eLen = (nBytes * 8) - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + + value = Math.abs(value) + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 + } + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) + } + if (value * c >= 2) { + e++ + c /= 2 + } + + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = ((value * c) - 1) * Math.pow(2, mLen) + e = e + eBias + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 + } + } - SHA256.call(this); - this.h = [ - 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, - 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ]; -} -utils.inherits(SHA224, SHA256); -module.exports = SHA224; + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} -SHA224.blockSize = 512; -SHA224.outSize = 224; -SHA224.hmacStrength = 192; -SHA224.padLength = 64; + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} -SHA224.prototype._digest = function digest(enc) { - // Just truncate output - if (enc === 'hex') - return utils.toHex32(this.h.slice(0, 7), 'big'); - else - return utils.split32(this.h.slice(0, 7), 'big'); -}; + buffer[offset + i - d] |= s * 128 +} +},{}],349:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }) + } + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } + } +} -},{"../utils":227,"./256":223}],223:[function(require,module,exports){ +},{}],350:[function(require,module,exports){ 'use strict'; -var utils = require('../utils'); -var common = require('../common'); -var shaCommon = require('./common'); -var assert = require('minimalistic-assert'); - -var sum32 = utils.sum32; -var sum32_4 = utils.sum32_4; -var sum32_5 = utils.sum32_5; -var ch32 = shaCommon.ch32; -var maj32 = shaCommon.maj32; -var s0_256 = shaCommon.s0_256; -var s1_256 = shaCommon.s1_256; -var g0_256 = shaCommon.g0_256; -var g1_256 = shaCommon.g1_256; - -var BlockHash = common.BlockHash; +var hasToStringTag = require('has-tostringtag/shams')(); +var callBound = require('call-bind/callBound'); -var sha256_K = [ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -]; +var $toString = callBound('Object.prototype.toString'); -function SHA256() { - if (!(this instanceof SHA256)) - return new SHA256(); +var isStandardArguments = function isArguments(value) { + if (hasToStringTag && value && typeof value === 'object' && Symbol.toStringTag in value) { + return false; + } + return $toString(value) === '[object Arguments]'; +}; - BlockHash.call(this); - this.h = [ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 - ]; - this.k = sha256_K; - this.W = new Array(64); -} -utils.inherits(SHA256, BlockHash); -module.exports = SHA256; +var isLegacyArguments = function isArguments(value) { + if (isStandardArguments(value)) { + return true; + } + return value !== null && + typeof value === 'object' && + typeof value.length === 'number' && + value.length >= 0 && + $toString(value) !== '[object Array]' && + $toString(value.callee) === '[object Function]'; +}; -SHA256.blockSize = 512; -SHA256.outSize = 256; -SHA256.hmacStrength = 192; -SHA256.padLength = 64; +var supportsStandardArguments = (function () { + return isStandardArguments(arguments); +}()); -SHA256.prototype._update = function _update(msg, start) { - var W = this.W; +isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests - for (var i = 0; i < 16; i++) - W[i] = msg[start + i]; - for (; i < W.length; i++) - W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]); +module.exports = supportsStandardArguments ? isStandardArguments : isLegacyArguments; - var a = this.h[0]; - var b = this.h[1]; - var c = this.h[2]; - var d = this.h[3]; - var e = this.h[4]; - var f = this.h[5]; - var g = this.h[6]; - var h = this.h[7]; +},{"call-bind/callBound":250,"has-tostringtag/shams":317}],351:[function(require,module,exports){ +/*! + * Determine if an object is a Buffer + * + * @author Feross Aboukhadijeh + * @license MIT + */ - assert(this.k.length === W.length); - for (i = 0; i < W.length; i++) { - var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]); - var T2 = sum32(s0_256(a), maj32(a, b, c)); - h = g; - g = f; - f = e; - e = sum32(d, T1); - d = c; - c = b; - b = a; - a = sum32(T1, T2); - } +// The _isBuffer check is for Safari 5-7 support, because it's missing +// Object.prototype.constructor. Remove this eventually +module.exports = function (obj) { + return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) +} - this.h[0] = sum32(this.h[0], a); - this.h[1] = sum32(this.h[1], b); - this.h[2] = sum32(this.h[2], c); - this.h[3] = sum32(this.h[3], d); - this.h[4] = sum32(this.h[4], e); - this.h[5] = sum32(this.h[5], f); - this.h[6] = sum32(this.h[6], g); - this.h[7] = sum32(this.h[7], h); -}; +function isBuffer (obj) { + return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) +} -SHA256.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h, 'big'); - else - return utils.split32(this.h, 'big'); -}; +// For Node v0.10 support. Remove this eventually. +function isSlowBuffer (obj) { + return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) +} -},{"../common":217,"../utils":227,"./common":226,"minimalistic-assert":238}],224:[function(require,module,exports){ +},{}],352:[function(require,module,exports){ 'use strict'; -var utils = require('../utils'); - -var SHA512 = require('./512'); - -function SHA384() { - if (!(this instanceof SHA384)) - return new SHA384(); - - SHA512.call(this); - this.h = [ - 0xcbbb9d5d, 0xc1059ed8, - 0x629a292a, 0x367cd507, - 0x9159015a, 0x3070dd17, - 0x152fecd8, 0xf70e5939, - 0x67332667, 0xffc00b31, - 0x8eb44a87, 0x68581511, - 0xdb0c2e0d, 0x64f98fa7, - 0x47b5481d, 0xbefa4fa4 ]; +var fnToStr = Function.prototype.toString; +var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply; +var badArrayLike; +var isCallableMarker; +if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') { + try { + badArrayLike = Object.defineProperty({}, 'length', { + get: function () { + throw isCallableMarker; + } + }); + isCallableMarker = {}; + // eslint-disable-next-line no-throw-literal + reflectApply(function () { throw 42; }, null, badArrayLike); + } catch (_) { + if (_ !== isCallableMarker) { + reflectApply = null; + } + } +} else { + reflectApply = null; } -utils.inherits(SHA384, SHA512); -module.exports = SHA384; -SHA384.blockSize = 1024; -SHA384.outSize = 384; -SHA384.hmacStrength = 192; -SHA384.padLength = 128; +var constructorRegex = /^\s*class\b/; +var isES6ClassFn = function isES6ClassFunction(value) { + try { + var fnStr = fnToStr.call(value); + return constructorRegex.test(fnStr); + } catch (e) { + return false; // not a function + } +}; -SHA384.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h.slice(0, 12), 'big'); - else - return utils.split32(this.h.slice(0, 12), 'big'); +var tryFunctionObject = function tryFunctionToStr(value) { + try { + if (isES6ClassFn(value)) { return false; } + fnToStr.call(value); + return true; + } catch (e) { + return false; + } }; +var toStr = Object.prototype.toString; +var objectClass = '[object Object]'; +var fnClass = '[object Function]'; +var genClass = '[object GeneratorFunction]'; +var ddaClass = '[object HTMLAllCollection]'; // IE 11 +var ddaClass2 = '[object HTML document.all class]'; +var ddaClass3 = '[object HTMLCollection]'; // IE 9-10 +var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag` + +var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing + +var isDDA = function isDocumentDotAll() { return false; }; +if (typeof document === 'object') { + // Firefox 3 canonicalizes DDA to undefined when it's not accessed directly + var all = document.all; + if (toStr.call(all) === toStr.call(document.all)) { + isDDA = function isDocumentDotAll(value) { + /* globals document: false */ + // in IE 6-8, typeof document.all is "object" and it's truthy + if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) { + try { + var str = toStr.call(value); + return ( + str === ddaClass + || str === ddaClass2 + || str === ddaClass3 // opera 12.16 + || str === objectClass // IE 6-8 + ) && value('') == null; // eslint-disable-line eqeqeq + } catch (e) { /**/ } + } + return false; + }; + } +} -},{"../utils":227,"./512":225}],225:[function(require,module,exports){ +module.exports = reflectApply + ? function isCallable(value) { + if (isDDA(value)) { return true; } + if (!value) { return false; } + if (typeof value !== 'function' && typeof value !== 'object') { return false; } + try { + reflectApply(value, null, badArrayLike); + } catch (e) { + if (e !== isCallableMarker) { return false; } + } + return !isES6ClassFn(value) && tryFunctionObject(value); + } + : function isCallable(value) { + if (isDDA(value)) { return true; } + if (!value) { return false; } + if (typeof value !== 'function' && typeof value !== 'object') { return false; } + if (hasToStringTag) { return tryFunctionObject(value); } + if (isES6ClassFn(value)) { return false; } + var strClass = toStr.call(value); + if (strClass !== fnClass && strClass !== genClass && !(/^\[object HTML/).test(strClass)) { return false; } + return tryFunctionObject(value); + }; + +},{}],353:[function(require,module,exports){ 'use strict'; -var utils = require('../utils'); -var common = require('../common'); -var assert = require('minimalistic-assert'); - -var rotr64_hi = utils.rotr64_hi; -var rotr64_lo = utils.rotr64_lo; -var shr64_hi = utils.shr64_hi; -var shr64_lo = utils.shr64_lo; -var sum64 = utils.sum64; -var sum64_hi = utils.sum64_hi; -var sum64_lo = utils.sum64_lo; -var sum64_4_hi = utils.sum64_4_hi; -var sum64_4_lo = utils.sum64_4_lo; -var sum64_5_hi = utils.sum64_5_hi; -var sum64_5_lo = utils.sum64_5_lo; +var toStr = Object.prototype.toString; +var fnToStr = Function.prototype.toString; +var isFnRegex = /^\s*(?:function)?\*/; +var hasToStringTag = require('has-tostringtag/shams')(); +var getProto = Object.getPrototypeOf; +var getGeneratorFunc = function () { // eslint-disable-line consistent-return + if (!hasToStringTag) { + return false; + } + try { + return Function('return function*() {}')(); + } catch (e) { + } +}; +var GeneratorFunction; -var BlockHash = common.BlockHash; +module.exports = function isGeneratorFunction(fn) { + if (typeof fn !== 'function') { + return false; + } + if (isFnRegex.test(fnToStr.call(fn))) { + return true; + } + if (!hasToStringTag) { + var str = toStr.call(fn); + return str === '[object GeneratorFunction]'; + } + if (!getProto) { + return false; + } + if (typeof GeneratorFunction === 'undefined') { + var generatorFunc = getGeneratorFunc(); + GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false; + } + return getProto(fn) === GeneratorFunction; +}; -var sha512_K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; +},{"has-tostringtag/shams":317}],354:[function(require,module,exports){ +'use strict'; -function SHA512() { - if (!(this instanceof SHA512)) - return new SHA512(); +var whichTypedArray = require('which-typed-array'); - BlockHash.call(this); - this.h = [ - 0x6a09e667, 0xf3bcc908, - 0xbb67ae85, 0x84caa73b, - 0x3c6ef372, 0xfe94f82b, - 0xa54ff53a, 0x5f1d36f1, - 0x510e527f, 0xade682d1, - 0x9b05688c, 0x2b3e6c1f, - 0x1f83d9ab, 0xfb41bd6b, - 0x5be0cd19, 0x137e2179 ]; - this.k = sha512_K; - this.W = new Array(160); -} -utils.inherits(SHA512, BlockHash); -module.exports = SHA512; +/** @type {import('.')} */ +module.exports = function isTypedArray(value) { + return !!whichTypedArray(value); +}; -SHA512.blockSize = 1024; -SHA512.outSize = 512; -SHA512.hmacStrength = 192; -SHA512.padLength = 128; +},{"which-typed-array":529}],355:[function(require,module,exports){ +(function (process,global){(function (){ +/** + * [js-sha256]{@link https://github.com/emn178/js-sha256} + * + * @version 0.9.0 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2014-2017 + * @license MIT + */ +/*jslint bitwise: true */ +(function () { + 'use strict'; -SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) { - var W = this.W; + var ERROR = 'input is invalid type'; + var WINDOW = typeof window === 'object'; + var root = WINDOW ? window : {}; + if (root.JS_SHA256_NO_WINDOW) { + WINDOW = false; + } + var WEB_WORKER = !WINDOW && typeof self === 'object'; + var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; + if (NODE_JS) { + root = global; + } else if (WEB_WORKER) { + root = self; + } + var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === 'object' && module.exports; + var AMD = typeof define === 'function' && define.amd; + var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; + var HEX_CHARS = '0123456789abcdef'.split(''); + var EXTRA = [-2147483648, 8388608, 32768, 128]; + var SHIFT = [24, 16, 8, 0]; + var K = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + ]; + var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer']; - // 32 x 32bit words - for (var i = 0; i < 32; i++) - W[i] = msg[start + i]; - for (; i < W.length; i += 2) { - var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2 - var c0_lo = g1_512_lo(W[i - 4], W[i - 3]); - var c1_hi = W[i - 14]; // i - 7 - var c1_lo = W[i - 13]; - var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15 - var c2_lo = g0_512_lo(W[i - 30], W[i - 29]); - var c3_hi = W[i - 32]; // i - 16 - var c3_lo = W[i - 31]; + var blocks = []; - W[i] = sum64_4_hi( - c0_hi, c0_lo, - c1_hi, c1_lo, - c2_hi, c2_lo, - c3_hi, c3_lo); - W[i + 1] = sum64_4_lo( - c0_hi, c0_lo, - c1_hi, c1_lo, - c2_hi, c2_lo, - c3_hi, c3_lo); + if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { + Array.isArray = function (obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; + }; } -}; -SHA512.prototype._update = function _update(msg, start) { - this._prepareBlock(msg, start); + if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { + ArrayBuffer.isView = function (obj) { + return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; + }; + } - var W = this.W; + var createOutputMethod = function (outputType, is224) { + return function (message) { + return new Sha256(is224, true).update(message)[outputType](); + }; + }; - var ah = this.h[0]; - var al = this.h[1]; - var bh = this.h[2]; - var bl = this.h[3]; - var ch = this.h[4]; - var cl = this.h[5]; - var dh = this.h[6]; - var dl = this.h[7]; - var eh = this.h[8]; - var el = this.h[9]; - var fh = this.h[10]; - var fl = this.h[11]; - var gh = this.h[12]; - var gl = this.h[13]; - var hh = this.h[14]; - var hl = this.h[15]; + var createMethod = function (is224) { + var method = createOutputMethod('hex', is224); + if (NODE_JS) { + method = nodeWrap(method, is224); + } + method.create = function () { + return new Sha256(is224); + }; + method.update = function (message) { + return method.create().update(message); + }; + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { + var type = OUTPUT_TYPES[i]; + method[type] = createOutputMethod(type, is224); + } + return method; + }; - assert(this.k.length === W.length); - for (var i = 0; i < W.length; i += 2) { - var c0_hi = hh; - var c0_lo = hl; - var c1_hi = s1_512_hi(eh, el); - var c1_lo = s1_512_lo(eh, el); - var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl); - var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl); - var c3_hi = this.k[i]; - var c3_lo = this.k[i + 1]; - var c4_hi = W[i]; - var c4_lo = W[i + 1]; + var nodeWrap = function (method, is224) { + var crypto = eval("require('crypto')"); + var Buffer = eval("require('buffer').Buffer"); + var algorithm = is224 ? 'sha224' : 'sha256'; + var nodeMethod = function (message) { + if (typeof message === 'string') { + return crypto.createHash(algorithm).update(message, 'utf8').digest('hex'); + } else { + if (message === null || message === undefined) { + throw new Error(ERROR); + } else if (message.constructor === ArrayBuffer) { + message = new Uint8Array(message); + } + } + if (Array.isArray(message) || ArrayBuffer.isView(message) || + message.constructor === Buffer) { + return crypto.createHash(algorithm).update(new Buffer(message)).digest('hex'); + } else { + return method(message); + } + }; + return nodeMethod; + }; - var T1_hi = sum64_5_hi( - c0_hi, c0_lo, - c1_hi, c1_lo, - c2_hi, c2_lo, - c3_hi, c3_lo, - c4_hi, c4_lo); - var T1_lo = sum64_5_lo( - c0_hi, c0_lo, - c1_hi, c1_lo, - c2_hi, c2_lo, - c3_hi, c3_lo, - c4_hi, c4_lo); + var createHmacOutputMethod = function (outputType, is224) { + return function (key, message) { + return new HmacSha256(key, is224, true).update(message)[outputType](); + }; + }; - c0_hi = s0_512_hi(ah, al); - c0_lo = s0_512_lo(ah, al); - c1_hi = maj64_hi(ah, al, bh, bl, ch, cl); - c1_lo = maj64_lo(ah, al, bh, bl, ch, cl); + var createHmacMethod = function (is224) { + var method = createHmacOutputMethod('hex', is224); + method.create = function (key) { + return new HmacSha256(key, is224); + }; + method.update = function (key, message) { + return method.create(key).update(message); + }; + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { + var type = OUTPUT_TYPES[i]; + method[type] = createHmacOutputMethod(type, is224); + } + return method; + }; - var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo); - var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo); + function Sha256(is224, sharedMemory) { + if (sharedMemory) { + blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + this.blocks = blocks; + } else { + this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } - hh = gh; - hl = gl; + if (is224) { + this.h0 = 0xc1059ed8; + this.h1 = 0x367cd507; + this.h2 = 0x3070dd17; + this.h3 = 0xf70e5939; + this.h4 = 0xffc00b31; + this.h5 = 0x68581511; + this.h6 = 0x64f98fa7; + this.h7 = 0xbefa4fa4; + } else { // 256 + this.h0 = 0x6a09e667; + this.h1 = 0xbb67ae85; + this.h2 = 0x3c6ef372; + this.h3 = 0xa54ff53a; + this.h4 = 0x510e527f; + this.h5 = 0x9b05688c; + this.h6 = 0x1f83d9ab; + this.h7 = 0x5be0cd19; + } - gh = fh; - gl = fl; + this.block = this.start = this.bytes = this.hBytes = 0; + this.finalized = this.hashed = false; + this.first = true; + this.is224 = is224; + } - fh = eh; - fl = el; + Sha256.prototype.update = function (message) { + if (this.finalized) { + return; + } + var notString, type = typeof message; + if (type !== 'string') { + if (type === 'object') { + if (message === null) { + throw new Error(ERROR); + } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { + message = new Uint8Array(message); + } else if (!Array.isArray(message)) { + if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { + throw new Error(ERROR); + } + } + } else { + throw new Error(ERROR); + } + notString = true; + } + var code, index = 0, i, length = message.length, blocks = this.blocks; - eh = sum64_hi(dh, dl, T1_hi, T1_lo); - el = sum64_lo(dl, dl, T1_hi, T1_lo); + while (index < length) { + if (this.hashed) { + this.hashed = false; + blocks[0] = this.block; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } - dh = ch; - dl = cl; + if (notString) { + for (i = this.start; index < length && i < 64; ++index) { + blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; + } + } else { + for (i = this.start; index < length && i < 64; ++index) { + code = message.charCodeAt(index); + if (code < 0x80) { + blocks[i >> 2] |= code << SHIFT[i++ & 3]; + } else if (code < 0x800) { + blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else if (code < 0xd800 || code >= 0xe000) { + blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); + blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } + } + } - ch = bh; - cl = bl; + this.lastByteIndex = i; + this.bytes += i - this.start; + if (i >= 64) { + this.block = blocks[16]; + this.start = i - 64; + this.hash(); + this.hashed = true; + } else { + this.start = i; + } + } + if (this.bytes > 4294967295) { + this.hBytes += this.bytes / 4294967296 << 0; + this.bytes = this.bytes % 4294967296; + } + return this; + }; - bh = ah; - bl = al; + Sha256.prototype.finalize = function () { + if (this.finalized) { + return; + } + this.finalized = true; + var blocks = this.blocks, i = this.lastByteIndex; + blocks[16] = this.block; + blocks[i >> 2] |= EXTRA[i & 3]; + this.block = blocks[16]; + if (i >= 56) { + if (!this.hashed) { + this.hash(); + } + blocks[0] = this.block; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } + blocks[14] = this.hBytes << 3 | this.bytes >>> 29; + blocks[15] = this.bytes << 3; + this.hash(); + }; - ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo); - al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo); - } + Sha256.prototype.hash = function () { + var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, + h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; - sum64(this.h, 0, ah, al); - sum64(this.h, 2, bh, bl); - sum64(this.h, 4, ch, cl); - sum64(this.h, 6, dh, dl); - sum64(this.h, 8, eh, el); - sum64(this.h, 10, fh, fl); - sum64(this.h, 12, gh, gl); - sum64(this.h, 14, hh, hl); -}; + for (j = 16; j < 64; ++j) { + // rightrotate + t1 = blocks[j - 15]; + s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3); + t1 = blocks[j - 2]; + s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10); + blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0; + } -SHA512.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h, 'big'); - else - return utils.split32(this.h, 'big'); -}; + bc = b & c; + for (j = 0; j < 64; j += 4) { + if (this.first) { + if (this.is224) { + ab = 300032; + t1 = blocks[0] - 1413257819; + h = t1 - 150054599 << 0; + d = t1 + 24177077 << 0; + } else { + ab = 704751109; + t1 = blocks[0] - 210244248; + h = t1 - 1521486534 << 0; + d = t1 + 143694565 << 0; + } + this.first = false; + } else { + s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10)); + s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7)); + ab = a & b; + maj = ab ^ (a & c) ^ bc; + ch = (e & f) ^ (~e & g); + t1 = h + s1 + ch + K[j] + blocks[j]; + t2 = s0 + maj; + h = d + t1 << 0; + d = t1 + t2 << 0; + } + s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10)); + s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7)); + da = d & a; + maj = da ^ (d & b) ^ ab; + ch = (h & e) ^ (~h & f); + t1 = g + s1 + ch + K[j + 1] + blocks[j + 1]; + t2 = s0 + maj; + g = c + t1 << 0; + c = t1 + t2 << 0; + s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10)); + s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7)); + cd = c & d; + maj = cd ^ (c & a) ^ da; + ch = (g & h) ^ (~g & e); + t1 = f + s1 + ch + K[j + 2] + blocks[j + 2]; + t2 = s0 + maj; + f = b + t1 << 0; + b = t1 + t2 << 0; + s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10)); + s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7)); + bc = b & c; + maj = bc ^ (b & d) ^ cd; + ch = (f & g) ^ (~f & h); + t1 = e + s1 + ch + K[j + 3] + blocks[j + 3]; + t2 = s0 + maj; + e = a + t1 << 0; + a = t1 + t2 << 0; + } -function ch64_hi(xh, xl, yh, yl, zh) { - var r = (xh & yh) ^ ((~xh) & zh); - if (r < 0) - r += 0x100000000; - return r; -} + this.h0 = this.h0 + a << 0; + this.h1 = this.h1 + b << 0; + this.h2 = this.h2 + c << 0; + this.h3 = this.h3 + d << 0; + this.h4 = this.h4 + e << 0; + this.h5 = this.h5 + f << 0; + this.h6 = this.h6 + g << 0; + this.h7 = this.h7 + h << 0; + }; -function ch64_lo(xh, xl, yh, yl, zh, zl) { - var r = (xl & yl) ^ ((~xl) & zl); - if (r < 0) - r += 0x100000000; - return r; -} + Sha256.prototype.hex = function () { + this.finalize(); -function maj64_hi(xh, xl, yh, yl, zh) { - var r = (xh & yh) ^ (xh & zh) ^ (yh & zh); - if (r < 0) - r += 0x100000000; - return r; -} + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, + h6 = this.h6, h7 = this.h7; -function maj64_lo(xh, xl, yh, yl, zh, zl) { - var r = (xl & yl) ^ (xl & zl) ^ (yl & zl); - if (r < 0) - r += 0x100000000; - return r; -} + var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + + HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + + HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + + HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + + HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + + HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + + HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + + HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + + HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + + HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + + HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + + HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + + HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] + + HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + + HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + + HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + + HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] + + HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] + + HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] + + HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] + + HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] + + HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] + + HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] + + HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] + + HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] + + HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] + + HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] + + HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F]; + if (!this.is224) { + hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] + + HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] + + HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] + + HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F]; + } + return hex; + }; -function s0_512_hi(xh, xl) { - var c0_hi = rotr64_hi(xh, xl, 28); - var c1_hi = rotr64_hi(xl, xh, 2); // 34 - var c2_hi = rotr64_hi(xl, xh, 7); // 39 + Sha256.prototype.toString = Sha256.prototype.hex; - var r = c0_hi ^ c1_hi ^ c2_hi; - if (r < 0) - r += 0x100000000; - return r; -} + Sha256.prototype.digest = function () { + this.finalize(); -function s0_512_lo(xh, xl) { - var c0_lo = rotr64_lo(xh, xl, 28); - var c1_lo = rotr64_lo(xl, xh, 2); // 34 - var c2_lo = rotr64_lo(xl, xh, 7); // 39 + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, + h6 = this.h6, h7 = this.h7; - var r = c0_lo ^ c1_lo ^ c2_lo; - if (r < 0) - r += 0x100000000; - return r; -} + var arr = [ + (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF, + (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF, + (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF, + (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF, + (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF, + (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF, + (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF + ]; + if (!this.is224) { + arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF); + } + return arr; + }; -function s1_512_hi(xh, xl) { - var c0_hi = rotr64_hi(xh, xl, 14); - var c1_hi = rotr64_hi(xh, xl, 18); - var c2_hi = rotr64_hi(xl, xh, 9); // 41 + Sha256.prototype.array = Sha256.prototype.digest; - var r = c0_hi ^ c1_hi ^ c2_hi; - if (r < 0) - r += 0x100000000; - return r; -} + Sha256.prototype.arrayBuffer = function () { + this.finalize(); -function s1_512_lo(xh, xl) { - var c0_lo = rotr64_lo(xh, xl, 14); - var c1_lo = rotr64_lo(xh, xl, 18); - var c2_lo = rotr64_lo(xl, xh, 9); // 41 + var buffer = new ArrayBuffer(this.is224 ? 28 : 32); + var dataView = new DataView(buffer); + dataView.setUint32(0, this.h0); + dataView.setUint32(4, this.h1); + dataView.setUint32(8, this.h2); + dataView.setUint32(12, this.h3); + dataView.setUint32(16, this.h4); + dataView.setUint32(20, this.h5); + dataView.setUint32(24, this.h6); + if (!this.is224) { + dataView.setUint32(28, this.h7); + } + return buffer; + }; - var r = c0_lo ^ c1_lo ^ c2_lo; - if (r < 0) - r += 0x100000000; - return r; -} + function HmacSha256(key, is224, sharedMemory) { + var i, type = typeof key; + if (type === 'string') { + var bytes = [], length = key.length, index = 0, code; + for (i = 0; i < length; ++i) { + code = key.charCodeAt(i); + if (code < 0x80) { + bytes[index++] = code; + } else if (code < 0x800) { + bytes[index++] = (0xc0 | (code >> 6)); + bytes[index++] = (0x80 | (code & 0x3f)); + } else if (code < 0xd800 || code >= 0xe000) { + bytes[index++] = (0xe0 | (code >> 12)); + bytes[index++] = (0x80 | ((code >> 6) & 0x3f)); + bytes[index++] = (0x80 | (code & 0x3f)); + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff)); + bytes[index++] = (0xf0 | (code >> 18)); + bytes[index++] = (0x80 | ((code >> 12) & 0x3f)); + bytes[index++] = (0x80 | ((code >> 6) & 0x3f)); + bytes[index++] = (0x80 | (code & 0x3f)); + } + } + key = bytes; + } else { + if (type === 'object') { + if (key === null) { + throw new Error(ERROR); + } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { + key = new Uint8Array(key); + } else if (!Array.isArray(key)) { + if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { + throw new Error(ERROR); + } + } + } else { + throw new Error(ERROR); + } + } -function g0_512_hi(xh, xl) { - var c0_hi = rotr64_hi(xh, xl, 1); - var c1_hi = rotr64_hi(xh, xl, 8); - var c2_hi = shr64_hi(xh, xl, 7); + if (key.length > 64) { + key = (new Sha256(is224, true)).update(key).array(); + } - var r = c0_hi ^ c1_hi ^ c2_hi; - if (r < 0) - r += 0x100000000; - return r; -} + var oKeyPad = [], iKeyPad = []; + for (i = 0; i < 64; ++i) { + var b = key[i] || 0; + oKeyPad[i] = 0x5c ^ b; + iKeyPad[i] = 0x36 ^ b; + } -function g0_512_lo(xh, xl) { - var c0_lo = rotr64_lo(xh, xl, 1); - var c1_lo = rotr64_lo(xh, xl, 8); - var c2_lo = shr64_lo(xh, xl, 7); + Sha256.call(this, is224, sharedMemory); - var r = c0_lo ^ c1_lo ^ c2_lo; - if (r < 0) - r += 0x100000000; - return r; -} + this.update(iKeyPad); + this.oKeyPad = oKeyPad; + this.inner = true; + this.sharedMemory = sharedMemory; + } + HmacSha256.prototype = new Sha256(); -function g1_512_hi(xh, xl) { - var c0_hi = rotr64_hi(xh, xl, 19); - var c1_hi = rotr64_hi(xl, xh, 29); // 61 - var c2_hi = shr64_hi(xh, xl, 6); + HmacSha256.prototype.finalize = function () { + Sha256.prototype.finalize.call(this); + if (this.inner) { + this.inner = false; + var innerHash = this.array(); + Sha256.call(this, this.is224, this.sharedMemory); + this.update(this.oKeyPad); + this.update(innerHash); + Sha256.prototype.finalize.call(this); + } + }; - var r = c0_hi ^ c1_hi ^ c2_hi; - if (r < 0) - r += 0x100000000; - return r; -} + var exports = createMethod(); + exports.sha256 = exports; + exports.sha224 = createMethod(true); + exports.sha256.hmac = createHmacMethod(); + exports.sha224.hmac = createHmacMethod(true); -function g1_512_lo(xh, xl) { - var c0_lo = rotr64_lo(xh, xl, 19); - var c1_lo = rotr64_lo(xl, xh, 29); // 61 - var c2_lo = shr64_lo(xh, xl, 6); + if (COMMON_JS) { + module.exports = exports; + } else { + root.sha256 = exports.sha256; + root.sha224 = exports.sha224; + if (AMD) { + define(function () { + return exports; + }); + } + } +})(); - var r = c0_lo ^ c1_lo ^ c2_lo; - if (r < 0) - r += 0x100000000; - return r; +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"_process":451}],356:[function(require,module,exports){ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.WalletPolicy = exports.DefaultWalletPolicy = exports.PsbtV2 = exports.AppClient = void 0; +const appClient_1 = __importDefault(require("./lib/appClient")); +exports.AppClient = appClient_1.default; +const policy_1 = require("./lib/policy"); +Object.defineProperty(exports, "DefaultWalletPolicy", { enumerable: true, get: function () { return policy_1.DefaultWalletPolicy; } }); +Object.defineProperty(exports, "WalletPolicy", { enumerable: true, get: function () { return policy_1.WalletPolicy; } }); +const psbtv2_1 = require("./lib/psbtv2"); +Object.defineProperty(exports, "PsbtV2", { enumerable: true, get: function () { return psbtv2_1.PsbtV2; } }); +exports.default = appClient_1.default; + +},{"./lib/appClient":357,"./lib/policy":364,"./lib/psbtv2":365}],357:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AppClient = exports.PartialSignature = void 0; +const bip32_1 = require("./bip32"); +const clientCommands_1 = require("./clientCommands"); +const merkelizedPsbt_1 = require("./merkelizedPsbt"); +const merkle_1 = require("./merkle"); +const psbtv2_1 = require("./psbtv2"); +const varint_1 = require("./varint"); +const CLA_BTC = 0xe1; +const CLA_FRAMEWORK = 0xf8; +const CURRENT_PROTOCOL_VERSION = 1; // supported from version 2.1.0 of the app +var BitcoinIns; +(function (BitcoinIns) { + BitcoinIns[BitcoinIns["GET_PUBKEY"] = 0] = "GET_PUBKEY"; + BitcoinIns[BitcoinIns["REGISTER_WALLET"] = 2] = "REGISTER_WALLET"; + BitcoinIns[BitcoinIns["GET_WALLET_ADDRESS"] = 3] = "GET_WALLET_ADDRESS"; + BitcoinIns[BitcoinIns["SIGN_PSBT"] = 4] = "SIGN_PSBT"; + BitcoinIns[BitcoinIns["GET_MASTER_FINGERPRINT"] = 5] = "GET_MASTER_FINGERPRINT"; + BitcoinIns[BitcoinIns["SIGN_MESSAGE"] = 16] = "SIGN_MESSAGE"; +})(BitcoinIns || (BitcoinIns = {})); +var FrameworkIns; +(function (FrameworkIns) { + FrameworkIns[FrameworkIns["CONTINUE_INTERRUPTED"] = 1] = "CONTINUE_INTERRUPTED"; +})(FrameworkIns || (FrameworkIns = {})); +/** + * This class represents a partial signature produced by the app during signing. + * It always contains the `signature` and the corresponding `pubkey` whose private key + * was used for signing; in the case of taproot script paths, it also contains the + * tapleaf hash. + */ +class PartialSignature { + constructor(pubkey, signature, tapleafHash) { + this.pubkey = pubkey; + this.signature = signature; + this.tapleafHash = tapleafHash; + } } - -},{"../common":217,"../utils":227,"minimalistic-assert":238}],226:[function(require,module,exports){ -'use strict'; - -var utils = require('../utils'); -var rotr32 = utils.rotr32; - -function ft_1(s, x, y, z) { - if (s === 0) - return ch32(x, y, z); - if (s === 1 || s === 3) - return p32(x, y, z); - if (s === 2) - return maj32(x, y, z); +exports.PartialSignature = PartialSignature; +/** + * Creates an instance of `PartialSignature` from the returned raw augmented pubkey and signature. + * @param pubkeyAugm the public key, concatenated with the tapleaf hash in the case of taproot script path spend. + * @param signature the signature + * @returns an instance of `PartialSignature`. + */ +function makePartialSignature(pubkeyAugm, signature) { + if (pubkeyAugm.length == 64) { + // tapscript spend: concatenation of 32-bytes x-only pubkey and 32-bytes tapleaf_hash + return new PartialSignature(pubkeyAugm.slice(0, 32), signature, pubkeyAugm.slice(32, 64)); + } + else if (pubkeyAugm.length == 32 || pubkeyAugm.length == 33) { + // legacy, segwit or taproot keypath spend: pubkeyAugm is just the pubkey + return new PartialSignature(pubkeyAugm, signature); + } + else { + throw new Error(`Invalid length for pubkeyAugm: ${pubkeyAugm.length} bytes.`); + } } -exports.ft_1 = ft_1; - -function ch32(x, y, z) { - return (x & y) ^ ((~x) & z); +/** + * Checks whether a descriptor template contains an `a:` fragment. + */ +function containsA(descriptorTemplate) { + const matches = descriptorTemplate.match(/[asctdvjnlu]+:/g) || []; + return matches.some(match => match.includes('a')); } -exports.ch32 = ch32; - -function maj32(x, y, z) { - return (x & y) ^ (x & z) ^ (y & z); +/** + * This class encapsulates the APDU protocol documented at + * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md + */ +class AppClient { + constructor(transport) { + this.transport = transport; + } + async makeRequest(ins, data, cci) { + let response = await this.transport.send(CLA_BTC, ins, 0, CURRENT_PROTOCOL_VERSION, data, [0x9000, 0xe000]); + while (response.readUInt16BE(response.length - 2) === 0xe000) { + if (!cci) { + throw new Error('Unexpected SW_INTERRUPTED_EXECUTION'); + } + const hwRequest = response.slice(0, -2); + const commandResponse = cci.execute(hwRequest); + response = await this.transport.send(CLA_FRAMEWORK, FrameworkIns.CONTINUE_INTERRUPTED, 0, 0, commandResponse, [0x9000, 0xe000]); + } + return response.slice(0, -2); // drop the status word (can only be 0x9000 at this point) + } + /** + * Returns an object containing the currently running app's name, version and the device status flags. + * + * @returns an object with app name, version and device status flags. + */ + async getAppAndVersion() { + const r = await this.transport.send(0xb0, 0x01, 0x00, 0x00); + let i = 0; + const format = r[i++]; + if (format !== 1) + throw new Error("Unexpected response"); + const nameLength = r[i++]; + const name = r.slice(i, (i += nameLength)).toString("ascii"); + const versionLength = r[i++]; + const version = r.slice(i, (i += versionLength)).toString("ascii"); + const flagLength = r[i++]; + const flags = r.slice(i, (i += flagLength)); + return { + name, + version, + flags, + }; + } + ; + /** + * Requests the BIP-32 extended pubkey to the hardware wallet. + * If `display` is `false`, only standard paths will be accepted; an error is returned if an unusual path is + * requested. + * If `display` is `true`, the requested path is shown on screen for user verification; unusual paths can be + * requested, and a warning is shown to the user in that case. + * + * @param path the requested BIP-32 path as a string + * @param display `false` to silently retrieve a pubkey for a standard path, `true` to display the path on screen + * @returns the base58-encoded serialized extended pubkey (xpub) + */ + async getExtendedPubkey(path, display = false) { + const pathElements = (0, bip32_1.pathStringToArray)(path); + if (pathElements.length > 6) { + throw new Error('Path too long. At most 6 levels allowed.'); + } + const response = await this.makeRequest(BitcoinIns.GET_PUBKEY, Buffer.concat([ + Buffer.from(display ? [1] : [0]), + (0, bip32_1.pathElementsToBuffer)(pathElements), + ])); + return response.toString('ascii'); + } + /** + * Registers a `WalletPolicy`, after interactive verification from the user. + * On success, after user's approval, this function returns the id (which is the same that can be computed with + * `walletPolicy.getid()`), followed by the 32-byte hmac. The client should store the hmac to use it for future + * requests to `getWalletAddress` or `signPsbt` using this `WalletPolicy`. + * + * @param walletPolicy the `WalletPolicy` to register + * @returns a pair of two 32-byte arrays: the id of the Wallet Policy, followed by the policy hmac + */ + async registerWallet(walletPolicy) { + await this.validatePolicy(walletPolicy); + const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(); + clientInterpreter.addKnownWalletPolicy(walletPolicy); + const serializedWalletPolicy = walletPolicy.serialize(); + const response = await this.makeRequest(BitcoinIns.REGISTER_WALLET, Buffer.concat([ + (0, varint_1.createVarint)(serializedWalletPolicy.length), + serializedWalletPolicy, + ]), clientInterpreter); + if (response.length != 64) { + throw Error(`Invalid response length. Expected 64 bytes, got ${response.length}`); + } + return [response.subarray(0, 32), response.subarray(32)]; + } + /** + * Returns the address of `walletPolicy` for the given `change` and `addressIndex`. + * + * @param walletPolicy the `WalletPolicy` to use + * @param walletHMAC the 32-byte hmac returned during wallet registration for a registered policy; otherwise + * `null` for a standard policy + * @param change `0` for a normal receive address, `1` for a change address + * @param addressIndex the address index to retrieve + * @param display `True` to show the address on screen, `False` to retrieve it silently + * @returns the address, as an ascii string. + */ + async getWalletAddress(walletPolicy, walletHMAC, change, addressIndex, display) { + if (change !== 0 && change !== 1) + throw new Error('Change can only be 0 or 1'); + if (addressIndex < 0 || !Number.isInteger(addressIndex)) + throw new Error('Invalid address index'); + if (walletHMAC != null && walletHMAC.length != 32) { + throw new Error('Invalid HMAC length'); + } + await this.validatePolicy(walletPolicy); + const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(); + clientInterpreter.addKnownWalletPolicy(walletPolicy); + const addressIndexBuffer = Buffer.alloc(4); + addressIndexBuffer.writeUInt32BE(addressIndex, 0); + const response = await this.makeRequest(BitcoinIns.GET_WALLET_ADDRESS, Buffer.concat([ + Buffer.from(display ? [1] : [0]), + walletPolicy.getId(), + walletHMAC || Buffer.alloc(32, 0), + Buffer.from([change]), + addressIndexBuffer, + ]), clientInterpreter); + return response.toString('ascii'); + } + /** + * Signs a psbt using a (standard or registered) `WalletPolicy`. This is an interactive command, as user validation + * is necessary using the device's secure screen. + * On success, a map of input indexes and signatures is returned. + * @param psbt a base64-encoded string, or a psbt in a binary Buffer. Using the `PsbtV2` type is deprecated. + * @param walletPolicy the `WalletPolicy` to use for signing + * @param walletHMAC the 32-byte hmac obtained during wallet policy registration, or `null` for a standard policy + * @param progressCallback optionally, a callback that will be called every time a signature is produced during + * the signing process. The callback does not receive any argument, but can be used to track progress. + * @returns an array of of tuples with 2 elements containing: + * - the index of the input being signed; + * - an instance of PartialSignature + */ + async signPsbt(psbt, walletPolicy, walletHMAC, progressCallback) { + await this.validatePolicy(walletPolicy); + if (typeof psbt === 'string') { + psbt = Buffer.from(psbt, "base64"); + } + if (Buffer.isBuffer(psbt)) { + const psbtObj = new psbtv2_1.PsbtV2(); + psbtObj.deserialize(psbt); + psbt = psbtObj; + } + const merkelizedPsbt = new merkelizedPsbt_1.MerkelizedPsbt(psbt); + if (walletHMAC != null && walletHMAC.length != 32) { + throw new Error('Invalid HMAC length'); + } + const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(progressCallback); + // prepare ClientCommandInterpreter + clientInterpreter.addKnownWalletPolicy(walletPolicy); + clientInterpreter.addKnownMapping(merkelizedPsbt.globalMerkleMap); + for (const map of merkelizedPsbt.inputMerkleMaps) { + clientInterpreter.addKnownMapping(map); + } + for (const map of merkelizedPsbt.outputMerkleMaps) { + clientInterpreter.addKnownMapping(map); + } + clientInterpreter.addKnownList(merkelizedPsbt.inputMapCommitments); + const inputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.inputMapCommitments.map((m) => (0, merkle_1.hashLeaf)(m))).getRoot(); + clientInterpreter.addKnownList(merkelizedPsbt.outputMapCommitments); + const outputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.outputMapCommitments.map((m) => (0, merkle_1.hashLeaf)(m))).getRoot(); + await this.makeRequest(BitcoinIns.SIGN_PSBT, Buffer.concat([ + merkelizedPsbt.getGlobalKeysValuesRoot(), + (0, varint_1.createVarint)(merkelizedPsbt.getGlobalInputCount()), + inputMapsRoot, + (0, varint_1.createVarint)(merkelizedPsbt.getGlobalOutputCount()), + outputMapsRoot, + walletPolicy.getId(), + walletHMAC || Buffer.alloc(32, 0), + ]), clientInterpreter); + const yielded = clientInterpreter.getYielded(); + const ret = []; + for (const inputAndSig of yielded) { + // inputAndSig contains: + // + const [inputIndex, inputIndexLen] = (0, varint_1.parseVarint)(inputAndSig, 0); + const pubkeyAugmLen = inputAndSig[inputIndexLen]; + const pubkeyAugm = inputAndSig.subarray(inputIndexLen + 1, inputIndexLen + 1 + pubkeyAugmLen); + const signature = inputAndSig.subarray(inputIndexLen + 1 + pubkeyAugmLen); + const partialSig = makePartialSignature(pubkeyAugm, signature); + ret.push([Number(inputIndex), partialSig]); + } + return ret; + } + /** + * Returns the fingerprint of the master public key, as per BIP-32 standard. + * @returns the master key fingerprint as a string of 8 hexadecimal digits. + */ + async getMasterFingerprint() { + const fpr = await this.makeRequest(BitcoinIns.GET_MASTER_FINGERPRINT, Buffer.from([])); + return fpr.toString("hex"); + } + /** + * Signs a message using the legacy Bitcoin Message Signing standard. The signed message is + * the double-sha256 hash of the concatenation of: + * - "\x18Bitcoin Signed Message:\n"; + * - the length of `message`, encoded as a Bitcoin-style variable length integer; + * - `message`. + * + * @param message the serialized message to sign + * @param path the BIP-32 path of the key used to sign the message + * @returns base64-encoded signature of the message. + */ + async signMessage(message, path) { + const pathElements = (0, bip32_1.pathStringToArray)(path); + const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(); + // prepare ClientCommandInterpreter + const nChunks = Math.ceil(message.length / 64); + const chunks = []; + for (let i = 0; i < nChunks; i++) { + chunks.push(message.subarray(64 * i, 64 * i + 64)); + } + clientInterpreter.addKnownList(chunks); + const chunksRoot = new merkle_1.Merkle(chunks.map((m) => (0, merkle_1.hashLeaf)(m))).getRoot(); + const result = await this.makeRequest(BitcoinIns.SIGN_MESSAGE, Buffer.concat([ + (0, bip32_1.pathElementsToBuffer)(pathElements), + (0, varint_1.createVarint)(message.length), + chunksRoot, + ]), clientInterpreter); + return result.toString('base64'); + } + /* Performs any additional checks on the policy before using it.*/ + async validatePolicy(walletPolicy) { + if (containsA(walletPolicy.descriptorTemplate)) { + const appAndVer = await this.getAppAndVersion(); + if (["2.1.0", "2.1.1"].includes(appAndVer.version)) { + // Versions 2.1.0 and 2.1.1 produced incorrect scripts for policies containing + // the `a:` fragment. + throw new Error("Please update your Ledger Bitcoin app."); + } + } + } } -exports.maj32 = maj32; +exports.AppClient = AppClient; +exports.default = AppClient; -function p32(x, y, z) { - return x ^ y ^ z; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./bip32":358,"./clientCommands":360,"./merkelizedPsbt":361,"./merkle":362,"./psbtv2":365,"./varint":366,"buffer":249}],358:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hardenedPathOf = exports.getXpubComponents = exports.pubkeyFromXpub = exports.pathStringToArray = exports.pathArrayToString = exports.bip32asBuffer = exports.pathElementsToBuffer = void 0; +const bip32_path_1 = __importDefault(require("bip32-path")); // TODO: get rid of this dependency +const bs58check_1 = __importDefault(require("bs58check")); +function pathElementsToBuffer(paths) { + const buffer = Buffer.alloc(1 + paths.length * 4); + buffer[0] = paths.length; + paths.forEach((element, index) => { + buffer.writeUInt32BE(element, 1 + 4 * index); + }); + return buffer; } -exports.p32 = p32; - -function s0_256(x) { - return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); +exports.pathElementsToBuffer = pathElementsToBuffer; +function bip32asBuffer(path) { + const pathElements = !path ? [] : pathStringToArray(path); + return pathElementsToBuffer(pathElements); } -exports.s0_256 = s0_256; - -function s1_256(x) { - return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); +exports.bip32asBuffer = bip32asBuffer; +function pathArrayToString(pathElements) { + // bippath doesn't handle an empty path. + if (pathElements.length == 0) { + return "m"; + } + return bip32_path_1.default.fromPathArray(pathElements).toString(); } -exports.s1_256 = s1_256; - -function g0_256(x) { - return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3); +exports.pathArrayToString = pathArrayToString; +function pathStringToArray(path) { + // bippath doesn't handle an empty path. + if (path == "m" || path == "") { + return []; + } + return bip32_path_1.default.fromString(path).toPathArray(); } -exports.g0_256 = g0_256; - -function g1_256(x) { - return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10); +exports.pathStringToArray = pathStringToArray; +function pubkeyFromXpub(xpub) { + const xpubBuf = bs58check_1.default.decode(xpub); + return xpubBuf.slice(xpubBuf.length - 33); } -exports.g1_256 = g1_256; - -},{"../utils":227}],227:[function(require,module,exports){ -'use strict'; - -var assert = require('minimalistic-assert'); -var inherits = require('inherits'); - -exports.inherits = inherits; - -function isSurrogatePair(msg, i) { - if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) { - return false; - } - if (i < 0 || i + 1 >= msg.length) { - return false; - } - return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00; +exports.pubkeyFromXpub = pubkeyFromXpub; +function getXpubComponents(xpub) { + const xpubBuf = bs58check_1.default.decode(xpub); + return { + chaincode: xpubBuf.slice(13, 13 + 32), + pubkey: xpubBuf.slice(xpubBuf.length - 33), + version: xpubBuf.readUInt32BE(0), + }; } - -function toArray(msg, enc) { - if (Array.isArray(msg)) - return msg.slice(); - if (!msg) - return []; - var res = []; - if (typeof msg === 'string') { - if (!enc) { - // Inspired by stringToUtf8ByteArray() in closure-library by Google - // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143 - // Apache License 2.0 - // https://github.com/google/closure-library/blob/master/LICENSE - var p = 0; - for (var i = 0; i < msg.length; i++) { - var c = msg.charCodeAt(i); - if (c < 128) { - res[p++] = c; - } else if (c < 2048) { - res[p++] = (c >> 6) | 192; - res[p++] = (c & 63) | 128; - } else if (isSurrogatePair(msg, i)) { - c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF); - res[p++] = (c >> 18) | 240; - res[p++] = ((c >> 12) & 63) | 128; - res[p++] = ((c >> 6) & 63) | 128; - res[p++] = (c & 63) | 128; - } else { - res[p++] = (c >> 12) | 224; - res[p++] = ((c >> 6) & 63) | 128; - res[p++] = (c & 63) | 128; +exports.getXpubComponents = getXpubComponents; +function hardenedPathOf(pathElements) { + for (let i = pathElements.length - 1; i >= 0; i--) { + if (pathElements[i] >= 0x80000000) { + return pathElements.slice(0, i + 1); } - } - } else if (enc === 'hex') { - msg = msg.replace(/[^a-z0-9]+/ig, ''); - if (msg.length % 2 !== 0) - msg = '0' + msg; - for (i = 0; i < msg.length; i += 2) - res.push(parseInt(msg[i] + msg[i + 1], 16)); } - } else { - for (i = 0; i < msg.length; i++) - res[i] = msg[i] | 0; - } - return res; + return []; } -exports.toArray = toArray; +exports.hardenedPathOf = hardenedPathOf; -function toHex(msg) { - var res = ''; - for (var i = 0; i < msg.length; i++) - res += zero2(msg[i].toString(16)); - return res; +}).call(this)}).call(this,require("buffer").Buffer) +},{"bip32-path":132,"bs58check":430,"buffer":249}],359:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BufferReader = exports.BufferWriter = exports.unsafeFrom64bitLE = exports.unsafeTo64bitLE = void 0; +const varint_1 = require("./varint"); +function unsafeTo64bitLE(n) { + // we want to represent the input as a 8-bytes array + if (n > Number.MAX_SAFE_INTEGER) { + throw new Error("Can't convert numbers > MAX_SAFE_INT"); + } + const byteArray = Buffer.alloc(8, 0); + for (let index = 0; index < byteArray.length; index++) { + const byte = n & 0xff; + byteArray[index] = byte; + n = (n - byte) / 256; + } + return byteArray; +} +exports.unsafeTo64bitLE = unsafeTo64bitLE; +function unsafeFrom64bitLE(byteArray) { + let value = 0; + if (byteArray.length != 8) { + throw new Error('Expected Bufffer of lenght 8'); + } + if (byteArray[7] != 0) { + throw new Error("Can't encode numbers > MAX_SAFE_INT"); + } + if (byteArray[6] > 0x1f) { + throw new Error("Can't encode numbers > MAX_SAFE_INT"); + } + for (let i = byteArray.length - 1; i >= 0; i--) { + value = value * 256 + byteArray[i]; + } + return value; } -exports.toHex = toHex; - -function htonl(w) { - var res = (w >>> 24) | - ((w >>> 8) & 0xff00) | - ((w << 8) & 0xff0000) | - ((w & 0xff) << 24); - return res >>> 0; +exports.unsafeFrom64bitLE = unsafeFrom64bitLE; +class BufferWriter { + constructor() { + this.bufs = []; + } + write(alloc, fn) { + const b = Buffer.alloc(alloc); + fn(b); + this.bufs.push(b); + } + writeUInt8(i) { + this.write(1, (b) => b.writeUInt8(i, 0)); + } + writeInt32(i) { + this.write(4, (b) => b.writeInt32LE(i, 0)); + } + writeUInt32(i) { + this.write(4, (b) => b.writeUInt32LE(i, 0)); + } + writeUInt64(i) { + const bytes = unsafeTo64bitLE(i); + this.writeSlice(bytes); + } + writeVarInt(i) { + this.bufs.push((0, varint_1.createVarint)(i)); + } + writeSlice(slice) { + this.bufs.push(Buffer.from(slice)); + } + writeVarSlice(slice) { + this.writeVarInt(slice.length); + this.writeSlice(slice); + } + buffer() { + return Buffer.concat(this.bufs); + } } -exports.htonl = htonl; - -function toHex32(msg, endian) { - var res = ''; - for (var i = 0; i < msg.length; i++) { - var w = msg[i]; - if (endian === 'little') - w = htonl(w); - res += zero8(w.toString(16)); - } - return res; +exports.BufferWriter = BufferWriter; +class BufferReader { + constructor(buffer, offset = 0) { + this.buffer = buffer; + this.offset = offset; + } + available() { + return this.buffer.length - this.offset; + } + readUInt8() { + const result = this.buffer.readUInt8(this.offset); + this.offset++; + return result; + } + readInt32() { + const result = this.buffer.readInt32LE(this.offset); + this.offset += 4; + return result; + } + readUInt32() { + const result = this.buffer.readUInt32LE(this.offset); + this.offset += 4; + return result; + } + readUInt64() { + const buf = this.readSlice(8); + return unsafeFrom64bitLE(buf); + } + readVarInt() { + const [vi, vi_size] = (0, varint_1.parseVarint)(this.buffer, this.offset); + this.offset += vi_size; + return vi; + } + readSlice(n) { + if (this.buffer.length < this.offset + n) { + throw new Error('Cannot read slice out of bounds'); + } + const result = this.buffer.slice(this.offset, this.offset + n); + this.offset += n; + return result; + } + readVarSlice() { + const n = (0, varint_1.sanitizeBigintToNumber)(this.readVarInt()); + return this.readSlice(n); + } + readVector() { + const count = this.readVarInt(); + const vector = []; + for (let i = 0; i < count; i++) + vector.push(this.readVarSlice()); + return vector; + } } -exports.toHex32 = toHex32; +exports.BufferReader = BufferReader; -function zero2(word) { - if (word.length === 1) - return '0' + word; - else - return word; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./varint":366,"buffer":249}],360:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ClientCommandInterpreter = exports.GetMoreElementsCommand = exports.GetMerkleLeafIndexCommand = exports.GetMerkleLeafProofCommand = exports.GetPreimageCommand = exports.YieldCommand = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const buffertools_1 = require("./buffertools"); +const merkle_1 = require("./merkle"); +const varint_1 = require("./varint"); +var ClientCommandCode; +(function (ClientCommandCode) { + ClientCommandCode[ClientCommandCode["YIELD"] = 16] = "YIELD"; + ClientCommandCode[ClientCommandCode["GET_PREIMAGE"] = 64] = "GET_PREIMAGE"; + ClientCommandCode[ClientCommandCode["GET_MERKLE_LEAF_PROOF"] = 65] = "GET_MERKLE_LEAF_PROOF"; + ClientCommandCode[ClientCommandCode["GET_MERKLE_LEAF_INDEX"] = 66] = "GET_MERKLE_LEAF_INDEX"; + ClientCommandCode[ClientCommandCode["GET_MORE_ELEMENTS"] = 160] = "GET_MORE_ELEMENTS"; +})(ClientCommandCode || (ClientCommandCode = {})); +class ClientCommand { +} +class YieldCommand extends ClientCommand { + constructor(results, progressCallback) { + super(); + this.progressCallback = progressCallback; + this.code = ClientCommandCode.YIELD; + this.results = results; + } + execute(request) { + this.results.push(Buffer.from(request.subarray(1))); + if (this.progressCallback) { + this.progressCallback(); + } + return Buffer.from(''); + } +} +exports.YieldCommand = YieldCommand; +class GetPreimageCommand extends ClientCommand { + constructor(known_preimages, queue) { + super(); + this.code = ClientCommandCode.GET_PREIMAGE; + this.known_preimages = known_preimages; + this.queue = queue; + } + execute(request) { + const req = Buffer.from(request.subarray(1)); + // we expect no more data to read + if (req.length != 1 + 32) { + throw new Error('Invalid request, unexpected trailing data'); + } + if (req[0] != 0) { + throw new Error('Unsupported request, the first byte should be 0'); + } + // read the hash + const hash = Buffer.alloc(32); + for (let i = 0; i < 32; i++) { + hash[i] = req[1 + i]; + } + const req_hash_hex = hash.toString('hex'); + const known_preimage = this.known_preimages.get(req_hash_hex); + if (known_preimage != undefined) { + const preimage_len_varint = (0, varint_1.createVarint)(known_preimage.length); + // We can send at most 255 - len(preimage_len_out) - 1 bytes in a single message; + // the rest will be stored in the queue for GET_MORE_ELEMENTS + const max_payload_size = 255 - preimage_len_varint.length - 1; + const payload_size = Math.min(max_payload_size, known_preimage.length); + if (payload_size < known_preimage.length) { + for (let i = payload_size; i < known_preimage.length; i++) { + this.queue.push(Buffer.from([known_preimage[i]])); + } + } + return Buffer.concat([ + preimage_len_varint, + Buffer.from([payload_size]), + Buffer.from(known_preimage.subarray(0, payload_size)), + ]); + } + throw Error(`Requested unknown preimage for: ${req_hash_hex}`); + } } -exports.zero2 = zero2; - -function zero8(word) { - if (word.length === 7) - return '0' + word; - else if (word.length === 6) - return '00' + word; - else if (word.length === 5) - return '000' + word; - else if (word.length === 4) - return '0000' + word; - else if (word.length === 3) - return '00000' + word; - else if (word.length === 2) - return '000000' + word; - else if (word.length === 1) - return '0000000' + word; - else - return word; +exports.GetPreimageCommand = GetPreimageCommand; +class GetMerkleLeafProofCommand extends ClientCommand { + constructor(known_trees, queue) { + super(); + this.code = ClientCommandCode.GET_MERKLE_LEAF_PROOF; + this.known_trees = known_trees; + this.queue = queue; + } + execute(request) { + const req = Buffer.from(request.subarray(1)); + if (req.length < 32 + 1 + 1) { + throw new Error('Invalid request, expected at least 34 bytes'); + } + const reqBuf = new buffertools_1.BufferReader(req); + const hash = reqBuf.readSlice(32); + const hash_hex = hash.toString('hex'); + let tree_size; + let leaf_index; + try { + tree_size = (0, varint_1.sanitizeBigintToNumber)(reqBuf.readVarInt()); + leaf_index = (0, varint_1.sanitizeBigintToNumber)(reqBuf.readVarInt()); + } + catch (e) { + throw new Error("Invalid request, couldn't parse tree_size or leaf_index"); + } + const mt = this.known_trees.get(hash_hex); + if (!mt) { + throw Error(`Requested Merkle leaf proof for unknown tree: ${hash_hex}`); + } + if (leaf_index >= tree_size || mt.size() != tree_size) { + throw Error('Invalid index or tree size.'); + } + if (this.queue.length != 0) { + throw Error('This command should not execute when the queue is not empty.'); + } + const proof = mt.getProof(leaf_index); + const n_response_elements = Math.min(Math.floor((255 - 32 - 1 - 1) / 32), proof.length); + const n_leftover_elements = proof.length - n_response_elements; + // Add to the queue any proof elements that do not fit the response + if (n_leftover_elements > 0) { + this.queue.push(...proof.slice(-n_leftover_elements)); + } + return Buffer.concat([ + mt.getLeafHash(leaf_index), + Buffer.from([proof.length]), + Buffer.from([n_response_elements]), + ...proof.slice(0, n_response_elements), + ]); + } +} +exports.GetMerkleLeafProofCommand = GetMerkleLeafProofCommand; +class GetMerkleLeafIndexCommand extends ClientCommand { + constructor(known_trees) { + super(); + this.code = ClientCommandCode.GET_MERKLE_LEAF_INDEX; + this.known_trees = known_trees; + } + execute(request) { + const req = Buffer.from(request.subarray(1)); + if (req.length != 32 + 32) { + throw new Error('Invalid request, unexpected trailing data'); + } + // read the root hash + const root_hash = Buffer.alloc(32); + for (let i = 0; i < 32; i++) { + root_hash[i] = req.readUInt8(i); + } + const root_hash_hex = root_hash.toString('hex'); + // read the leaf hash + const leef_hash = Buffer.alloc(32); + for (let i = 0; i < 32; i++) { + leef_hash[i] = req.readUInt8(32 + i); + } + const leef_hash_hex = leef_hash.toString('hex'); + const mt = this.known_trees.get(root_hash_hex); + if (!mt) { + throw Error(`Requested Merkle leaf index for unknown root: ${root_hash_hex}`); + } + let leaf_index = 0; + let found = 0; + for (let i = 0; i < mt.size(); i++) { + if (mt.getLeafHash(i).toString('hex') == leef_hash_hex) { + found = 1; + leaf_index = i; + break; + } + } + return Buffer.concat([Buffer.from([found]), (0, varint_1.createVarint)(leaf_index)]); + } } -exports.zero8 = zero8; - -function join32(msg, start, end, endian) { - var len = end - start; - assert(len % 4 === 0); - var res = new Array(len / 4); - for (var i = 0, k = start; i < res.length; i++, k += 4) { - var w; - if (endian === 'big') - w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3]; - else - w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k]; - res[i] = w >>> 0; - } - return res; +exports.GetMerkleLeafIndexCommand = GetMerkleLeafIndexCommand; +class GetMoreElementsCommand extends ClientCommand { + constructor(queue) { + super(); + this.code = ClientCommandCode.GET_MORE_ELEMENTS; + this.queue = queue; + } + execute(request) { + if (request.length != 1) { + throw new Error('Invalid request, unexpected trailing data'); + } + if (this.queue.length === 0) { + throw new Error('No elements to get'); + } + // all elements should have the same length + const element_len = this.queue[0].length; + if (this.queue.some((el) => el.length != element_len)) { + throw new Error('The queue contains elements with different byte length, which is not expected'); + } + const max_elements = Math.floor(253 / element_len); + const n_returned_elements = Math.min(max_elements, this.queue.length); + const returned_elements = this.queue.splice(0, n_returned_elements); + return Buffer.concat([ + Buffer.from([n_returned_elements]), + Buffer.from([element_len]), + ...returned_elements, + ]); + } } -exports.join32 = join32; - -function split32(msg, endian) { - var res = new Array(msg.length * 4); - for (var i = 0, k = 0; i < msg.length; i++, k += 4) { - var m = msg[i]; - if (endian === 'big') { - res[k] = m >>> 24; - res[k + 1] = (m >>> 16) & 0xff; - res[k + 2] = (m >>> 8) & 0xff; - res[k + 3] = m & 0xff; - } else { - res[k + 3] = m >>> 24; - res[k + 2] = (m >>> 16) & 0xff; - res[k + 1] = (m >>> 8) & 0xff; - res[k] = m & 0xff; +exports.GetMoreElementsCommand = GetMoreElementsCommand; +/** + * This class will dispatch a client command coming from the hardware device to + * the appropriate client command implementation. Those client commands + * typically requests data from a merkle tree or merkelized maps. + * + * A ClientCommandInterpreter is prepared by adding the merkle trees and + * merkelized maps it should be able to serve to the hardware device. This class + * doesn't know anything about the semantics of the data it holds, it just + * serves merkle data. It doesn't even know in what context it is being + * executed, ie SignPsbt, getWalletAddress, etc. + * + * If the command yelds results to the client, as signPsbt does, the yielded + * data will be accessible after the command completed by calling getYielded(), + * which will return the yields in the same order as they came in. + */ +class ClientCommandInterpreter { + constructor(progressCallback) { + this.roots = new Map(); + this.preimages = new Map(); + this.yielded = []; + this.queue = []; + this.commands = new Map(); + const commands = [ + new YieldCommand(this.yielded, progressCallback), + new GetPreimageCommand(this.preimages, this.queue), + new GetMerkleLeafIndexCommand(this.roots), + new GetMerkleLeafProofCommand(this.roots, this.queue), + new GetMoreElementsCommand(this.queue), + ]; + for (const cmd of commands) { + if (this.commands.has(cmd.code)) { + throw new Error(`Multiple commands with code ${cmd.code}`); + } + this.commands.set(cmd.code, cmd); + } + } + getYielded() { + return this.yielded; + } + addKnownPreimage(preimage) { + this.preimages.set(bitcoinjs_lib_1.crypto.sha256(preimage).toString('hex'), preimage); + } + addKnownList(elements) { + for (const el of elements) { + const preimage = Buffer.concat([Buffer.from([0]), el]); + this.addKnownPreimage(preimage); + } + const mt = new merkle_1.Merkle(elements.map((el) => (0, merkle_1.hashLeaf)(el))); + this.roots.set(mt.getRoot().toString('hex'), mt); + } + addKnownMapping(mm) { + this.addKnownList(mm.keys); + this.addKnownList(mm.values); + } + addKnownWalletPolicy(wp) { + this.addKnownPreimage(wp.serialize()); + this.addKnownList(wp.keys.map((k) => Buffer.from(k, 'ascii'))); + this.addKnownPreimage(Buffer.from(wp.descriptorTemplate)); + } + execute(request) { + if (request.length == 0) { + throw new Error('Unexpected empty command'); + } + const cmdCode = request[0]; + const cmd = this.commands.get(cmdCode); + if (!cmd) { + throw new Error(`Unexpected command code ${cmdCode}`); + } + return cmd.execute(request); } - } - return res; } -exports.split32 = split32; +exports.ClientCommandInterpreter = ClientCommandInterpreter; -function rotr32(w, b) { - return (w >>> b) | (w << (32 - b)); +}).call(this)}).call(this,require("buffer").Buffer) +},{"./buffertools":359,"./merkle":362,"./varint":366,"bitcoinjs-lib":404,"buffer":249}],361:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MerkelizedPsbt = void 0; +const merkleMap_1 = require("./merkleMap"); +const psbtv2_1 = require("./psbtv2"); +/** + * This class merkelizes a PSBTv2, by merkelizing the different + * maps of the psbt. This is used during the transaction signing process, + * where the hardware app can request specific parts of the psbt from the + * client code and be sure that the response data actually belong to the psbt. + * The reason for this is the limited amount of memory available to the app, + * so it can't always store the full psbt in memory. + * + * The signing process is documented at + * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#sign_psbt + */ +class MerkelizedPsbt extends psbtv2_1.PsbtV2 { + constructor(psbt) { + super(); + this.inputMerkleMaps = []; + this.outputMerkleMaps = []; + psbt.copy(this); + this.globalMerkleMap = MerkelizedPsbt.createMerkleMap(this.globalMap); + for (let i = 0; i < this.getGlobalInputCount(); i++) { + this.inputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.inputMaps[i])); + } + this.inputMapCommitments = [...this.inputMerkleMaps.values()].map((v) => v.commitment()); + for (let i = 0; i < this.getGlobalOutputCount(); i++) { + this.outputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.outputMaps[i])); + } + this.outputMapCommitments = [...this.outputMerkleMaps.values()].map((v) => v.commitment()); + } + // These public functions are for MerkelizedPsbt. + getGlobalSize() { + return this.globalMap.size; + } + getGlobalKeysValuesRoot() { + return this.globalMerkleMap.commitment(); + } + static createMerkleMap(map) { + const sortedKeysStrings = [...map.keys()].sort(); + const values = sortedKeysStrings.map((k) => { + const v = map.get(k); + if (!v) { + throw new Error('No value for key ' + k); + } + return v; + }); + const sortedKeys = sortedKeysStrings.map((k) => Buffer.from(k, 'hex')); + return new merkleMap_1.MerkleMap(sortedKeys, values); + } } -exports.rotr32 = rotr32; +exports.MerkelizedPsbt = MerkelizedPsbt; -function rotl32(w, b) { - return (w << b) | (w >>> (32 - b)); +}).call(this)}).call(this,require("buffer").Buffer) +},{"./merkleMap":363,"./psbtv2":365,"buffer":249}],362:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hashLeaf = exports.Merkle = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +/** + * This class implements the merkle tree used by Ledger Bitcoin app v2+, + * which is documented at + * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md + */ +class Merkle { + constructor(leaves, hasher = bitcoinjs_lib_1.crypto.sha256) { + this.leaves = leaves; + this.h = hasher; + const nodes = this.calculateRoot(leaves); + this.rootNode = nodes.root; + this.leafNodes = nodes.leaves; + } + getRoot() { + return this.rootNode.hash; + } + size() { + return this.leaves.length; + } + getLeaves() { + return this.leaves; + } + getLeafHash(index) { + return this.leafNodes[index].hash; + } + getProof(index) { + if (index >= this.leaves.length) + throw Error('Index out of bounds'); + return proveNode(this.leafNodes[index]); + } + calculateRoot(leaves) { + const n = leaves.length; + if (n == 0) { + return { + root: new Node(undefined, undefined, Buffer.alloc(32, 0)), + leaves: [], + }; + } + if (n == 1) { + const newNode = new Node(undefined, undefined, leaves[0]); + return { root: newNode, leaves: [newNode] }; + } + const leftCount = highestPowerOf2LessThan(n); + const leftBranch = this.calculateRoot(leaves.slice(0, leftCount)); + const rightBranch = this.calculateRoot(leaves.slice(leftCount)); + const leftChild = leftBranch.root; + const rightChild = rightBranch.root; + const hash = this.hashNode(leftChild.hash, rightChild.hash); + const node = new Node(leftChild, rightChild, hash); + leftChild.parent = node; + rightChild.parent = node; + return { root: node, leaves: leftBranch.leaves.concat(rightBranch.leaves) }; + } + hashNode(left, right) { + return this.h(Buffer.concat([Buffer.from([1]), left, right])); + } +} +exports.Merkle = Merkle; +function hashLeaf(buf, hashFunction = bitcoinjs_lib_1.crypto.sha256) { + return hashConcat(Buffer.from([0]), buf, hashFunction); +} +exports.hashLeaf = hashLeaf; +function hashConcat(bufA, bufB, hashFunction) { + return hashFunction(Buffer.concat([bufA, bufB])); +} +class Node { + constructor(left, right, hash) { + this.leftChild = left; + this.rightChild = right; + this.hash = hash; + } + isLeaf() { + return this.leftChild == undefined; + } +} +function proveNode(node) { + if (!node.parent) { + return []; + } + if (node.parent.leftChild == node) { + if (!node.parent.rightChild) { + throw new Error('Expected right child to exist'); + } + return [node.parent.rightChild.hash, ...proveNode(node.parent)]; + } + else { + if (!node.parent.leftChild) { + throw new Error('Expected left child to exist'); + } + return [node.parent.leftChild.hash, ...proveNode(node.parent)]; + } } -exports.rotl32 = rotl32; - -function sum32(a, b) { - return (a + b) >>> 0; +function highestPowerOf2LessThan(n) { + if (n < 2) { + throw Error('Expected n >= 2'); + } + if (isPowerOf2(n)) { + return n / 2; + } + return 1 << Math.floor(Math.log2(n)); } -exports.sum32 = sum32; - -function sum32_3(a, b, c) { - return (a + b + c) >>> 0; +function isPowerOf2(n) { + return (n & (n - 1)) == 0; } -exports.sum32_3 = sum32_3; -function sum32_4(a, b, c, d) { - return (a + b + c + d) >>> 0; +}).call(this)}).call(this,require("buffer").Buffer) +},{"bitcoinjs-lib":404,"buffer":249}],363:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MerkleMap = void 0; +const merkle_1 = require("./merkle"); +const varint_1 = require("./varint"); +/** + * This implements "Merkelized Maps", documented at + * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md#merkleized-maps + * + * A merkelized map consist of two merkle trees, one for the keys of + * a map and one for the values of the same map, thus the two merkle + * trees have the same shape. The commitment is the number elements + * in the map followed by the keys' merkle root followed by the + * values' merkle root. + */ +class MerkleMap { + /** + * @param keys Sorted list of (unhashed) keys + * @param values values, in corresponding order as the keys, and of equal length + */ + constructor(keys, values) { + if (keys.length != values.length) { + throw new Error('keys and values should have the same length'); + } + // Sanity check: verify that keys are actually sorted and with no duplicates + for (let i = 0; i < keys.length - 1; i++) { + if (keys[i].toString('hex') >= keys[i + 1].toString('hex')) { + throw new Error('keys must be in strictly increasing order'); + } + } + this.keys = keys; + this.keysTree = new merkle_1.Merkle(keys.map((k) => (0, merkle_1.hashLeaf)(k))); + this.values = values; + this.valuesTree = new merkle_1.Merkle(values.map((v) => (0, merkle_1.hashLeaf)(v))); + } + commitment() { + // returns a buffer between 65 and 73 (included) bytes long + return Buffer.concat([ + (0, varint_1.createVarint)(this.keys.length), + this.keysTree.getRoot(), + this.valuesTree.getRoot(), + ]); + } } -exports.sum32_4 = sum32_4; +exports.MerkleMap = MerkleMap; -function sum32_5(a, b, c, d, e) { - return (a + b + c + d + e) >>> 0; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./merkle":362,"./varint":366,"buffer":249}],364:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DefaultWalletPolicy = exports.WalletPolicy = void 0; +const bitcoinjs_lib_1 = require("bitcoinjs-lib"); +const buffertools_1 = require("./buffertools"); +const merkle_1 = require("./merkle"); +const WALLET_POLICY_V2 = 2; +/** + * The Bitcon hardware app uses a descriptors-like thing to describe + * how to construct output scripts from keys. A "Wallet Policy" consists + * of a "Descriptor Template" and a list of "keys". A key is basically + * a serialized BIP32 extended public key with some added derivation path + * information. This is documented at + * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/wallet.md + */ +class WalletPolicy { + /** + * Creates and instance of a wallet policy. + * @param name an ascii string, up to 16 bytes long; it must be an empty string for default wallet policies + * @param descriptorTemplate the wallet policy template + * @param keys and array of the keys, with the key derivation information + */ + constructor(name, descriptorTemplate, keys) { + this.name = name; + this.descriptorTemplate = descriptorTemplate; + this.keys = keys; + } + /** + * Returns the unique 32-bytes id of this wallet policy. + */ + getId() { + return bitcoinjs_lib_1.crypto.sha256(this.serialize()); + } + /** + * Serializes the wallet policy for transmission via the hardware wallet protocol. + * @returns the serialized wallet policy + */ + serialize() { + const keyBuffers = this.keys.map((k) => { + return Buffer.from(k, 'ascii'); + }); + const m = new merkle_1.Merkle(keyBuffers.map((k) => (0, merkle_1.hashLeaf)(k))); + const buf = new buffertools_1.BufferWriter(); + buf.writeUInt8(WALLET_POLICY_V2); // wallet version + // length of wallet name, and wallet name + buf.writeVarSlice(Buffer.from(this.name, 'ascii')); + // length of descriptor template + buf.writeVarInt(this.descriptorTemplate.length); + // sha256 hash of descriptor template + buf.writeSlice(bitcoinjs_lib_1.crypto.sha256(Buffer.from(this.descriptorTemplate))); + // number of keys + buf.writeVarInt(this.keys.length); + // root of Merkle tree of keys + buf.writeSlice(m.getRoot()); + return buf.buffer(); + } +} +exports.WalletPolicy = WalletPolicy; +/** + * Simplified class to handle default wallet policies that can be used without policy registration. + */ +class DefaultWalletPolicy extends WalletPolicy { + constructor(descriptorTemplate, key) { + super('', descriptorTemplate, [key]); + } } -exports.sum32_5 = sum32_5; - -function sum64(buf, pos, ah, al) { - var bh = buf[pos]; - var bl = buf[pos + 1]; +exports.DefaultWalletPolicy = DefaultWalletPolicy; - var lo = (al + bl) >>> 0; - var hi = (lo < al ? 1 : 0) + ah + bh; - buf[pos] = hi >>> 0; - buf[pos + 1] = lo; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./buffertools":359,"./merkle":362,"bitcoinjs-lib":404,"buffer":249}],365:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PsbtV2 = exports.NoSuchEntry = exports.psbtOut = exports.psbtIn = exports.psbtGlobal = void 0; +const bjs = __importStar(require("bitcoinjs-lib")); +const buffertools_1 = require("./buffertools"); +const varint_1 = require("./varint"); +var psbtGlobal; +(function (psbtGlobal) { + psbtGlobal[psbtGlobal["UNSIGNED_TX"] = 0] = "UNSIGNED_TX"; + psbtGlobal[psbtGlobal["XPUB"] = 1] = "XPUB"; + psbtGlobal[psbtGlobal["TX_VERSION"] = 2] = "TX_VERSION"; + psbtGlobal[psbtGlobal["FALLBACK_LOCKTIME"] = 3] = "FALLBACK_LOCKTIME"; + psbtGlobal[psbtGlobal["INPUT_COUNT"] = 4] = "INPUT_COUNT"; + psbtGlobal[psbtGlobal["OUTPUT_COUNT"] = 5] = "OUTPUT_COUNT"; + psbtGlobal[psbtGlobal["TX_MODIFIABLE"] = 6] = "TX_MODIFIABLE"; + psbtGlobal[psbtGlobal["VERSION"] = 251] = "VERSION"; +})(psbtGlobal = exports.psbtGlobal || (exports.psbtGlobal = {})); +var psbtIn; +(function (psbtIn) { + psbtIn[psbtIn["NON_WITNESS_UTXO"] = 0] = "NON_WITNESS_UTXO"; + psbtIn[psbtIn["WITNESS_UTXO"] = 1] = "WITNESS_UTXO"; + psbtIn[psbtIn["PARTIAL_SIG"] = 2] = "PARTIAL_SIG"; + psbtIn[psbtIn["SIGHASH_TYPE"] = 3] = "SIGHASH_TYPE"; + psbtIn[psbtIn["REDEEM_SCRIPT"] = 4] = "REDEEM_SCRIPT"; + psbtIn[psbtIn["WITNESS_SCRIPT"] = 5] = "WITNESS_SCRIPT"; + psbtIn[psbtIn["BIP32_DERIVATION"] = 6] = "BIP32_DERIVATION"; + psbtIn[psbtIn["FINAL_SCRIPTSIG"] = 7] = "FINAL_SCRIPTSIG"; + psbtIn[psbtIn["FINAL_SCRIPTWITNESS"] = 8] = "FINAL_SCRIPTWITNESS"; + psbtIn[psbtIn["PREVIOUS_TXID"] = 14] = "PREVIOUS_TXID"; + psbtIn[psbtIn["OUTPUT_INDEX"] = 15] = "OUTPUT_INDEX"; + psbtIn[psbtIn["SEQUENCE"] = 16] = "SEQUENCE"; + psbtIn[psbtIn["TAP_KEY_SIG"] = 19] = "TAP_KEY_SIG"; + psbtIn[psbtIn["TAP_BIP32_DERIVATION"] = 22] = "TAP_BIP32_DERIVATION"; +})(psbtIn = exports.psbtIn || (exports.psbtIn = {})); +var psbtOut; +(function (psbtOut) { + psbtOut[psbtOut["REDEEM_SCRIPT"] = 0] = "REDEEM_SCRIPT"; + psbtOut[psbtOut["WITNESS_SCRIPT"] = 1] = "WITNESS_SCRIPT"; + psbtOut[psbtOut["BIP_32_DERIVATION"] = 2] = "BIP_32_DERIVATION"; + psbtOut[psbtOut["AMOUNT"] = 3] = "AMOUNT"; + psbtOut[psbtOut["SCRIPT"] = 4] = "SCRIPT"; + psbtOut[psbtOut["TAP_BIP32_DERIVATION"] = 7] = "TAP_BIP32_DERIVATION"; +})(psbtOut = exports.psbtOut || (exports.psbtOut = {})); +const PSBT_MAGIC_BYTES = Buffer.from([0x70, 0x73, 0x62, 0x74, 0xff]); +class NoSuchEntry extends Error { +} +exports.NoSuchEntry = NoSuchEntry; +/** + * Implements Partially Signed Bitcoin Transaction version 2, BIP370, as + * documented at https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki + * and https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki + * + * A psbt is a data structure that can carry all relevant information about a + * transaction through all stages of the signing process. From constructing an + * unsigned transaction to extracting the final serialized transaction ready for + * broadcast. + * + * This implementation is limited to what's needed in ledgerjs to carry out its + * duties, which means that support for features like multisig or taproot script + * path spending are not implemented. Specifically, it supports p2pkh, + * p2wpkhWrappedInP2sh, p2wpkh and p2tr key path spending. + * + * This class is made purposefully dumb, so it's easy to add support for + * complemantary fields as needed in the future. + */ +class PsbtV2 { + constructor() { + this.globalMap = new Map(); + this.inputMaps = []; + this.outputMaps = []; + } + setGlobalTxVersion(version) { + this.setGlobal(psbtGlobal.TX_VERSION, uint32LE(version)); + } + getGlobalTxVersion() { + return this.getGlobal(psbtGlobal.TX_VERSION).readUInt32LE(0); + } + setGlobalFallbackLocktime(locktime) { + this.setGlobal(psbtGlobal.FALLBACK_LOCKTIME, uint32LE(locktime)); + } + getGlobalFallbackLocktime() { + var _a; + return (_a = this.getGlobalOptional(psbtGlobal.FALLBACK_LOCKTIME)) === null || _a === void 0 ? void 0 : _a.readUInt32LE(0); + } + setGlobalInputCount(inputCount) { + this.setGlobal(psbtGlobal.INPUT_COUNT, varint(inputCount)); + } + getGlobalInputCount() { + return fromVarint(this.getGlobal(psbtGlobal.INPUT_COUNT)); + } + setGlobalOutputCount(outputCount) { + this.setGlobal(psbtGlobal.OUTPUT_COUNT, varint(outputCount)); + } + getGlobalOutputCount() { + return fromVarint(this.getGlobal(psbtGlobal.OUTPUT_COUNT)); + } + setGlobalTxModifiable(byte) { + this.setGlobal(psbtGlobal.TX_MODIFIABLE, byte); + } + getGlobalTxModifiable() { + return this.getGlobalOptional(psbtGlobal.TX_MODIFIABLE); + } + setGlobalPsbtVersion(psbtVersion) { + this.setGlobal(psbtGlobal.VERSION, uint32LE(psbtVersion)); + } + getGlobalPsbtVersion() { + return this.getGlobal(psbtGlobal.VERSION).readUInt32LE(0); + } + setInputNonWitnessUtxo(inputIndex, transaction) { + this.setInput(inputIndex, psbtIn.NON_WITNESS_UTXO, b(), transaction); + } + getInputNonWitnessUtxo(inputIndex) { + return this.getInputOptional(inputIndex, psbtIn.NON_WITNESS_UTXO, b()); + } + setInputWitnessUtxo(inputIndex, amount, scriptPubKey) { + const buf = new buffertools_1.BufferWriter(); + buf.writeSlice(uint64LE(amount)); + buf.writeVarSlice(scriptPubKey); + this.setInput(inputIndex, psbtIn.WITNESS_UTXO, b(), buf.buffer()); + } + getInputWitnessUtxo(inputIndex) { + const utxo = this.getInputOptional(inputIndex, psbtIn.WITNESS_UTXO, b()); + if (!utxo) + return undefined; + const buf = new buffertools_1.BufferReader(utxo); + return { + amount: (0, buffertools_1.unsafeFrom64bitLE)(buf.readSlice(8)), + scriptPubKey: buf.readVarSlice() + }; + } + setInputPartialSig(inputIndex, pubkey, signature) { + this.setInput(inputIndex, psbtIn.PARTIAL_SIG, pubkey, signature); + } + getInputPartialSig(inputIndex, pubkey) { + return this.getInputOptional(inputIndex, psbtIn.PARTIAL_SIG, pubkey); + } + setInputSighashType(inputIndex, sigHashtype) { + this.setInput(inputIndex, psbtIn.SIGHASH_TYPE, b(), uint32LE(sigHashtype)); + } + getInputSighashType(inputIndex) { + const result = this.getInputOptional(inputIndex, psbtIn.SIGHASH_TYPE, b()); + if (!result) + return undefined; + return result.readUInt32LE(0); + } + setInputRedeemScript(inputIndex, redeemScript) { + this.setInput(inputIndex, psbtIn.REDEEM_SCRIPT, b(), redeemScript); + } + getInputRedeemScript(inputIndex) { + return this.getInputOptional(inputIndex, psbtIn.REDEEM_SCRIPT, b()); + } + setInputWitnessScript(inputIndex, witnessScript) { + this.setInput(inputIndex, psbtIn.WITNESS_SCRIPT, b(), witnessScript); + } + getInputWitnessScript(inputIndex) { + return this.getInputOptional(inputIndex, psbtIn.WITNESS_SCRIPT, b()); + } + setInputBip32Derivation(inputIndex, pubkey, masterFingerprint, path) { + if (pubkey.length != 33) + throw new Error('Invalid pubkey length: ' + pubkey.length); + this.setInput(inputIndex, psbtIn.BIP32_DERIVATION, pubkey, this.encodeBip32Derivation(masterFingerprint, path)); + } + getInputBip32Derivation(inputIndex, pubkey) { + const buf = this.getInputOptional(inputIndex, psbtIn.BIP32_DERIVATION, pubkey); + if (!buf) + return undefined; + return this.decodeBip32Derivation(buf); + } + setInputFinalScriptsig(inputIndex, scriptSig) { + this.setInput(inputIndex, psbtIn.FINAL_SCRIPTSIG, b(), scriptSig); + } + getInputFinalScriptsig(inputIndex) { + return this.getInputOptional(inputIndex, psbtIn.FINAL_SCRIPTSIG, b()); + } + setInputFinalScriptwitness(inputIndex, scriptWitness) { + this.setInput(inputIndex, psbtIn.FINAL_SCRIPTWITNESS, b(), scriptWitness); + } + getInputFinalScriptwitness(inputIndex) { + return this.getInput(inputIndex, psbtIn.FINAL_SCRIPTWITNESS, b()); + } + setInputPreviousTxId(inputIndex, txid) { + this.setInput(inputIndex, psbtIn.PREVIOUS_TXID, b(), txid); + } + getInputPreviousTxid(inputIndex) { + return this.getInput(inputIndex, psbtIn.PREVIOUS_TXID, b()); + } + setInputOutputIndex(inputIndex, outputIndex) { + this.setInput(inputIndex, psbtIn.OUTPUT_INDEX, b(), uint32LE(outputIndex)); + } + getInputOutputIndex(inputIndex) { + return this.getInput(inputIndex, psbtIn.OUTPUT_INDEX, b()).readUInt32LE(0); + } + setInputSequence(inputIndex, sequence) { + this.setInput(inputIndex, psbtIn.SEQUENCE, b(), uint32LE(sequence)); + } + getInputSequence(inputIndex) { + var _a, _b; + return ((_b = (_a = this.getInputOptional(inputIndex, psbtIn.SEQUENCE, b())) === null || _a === void 0 ? void 0 : _a.readUInt32LE(0)) !== null && _b !== void 0 ? _b : 0xffffffff); + } + setInputTapKeySig(inputIndex, sig) { + this.setInput(inputIndex, psbtIn.TAP_KEY_SIG, b(), sig); + } + getInputTapKeySig(inputIndex) { + return this.getInputOptional(inputIndex, psbtIn.TAP_KEY_SIG, b()); + } + setInputTapBip32Derivation(inputIndex, pubkey, hashes, masterFingerprint, path) { + if (pubkey.length != 32) + throw new Error('Invalid pubkey length: ' + pubkey.length); + const buf = this.encodeTapBip32Derivation(hashes, masterFingerprint, path); + this.setInput(inputIndex, psbtIn.TAP_BIP32_DERIVATION, pubkey, buf); + } + getInputTapBip32Derivation(inputIndex, pubkey) { + const buf = this.getInput(inputIndex, psbtIn.TAP_BIP32_DERIVATION, pubkey); + return this.decodeTapBip32Derivation(buf); + } + getInputKeyDatas(inputIndex, keyType) { + return this.getKeyDatas(this.inputMaps[inputIndex], keyType); + } + setOutputRedeemScript(outputIndex, redeemScript) { + this.setOutput(outputIndex, psbtOut.REDEEM_SCRIPT, b(), redeemScript); + } + getOutputRedeemScript(outputIndex) { + return this.getOutput(outputIndex, psbtOut.REDEEM_SCRIPT, b()); + } + setOutputBip32Derivation(outputIndex, pubkey, masterFingerprint, path) { + this.setOutput(outputIndex, psbtOut.BIP_32_DERIVATION, pubkey, this.encodeBip32Derivation(masterFingerprint, path)); + } + getOutputBip32Derivation(outputIndex, pubkey) { + const buf = this.getOutput(outputIndex, psbtOut.BIP_32_DERIVATION, pubkey); + return this.decodeBip32Derivation(buf); + } + setOutputAmount(outputIndex, amount) { + this.setOutput(outputIndex, psbtOut.AMOUNT, b(), uint64LE(amount)); + } + getOutputAmount(outputIndex) { + const buf = this.getOutput(outputIndex, psbtOut.AMOUNT, b()); + return (0, buffertools_1.unsafeFrom64bitLE)(buf); + } + setOutputScript(outputIndex, scriptPubKey) { + this.setOutput(outputIndex, psbtOut.SCRIPT, b(), scriptPubKey); + } + getOutputScript(outputIndex) { + return this.getOutput(outputIndex, psbtOut.SCRIPT, b()); + } + setOutputTapBip32Derivation(outputIndex, pubkey, hashes, fingerprint, path) { + const buf = this.encodeTapBip32Derivation(hashes, fingerprint, path); + this.setOutput(outputIndex, psbtOut.TAP_BIP32_DERIVATION, pubkey, buf); + } + getOutputTapBip32Derivation(outputIndex, pubkey) { + const buf = this.getOutput(outputIndex, psbtOut.TAP_BIP32_DERIVATION, pubkey); + return this.decodeTapBip32Derivation(buf); + } + deleteInputEntries(inputIndex, keyTypes) { + const map = this.inputMaps[inputIndex]; + map.forEach((_v, k, m) => { + if (this.isKeyType(k, keyTypes)) { + m.delete(k); + } + }); + } + copy(to) { + this.copyMap(this.globalMap, to.globalMap); + this.copyMaps(this.inputMaps, to.inputMaps); + this.copyMaps(this.outputMaps, to.outputMaps); + } + copyMaps(from, to) { + from.forEach((m, index) => { + const to_index = new Map(); + this.copyMap(m, to_index); + to[index] = to_index; + }); + } + copyMap(from, to) { + from.forEach((v, k) => to.set(k, Buffer.from(v))); + } + serialize() { + const buf = new buffertools_1.BufferWriter(); + buf.writeSlice(Buffer.from([0x70, 0x73, 0x62, 0x74, 0xff])); + serializeMap(buf, this.globalMap); + this.inputMaps.forEach((map) => { + serializeMap(buf, map); + }); + this.outputMaps.forEach((map) => { + serializeMap(buf, map); + }); + return buf.buffer(); + } + deserialize(psbt) { + const buf = new buffertools_1.BufferReader(psbt); + if (!buf.readSlice(5).equals(PSBT_MAGIC_BYTES)) { + throw new Error('Invalid magic bytes'); + } + while (this.readKeyPair(this.globalMap, buf)) + ; + let psbtVersion; + try { + psbtVersion = this.getGlobalPsbtVersion(); + } + catch (_a) { + psbtVersion = 0; + } + if (psbtVersion !== 0 && psbtVersion !== 2) + throw new Error("Only PSBTs of version 0 or 2 are supported"); + let nInputs; + let nOutputs; + if (psbtVersion == 0) { + // if PSBTv0, we parse the PSBT_GLOBAL_UNSIGNED_TX field + const txRaw = this.getGlobal(psbtGlobal.UNSIGNED_TX); + const tx = bjs.Transaction.fromBuffer(txRaw); + nInputs = tx.ins.length; + nOutputs = tx.outs.length; + } + else { + // if PSBTv2, we already have the counts + nInputs = this.getGlobalInputCount(); + nOutputs = this.getGlobalOutputCount(); + } + for (let i = 0; i < nInputs; i++) { + this.inputMaps[i] = new Map(); + while (this.readKeyPair(this.inputMaps[i], buf)) + ; + } + for (let i = 0; i < nOutputs; i++) { + this.outputMaps[i] = new Map(); + while (this.readKeyPair(this.outputMaps[i], buf)) + ; + } + this.normalizeToV2(); + } + normalizeToV2() { + var _a; + // if the psbt is a PsbtV0, convert it to PsbtV2 instead. + // throw an error for any version other than 0 or 2, + const psbtVersion = (_a = this.getGlobalOptional(psbtGlobal.VERSION)) === null || _a === void 0 ? void 0 : _a.readInt32LE(0); + if (psbtVersion === 2) + return; + else if (psbtVersion !== undefined) { + throw new Error('Invalid or unsupported value for PSBT_GLOBAL_VERSION'); + } + // Convert PsbtV0 to PsbtV2 by parsing the PSBT_GLOBAL_UNSIGNED_TX field + // and filling in the corresponding fields. + const txRaw = this.getGlobal(psbtGlobal.UNSIGNED_TX); + const tx = bjs.Transaction.fromBuffer(txRaw); + this.setGlobalPsbtVersion(2); + this.setGlobalTxVersion(tx.version); + this.setGlobalFallbackLocktime(tx.locktime); + this.setGlobalInputCount(tx.ins.length); + this.setGlobalOutputCount(tx.outs.length); + for (let i = 0; i < tx.ins.length; i++) { + this.setInputPreviousTxId(i, tx.ins[i].hash); + this.setInputOutputIndex(i, tx.ins[i].index); + this.setInputSequence(i, tx.ins[i].sequence); + } + for (let i = 0; i < tx.outs.length; i++) { + this.setOutputAmount(i, tx.outs[i].value); + this.setOutputScript(i, tx.outs[i].script); + } + // PSBT_GLOBAL_UNSIGNED_TX must be removed in a valid PSBTv2 + this.globalMap.delete(psbtGlobal.UNSIGNED_TX.toString(16).padStart(2, '0')); + } + /** + * Imports a BitcoinJS (bitcoinjs-lib) Psbt object. + * https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/psbt.ts + * + * Prepares the fields required for signing a Psbt on a Ledger + * device. It should be used exclusively before calling + * `appClient.signPsbt()` and not as a general Psbt conversion method. + * + * Note: This method supports all the policies that the Ledger is able to + * sign, with the exception of taproot: tr(@0). + */ + fromBitcoinJS(psbtBJS) { + function isTaprootInput(input) { + let isP2TR; + try { + bjs.payments.p2tr({ output: input.witnessUtxo.script }); + isP2TR = true; + } + catch (err) { + isP2TR = false; + } + return (input && + !!(input.tapInternalKey || + input.tapMerkleRoot || + (input.tapLeafScript && input.tapLeafScript.length) || + (input.tapBip32Derivation && input.tapBip32Derivation.length) || + isP2TR)); + } + this.setGlobalPsbtVersion(2); + this.setGlobalTxVersion(psbtBJS.version); + this.setGlobalInputCount(psbtBJS.data.inputs.length); + this.setGlobalOutputCount(psbtBJS.txOutputs.length); + if (psbtBJS.locktime !== undefined) + this.setGlobalFallbackLocktime(psbtBJS.locktime); + psbtBJS.data.inputs.forEach((input, index) => { + if (isTaprootInput(input)) + throw new Error(`Taproot inputs not supported`); + this.setInputPreviousTxId(index, psbtBJS.txInputs[index].hash); + if (psbtBJS.txInputs[index].sequence !== undefined) + this.setInputSequence(index, psbtBJS.txInputs[index].sequence); + this.setInputOutputIndex(index, psbtBJS.txInputs[index].index); + if (input.sighashType !== undefined) + this.setInputSighashType(index, input.sighashType); + if (input.nonWitnessUtxo) + this.setInputNonWitnessUtxo(index, input.nonWitnessUtxo); + if (input.witnessUtxo) { + this.setInputWitnessUtxo(index, input.witnessUtxo.value, input.witnessUtxo.script); + } + if (input.witnessScript) + this.setInputWitnessScript(index, input.witnessScript); + if (input.redeemScript) + this.setInputRedeemScript(index, input.redeemScript); + psbtBJS.data.inputs[index].bip32Derivation.forEach(derivation => { + if (!/^m\//i.test(derivation.path)) + throw new Error(`Invalid input bip32 derivation`); + const pathArray = derivation.path + .replace(/m\//i, '') + .split('/') + .map(level => level.match(/['h]/i) ? parseInt(level) + 0x80000000 : Number(level)); + this.setInputBip32Derivation(index, derivation.pubkey, derivation.masterFingerprint, pathArray); + }); + }); + psbtBJS.txOutputs.forEach((output, index) => { + this.setOutputAmount(index, output.value); + this.setOutputScript(index, output.script); + }); + return this; + } + readKeyPair(map, buf) { + const keyLen = (0, varint_1.sanitizeBigintToNumber)(buf.readVarInt()); + if (keyLen == 0) { + return false; + } + const keyType = buf.readUInt8(); + const keyData = buf.readSlice(keyLen - 1); + const value = buf.readVarSlice(); + set(map, keyType, keyData, value); + return true; + } + getKeyDatas(map, keyType) { + const result = []; + map.forEach((_v, k) => { + if (this.isKeyType(k, [keyType])) { + result.push(Buffer.from(k.substring(2), 'hex')); + } + }); + return result; + } + isKeyType(hexKey, keyTypes) { + const keyType = Buffer.from(hexKey.substring(0, 2), 'hex').readUInt8(0); + return keyTypes.some((k) => k == keyType); + } + setGlobal(keyType, value) { + const key = new Key(keyType, Buffer.from([])); + this.globalMap.set(key.toString(), value); + } + getGlobal(keyType) { + return get(this.globalMap, keyType, b(), false); + } + getGlobalOptional(keyType) { + return get(this.globalMap, keyType, b(), true); + } + setInput(index, keyType, keyData, value) { + set(this.getMap(index, this.inputMaps), keyType, keyData, value); + } + getInput(index, keyType, keyData) { + return get(this.inputMaps[index], keyType, keyData, false); + } + getInputOptional(index, keyType, keyData) { + return get(this.inputMaps[index], keyType, keyData, true); + } + setOutput(index, keyType, keyData, value) { + set(this.getMap(index, this.outputMaps), keyType, keyData, value); + } + getOutput(index, keyType, keyData) { + return get(this.outputMaps[index], keyType, keyData, false); + } + getMap(index, maps) { + if (maps[index]) { + return maps[index]; + } + return (maps[index] = new Map()); + } + encodeBip32Derivation(masterFingerprint, path) { + const buf = new buffertools_1.BufferWriter(); + this.writeBip32Derivation(buf, masterFingerprint, path); + return buf.buffer(); + } + decodeBip32Derivation(buffer) { + const buf = new buffertools_1.BufferReader(buffer); + return this.readBip32Derivation(buf); + } + writeBip32Derivation(buf, masterFingerprint, path) { + buf.writeSlice(masterFingerprint); + path.forEach((element) => { + buf.writeUInt32(element); + }); + } + readBip32Derivation(buf) { + const masterFingerprint = buf.readSlice(4); + const path = []; + while (buf.offset < buf.buffer.length) { + path.push(buf.readUInt32()); + } + return { masterFingerprint, path }; + } + encodeTapBip32Derivation(hashes, masterFingerprint, path) { + const buf = new buffertools_1.BufferWriter(); + buf.writeVarInt(hashes.length); + hashes.forEach((h) => { + buf.writeSlice(h); + }); + this.writeBip32Derivation(buf, masterFingerprint, path); + return buf.buffer(); + } + decodeTapBip32Derivation(buffer) { + const buf = new buffertools_1.BufferReader(buffer); + const hashCount = (0, varint_1.sanitizeBigintToNumber)(buf.readVarInt()); + const hashes = []; + for (let i = 0; i < hashCount; i++) { + hashes.push(buf.readSlice(32)); + } + const deriv = this.readBip32Derivation(buf); + return Object.assign({ hashes }, deriv); + } +} +exports.PsbtV2 = PsbtV2; +function get(map, keyType, keyData, acceptUndefined) { + if (!map) + throw Error('No such map'); + const key = new Key(keyType, keyData); + const value = map.get(key.toString()); + if (!value) { + if (acceptUndefined) { + return undefined; + } + throw new NoSuchEntry(key.toString()); + } + // Make sure to return a copy, to protect the underlying data. + return Buffer.from(value); } -exports.sum64 = sum64; - -function sum64_hi(ah, al, bh, bl) { - var lo = (al + bl) >>> 0; - var hi = (lo < al ? 1 : 0) + ah + bh; - return hi >>> 0; +class Key { + constructor(keyType, keyData) { + this.keyType = keyType; + this.keyData = keyData; + } + toString() { + const buf = new buffertools_1.BufferWriter(); + this.toBuffer(buf); + return buf.buffer().toString('hex'); + } + serialize(buf) { + buf.writeVarInt(1 + this.keyData.length); + this.toBuffer(buf); + } + toBuffer(buf) { + buf.writeUInt8(this.keyType); + buf.writeSlice(this.keyData); + } } -exports.sum64_hi = sum64_hi; - -function sum64_lo(ah, al, bh, bl) { - var lo = al + bl; - return lo >>> 0; +class KeyPair { + constructor(key, value) { + this.key = key; + this.value = value; + } + serialize(buf) { + this.key.serialize(buf); + buf.writeVarSlice(this.value); + } } -exports.sum64_lo = sum64_lo; - -function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { - var carry = 0; - var lo = al; - lo = (lo + bl) >>> 0; - carry += lo < al ? 1 : 0; - lo = (lo + cl) >>> 0; - carry += lo < cl ? 1 : 0; - lo = (lo + dl) >>> 0; - carry += lo < dl ? 1 : 0; - - var hi = ah + bh + ch + dh + carry; - return hi >>> 0; +function createKey(buf) { + return new Key(buf.readUInt8(0), buf.slice(1)); +} +function serializeMap(buf, map) { + // serialize in lexicographical order of keys + for (let [key, value] of [...map].sort(([k1], [k2]) => k1.localeCompare(k2))) { + const keyPair = new KeyPair(createKey(Buffer.from(key, 'hex')), value); + keyPair.serialize(buf); + } + buf.writeUInt8(0); } -exports.sum64_4_hi = sum64_4_hi; - -function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { - var lo = al + bl + cl + dl; - return lo >>> 0; +function b() { + return Buffer.from([]); } -exports.sum64_4_lo = sum64_4_lo; - -function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { - var carry = 0; - var lo = al; - lo = (lo + bl) >>> 0; - carry += lo < al ? 1 : 0; - lo = (lo + cl) >>> 0; - carry += lo < cl ? 1 : 0; - lo = (lo + dl) >>> 0; - carry += lo < dl ? 1 : 0; - lo = (lo + el) >>> 0; - carry += lo < el ? 1 : 0; - - var hi = ah + bh + ch + dh + eh + carry; - return hi >>> 0; +function set(map, keyType, keyData, value) { + const key = new Key(keyType, keyData); + map.set(key.toString(), value); } -exports.sum64_5_hi = sum64_5_hi; - -function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { - var lo = al + bl + cl + dl + el; - - return lo >>> 0; +function uint32LE(n) { + const buf = Buffer.alloc(4); + buf.writeUInt32LE(n, 0); + return buf; } -exports.sum64_5_lo = sum64_5_lo; - -function rotr64_hi(ah, al, num) { - var r = (al << (32 - num)) | (ah >>> num); - return r >>> 0; +function uint64LE(n) { + return (0, buffertools_1.unsafeTo64bitLE)(n); } -exports.rotr64_hi = rotr64_hi; - -function rotr64_lo(ah, al, num) { - var r = (ah << (32 - num)) | (al >>> num); - return r >>> 0; +function varint(n) { + const buf = new buffertools_1.BufferWriter(); + buf.writeVarInt(n); + return buf.buffer(); } -exports.rotr64_lo = rotr64_lo; - -function shr64_hi(ah, al, num) { - return ah >>> num; +function fromVarint(buf) { + return (0, varint_1.sanitizeBigintToNumber)(new buffertools_1.BufferReader(buf).readVarInt()); } -exports.shr64_hi = shr64_hi; -function shr64_lo(ah, al, num) { - var r = (ah << (32 - num)) | (al >>> num); - return r >>> 0; +}).call(this)}).call(this,require("buffer").Buffer) +},{"./buffertools":359,"./varint":366,"bitcoinjs-lib":404,"buffer":249}],366:[function(require,module,exports){ +(function (Buffer){(function (){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createVarint = exports.parseVarint = exports.sanitizeBigintToNumber = void 0; +function bigintToSmallEndian(value, length, buffer, offset) { + for (let i = 0; i < length; i++) { + if (buffer[i + offset] == undefined) { + throw Error('Buffer too small'); + } + buffer[i + offset] = Number(value % BigInt(256)); + value = value >> BigInt(8); + } } -exports.shr64_lo = shr64_lo; - -},{"inherits":230,"minimalistic-assert":238}],228:[function(require,module,exports){ -'use strict'; - -var hash = require('hash.js'); -var utils = require('minimalistic-crypto-utils'); -var assert = require('minimalistic-assert'); - -function HmacDRBG(options) { - if (!(this instanceof HmacDRBG)) - return new HmacDRBG(options); - this.hash = options.hash; - this.predResist = !!options.predResist; - - this.outLen = this.hash.outSize; - this.minEntropy = options.minEntropy || this.hash.hmacStrength; - - this._reseed = null; - this.reseedInterval = null; - this.K = null; - this.V = null; - - var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex'); - var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex'); - var pers = utils.toArray(options.pers, options.persEnc || 'hex'); - assert(entropy.length >= (this.minEntropy / 8), - 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); - this._init(entropy, nonce, pers); +function smallEndianToBigint(buffer, offset, length) { + let result = BigInt(0); + for (let i = 0; i < length; i++) { + if (buffer[i + offset] == undefined) { + throw Error('Buffer too small'); + } + result += BigInt(buffer[i + offset]) << BigInt(i * 8); + } + return result; } -module.exports = HmacDRBG; - -HmacDRBG.prototype._init = function init(entropy, nonce, pers) { - var seed = entropy.concat(nonce).concat(pers); - - this.K = new Array(this.outLen / 8); - this.V = new Array(this.outLen / 8); - for (var i = 0; i < this.V.length; i++) { - this.K[i] = 0x00; - this.V[i] = 0x01; - } - - this._update(seed); - this._reseed = 1; - this.reseedInterval = 0x1000000000000; // 2^48 -}; - -HmacDRBG.prototype._hmac = function hmac() { - return new hash.hmac(this.hash, this.K); -}; - -HmacDRBG.prototype._update = function update(seed) { - var kmac = this._hmac() - .update(this.V) - .update([ 0x00 ]); - if (seed) - kmac = kmac.update(seed); - this.K = kmac.digest(); - this.V = this._hmac().update(this.V).digest(); - if (!seed) - return; - - this.K = this._hmac() - .update(this.V) - .update([ 0x01 ]) - .update(seed) - .digest(); - this.V = this._hmac().update(this.V).digest(); -}; - -HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { - // Optional entropy enc - if (typeof entropyEnc !== 'string') { - addEnc = add; - add = entropyEnc; - entropyEnc = null; - } - - entropy = utils.toArray(entropy, entropyEnc); - add = utils.toArray(add, addEnc); - - assert(entropy.length >= (this.minEntropy / 8), - 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits'); - - this._update(entropy.concat(add || [])); - this._reseed = 1; -}; - -HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { - if (this._reseed > this.reseedInterval) - throw new Error('Reseed is required'); - - // Optional encoding - if (typeof enc !== 'string') { - addEnc = add; - add = enc; - enc = null; - } - - // Optional additional data - if (add) { - add = utils.toArray(add, addEnc || 'hex'); - this._update(add); - } - - var temp = []; - while (temp.length < len) { - this.V = this._hmac().update(this.V).digest(); - temp = temp.concat(this.V); - } - - var res = temp.slice(0, len); - this._update(add); - this._reseed++; - return utils.encode(res, enc); -}; - -},{"hash.js":216,"minimalistic-assert":238,"minimalistic-crypto-utils":239}],229:[function(require,module,exports){ -exports.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var nBits = -7 - var i = isLE ? (nBytes - 1) : 0 - var d = isLE ? -1 : 1 - var s = buffer[offset + i] - - i += d - - e = s & ((1 << (-nBits)) - 1) - s >>= (-nBits) - nBits += eLen - for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} - - m = e & ((1 << (-nBits)) - 1) - e >>= (-nBits) - nBits += mLen - for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} - - if (e === 0) { - e = 1 - eBias - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen) - e = e - eBias - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +/** + * Converts a `bigint` to a `number` if it non-negative and at most MAX_SAFE_INTEGER; throws `RangeError` otherwise. + * Used when converting a Bitcoin-style varint to a `number`, since varints could be larger than what the `Number` + * class can represent without loss of precision. + * + * @param n the number to convert + * @returns `n` as a `number` + */ +function sanitizeBigintToNumber(n) { + if (n < 0) + throw RangeError('Negative bigint is not a valid varint'); + if (n > Number.MAX_SAFE_INTEGER) + throw RangeError('Too large for a Number'); + return Number(n); +} +exports.sanitizeBigintToNumber = sanitizeBigintToNumber; +function getVarintSize(value) { + if (typeof value == 'number') { + value = sanitizeBigintToNumber(value); + } + if (value < BigInt(0)) { + throw new RangeError('Negative numbers are not supported'); + } + if (value >= BigInt(1) << BigInt(64)) { + throw new RangeError('Too large for a Bitcoin-style varint'); + } + if (value < BigInt(0xfd)) + return 1; + else if (value <= BigInt(0xffff)) + return 3; + else if (value <= BigInt(0xffffffff)) + return 5; + else + return 9; } - -exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c - var eLen = (nBytes * 8) - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) - var i = isLE ? 0 : (nBytes - 1) - var d = isLE ? 1 : -1 - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 - - value = Math.abs(value) - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0 - e = eMax - } else { - e = Math.floor(Math.log(value) / Math.LN2) - if (value * (c = Math.pow(2, -e)) < 1) { - e-- - c *= 2 +/** + * Parses a Bitcoin-style variable length integer from a buffer, starting at the given `offset`. Returns a pair + * containing the parsed `BigInt`, and its length in bytes from the buffer. + * + * @param data the `Buffer` from which the variable-length integer is read + * @param offset a non-negative offset to read from + * @returns a pair where the first element is the parsed BigInt, and the second element is the length in bytes parsed + * from the buffer. + * + * @throws `RangeError` if offset is negative. + * @throws `Error` if the buffer's end is reached withut parsing being completed. + */ +function parseVarint(data, offset) { + if (offset < 0) { + throw RangeError("Negative offset is invalid"); } - if (e + eBias >= 1) { - value += rt / c - } else { - value += rt * Math.pow(2, 1 - eBias) + if (data[offset] == undefined) { + throw Error('Buffer too small'); } - if (value * c >= 2) { - e++ - c /= 2 + if (data[offset] < 0xfd) { + return [BigInt(data[offset]), 1]; } - - if (e + eBias >= eMax) { - m = 0 - e = eMax - } else if (e + eBias >= 1) { - m = ((value * c) - 1) * Math.pow(2, mLen) - e = e + eBias - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) - e = 0 + else { + let size; + if (data[offset] === 0xfd) + size = 2; + else if (data[offset] === 0xfe) + size = 4; + else + size = 8; + return [smallEndianToBigint(data, offset + 1, size), size + 1]; + } +} +exports.parseVarint = parseVarint; +function createVarint(value) { + if (typeof value == 'number') { + value = sanitizeBigintToNumber(value); + } + const size = getVarintSize(value); + value = BigInt(value); + const buffer = Buffer.alloc(size); + if (size == 1) { + buffer[0] = Number(value); + } + else { + if (size == 3) + buffer[0] = 0xfd; + else if (size === 5) + buffer[0] = 0xfe; + else + buffer[0] = 0xff; + bigintToSmallEndian(value, size - 1, buffer, 1); + } + return buffer; +} +exports.createVarint = createVarint; + +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],367:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"dup":12}],368:[function(require,module,exports){ +arguments[4][13][0].apply(exports,arguments) +},{"../parser":393,"dup":13}],369:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":14}],370:[function(require,module,exports){ +arguments[4][15][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":15}],371:[function(require,module,exports){ +arguments[4][16][0].apply(exports,arguments) +},{"../typeFields":396,"./global/globalXpub":369,"./global/unsignedTx":370,"./input/finalScriptSig":372,"./input/finalScriptWitness":373,"./input/nonWitnessUtxo":374,"./input/partialSig":375,"./input/porCommitment":376,"./input/sighashType":377,"./input/tapKeySig":378,"./input/tapLeafScript":379,"./input/tapMerkleRoot":380,"./input/tapScriptSig":381,"./input/witnessUtxo":382,"./output/tapTree":383,"./shared/bip32Derivation":384,"./shared/checkPubkey":385,"./shared/redeemScript":386,"./shared/tapBip32Derivation":387,"./shared/tapInternalKey":388,"./shared/witnessScript":389,"dup":16}],372:[function(require,module,exports){ +arguments[4][17][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":17}],373:[function(require,module,exports){ +arguments[4][18][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":18}],374:[function(require,module,exports){ +arguments[4][19][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":19}],375:[function(require,module,exports){ +arguments[4][20][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":20}],376:[function(require,module,exports){ +arguments[4][21][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":21}],377:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":22}],378:[function(require,module,exports){ +arguments[4][23][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":23}],379:[function(require,module,exports){ +arguments[4][24][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":24}],380:[function(require,module,exports){ +arguments[4][25][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":25}],381:[function(require,module,exports){ +arguments[4][26][0].apply(exports,arguments) +},{"../../typeFields":396,"buffer":249,"dup":26}],382:[function(require,module,exports){ +arguments[4][27][0].apply(exports,arguments) +},{"../../typeFields":396,"../tools":390,"../varint":391,"buffer":249,"dup":27}],383:[function(require,module,exports){ +arguments[4][28][0].apply(exports,arguments) +},{"../../typeFields":396,"../varint":391,"buffer":249,"dup":28}],384:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"buffer":249,"dup":29}],385:[function(require,module,exports){ +arguments[4][30][0].apply(exports,arguments) +},{"dup":30}],386:[function(require,module,exports){ +arguments[4][31][0].apply(exports,arguments) +},{"buffer":249,"dup":31}],387:[function(require,module,exports){ +arguments[4][32][0].apply(exports,arguments) +},{"../varint":391,"./bip32Derivation":384,"buffer":249,"dup":32}],388:[function(require,module,exports){ +arguments[4][33][0].apply(exports,arguments) +},{"buffer":249,"dup":33}],389:[function(require,module,exports){ +arguments[4][34][0].apply(exports,arguments) +},{"buffer":249,"dup":34}],390:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"./varint":391,"buffer":249,"dup":35}],391:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"buffer":249,"dup":36}],392:[function(require,module,exports){ +arguments[4][37][0].apply(exports,arguments) +},{"../converter":371,"../converter/tools":390,"../converter/varint":391,"../typeFields":396,"buffer":249,"dup":37}],393:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"./fromBuffer":392,"./toBuffer":394,"dup":38}],394:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"../converter":371,"../converter/tools":390,"buffer":249,"dup":39}],395:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"./combiner":368,"./parser":393,"./typeFields":396,"./utils":397,"buffer":249,"dup":40}],396:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"dup":41}],397:[function(require,module,exports){ +(function (Buffer){(function (){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +const converter = require('./converter'); +function checkForInput(inputs, inputIndex) { + const input = inputs[inputIndex]; + if (input === undefined) throw new Error(`No input #${inputIndex}`); + return input; +} +exports.checkForInput = checkForInput; +function checkForOutput(outputs, outputIndex) { + const output = outputs[outputIndex]; + if (output === undefined) throw new Error(`No output #${outputIndex}`); + return output; +} +exports.checkForOutput = checkForOutput; +function checkHasKey(checkKeyVal, keyVals, enumLength) { + if (checkKeyVal.key[0] < enumLength) { + throw new Error( + `Use the method for your specific key instead of addUnknownKeyVal*`, + ); + } + if ( + keyVals && + keyVals.filter(kv => kv.key.equals(checkKeyVal.key)).length !== 0 + ) { + throw new Error(`Duplicate Key: ${checkKeyVal.key.toString('hex')}`); + } +} +exports.checkHasKey = checkHasKey; +function getEnumLength(myenum) { + let count = 0; + Object.keys(myenum).forEach(val => { + if (Number(isNaN(Number(val)))) { + count++; } + }); + return count; +} +exports.getEnumLength = getEnumLength; +function inputCheckUncleanFinalized(inputIndex, input) { + let result = false; + if (input.nonWitnessUtxo || input.witnessUtxo) { + const needScriptSig = !!input.redeemScript; + const needWitnessScript = !!input.witnessScript; + const scriptSigOK = !needScriptSig || !!input.finalScriptSig; + const witnessScriptOK = !needWitnessScript || !!input.finalScriptWitness; + const hasOneFinal = !!input.finalScriptSig || !!input.finalScriptWitness; + result = scriptSigOK && witnessScriptOK && hasOneFinal; + } + if (result === false) { + throw new Error( + `Input #${inputIndex} has too much or too little data to clean`, + ); } - - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} - - e = (e << mLen) | m - eLen += mLen - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} - - buffer[offset + i - d] |= s * 128 } - -},{}],230:[function(require,module,exports){ -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true +exports.inputCheckUncleanFinalized = inputCheckUncleanFinalized; +function throwForUpdateMaker(typeName, name, expected, data) { + throw new Error( + `Data for ${typeName} key ${name} is incorrect: Expected ` + + `${expected} and got ${JSON.stringify(data)}`, + ); +} +function updateMaker(typeName) { + return (updateData, mainData) => { + for (const name of Object.keys(updateData)) { + // @ts-ignore + const data = updateData[name]; + // @ts-ignore + const { canAdd, canAddToArray, check, expected } = + // @ts-ignore + converter[typeName + 's'][name] || {}; + const isArray = !!canAddToArray; + // If unknown data. ignore and do not add + if (check) { + if (isArray) { + if ( + !Array.isArray(data) || + // @ts-ignore + (mainData[name] && !Array.isArray(mainData[name])) + ) { + throw new Error(`Key type ${name} must be an array`); + } + if (!data.every(check)) { + throwForUpdateMaker(typeName, name, expected, data); + } + // @ts-ignore + const arr = mainData[name] || []; + const dupeCheckSet = new Set(); + if (!data.every(v => canAddToArray(arr, v, dupeCheckSet))) { + throw new Error('Can not add duplicate data to array'); + } + // @ts-ignore + mainData[name] = arr.concat(data); + } else { + if (!check(data)) { + throwForUpdateMaker(typeName, name, expected, data); + } + if (!canAdd(mainData, data)) { + throw new Error(`Can not add duplicate data to ${typeName}`); + } + // @ts-ignore + mainData[name] = data; } - }) + } } }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } - } } - -},{}],231:[function(require,module,exports){ -/*! - * Determine if an object is a Buffer - * - * @author Feross Aboukhadijeh - * @license MIT +exports.updateGlobal = updateMaker('global'); +exports.updateInput = updateMaker('input'); +exports.updateOutput = updateMaker('output'); +function addInputAttributes(inputs, data) { + const index = inputs.length - 1; + const input = checkForInput(inputs, index); + exports.updateInput(data, input); +} +exports.addInputAttributes = addInputAttributes; +function addOutputAttributes(outputs, data) { + const index = outputs.length - 1; + const output = checkForOutput(outputs, index); + exports.updateOutput(data, output); +} +exports.addOutputAttributes = addOutputAttributes; +function defaultVersionSetter(version, txBuf) { + if (!Buffer.isBuffer(txBuf) || txBuf.length < 4) { + throw new Error('Set Version: Invalid Transaction'); + } + txBuf.writeUInt32LE(version, 0); + return txBuf; +} +exports.defaultVersionSetter = defaultVersionSetter; +function defaultLocktimeSetter(locktime, txBuf) { + if (!Buffer.isBuffer(txBuf) || txBuf.length < 4) { + throw new Error('Set Locktime: Invalid Transaction'); + } + txBuf.writeUInt32LE(locktime, txBuf.length - 4); + return txBuf; +} +exports.defaultLocktimeSetter = defaultLocktimeSetter; + +}).call(this)}).call(this,{"isBuffer":require("../../../../../is-buffer/index.js")}) +},{"../../../../../is-buffer/index.js":351,"./converter":371}],398:[function(require,module,exports){ +arguments[4][47][0].apply(exports,arguments) +},{"./networks":406,"./payments":410,"./script":423,"./types":427,"bech32":120,"bs58check":430,"buffer":249,"dup":47}],399:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"buffer":249,"dup":48}],400:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"./bufferutils":401,"./crypto":402,"./merkle":405,"./transaction":426,"./types":427,"buffer":249,"dup":49}],401:[function(require,module,exports){ +arguments[4][50][0].apply(exports,arguments) +},{"./types":427,"buffer":249,"dup":50,"varuint-bitcoin":528}],402:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"@noble/hashes/ripemd160":87,"@noble/hashes/sha1":88,"@noble/hashes/sha256":89,"buffer":249,"dup":51}],403:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"buffer":249,"dup":52}],404:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"./address":398,"./block":400,"./crypto":402,"./ecc_lib":403,"./networks":406,"./ops":407,"./payments":410,"./psbt":419,"./script":423,"./transaction":426,"dup":53}],405:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"buffer":249,"dup":54}],406:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],407:[function(require,module,exports){ +arguments[4][56][0].apply(exports,arguments) +},{"dup":56}],408:[function(require,module,exports){ +arguments[4][57][0].apply(exports,arguments) +},{"../bufferutils":401,"../crypto":402,"../ecc_lib":403,"../types":427,"buffer":249,"dup":57}],409:[function(require,module,exports){ +arguments[4][58][0].apply(exports,arguments) +},{"../networks":406,"../script":423,"../types":427,"./lazy":411,"dup":58}],410:[function(require,module,exports){ +arguments[4][59][0].apply(exports,arguments) +},{"./embed":409,"./p2ms":412,"./p2pk":413,"./p2pkh":414,"./p2sh":415,"./p2tr":416,"./p2wpkh":417,"./p2wsh":418,"dup":59}],411:[function(require,module,exports){ +arguments[4][60][0].apply(exports,arguments) +},{"dup":60}],412:[function(require,module,exports){ +arguments[4][61][0].apply(exports,arguments) +},{"../networks":406,"../script":423,"../types":427,"./lazy":411,"dup":61}],413:[function(require,module,exports){ +arguments[4][62][0].apply(exports,arguments) +},{"../networks":406,"../script":423,"../types":427,"./lazy":411,"dup":62}],414:[function(require,module,exports){ +arguments[4][63][0].apply(exports,arguments) +},{"../crypto":402,"../networks":406,"../script":423,"../types":427,"./lazy":411,"bs58check":430,"buffer":249,"dup":63}],415:[function(require,module,exports){ +arguments[4][64][0].apply(exports,arguments) +},{"../crypto":402,"../networks":406,"../script":423,"../types":427,"./lazy":411,"bs58check":430,"buffer":249,"dup":64}],416:[function(require,module,exports){ +arguments[4][65][0].apply(exports,arguments) +},{"../address":398,"../ecc_lib":403,"../networks":406,"../script":423,"../types":427,"./bip341":408,"./lazy":411,"bech32":120,"buffer":249,"dup":65}],417:[function(require,module,exports){ +arguments[4][66][0].apply(exports,arguments) +},{"../crypto":402,"../networks":406,"../script":423,"../types":427,"./lazy":411,"bech32":120,"buffer":249,"dup":66}],418:[function(require,module,exports){ +arguments[4][67][0].apply(exports,arguments) +},{"../crypto":402,"../networks":406,"../script":423,"../types":427,"./lazy":411,"bech32":120,"buffer":249,"dup":67}],419:[function(require,module,exports){ +arguments[4][68][0].apply(exports,arguments) +},{"./address":398,"./bufferutils":401,"./networks":406,"./payments":410,"./payments/bip341":408,"./psbt/bip371":420,"./psbt/psbtutils":421,"./script":423,"./transaction":426,"bip174":395,"bip174/src/lib/converter/varint":391,"bip174/src/lib/utils":397,"buffer":249,"dup":68}],420:[function(require,module,exports){ +arguments[4][69][0].apply(exports,arguments) +},{"../payments":410,"../payments/bip341":408,"../transaction":426,"../types":427,"./psbtutils":421,"buffer":249,"dup":69}],421:[function(require,module,exports){ +arguments[4][70][0].apply(exports,arguments) +},{"../crypto":402,"../payments":410,"../script":423,"../transaction":426,"bip174/src/lib/converter/varint":391,"buffer":249,"dup":70}],422:[function(require,module,exports){ +arguments[4][71][0].apply(exports,arguments) +},{"./ops":407,"dup":71}],423:[function(require,module,exports){ +arguments[4][72][0].apply(exports,arguments) +},{"./bip66":399,"./ops":407,"./push_data":422,"./script_number":424,"./script_signature":425,"./types":427,"buffer":249,"dup":72}],424:[function(require,module,exports){ +arguments[4][73][0].apply(exports,arguments) +},{"buffer":249,"dup":73}],425:[function(require,module,exports){ +arguments[4][74][0].apply(exports,arguments) +},{"./bip66":399,"./script":423,"./types":427,"buffer":249,"dup":74}],426:[function(require,module,exports){ +arguments[4][75][0].apply(exports,arguments) +},{"./bufferutils":401,"./crypto":402,"./script":423,"./types":427,"buffer":249,"dup":75}],427:[function(require,module,exports){ +arguments[4][76][0].apply(exports,arguments) +},{"buffer":249,"dup":76,"typeforce":521}],428:[function(require,module,exports){ +arguments[4][77][0].apply(exports,arguments) +},{"base-x":367,"dup":77}],429:[function(require,module,exports){ +arguments[4][78][0].apply(exports,arguments) +},{"bs58":428,"dup":78}],430:[function(require,module,exports){ +arguments[4][79][0].apply(exports,arguments) +},{"./base":429,"@noble/hashes/sha256":89,"dup":79}],431:[function(require,module,exports){ +(function (global){(function (){ +/** + * lodash (Custom Build) + * Build: `lodash modularize exports="npm" -o ./` + * Copyright jQuery Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */ -// The _isBuffer check is for Safari 5-7 support, because it's missing -// Object.prototype.constructor. Remove this eventually -module.exports = function (obj) { - return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) -} +/** Used as the `TypeError` message for "Functions" methods. */ +var FUNC_ERROR_TEXT = 'Expected a function'; -function isBuffer (obj) { - return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) -} +/** Used to stand-in for `undefined` hash values. */ +var HASH_UNDEFINED = '__lodash_hash_undefined__'; -// For Node v0.10 support. Remove this eventually. -function isSlowBuffer (obj) { - return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) -} +/** `Object#toString` result references. */ +var funcTag = '[object Function]', + genTag = '[object GeneratorFunction]'; -},{}],232:[function(require,module,exports){ -var toString = {}.toString; +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ +var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; -module.exports = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; -}; +/** Used to detect host constructors (Safari). */ +var reIsHostCtor = /^\[object .+?Constructor\]$/; + +/** Detect free variable `global` from Node.js. */ +var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + +/** Detect free variable `self`. */ +var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + +/** Used as a reference to the global object. */ +var root = freeGlobal || freeSelf || Function('return this')(); -},{}],233:[function(require,module,exports){ -(function (process,global){ /** - * [js-sha256]{@link https://github.com/emn178/js-sha256} + * Gets the value at `key` of `object`. * - * @version 0.9.0 - * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2017 - * @license MIT + * @private + * @param {Object} [object] The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. */ -/*jslint bitwise: true */ -(function () { - 'use strict'; +function getValue(object, key) { + return object == null ? undefined : object[key]; +} - var ERROR = 'input is invalid type'; - var WINDOW = typeof window === 'object'; - var root = WINDOW ? window : {}; - if (root.JS_SHA256_NO_WINDOW) { - WINDOW = false; - } - var WEB_WORKER = !WINDOW && typeof self === 'object'; - var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; - if (NODE_JS) { - root = global; - } else if (WEB_WORKER) { - root = self; +/** + * Checks if `value` is a host object in IE < 9. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a host object, else `false`. + */ +function isHostObject(value) { + // Many host objects are `Object` objects that can coerce to strings + // despite having improperly defined `toString` methods. + var result = false; + if (value != null && typeof value.toString != 'function') { + try { + result = !!(value + ''); + } catch (e) {} } - var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === 'object' && module.exports; - var AMD = typeof define === 'function' && define.amd; - var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; - var HEX_CHARS = '0123456789abcdef'.split(''); - var EXTRA = [-2147483648, 8388608, 32768, 128]; - var SHIFT = [24, 16, 8, 0]; - var K = [ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - ]; - var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer']; + return result; +} - var blocks = []; +/** Used for built-in method references. */ +var arrayProto = Array.prototype, + funcProto = Function.prototype, + objectProto = Object.prototype; - if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { - Array.isArray = function (obj) { - return Object.prototype.toString.call(obj) === '[object Array]'; - }; - } +/** Used to detect overreaching core-js shims. */ +var coreJsData = root['__core-js_shared__']; - if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { - ArrayBuffer.isView = function (obj) { - return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; - }; - } +/** Used to detect methods masquerading as native. */ +var maskSrcKey = (function() { + var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); + return uid ? ('Symbol(src)_1.' + uid) : ''; +}()); - var createOutputMethod = function (outputType, is224) { - return function (message) { - return new Sha256(is224, true).update(message)[outputType](); - }; - }; +/** Used to resolve the decompiled source of functions. */ +var funcToString = funcProto.toString; - var createMethod = function (is224) { - var method = createOutputMethod('hex', is224); - if (NODE_JS) { - method = nodeWrap(method, is224); - } - method.create = function () { - return new Sha256(is224); - }; - method.update = function (message) { - return method.create().update(message); - }; - for (var i = 0; i < OUTPUT_TYPES.length; ++i) { - var type = OUTPUT_TYPES[i]; - method[type] = createOutputMethod(type, is224); - } - return method; - }; +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; - var nodeWrap = function (method, is224) { - var crypto = eval("require('crypto')"); - var Buffer = eval("require('buffer').Buffer"); - var algorithm = is224 ? 'sha224' : 'sha256'; - var nodeMethod = function (message) { - if (typeof message === 'string') { - return crypto.createHash(algorithm).update(message, 'utf8').digest('hex'); - } else { - if (message === null || message === undefined) { - throw new Error(ERROR); - } else if (message.constructor === ArrayBuffer) { - message = new Uint8Array(message); - } - } - if (Array.isArray(message) || ArrayBuffer.isView(message) || - message.constructor === Buffer) { - return crypto.createHash(algorithm).update(new Buffer(message)).digest('hex'); - } else { - return method(message); - } - }; - return nodeMethod; - }; +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ +var objectToString = objectProto.toString; - var createHmacOutputMethod = function (outputType, is224) { - return function (key, message) { - return new HmacSha256(key, is224, true).update(message)[outputType](); - }; - }; +/** Used to detect if a method is native. */ +var reIsNative = RegExp('^' + + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' +); - var createHmacMethod = function (is224) { - var method = createHmacOutputMethod('hex', is224); - method.create = function (key) { - return new HmacSha256(key, is224); - }; - method.update = function (key, message) { - return method.create(key).update(message); - }; - for (var i = 0; i < OUTPUT_TYPES.length; ++i) { - var type = OUTPUT_TYPES[i]; - method[type] = createHmacOutputMethod(type, is224); - } - return method; - }; +/** Built-in value references. */ +var splice = arrayProto.splice; - function Sha256(is224, sharedMemory) { - if (sharedMemory) { - blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - this.blocks = blocks; - } else { - this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - } +/* Built-in method references that are verified to be native. */ +var Map = getNative(root, 'Map'), + nativeCreate = getNative(Object, 'create'); - if (is224) { - this.h0 = 0xc1059ed8; - this.h1 = 0x367cd507; - this.h2 = 0x3070dd17; - this.h3 = 0xf70e5939; - this.h4 = 0xffc00b31; - this.h5 = 0x68581511; - this.h6 = 0x64f98fa7; - this.h7 = 0xbefa4fa4; - } else { // 256 - this.h0 = 0x6a09e667; - this.h1 = 0xbb67ae85; - this.h2 = 0x3c6ef372; - this.h3 = 0xa54ff53a; - this.h4 = 0x510e527f; - this.h5 = 0x9b05688c; - this.h6 = 0x1f83d9ab; - this.h7 = 0x5be0cd19; - } +/** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ +function Hash(entries) { + var index = -1, + length = entries ? entries.length : 0; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } +} + +/** + * Removes all key-value entries from the hash. + * + * @private + * @name clear + * @memberOf Hash + */ +function hashClear() { + this.__data__ = nativeCreate ? nativeCreate(null) : {}; +} + +/** + * Removes `key` and its value from the hash. + * + * @private + * @name delete + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ +function hashDelete(key) { + return this.has(key) && delete this.__data__[key]; +} - this.block = this.start = this.bytes = this.hBytes = 0; - this.finalized = this.hashed = false; - this.first = true; - this.is224 = is224; +/** + * Gets the hash value for `key`. + * + * @private + * @name get + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ +function hashGet(key) { + var data = this.__data__; + if (nativeCreate) { + var result = data[key]; + return result === HASH_UNDEFINED ? undefined : result; } + return hasOwnProperty.call(data, key) ? data[key] : undefined; +} - Sha256.prototype.update = function (message) { - if (this.finalized) { - return; - } - var notString, type = typeof message; - if (type !== 'string') { - if (type === 'object') { - if (message === null) { - throw new Error(ERROR); - } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { - message = new Uint8Array(message); - } else if (!Array.isArray(message)) { - if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { - throw new Error(ERROR); - } - } - } else { - throw new Error(ERROR); - } - notString = true; - } - var code, index = 0, i, length = message.length, blocks = this.blocks; +/** + * Checks if a hash value for `key` exists. + * + * @private + * @name has + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ +function hashHas(key) { + var data = this.__data__; + return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key); +} - while (index < length) { - if (this.hashed) { - this.hashed = false; - blocks[0] = this.block; - blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - } +/** + * Sets the hash `key` to `value`. + * + * @private + * @name set + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */ +function hashSet(key, value) { + var data = this.__data__; + data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; + return this; +} - if (notString) { - for (i = this.start; index < length && i < 64; ++index) { - blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; - } - } else { - for (i = this.start; index < length && i < 64; ++index) { - code = message.charCodeAt(index); - if (code < 0x80) { - blocks[i >> 2] |= code << SHIFT[i++ & 3]; - } else if (code < 0x800) { - blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } else if (code < 0xd800 || code >= 0xe000) { - blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } else { - code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); - blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } - } - } +// Add methods to `Hash`. +Hash.prototype.clear = hashClear; +Hash.prototype['delete'] = hashDelete; +Hash.prototype.get = hashGet; +Hash.prototype.has = hashHas; +Hash.prototype.set = hashSet; - this.lastByteIndex = i; - this.bytes += i - this.start; - if (i >= 64) { - this.block = blocks[16]; - this.start = i - 64; - this.hash(); - this.hashed = true; - } else { - this.start = i; - } - } - if (this.bytes > 4294967295) { - this.hBytes += this.bytes / 4294967296 << 0; - this.bytes = this.bytes % 4294967296; - } - return this; - }; +/** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ +function ListCache(entries) { + var index = -1, + length = entries ? entries.length : 0; - Sha256.prototype.finalize = function () { - if (this.finalized) { - return; - } - this.finalized = true; - var blocks = this.blocks, i = this.lastByteIndex; - blocks[16] = this.block; - blocks[i >> 2] |= EXTRA[i & 3]; - this.block = blocks[16]; - if (i >= 56) { - if (!this.hashed) { - this.hash(); - } - blocks[0] = this.block; - blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - } - blocks[14] = this.hBytes << 3 | this.bytes >>> 29; - blocks[15] = this.bytes << 3; - this.hash(); - }; + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } +} - Sha256.prototype.hash = function () { - var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, - h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; +/** + * Removes all key-value entries from the list cache. + * + * @private + * @name clear + * @memberOf ListCache + */ +function listCacheClear() { + this.__data__ = []; +} - for (j = 16; j < 64; ++j) { - // rightrotate - t1 = blocks[j - 15]; - s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3); - t1 = blocks[j - 2]; - s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10); - blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0; - } +/** + * Removes `key` and its value from the list cache. + * + * @private + * @name delete + * @memberOf ListCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ +function listCacheDelete(key) { + var data = this.__data__, + index = assocIndexOf(data, key); - bc = b & c; - for (j = 0; j < 64; j += 4) { - if (this.first) { - if (this.is224) { - ab = 300032; - t1 = blocks[0] - 1413257819; - h = t1 - 150054599 << 0; - d = t1 + 24177077 << 0; - } else { - ab = 704751109; - t1 = blocks[0] - 210244248; - h = t1 - 1521486534 << 0; - d = t1 + 143694565 << 0; - } - this.first = false; - } else { - s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10)); - s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7)); - ab = a & b; - maj = ab ^ (a & c) ^ bc; - ch = (e & f) ^ (~e & g); - t1 = h + s1 + ch + K[j] + blocks[j]; - t2 = s0 + maj; - h = d + t1 << 0; - d = t1 + t2 << 0; - } - s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10)); - s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7)); - da = d & a; - maj = da ^ (d & b) ^ ab; - ch = (h & e) ^ (~h & f); - t1 = g + s1 + ch + K[j + 1] + blocks[j + 1]; - t2 = s0 + maj; - g = c + t1 << 0; - c = t1 + t2 << 0; - s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10)); - s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7)); - cd = c & d; - maj = cd ^ (c & a) ^ da; - ch = (g & h) ^ (~g & e); - t1 = f + s1 + ch + K[j + 2] + blocks[j + 2]; - t2 = s0 + maj; - f = b + t1 << 0; - b = t1 + t2 << 0; - s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10)); - s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7)); - bc = b & c; - maj = bc ^ (b & d) ^ cd; - ch = (f & g) ^ (~f & h); - t1 = e + s1 + ch + K[j + 3] + blocks[j + 3]; - t2 = s0 + maj; - e = a + t1 << 0; - a = t1 + t2 << 0; - } + if (index < 0) { + return false; + } + var lastIndex = data.length - 1; + if (index == lastIndex) { + data.pop(); + } else { + splice.call(data, index, 1); + } + return true; +} - this.h0 = this.h0 + a << 0; - this.h1 = this.h1 + b << 0; - this.h2 = this.h2 + c << 0; - this.h3 = this.h3 + d << 0; - this.h4 = this.h4 + e << 0; - this.h5 = this.h5 + f << 0; - this.h6 = this.h6 + g << 0; - this.h7 = this.h7 + h << 0; - }; +/** + * Gets the list cache value for `key`. + * + * @private + * @name get + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ +function listCacheGet(key) { + var data = this.__data__, + index = assocIndexOf(data, key); - Sha256.prototype.hex = function () { - this.finalize(); + return index < 0 ? undefined : data[index][1]; +} - var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, - h6 = this.h6, h7 = this.h7; +/** + * Checks if a list cache value for `key` exists. + * + * @private + * @name has + * @memberOf ListCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ +function listCacheHas(key) { + return assocIndexOf(this.__data__, key) > -1; +} - var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + - HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + - HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + - HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + - HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + - HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + - HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + - HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + - HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + - HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + - HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + - HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + - HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] + - HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + - HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + - HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + - HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] + - HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] + - HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] + - HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] + - HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] + - HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] + - HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] + - HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] + - HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] + - HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] + - HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] + - HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F]; - if (!this.is224) { - hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] + - HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] + - HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] + - HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F]; - } - return hex; - }; +/** + * Sets the list cache `key` to `value`. + * + * @private + * @name set + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */ +function listCacheSet(key, value) { + var data = this.__data__, + index = assocIndexOf(data, key); - Sha256.prototype.toString = Sha256.prototype.hex; + if (index < 0) { + data.push([key, value]); + } else { + data[index][1] = value; + } + return this; +} - Sha256.prototype.digest = function () { - this.finalize(); +// Add methods to `ListCache`. +ListCache.prototype.clear = listCacheClear; +ListCache.prototype['delete'] = listCacheDelete; +ListCache.prototype.get = listCacheGet; +ListCache.prototype.has = listCacheHas; +ListCache.prototype.set = listCacheSet; - var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, - h6 = this.h6, h7 = this.h7; +/** + * Creates a map cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ +function MapCache(entries) { + var index = -1, + length = entries ? entries.length : 0; - var arr = [ - (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF, - (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF, - (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF, - (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF, - (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF, - (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF, - (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF - ]; - if (!this.is224) { - arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF); - } - return arr; + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } +} + +/** + * Removes all key-value entries from the map. + * + * @private + * @name clear + * @memberOf MapCache + */ +function mapCacheClear() { + this.__data__ = { + 'hash': new Hash, + 'map': new (Map || ListCache), + 'string': new Hash }; +} - Sha256.prototype.array = Sha256.prototype.digest; +/** + * Removes `key` and its value from the map. + * + * @private + * @name delete + * @memberOf MapCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ +function mapCacheDelete(key) { + return getMapData(this, key)['delete'](key); +} - Sha256.prototype.arrayBuffer = function () { - this.finalize(); +/** + * Gets the map value for `key`. + * + * @private + * @name get + * @memberOf MapCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ +function mapCacheGet(key) { + return getMapData(this, key).get(key); +} - var buffer = new ArrayBuffer(this.is224 ? 28 : 32); - var dataView = new DataView(buffer); - dataView.setUint32(0, this.h0); - dataView.setUint32(4, this.h1); - dataView.setUint32(8, this.h2); - dataView.setUint32(12, this.h3); - dataView.setUint32(16, this.h4); - dataView.setUint32(20, this.h5); - dataView.setUint32(24, this.h6); - if (!this.is224) { - dataView.setUint32(28, this.h7); - } - return buffer; - }; +/** + * Checks if a map value for `key` exists. + * + * @private + * @name has + * @memberOf MapCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ +function mapCacheHas(key) { + return getMapData(this, key).has(key); +} - function HmacSha256(key, is224, sharedMemory) { - var i, type = typeof key; - if (type === 'string') { - var bytes = [], length = key.length, index = 0, code; - for (i = 0; i < length; ++i) { - code = key.charCodeAt(i); - if (code < 0x80) { - bytes[index++] = code; - } else if (code < 0x800) { - bytes[index++] = (0xc0 | (code >> 6)); - bytes[index++] = (0x80 | (code & 0x3f)); - } else if (code < 0xd800 || code >= 0xe000) { - bytes[index++] = (0xe0 | (code >> 12)); - bytes[index++] = (0x80 | ((code >> 6) & 0x3f)); - bytes[index++] = (0x80 | (code & 0x3f)); - } else { - code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff)); - bytes[index++] = (0xf0 | (code >> 18)); - bytes[index++] = (0x80 | ((code >> 12) & 0x3f)); - bytes[index++] = (0x80 | ((code >> 6) & 0x3f)); - bytes[index++] = (0x80 | (code & 0x3f)); - } - } - key = bytes; - } else { - if (type === 'object') { - if (key === null) { - throw new Error(ERROR); - } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { - key = new Uint8Array(key); - } else if (!Array.isArray(key)) { - if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { - throw new Error(ERROR); - } - } - } else { - throw new Error(ERROR); - } - } +/** + * Sets the map `key` to `value`. + * + * @private + * @name set + * @memberOf MapCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the map cache instance. + */ +function mapCacheSet(key, value) { + getMapData(this, key).set(key, value); + return this; +} - if (key.length > 64) { - key = (new Sha256(is224, true)).update(key).array(); - } +// Add methods to `MapCache`. +MapCache.prototype.clear = mapCacheClear; +MapCache.prototype['delete'] = mapCacheDelete; +MapCache.prototype.get = mapCacheGet; +MapCache.prototype.has = mapCacheHas; +MapCache.prototype.set = mapCacheSet; - var oKeyPad = [], iKeyPad = []; - for (i = 0; i < 64; ++i) { - var b = key[i] || 0; - oKeyPad[i] = 0x5c ^ b; - iKeyPad[i] = 0x36 ^ b; +/** + * Gets the index at which the `key` is found in `array` of key-value pairs. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} key The key to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function assocIndexOf(array, key) { + var length = array.length; + while (length--) { + if (eq(array[length][0], key)) { + return length; } + } + return -1; +} - Sha256.call(this, is224, sharedMemory); +/** + * The base implementation of `_.isNative` without bad shim checks. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + */ +function baseIsNative(value) { + if (!isObject(value) || isMasked(value)) { + return false; + } + var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; + return pattern.test(toSource(value)); +} - this.update(iKeyPad); - this.oKeyPad = oKeyPad; - this.inner = true; - this.sharedMemory = sharedMemory; +/** + * Gets the data for `map`. + * + * @private + * @param {Object} map The map to query. + * @param {string} key The reference key. + * @returns {*} Returns the map data. + */ +function getMapData(map, key) { + var data = map.__data__; + return isKeyable(key) + ? data[typeof key == 'string' ? 'string' : 'hash'] + : data.map; +} + +/** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ +function getNative(object, key) { + var value = getValue(object, key); + return baseIsNative(value) ? value : undefined; +} + +/** + * Checks if `value` is suitable for use as unique object key. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is suitable, else `false`. + */ +function isKeyable(value) { + var type = typeof value; + return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') + ? (value !== '__proto__') + : (value === null); +} + +/** + * Checks if `func` has its source masked. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` is masked, else `false`. + */ +function isMasked(func) { + return !!maskSrcKey && (maskSrcKey in func); +} + +/** + * Converts `func` to its source code. + * + * @private + * @param {Function} func The function to process. + * @returns {string} Returns the source code. + */ +function toSource(func) { + if (func != null) { + try { + return funcToString.call(func); + } catch (e) {} + try { + return (func + ''); + } catch (e) {} } - HmacSha256.prototype = new Sha256(); + return ''; +} - HmacSha256.prototype.finalize = function () { - Sha256.prototype.finalize.call(this); - if (this.inner) { - this.inner = false; - var innerHash = this.array(); - Sha256.call(this, this.is224, this.sharedMemory); - this.update(this.oKeyPad); - this.update(innerHash); - Sha256.prototype.finalize.call(this); +/** + * Creates a function that memoizes the result of `func`. If `resolver` is + * provided, it determines the cache key for storing the result based on the + * arguments provided to the memoized function. By default, the first argument + * provided to the memoized function is used as the map cache key. The `func` + * is invoked with the `this` binding of the memoized function. + * + * **Note:** The cache is exposed as the `cache` property on the memoized + * function. Its creation may be customized by replacing the `_.memoize.Cache` + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) + * method interface of `delete`, `get`, `has`, and `set`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to have its output memoized. + * @param {Function} [resolver] The function to resolve the cache key. + * @returns {Function} Returns the new memoized function. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * var other = { 'c': 3, 'd': 4 }; + * + * var values = _.memoize(_.values); + * values(object); + * // => [1, 2] + * + * values(other); + * // => [3, 4] + * + * object.a = 2; + * values(object); + * // => [1, 2] + * + * // Modify the result cache. + * values.cache.set(object, ['a', 'b']); + * values(object); + * // => ['a', 'b'] + * + * // Replace `_.memoize.Cache`. + * _.memoize.Cache = WeakMap; + */ +function memoize(func, resolver) { + if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { + throw new TypeError(FUNC_ERROR_TEXT); + } + var memoized = function() { + var args = arguments, + key = resolver ? resolver.apply(this, args) : args[0], + cache = memoized.cache; + + if (cache.has(key)) { + return cache.get(key); } + var result = func.apply(this, args); + memoized.cache = cache.set(key, result); + return result; }; + memoized.cache = new (memoize.Cache || MapCache); + return memoized; +} - var exports = createMethod(); - exports.sha256 = exports; - exports.sha224 = createMethod(true); - exports.sha256.hmac = createHmacMethod(); - exports.sha224.hmac = createHmacMethod(true); +// Assign cache to `_.memoize`. +memoize.Cache = MapCache; - if (COMMON_JS) { - module.exports = exports; - } else { - root.sha256 = exports.sha256; - root.sha224 = exports.sha224; - if (AMD) { - define(function () { - return exports; - }); - } - } -})(); +/** + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * comparison between two values to determine if they are equivalent. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.eq(object, object); + * // => true + * + * _.eq(object, other); + * // => false + * + * _.eq('a', 'a'); + * // => true + * + * _.eq('a', Object('a')); + * // => false + * + * _.eq(NaN, NaN); + * // => true + */ +function eq(value, other) { + return value === other || (value !== value && other !== other); +} + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +function isFunction(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 8-9 which returns 'object' for typed array and other constructors. + var tag = isObject(value) ? objectToString.call(value) : ''; + return tag == funcTag || tag == genTag; +} + +/** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ +function isObject(value) { + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"_process":253}],234:[function(require,module,exports){ +module.exports = memoize; + +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],432:[function(require,module,exports){ /** A JavaScript implementation of [macaroons](http://theory.stanford.edu/~ataly/Papers/macaroons.pdf) @@ -53152,7 +73503,7 @@ module.exports = { base64ToBytes: base64ToBytes, }; -},{"sjcl":296,"tweetnacl":321,"tweetnacl-util":320,"util":330}],235:[function(require,module,exports){ +},{"sjcl":480,"tweetnacl":518,"tweetnacl-util":517,"util":527}],433:[function(require,module,exports){ 'use strict' var inherits = require('inherits') var HashBase = require('hash-base') @@ -53300,8 +73651,8 @@ function fnI (a, b, c, d, m, k, s) { module.exports = MD5 -},{"hash-base":199,"inherits":230,"safe-buffer":280}],236:[function(require,module,exports){ -(function (Buffer){ +},{"hash-base":318,"inherits":349,"safe-buffer":463}],434:[function(require,module,exports){ +(function (Buffer){(function (){ // constant-space merkle root calculation algorithm module.exports = function fastRoot (values, digestFn) { if (!Array.isArray(values)) throw TypeError('Expected values Array') @@ -53327,8 +73678,8 @@ module.exports = function fastRoot (values, digestFn) { return results[0] } -}).call(this,require("buffer").Buffer) -},{"buffer":155}],237:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249}],435:[function(require,module,exports){ var bn = require('bn.js'); var brorand = require('brorand'); @@ -53445,7 +73796,7 @@ MillerRabin.prototype.getDivisor = function getDivisor(n, k) { return false; }; -},{"bn.js":103,"brorand":104}],238:[function(require,module,exports){ +},{"bn.js":198,"brorand":199}],436:[function(require,module,exports){ module.exports = assert; function assert(val, msg) { @@ -53458,7 +73809,7 @@ assert.equal = function assertEqual(l, r, msg) { throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r)); }; -},{}],239:[function(require,module,exports){ +},{}],437:[function(require,module,exports){ 'use strict'; var utils = exports; @@ -53518,7 +73869,7 @@ utils.encode = function encode(arr, enc) { return arr; }; -},{}],240:[function(require,module,exports){ +},{}],438:[function(require,module,exports){ /* object-assign (c) Sindre Sorhus @@ -53610,7 +73961,7 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) { return to; }; -},{}],241:[function(require,module,exports){ +},{}],439:[function(require,module,exports){ module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.2": "aes-128-cbc", "2.16.840.1.101.3.4.1.3": "aes-128-ofb", @@ -53624,7 +73975,7 @@ module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.43": "aes-256-ofb", "2.16.840.1.101.3.4.1.44": "aes-256-cfb" } -},{}],242:[function(require,module,exports){ +},{}],440:[function(require,module,exports){ // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js // Fedor, you are amazing. 'use strict' @@ -53748,7 +74099,7 @@ exports.signature = asn1.define('signature', function () { ) }) -},{"./certificate":243,"asn1.js":7}],243:[function(require,module,exports){ +},{"./certificate":441,"asn1.js":99}],441:[function(require,module,exports){ // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js // thanks to @Rantanen @@ -53839,7 +74190,7 @@ var X509Certificate = asn.define('X509Certificate', function () { module.exports = X509Certificate -},{"asn1.js":7}],244:[function(require,module,exports){ +},{"asn1.js":99}],442:[function(require,module,exports){ // adapted from https://github.com/apatil/pemstrip var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m @@ -53872,7 +74223,7 @@ module.exports = function (okey, password) { } } -},{"browserify-aes":108,"evp_bytestokey":196,"safe-buffer":280}],245:[function(require,module,exports){ +},{"browserify-aes":203,"evp_bytestokey":305,"safe-buffer":463}],443:[function(require,module,exports){ var asn1 = require('./asn1') var aesid = require('./aesid.json') var fixProc = require('./fixProc') @@ -53981,12 +74332,12 @@ function decrypt (data, password) { return Buffer.concat(out) } -},{"./aesid.json":241,"./asn1":242,"./fixProc":244,"browserify-aes":108,"pbkdf2":246,"safe-buffer":280}],246:[function(require,module,exports){ +},{"./aesid.json":439,"./asn1":440,"./fixProc":442,"browserify-aes":203,"pbkdf2":444,"safe-buffer":463}],444:[function(require,module,exports){ exports.pbkdf2 = require('./lib/async') exports.pbkdf2Sync = require('./lib/sync') -},{"./lib/async":247,"./lib/sync":250}],247:[function(require,module,exports){ -(function (process,global){ +},{"./lib/async":445,"./lib/sync":448}],445:[function(require,module,exports){ +(function (process,global){(function (){ var Buffer = require('safe-buffer').Buffer var checkParameters = require('./precondition') @@ -54090,9 +74441,9 @@ module.exports = function (password, salt, iterations, keylen, digest, callback) }), callback) } -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./default-encoding":248,"./precondition":249,"./sync":250,"./to-buffer":251,"_process":253,"safe-buffer":280}],248:[function(require,module,exports){ -(function (process){ +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./default-encoding":446,"./precondition":447,"./sync":448,"./to-buffer":449,"_process":451,"safe-buffer":463}],446:[function(require,module,exports){ +(function (process){(function (){ var defaultEncoding /* istanbul ignore next */ if (process.browser) { @@ -54106,8 +74457,8 @@ if (process.browser) { } module.exports = defaultEncoding -}).call(this,require('_process')) -},{"_process":253}],249:[function(require,module,exports){ +}).call(this)}).call(this,require('_process')) +},{"_process":451}],447:[function(require,module,exports){ var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs module.exports = function (iterations, keylen) { @@ -54128,7 +74479,7 @@ module.exports = function (iterations, keylen) { } } -},{}],250:[function(require,module,exports){ +},{}],448:[function(require,module,exports){ var md5 = require('create-hash/md5') var RIPEMD160 = require('ripemd160') var sha = require('sha.js') @@ -54235,7 +74586,7 @@ function pbkdf2 (password, salt, iterations, keylen, digest) { module.exports = pbkdf2 -},{"./default-encoding":248,"./precondition":249,"./to-buffer":251,"create-hash/md5":160,"ripemd160":279,"safe-buffer":280,"sha.js":289}],251:[function(require,module,exports){ +},{"./default-encoding":446,"./precondition":447,"./to-buffer":449,"create-hash/md5":255,"ripemd160":462,"safe-buffer":463,"sha.js":473}],449:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer module.exports = function (thing, encoding, name) { @@ -54250,56 +74601,25 @@ module.exports = function (thing, encoding, name) { } } -},{"safe-buffer":280}],252:[function(require,module,exports){ -(function (process){ +},{"safe-buffer":463}],450:[function(require,module,exports){ 'use strict'; -if (typeof process === 'undefined' || - !process.version || - process.version.indexOf('v0.') === 0 || - process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { - module.exports = { nextTick: nextTick }; -} else { - module.exports = process -} - -function nextTick(fn, arg1, arg2, arg3) { - if (typeof fn !== 'function') { - throw new TypeError('"callback" argument must be a function'); - } - var len = arguments.length; - var args, i; - switch (len) { - case 0: - case 1: - return process.nextTick(fn); - case 2: - return process.nextTick(function afterTickOne() { - fn.call(null, arg1); - }); - case 3: - return process.nextTick(function afterTickTwo() { - fn.call(null, arg1, arg2); - }); - case 4: - return process.nextTick(function afterTickThree() { - fn.call(null, arg1, arg2, arg3); - }); - default: - args = new Array(len - 1); - i = 0; - while (i < args.length) { - args[i++] = arguments[i]; - } - return process.nextTick(function afterTick() { - fn.apply(null, args); - }); - } -} - +/** @type {import('.')} */ +module.exports = [ + 'Float32Array', + 'Float64Array', + 'Int8Array', + 'Int16Array', + 'Int32Array', + 'Uint8Array', + 'Uint8ClampedArray', + 'Uint16Array', + 'Uint32Array', + 'BigInt64Array', + 'BigUint64Array' +]; -}).call(this,require('_process')) -},{"_process":253}],253:[function(require,module,exports){ +},{}],451:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -54485,7 +74805,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],254:[function(require,module,exports){ +},{}],452:[function(require,module,exports){ exports.publicEncrypt = require('./publicEncrypt') exports.privateDecrypt = require('./privateDecrypt') @@ -54497,7 +74817,7 @@ exports.publicDecrypt = function publicDecrypt (key, buf) { return exports.privateDecrypt(key, buf, true) } -},{"./privateDecrypt":256,"./publicEncrypt":257}],255:[function(require,module,exports){ +},{"./privateDecrypt":454,"./publicEncrypt":455}],453:[function(require,module,exports){ var createHash = require('create-hash') var Buffer = require('safe-buffer').Buffer @@ -54518,7 +74838,7 @@ function i2ops (c) { return out } -},{"create-hash":159,"safe-buffer":280}],256:[function(require,module,exports){ +},{"create-hash":254,"safe-buffer":463}],454:[function(require,module,exports){ var parseKeys = require('parse-asn1') var mgf = require('./mgf') var xor = require('./xor') @@ -54625,7 +74945,7 @@ function compare (a, b) { return dif } -},{"./mgf":255,"./withPublic":258,"./xor":259,"bn.js":103,"browserify-rsa":126,"create-hash":159,"parse-asn1":245,"safe-buffer":280}],257:[function(require,module,exports){ +},{"./mgf":453,"./withPublic":456,"./xor":457,"bn.js":198,"browserify-rsa":221,"create-hash":254,"parse-asn1":443,"safe-buffer":463}],455:[function(require,module,exports){ var parseKeys = require('parse-asn1') var randomBytes = require('randombytes') var createHash = require('create-hash') @@ -54715,7 +75035,7 @@ function nonZero (len) { return out } -},{"./mgf":255,"./withPublic":258,"./xor":259,"bn.js":103,"browserify-rsa":126,"create-hash":159,"parse-asn1":245,"randombytes":262,"safe-buffer":280}],258:[function(require,module,exports){ +},{"./mgf":453,"./withPublic":456,"./xor":457,"bn.js":198,"browserify-rsa":221,"create-hash":254,"parse-asn1":443,"randombytes":460,"safe-buffer":463}],456:[function(require,module,exports){ var BN = require('bn.js') var Buffer = require('safe-buffer').Buffer @@ -54729,7 +75049,7 @@ function withPublic (paddedMsg, key) { module.exports = withPublic -},{"bn.js":103,"safe-buffer":280}],259:[function(require,module,exports){ +},{"bn.js":198,"safe-buffer":463}],457:[function(require,module,exports){ module.exports = function xor (a, b) { var len = a.length var i = -1 @@ -54739,7 +75059,7 @@ module.exports = function xor (a, b) { return a } -},{}],260:[function(require,module,exports){ +},{}],458:[function(require,module,exports){ var OPS = require('bitcoin-ops') function encodingLength (i) { @@ -54818,8 +75138,8 @@ module.exports = { decode: decode } -},{"bitcoin-ops":53}],261:[function(require,module,exports){ -(function (global){ +},{"bitcoin-ops":148}],459:[function(require,module,exports){ +(function (global){(function (){ /*! * random-bytes * Copyright(c) 2016 Douglas Christopher Wilson @@ -54922,5344 +75242,5869 @@ function generateRandomBytes(size, attempts, callback) { }) } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"crypto":163}],262:[function(require,module,exports){ -(function (process,global){ +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"crypto":258}],460:[function(require,module,exports){ +(function (process,global){(function (){ 'use strict' // limit of Crypto.getRandomValues() // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues -var MAX_BYTES = 65536 - -// Node supports requesting up to this number of bytes -// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 -var MAX_UINT32 = 4294967295 - -function oldBrowser () { - throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') -} - -var Buffer = require('safe-buffer').Buffer -var crypto = global.crypto || global.msCrypto - -if (crypto && crypto.getRandomValues) { - module.exports = randomBytes -} else { - module.exports = oldBrowser -} - -function randomBytes (size, cb) { - // phantomjs needs to throw - if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') - - var bytes = Buffer.allocUnsafe(size) - - if (size > 0) { // getRandomValues fails on IE if size == 0 - if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues - // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues - for (var generated = 0; generated < size; generated += MAX_BYTES) { - // buffer.slice automatically checks if the end is past the end of - // the buffer so we don't have to here - crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)) - } - } else { - crypto.getRandomValues(bytes) - } - } - - if (typeof cb === 'function') { - return process.nextTick(function () { - cb(null, bytes) - }) - } - - return bytes -} - -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"_process":253,"safe-buffer":280}],263:[function(require,module,exports){ -(function (process,global){ -'use strict' - -function oldBrowser () { - throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11') -} -var safeBuffer = require('safe-buffer') -var randombytes = require('randombytes') -var Buffer = safeBuffer.Buffer -var kBufferMaxLength = safeBuffer.kMaxLength -var crypto = global.crypto || global.msCrypto -var kMaxUint32 = Math.pow(2, 32) - 1 -function assertOffset (offset, length) { - if (typeof offset !== 'number' || offset !== offset) { // eslint-disable-line no-self-compare - throw new TypeError('offset must be a number') - } - - if (offset > kMaxUint32 || offset < 0) { - throw new TypeError('offset must be a uint32') - } - - if (offset > kBufferMaxLength || offset > length) { - throw new RangeError('offset out of range') - } -} - -function assertSize (size, offset, length) { - if (typeof size !== 'number' || size !== size) { // eslint-disable-line no-self-compare - throw new TypeError('size must be a number') - } - - if (size > kMaxUint32 || size < 0) { - throw new TypeError('size must be a uint32') - } - - if (size + offset > length || size > kBufferMaxLength) { - throw new RangeError('buffer too small') - } -} -if ((crypto && crypto.getRandomValues) || !process.browser) { - exports.randomFill = randomFill - exports.randomFillSync = randomFillSync -} else { - exports.randomFill = oldBrowser - exports.randomFillSync = oldBrowser -} -function randomFill (buf, offset, size, cb) { - if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) { - throw new TypeError('"buf" argument must be a Buffer or Uint8Array') - } - - if (typeof offset === 'function') { - cb = offset - offset = 0 - size = buf.length - } else if (typeof size === 'function') { - cb = size - size = buf.length - offset - } else if (typeof cb !== 'function') { - throw new TypeError('"cb" argument must be a function') - } - assertOffset(offset, buf.length) - assertSize(size, offset, buf.length) - return actualFill(buf, offset, size, cb) -} - -function actualFill (buf, offset, size, cb) { - if (process.browser) { - var ourBuf = buf.buffer - var uint = new Uint8Array(ourBuf, offset, size) - crypto.getRandomValues(uint) - if (cb) { - process.nextTick(function () { - cb(null, buf) - }) - return - } - return buf - } - if (cb) { - randombytes(size, function (err, bytes) { - if (err) { - return cb(err) - } - bytes.copy(buf, offset) - cb(null, buf) - }) - return - } - var bytes = randombytes(size) - bytes.copy(buf, offset) - return buf -} -function randomFillSync (buf, offset, size) { - if (typeof offset === 'undefined') { - offset = 0 - } - if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) { - throw new TypeError('"buf" argument must be a Buffer or Uint8Array') - } - - assertOffset(offset, buf.length) - - if (size === undefined) size = buf.length - offset - - assertSize(size, offset, buf.length) - - return actualFill(buf, offset, size) -} - -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"_process":253,"randombytes":262,"safe-buffer":280}],264:[function(require,module,exports){ -module.exports = require('./lib/_stream_duplex.js'); - -},{"./lib/_stream_duplex.js":265}],265:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// a duplex stream is just a stream that is both readable and writable. -// Since JS doesn't have multiple prototypal inheritance, this class -// prototypally inherits from Readable, and then parasitically from -// Writable. - -'use strict'; - -/**/ - -var pna = require('process-nextick-args'); -/**/ - -/**/ -var objectKeys = Object.keys || function (obj) { - var keys = []; - for (var key in obj) { - keys.push(key); - }return keys; -}; -/**/ - -module.exports = Duplex; - -/**/ -var util = Object.create(require('core-util-is')); -util.inherits = require('inherits'); -/**/ - -var Readable = require('./_stream_readable'); -var Writable = require('./_stream_writable'); - -util.inherits(Duplex, Readable); - -{ - // avoid scope creep, the keys array can then be collected - var keys = objectKeys(Writable.prototype); - for (var v = 0; v < keys.length; v++) { - var method = keys[v]; - if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; - } -} - -function Duplex(options) { - if (!(this instanceof Duplex)) return new Duplex(options); - - Readable.call(this, options); - Writable.call(this, options); - - if (options && options.readable === false) this.readable = false; - - if (options && options.writable === false) this.writable = false; - - this.allowHalfOpen = true; - if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; - - this.once('end', onend); -} - -Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function () { - return this._writableState.highWaterMark; - } -}); - -// the no-half-open enforcer -function onend() { - // if we allow half-open state, or if the writable side ended, - // then we're ok. - if (this.allowHalfOpen || this._writableState.ended) return; - - // no more data can be written. - // But allow more writes to happen in this tick. - pna.nextTick(onEndNT, this); -} - -function onEndNT(self) { - self.end(); -} - -Object.defineProperty(Duplex.prototype, 'destroyed', { - get: function () { - if (this._readableState === undefined || this._writableState === undefined) { - return false; - } - return this._readableState.destroyed && this._writableState.destroyed; - }, - set: function (value) { - // we ignore the value if the stream - // has not been initialized yet - if (this._readableState === undefined || this._writableState === undefined) { - return; - } - - // backward compatibility, the user is explicitly - // managing destroyed - this._readableState.destroyed = value; - this._writableState.destroyed = value; - } -}); - -Duplex.prototype._destroy = function (err, cb) { - this.push(null); - this.end(); - - pna.nextTick(cb, err); -}; -},{"./_stream_readable":267,"./_stream_writable":269,"core-util-is":157,"inherits":230,"process-nextick-args":252}],266:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// a passthrough stream. -// basically just the most minimal sort of Transform stream. -// Every written chunk gets output as-is. - -'use strict'; - -module.exports = PassThrough; - -var Transform = require('./_stream_transform'); - -/**/ -var util = Object.create(require('core-util-is')); -util.inherits = require('inherits'); -/**/ - -util.inherits(PassThrough, Transform); - -function PassThrough(options) { - if (!(this instanceof PassThrough)) return new PassThrough(options); - - Transform.call(this, options); -} - -PassThrough.prototype._transform = function (chunk, encoding, cb) { - cb(null, chunk); -}; -},{"./_stream_transform":268,"core-util-is":157,"inherits":230}],267:[function(require,module,exports){ -(function (process,global){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -/**/ - -var pna = require('process-nextick-args'); -/**/ - -module.exports = Readable; - -/**/ -var isArray = require('isarray'); -/**/ - -/**/ -var Duplex; -/**/ - -Readable.ReadableState = ReadableState; - -/**/ -var EE = require('events').EventEmitter; - -var EElistenerCount = function (emitter, type) { - return emitter.listeners(type).length; -}; -/**/ - -/**/ -var Stream = require('./internal/streams/stream'); -/**/ - -/**/ - -var Buffer = require('safe-buffer').Buffer; -var OurUint8Array = global.Uint8Array || function () {}; -function _uint8ArrayToBuffer(chunk) { - return Buffer.from(chunk); -} -function _isUint8Array(obj) { - return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; -} - -/**/ - -/**/ -var util = Object.create(require('core-util-is')); -util.inherits = require('inherits'); -/**/ - -/**/ -var debugUtil = require('util'); -var debug = void 0; -if (debugUtil && debugUtil.debuglog) { - debug = debugUtil.debuglog('stream'); -} else { - debug = function () {}; -} -/**/ - -var BufferList = require('./internal/streams/BufferList'); -var destroyImpl = require('./internal/streams/destroy'); -var StringDecoder; - -util.inherits(Readable, Stream); - -var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; - -function prependListener(emitter, event, fn) { - // Sadly this is not cacheable as some libraries bundle their own - // event emitter implementation with them. - if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); - - // This is a hack to make sure that our error handler is attached before any - // userland ones. NEVER DO THIS. This is here only because this code needs - // to continue to work with older versions of Node.js that do not include - // the prependListener() method. The goal is to eventually remove this hack. - if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; -} - -function ReadableState(options, stream) { - Duplex = Duplex || require('./_stream_duplex'); - - options = options || {}; - - // Duplex streams are both readable and writable, but share - // the same options object. - // However, some cases require setting options to different - // values for the readable and the writable sides of the duplex stream. - // These options can be provided separately as readableXXX and writableXXX. - var isDuplex = stream instanceof Duplex; - - // object stream flag. Used to make read(n) ignore n and to - // make all the buffer merging and length checks go away - this.objectMode = !!options.objectMode; - - if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; - - // the point at which it stops calling _read() to fill the buffer - // Note: 0 is a valid value, means "don't call _read preemptively ever" - var hwm = options.highWaterMark; - var readableHwm = options.readableHighWaterMark; - var defaultHwm = this.objectMode ? 16 : 16 * 1024; - - if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm; - - // cast to ints. - this.highWaterMark = Math.floor(this.highWaterMark); - - // A linked list is used to store data chunks instead of an array because the - // linked list can remove elements from the beginning faster than - // array.shift() - this.buffer = new BufferList(); - this.length = 0; - this.pipes = null; - this.pipesCount = 0; - this.flowing = null; - this.ended = false; - this.endEmitted = false; - this.reading = false; - - // a flag to be able to tell if the event 'readable'/'data' is emitted - // immediately, or on a later tick. We set this to true at first, because - // any actions that shouldn't happen until "later" should generally also - // not happen before the first read call. - this.sync = true; - - // whenever we return null, then we set a flag to say - // that we're awaiting a 'readable' event emission. - this.needReadable = false; - this.emittedReadable = false; - this.readableListening = false; - this.resumeScheduled = false; - - // has it been destroyed - this.destroyed = false; - - // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - this.defaultEncoding = options.defaultEncoding || 'utf8'; - - // the number of writers that are awaiting a drain event in .pipe()s - this.awaitDrain = 0; +var MAX_BYTES = 65536 - // if true, a maybeReadMore has been scheduled - this.readingMore = false; +// Node supports requesting up to this number of bytes +// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 +var MAX_UINT32 = 4294967295 - this.decoder = null; - this.encoding = null; - if (options.encoding) { - if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; - this.decoder = new StringDecoder(options.encoding); - this.encoding = options.encoding; - } +function oldBrowser () { + throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') } -function Readable(options) { - Duplex = Duplex || require('./_stream_duplex'); +var Buffer = require('safe-buffer').Buffer +var crypto = global.crypto || global.msCrypto - if (!(this instanceof Readable)) return new Readable(options); +if (crypto && crypto.getRandomValues) { + module.exports = randomBytes +} else { + module.exports = oldBrowser +} - this._readableState = new ReadableState(options, this); +function randomBytes (size, cb) { + // phantomjs needs to throw + if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') - // legacy - this.readable = true; + var bytes = Buffer.allocUnsafe(size) - if (options) { - if (typeof options.read === 'function') this._read = options.read; + if (size > 0) { // getRandomValues fails on IE if size == 0 + if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues + // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + for (var generated = 0; generated < size; generated += MAX_BYTES) { + // buffer.slice automatically checks if the end is past the end of + // the buffer so we don't have to here + crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)) + } + } else { + crypto.getRandomValues(bytes) + } + } - if (typeof options.destroy === 'function') this._destroy = options.destroy; + if (typeof cb === 'function') { + return process.nextTick(function () { + cb(null, bytes) + }) } - Stream.call(this); + return bytes } -Object.defineProperty(Readable.prototype, 'destroyed', { - get: function () { - if (this._readableState === undefined) { - return false; - } - return this._readableState.destroyed; - }, - set: function (value) { - // we ignore the value if the stream - // has not been initialized yet - if (!this._readableState) { - return; - } +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"_process":451,"safe-buffer":463}],461:[function(require,module,exports){ +(function (process,global){(function (){ +'use strict' - // backward compatibility, the user is explicitly - // managing destroyed - this._readableState.destroyed = value; +function oldBrowser () { + throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11') +} +var safeBuffer = require('safe-buffer') +var randombytes = require('randombytes') +var Buffer = safeBuffer.Buffer +var kBufferMaxLength = safeBuffer.kMaxLength +var crypto = global.crypto || global.msCrypto +var kMaxUint32 = Math.pow(2, 32) - 1 +function assertOffset (offset, length) { + if (typeof offset !== 'number' || offset !== offset) { // eslint-disable-line no-self-compare + throw new TypeError('offset must be a number') } -}); -Readable.prototype.destroy = destroyImpl.destroy; -Readable.prototype._undestroy = destroyImpl.undestroy; -Readable.prototype._destroy = function (err, cb) { - this.push(null); - cb(err); -}; + if (offset > kMaxUint32 || offset < 0) { + throw new TypeError('offset must be a uint32') + } -// Manually shove something into the read() buffer. -// This returns true if the highWaterMark has not been hit yet, -// similar to how Writable.write() returns true if you should -// write() some more. -Readable.prototype.push = function (chunk, encoding) { - var state = this._readableState; - var skipChunkCheck; + if (offset > kBufferMaxLength || offset > length) { + throw new RangeError('offset out of range') + } +} - if (!state.objectMode) { - if (typeof chunk === 'string') { - encoding = encoding || state.defaultEncoding; - if (encoding !== state.encoding) { - chunk = Buffer.from(chunk, encoding); - encoding = ''; - } - skipChunkCheck = true; - } - } else { - skipChunkCheck = true; +function assertSize (size, offset, length) { + if (typeof size !== 'number' || size !== size) { // eslint-disable-line no-self-compare + throw new TypeError('size must be a number') } - return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); -}; + if (size > kMaxUint32 || size < 0) { + throw new TypeError('size must be a uint32') + } -// Unshift should *always* be something directly out of read() -Readable.prototype.unshift = function (chunk) { - return readableAddChunk(this, chunk, null, true, false); -}; + if (size + offset > length || size > kBufferMaxLength) { + throw new RangeError('buffer too small') + } +} +if ((crypto && crypto.getRandomValues) || !process.browser) { + exports.randomFill = randomFill + exports.randomFillSync = randomFillSync +} else { + exports.randomFill = oldBrowser + exports.randomFillSync = oldBrowser +} +function randomFill (buf, offset, size, cb) { + if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) { + throw new TypeError('"buf" argument must be a Buffer or Uint8Array') + } -function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { - var state = stream._readableState; - if (chunk === null) { - state.reading = false; - onEofChunk(stream, state); - } else { - var er; - if (!skipChunkCheck) er = chunkInvalid(state, chunk); - if (er) { - stream.emit('error', er); - } else if (state.objectMode || chunk && chunk.length > 0) { - if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { - chunk = _uint8ArrayToBuffer(chunk); - } + if (typeof offset === 'function') { + cb = offset + offset = 0 + size = buf.length + } else if (typeof size === 'function') { + cb = size + size = buf.length - offset + } else if (typeof cb !== 'function') { + throw new TypeError('"cb" argument must be a function') + } + assertOffset(offset, buf.length) + assertSize(size, offset, buf.length) + return actualFill(buf, offset, size, cb) +} - if (addToFront) { - if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true); - } else if (state.ended) { - stream.emit('error', new Error('stream.push() after EOF')); - } else { - state.reading = false; - if (state.decoder && !encoding) { - chunk = state.decoder.write(chunk); - if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); - } else { - addChunk(stream, state, chunk, false); - } - } - } else if (!addToFront) { - state.reading = false; +function actualFill (buf, offset, size, cb) { + if (process.browser) { + var ourBuf = buf.buffer + var uint = new Uint8Array(ourBuf, offset, size) + crypto.getRandomValues(uint) + if (cb) { + process.nextTick(function () { + cb(null, buf) + }) + return } + return buf } - - return needMoreData(state); + if (cb) { + randombytes(size, function (err, bytes) { + if (err) { + return cb(err) + } + bytes.copy(buf, offset) + cb(null, buf) + }) + return + } + var bytes = randombytes(size) + bytes.copy(buf, offset) + return buf } +function randomFillSync (buf, offset, size) { + if (typeof offset === 'undefined') { + offset = 0 + } + if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) { + throw new TypeError('"buf" argument must be a Buffer or Uint8Array') + } -function addChunk(stream, state, chunk, addToFront) { - if (state.flowing && state.length === 0 && !state.sync) { - stream.emit('data', chunk); - stream.read(0); - } else { - // update the buffer info. - state.length += state.objectMode ? 1 : chunk.length; - if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + assertOffset(offset, buf.length) - if (state.needReadable) emitReadable(stream); - } - maybeReadMore(stream, state); -} + if (size === undefined) size = buf.length - offset -function chunkInvalid(state, chunk) { - var er; - if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { - er = new TypeError('Invalid non-string/buffer chunk'); - } - return er; + assertSize(size, offset, buf.length) + + return actualFill(buf, offset, size) } -// if it's past the high water mark, we can push in some more. -// Also, if we have no data yet, we can stand some -// more bytes. This is to work around cases where hwm=0, -// such as the repl. Also, if the push() triggered a -// readable event, and the user called read(largeNumber) such that -// needReadable was set, then we ought to push more, so that another -// 'readable' event will be triggered. -function needMoreData(state) { - return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"_process":451,"randombytes":460,"safe-buffer":463}],462:[function(require,module,exports){ +'use strict' +var Buffer = require('buffer').Buffer +var inherits = require('inherits') +var HashBase = require('hash-base') + +var ARRAY16 = new Array(16) + +var zl = [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 +] + +var zr = [ + 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 +] + +var sl = [ + 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 +] + +var sr = [ + 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 +] + +var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e] +var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000] + +function RIPEMD160 () { + HashBase.call(this, 64) + + // state + this._a = 0x67452301 + this._b = 0xefcdab89 + this._c = 0x98badcfe + this._d = 0x10325476 + this._e = 0xc3d2e1f0 } -Readable.prototype.isPaused = function () { - return this._readableState.flowing === false; -}; +inherits(RIPEMD160, HashBase) -// backwards compatibility. -Readable.prototype.setEncoding = function (enc) { - if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; - this._readableState.decoder = new StringDecoder(enc); - this._readableState.encoding = enc; - return this; -}; +RIPEMD160.prototype._update = function () { + var words = ARRAY16 + for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4) -// Don't raise the hwm > 8MB -var MAX_HWM = 0x800000; -function computeNewHighWaterMark(n) { - if (n >= MAX_HWM) { - n = MAX_HWM; - } else { - // Get the next highest power of 2 to prevent increasing hwm excessively in - // tiny amounts - n--; - n |= n >>> 1; - n |= n >>> 2; - n |= n >>> 4; - n |= n >>> 8; - n |= n >>> 16; - n++; + var al = this._a | 0 + var bl = this._b | 0 + var cl = this._c | 0 + var dl = this._d | 0 + var el = this._e | 0 + + var ar = this._a | 0 + var br = this._b | 0 + var cr = this._c | 0 + var dr = this._d | 0 + var er = this._e | 0 + + // computation + for (var i = 0; i < 80; i += 1) { + var tl + var tr + if (i < 16) { + tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]) + tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]) + } else if (i < 32) { + tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]) + tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]) + } else if (i < 48) { + tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]) + tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]) + } else if (i < 64) { + tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]) + tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]) + } else { // if (i<80) { + tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]) + tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]) + } + + al = el + el = dl + dl = rotl(cl, 10) + cl = bl + bl = tl + + ar = er + er = dr + dr = rotl(cr, 10) + cr = br + br = tr } - return n; + + // update state + var t = (this._b + cl + dr) | 0 + this._b = (this._c + dl + er) | 0 + this._c = (this._d + el + ar) | 0 + this._d = (this._e + al + br) | 0 + this._e = (this._a + bl + cr) | 0 + this._a = t } -// This function is designed to be inlinable, so please take care when making -// changes to the function body. -function howMuchToRead(n, state) { - if (n <= 0 || state.length === 0 && state.ended) return 0; - if (state.objectMode) return 1; - if (n !== n) { - // Only flow one buffer at a time - if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; - } - // If we're asking for more than the current hwm, then raise the hwm. - if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); - if (n <= state.length) return n; - // Don't have enough - if (!state.ended) { - state.needReadable = true; - return 0; +RIPEMD160.prototype._digest = function () { + // create padding and handle blocks + this._block[this._blockOffset++] = 0x80 + if (this._blockOffset > 56) { + this._block.fill(0, this._blockOffset, 64) + this._update() + this._blockOffset = 0 } - return state.length; -} -// you can override either this method, or the async _read(n) below. -Readable.prototype.read = function (n) { - debug('read', n); - n = parseInt(n, 10); - var state = this._readableState; - var nOrig = n; + this._block.fill(0, this._blockOffset, 56) + this._block.writeUInt32LE(this._length[0], 56) + this._block.writeUInt32LE(this._length[1], 60) + this._update() - if (n !== 0) state.emittedReadable = false; + // produce result + var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20) + buffer.writeInt32LE(this._a, 0) + buffer.writeInt32LE(this._b, 4) + buffer.writeInt32LE(this._c, 8) + buffer.writeInt32LE(this._d, 12) + buffer.writeInt32LE(this._e, 16) + return buffer +} - // if we're doing read(0) to trigger a readable event, but we - // already have a bunch of data in the buffer, then just trigger - // the 'readable' event and move on. - if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { - debug('read: emitReadable', state.length, state.ended); - if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); - return null; - } +function rotl (x, n) { + return (x << n) | (x >>> (32 - n)) +} - n = howMuchToRead(n, state); +function fn1 (a, b, c, d, e, m, k, s) { + return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0 +} - // if we've ended, and we're now clear, then finish it up. - if (n === 0 && state.ended) { - if (state.length === 0) endReadable(this); - return null; - } +function fn2 (a, b, c, d, e, m, k, s) { + return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0 +} - // All the actual chunk generation logic needs to be - // *below* the call to _read. The reason is that in certain - // synthetic stream cases, such as passthrough streams, _read - // may be a completely synchronous operation which may change - // the state of the read buffer, providing enough data when - // before there was *not* enough. - // - // So, the steps are: - // 1. Figure out what the state of things will be after we do - // a read from the buffer. - // - // 2. If that resulting state will trigger a _read, then call _read. - // Note that this may be asynchronous, or synchronous. Yes, it is - // deeply ugly to write APIs this way, but that still doesn't mean - // that the Readable class should behave improperly, as streams are - // designed to be sync/async agnostic. - // Take note if the _read call is sync or async (ie, if the read call - // has returned yet), so that we know whether or not it's safe to emit - // 'readable' etc. - // - // 3. Actually pull the requested chunks out of the buffer and return. +function fn3 (a, b, c, d, e, m, k, s) { + return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0 +} - // if we need a readable event, then we need to do some reading. - var doRead = state.needReadable; - debug('need readable', doRead); +function fn4 (a, b, c, d, e, m, k, s) { + return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0 +} - // if we currently have less than the highWaterMark, then also read some - if (state.length === 0 || state.length - n < state.highWaterMark) { - doRead = true; - debug('length less than watermark', doRead); - } +function fn5 (a, b, c, d, e, m, k, s) { + return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0 +} - // however, if we've ended, then there's no point, and if we're already - // reading, then it's unnecessary. - if (state.ended || state.reading) { - doRead = false; - debug('reading or ended', doRead); - } else if (doRead) { - debug('do read'); - state.reading = true; - state.sync = true; - // if the length is currently zero, then we *need* a readable event. - if (state.length === 0) state.needReadable = true; - // call internal read method - this._read(state.highWaterMark); - state.sync = false; - // If _read pushed data synchronously, then `reading` will be false, - // and we need to re-evaluate how much data we can return to the user. - if (!state.reading) n = howMuchToRead(nOrig, state); - } +module.exports = RIPEMD160 - var ret; - if (n > 0) ret = fromList(n, state);else ret = null; +},{"buffer":249,"hash-base":318,"inherits":349}],463:[function(require,module,exports){ +/*! safe-buffer. MIT License. Feross Aboukhadijeh */ +/* eslint-disable node/no-deprecated-api */ +var buffer = require('buffer') +var Buffer = buffer.Buffer - if (ret === null) { - state.needReadable = true; - n = 0; - } else { - state.length -= n; +// alternative to using Object.keys for old browsers +function copyProps (src, dst) { + for (var key in src) { + dst[key] = src[key] } +} +if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + module.exports = buffer +} else { + // Copy properties from require('buffer') + copyProps(buffer, exports) + exports.Buffer = SafeBuffer +} - if (state.length === 0) { - // If we have nothing in the buffer, then we want to know - // as soon as we *do* get something into the buffer. - if (!state.ended) state.needReadable = true; - - // If we tried to read() past the EOF, then emit end on the next tick. - if (nOrig !== n && state.ended) endReadable(this); - } +function SafeBuffer (arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length) +} - if (ret !== null) this.emit('data', ret); +SafeBuffer.prototype = Object.create(Buffer.prototype) - return ret; -}; +// Copy static methods from Buffer +copyProps(Buffer, SafeBuffer) -function onEofChunk(stream, state) { - if (state.ended) return; - if (state.decoder) { - var chunk = state.decoder.end(); - if (chunk && chunk.length) { - state.buffer.push(chunk); - state.length += state.objectMode ? 1 : chunk.length; - } +SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === 'number') { + throw new TypeError('Argument must not be a number') } - state.ended = true; - - // emit 'readable' now to make sure it gets picked up. - emitReadable(stream); + return Buffer(arg, encodingOrOffset, length) } -// Don't emit readable right away in sync mode, because this can trigger -// another read() call => stack overflow. This way, it might trigger -// a nextTick recursion warning, but that's not so bad. -function emitReadable(stream) { - var state = stream._readableState; - state.needReadable = false; - if (!state.emittedReadable) { - debug('emitReadable', state.flowing); - state.emittedReadable = true; - if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream); +SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') } + var buf = Buffer(size) + if (fill !== undefined) { + if (typeof encoding === 'string') { + buf.fill(fill, encoding) + } else { + buf.fill(fill) + } + } else { + buf.fill(0) + } + return buf } -function emitReadable_(stream) { - debug('emit readable'); - stream.emit('readable'); - flow(stream); -} - -// at this point, the user has presumably seen the 'readable' event, -// and called read() to consume some data. that may have triggered -// in turn another _read(n) call, in which case reading = true if -// it's in progress. -// However, if we're not ended, or reading, and the length < hwm, -// then go ahead and try to read some more preemptively. -function maybeReadMore(stream, state) { - if (!state.readingMore) { - state.readingMore = true; - pna.nextTick(maybeReadMore_, stream, state); +SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') } + return Buffer(size) } -function maybeReadMore_(stream, state) { - var len = state.length; - while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { - debug('maybeReadMore read 0'); - stream.read(0); - if (len === state.length) - // didn't get any data, stop spinning. - break;else len = state.length; +SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') } - state.readingMore = false; + return buffer.SlowBuffer(size) } -// abstract method. to be overridden in specific implementation classes. -// call cb(er, data) where data is <= n in length. -// for virtual (non-string, non-buffer) streams, "length" is somewhat -// arbitrary, and perhaps not very meaningful. -Readable.prototype._read = function (n) { - this.emit('error', new Error('_read() is not implemented')); -}; - -Readable.prototype.pipe = function (dest, pipeOpts) { - var src = this; - var state = this._readableState; - - switch (state.pipesCount) { - case 0: - state.pipes = dest; - break; - case 1: - state.pipes = [state.pipes, dest]; - break; - default: - state.pipes.push(dest); - break; - } - state.pipesCount += 1; - debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); +},{"buffer":249}],464:[function(require,module,exports){ +(function (process){(function (){ +/* eslint-disable node/no-deprecated-api */ - var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; +'use strict' - var endFn = doEnd ? onend : unpipe; - if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn); +var buffer = require('buffer') +var Buffer = buffer.Buffer - dest.on('unpipe', onunpipe); - function onunpipe(readable, unpipeInfo) { - debug('onunpipe'); - if (readable === src) { - if (unpipeInfo && unpipeInfo.hasUnpiped === false) { - unpipeInfo.hasUnpiped = true; - cleanup(); - } - } - } +var safer = {} - function onend() { - debug('onend'); - dest.end(); - } +var key - // when the dest drains, it reduces the awaitDrain counter - // on the source. This would be more elegant with a .once() - // handler in flow(), but adding and removing repeatedly is - // too slow. - var ondrain = pipeOnDrain(src); - dest.on('drain', ondrain); +for (key in buffer) { + if (!buffer.hasOwnProperty(key)) continue + if (key === 'SlowBuffer' || key === 'Buffer') continue + safer[key] = buffer[key] +} - var cleanedUp = false; - function cleanup() { - debug('cleanup'); - // cleanup event handlers once the pipe is broken - dest.removeListener('close', onclose); - dest.removeListener('finish', onfinish); - dest.removeListener('drain', ondrain); - dest.removeListener('error', onerror); - dest.removeListener('unpipe', onunpipe); - src.removeListener('end', onend); - src.removeListener('end', unpipe); - src.removeListener('data', ondata); +var Safer = safer.Buffer = {} +for (key in Buffer) { + if (!Buffer.hasOwnProperty(key)) continue + if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue + Safer[key] = Buffer[key] +} - cleanedUp = true; +safer.Buffer.prototype = Buffer.prototype - // if the reader is waiting for a drain event from this - // specific writer, then it would cause it to never start - // flowing again. - // So, if this is awaiting a drain, then we just call it now. - // If we don't know, then assume that we are waiting for one. - if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); +if (!Safer.from || Safer.from === Uint8Array.from) { + Safer.from = function (value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value) + } + if (value && typeof value.length === 'undefined') { + throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value) + } + return Buffer(value, encodingOrOffset, length) } +} - // If the user pushes more data while we're writing to dest then we'll end up - // in ondata again. However, we only want to increase awaitDrain once because - // dest will only emit one 'drain' event for the multiple writes. - // => Introduce a guard on increasing awaitDrain. - var increasedAwaitDrain = false; - src.on('data', ondata); - function ondata(chunk) { - debug('ondata'); - increasedAwaitDrain = false; - var ret = dest.write(chunk); - if (false === ret && !increasedAwaitDrain) { - // If the user unpiped during `dest.write()`, it is possible - // to get stuck in a permanently paused state if that write - // also returned false. - // => Check whether `dest` is still a piping destination. - if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { - debug('false write response, pause', src._readableState.awaitDrain); - src._readableState.awaitDrain++; - increasedAwaitDrain = true; - } - src.pause(); +if (!Safer.alloc) { + Safer.alloc = function (size, fill, encoding) { + if (typeof size !== 'number') { + throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size) + } + if (size < 0 || size >= 2 * (1 << 30)) { + throw new RangeError('The value "' + size + '" is invalid for option "size"') + } + var buf = Buffer(size) + if (!fill || fill.length === 0) { + buf.fill(0) + } else if (typeof encoding === 'string') { + buf.fill(fill, encoding) + } else { + buf.fill(fill) } + return buf } +} - // if the dest has an error, then stop piping into it. - // however, don't suppress the throwing behavior for this. - function onerror(er) { - debug('onerror', er); - unpipe(); - dest.removeListener('error', onerror); - if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); +if (!safer.kStringMaxLength) { + try { + safer.kStringMaxLength = process.binding('buffer').kStringMaxLength + } catch (e) { + // we can't determine kStringMaxLength in environments where process.binding + // is unsupported, so let's not set it } +} - // Make sure our error handler is attached before userland ones. - prependListener(dest, 'error', onerror); - - // Both close and finish should trigger unpipe, but only once. - function onclose() { - dest.removeListener('finish', onfinish); - unpipe(); - } - dest.once('close', onclose); - function onfinish() { - debug('onfinish'); - dest.removeListener('close', onclose); - unpipe(); +if (!safer.constants) { + safer.constants = { + MAX_LENGTH: safer.kMaxLength } - dest.once('finish', onfinish); - - function unpipe() { - debug('unpipe'); - src.unpipe(dest); + if (safer.kStringMaxLength) { + safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength } +} - // tell the dest that it's being piped to - dest.emit('pipe', src); - - // start the flow if it hasn't been started already. - if (!state.flowing) { - debug('pipe resume'); - src.resume(); - } +module.exports = safer - return dest; -}; +}).call(this)}).call(this,require('_process')) +},{"_process":451,"buffer":249}],465:[function(require,module,exports){ +(function (setImmediate){(function (){ +"use strict"; -function pipeOnDrain(src) { - return function () { - var state = src._readableState; - debug('pipeOnDrain', state.awaitDrain); - if (state.awaitDrain) state.awaitDrain--; - if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { - state.flowing = true; - flow(src); - } - }; -} +(function(root) { + const MAX_VALUE = 0x7fffffff; -Readable.prototype.unpipe = function (dest) { - var state = this._readableState; - var unpipeInfo = { hasUnpiped: false }; + // The SHA256 and PBKDF2 implementation are from scrypt-async-js: + // See: https://github.com/dchest/scrypt-async-js + function SHA256(m) { + const K = new Uint32Array([ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, + 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, + 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, + 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, + 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, + 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, + 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, + 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, + 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + ]); - // if we're not piping anywhere, then do nothing. - if (state.pipesCount === 0) return this; + let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a; + let h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19; + const w = new Uint32Array(64); - // just one destination. most common case. - if (state.pipesCount === 1) { - // passed in one, but it's not the right one. - if (dest && dest !== state.pipes) return this; + function blocks(p) { + let off = 0, len = p.length; + while (len >= 64) { + let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, u, i, j, t1, t2; - if (!dest) dest = state.pipes; + for (i = 0; i < 16; i++) { + j = off + i*4; + w[i] = ((p[j] & 0xff)<<24) | ((p[j+1] & 0xff)<<16) | + ((p[j+2] & 0xff)<<8) | (p[j+3] & 0xff); + } - // got a match. - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; - if (dest) dest.emit('unpipe', this, unpipeInfo); - return this; - } + for (i = 16; i < 64; i++) { + u = w[i-2]; + t1 = ((u>>>17) | (u<<(32-17))) ^ ((u>>>19) | (u<<(32-19))) ^ (u>>>10); - // slow case. multiple pipe destinations. + u = w[i-15]; + t2 = ((u>>>7) | (u<<(32-7))) ^ ((u>>>18) | (u<<(32-18))) ^ (u>>>3); - if (!dest) { - // remove all. - var dests = state.pipes; - var len = state.pipesCount; - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; + w[i] = (((t1 + w[i-7]) | 0) + ((t2 + w[i-16]) | 0)) | 0; + } - for (var i = 0; i < len; i++) { - dests[i].emit('unpipe', this, unpipeInfo); - }return this; - } + for (i = 0; i < 64; i++) { + t1 = ((((((e>>>6) | (e<<(32-6))) ^ ((e>>>11) | (e<<(32-11))) ^ + ((e>>>25) | (e<<(32-25)))) + ((e & f) ^ (~e & g))) | 0) + + ((h + ((K[i] + w[i]) | 0)) | 0)) | 0; - // try to find the right one. - var index = indexOf(state.pipes, dest); - if (index === -1) return this; + t2 = ((((a>>>2) | (a<<(32-2))) ^ ((a>>>13) | (a<<(32-13))) ^ + ((a>>>22) | (a<<(32-22)))) + ((a & b) ^ (a & c) ^ (b & c))) | 0; - state.pipes.splice(index, 1); - state.pipesCount -= 1; - if (state.pipesCount === 1) state.pipes = state.pipes[0]; + h = g; + g = f; + f = e; + e = (d + t1) | 0; + d = c; + c = b; + b = a; + a = (t1 + t2) | 0; + } - dest.emit('unpipe', this, unpipeInfo); + h0 = (h0 + a) | 0; + h1 = (h1 + b) | 0; + h2 = (h2 + c) | 0; + h3 = (h3 + d) | 0; + h4 = (h4 + e) | 0; + h5 = (h5 + f) | 0; + h6 = (h6 + g) | 0; + h7 = (h7 + h) | 0; - return this; -}; + off += 64; + len -= 64; + } + } -// set up data events if they are asked for -// Ensure readable listeners eventually get something -Readable.prototype.on = function (ev, fn) { - var res = Stream.prototype.on.call(this, ev, fn); + blocks(m); - if (ev === 'data') { - // Start flowing on next tick if stream isn't explicitly paused - if (this._readableState.flowing !== false) this.resume(); - } else if (ev === 'readable') { - var state = this._readableState; - if (!state.endEmitted && !state.readableListening) { - state.readableListening = state.needReadable = true; - state.emittedReadable = false; - if (!state.reading) { - pna.nextTick(nReadingNextTick, this); - } else if (state.length) { - emitReadable(this); - } - } - } + let i, bytesLeft = m.length % 64, + bitLenHi = (m.length / 0x20000000) | 0, + bitLenLo = m.length << 3, + numZeros = (bytesLeft < 56) ? 56 : 120, + p = m.slice(m.length - bytesLeft, m.length); - return res; -}; -Readable.prototype.addListener = Readable.prototype.on; + p.push(0x80); + for (i = bytesLeft + 1; i < numZeros; i++) { p.push(0); } + p.push((bitLenHi >>> 24) & 0xff); + p.push((bitLenHi >>> 16) & 0xff); + p.push((bitLenHi >>> 8) & 0xff); + p.push((bitLenHi >>> 0) & 0xff); + p.push((bitLenLo >>> 24) & 0xff); + p.push((bitLenLo >>> 16) & 0xff); + p.push((bitLenLo >>> 8) & 0xff); + p.push((bitLenLo >>> 0) & 0xff); -function nReadingNextTick(self) { - debug('readable nexttick read 0'); - self.read(0); -} + blocks(p); -// pause() and resume() are remnants of the legacy readable stream API -// If the user uses them, then switch into old mode. -Readable.prototype.resume = function () { - var state = this._readableState; - if (!state.flowing) { - debug('resume'); - state.flowing = true; - resume(this, state); - } - return this; -}; + return [ + (h0 >>> 24) & 0xff, (h0 >>> 16) & 0xff, (h0 >>> 8) & 0xff, (h0 >>> 0) & 0xff, + (h1 >>> 24) & 0xff, (h1 >>> 16) & 0xff, (h1 >>> 8) & 0xff, (h1 >>> 0) & 0xff, + (h2 >>> 24) & 0xff, (h2 >>> 16) & 0xff, (h2 >>> 8) & 0xff, (h2 >>> 0) & 0xff, + (h3 >>> 24) & 0xff, (h3 >>> 16) & 0xff, (h3 >>> 8) & 0xff, (h3 >>> 0) & 0xff, + (h4 >>> 24) & 0xff, (h4 >>> 16) & 0xff, (h4 >>> 8) & 0xff, (h4 >>> 0) & 0xff, + (h5 >>> 24) & 0xff, (h5 >>> 16) & 0xff, (h5 >>> 8) & 0xff, (h5 >>> 0) & 0xff, + (h6 >>> 24) & 0xff, (h6 >>> 16) & 0xff, (h6 >>> 8) & 0xff, (h6 >>> 0) & 0xff, + (h7 >>> 24) & 0xff, (h7 >>> 16) & 0xff, (h7 >>> 8) & 0xff, (h7 >>> 0) & 0xff + ]; + } -function resume(stream, state) { - if (!state.resumeScheduled) { - state.resumeScheduled = true; - pna.nextTick(resume_, stream, state); - } -} + function PBKDF2_HMAC_SHA256_OneIter(password, salt, dkLen) { + // compress password if it's longer than hash block length + password = (password.length <= 64) ? password : SHA256(password); -function resume_(stream, state) { - if (!state.reading) { - debug('resume read 0'); - stream.read(0); - } + const innerLen = 64 + salt.length + 4; + const inner = new Array(innerLen); + const outerKey = new Array(64); - state.resumeScheduled = false; - state.awaitDrain = 0; - stream.emit('resume'); - flow(stream); - if (state.flowing && !state.reading) stream.read(0); -} + let i; + let dk = []; -Readable.prototype.pause = function () { - debug('call pause flowing=%j', this._readableState.flowing); - if (false !== this._readableState.flowing) { - debug('pause'); - this._readableState.flowing = false; - this.emit('pause'); - } - return this; -}; + // inner = (password ^ ipad) || salt || counter + for (i = 0; i < 64; i++) { inner[i] = 0x36; } + for (i = 0; i < password.length; i++) { inner[i] ^= password[i]; } + for (i = 0; i < salt.length; i++) { inner[64 + i] = salt[i]; } + for (i = innerLen - 4; i < innerLen; i++) { inner[i] = 0; } -function flow(stream) { - var state = stream._readableState; - debug('flow', state.flowing); - while (state.flowing && stream.read() !== null) {} -} + // outerKey = password ^ opad + for (i = 0; i < 64; i++) outerKey[i] = 0x5c; + for (i = 0; i < password.length; i++) outerKey[i] ^= password[i]; -// wrap an old-style stream as the async data source. -// This is *not* part of the readable stream interface. -// It is an ugly unfortunate mess of history. -Readable.prototype.wrap = function (stream) { - var _this = this; + // increments counter inside inner + function incrementCounter() { + for (let i = innerLen - 1; i >= innerLen - 4; i--) { + inner[i]++; + if (inner[i] <= 0xff) return; + inner[i] = 0; + } + } - var state = this._readableState; - var paused = false; + // output blocks = SHA256(outerKey || SHA256(inner)) ... + while (dkLen >= 32) { + incrementCounter(); + dk = dk.concat(SHA256(outerKey.concat(SHA256(inner)))); + dkLen -= 32; + } + if (dkLen > 0) { + incrementCounter(); + dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))).slice(0, dkLen)); + } - stream.on('end', function () { - debug('wrapped end'); - if (state.decoder && !state.ended) { - var chunk = state.decoder.end(); - if (chunk && chunk.length) _this.push(chunk); + return dk; } - _this.push(null); - }); - - stream.on('data', function (chunk) { - debug('wrapped data'); - if (state.decoder) chunk = state.decoder.write(chunk); - - // don't skip over falsy values in objectMode - if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + // The following is an adaptation of scryptsy + // See: https://www.npmjs.com/package/scryptsy + function blockmix_salsa8(BY, Yi, r, x, _X) { + let i; - var ret = _this.push(chunk); - if (!ret) { - paused = true; - stream.pause(); - } - }); + arraycopy(BY, (2 * r - 1) * 16, _X, 0, 16); + for (i = 0; i < 2 * r; i++) { + blockxor(BY, i * 16, _X, 16); + salsa20_8(_X, x); + arraycopy(_X, 0, BY, Yi + (i * 16), 16); + } - // proxy all the other methods. - // important when wrapping filters and duplexes. - for (var i in stream) { - if (this[i] === undefined && typeof stream[i] === 'function') { - this[i] = function (method) { - return function () { - return stream[method].apply(stream, arguments); - }; - }(i); - } - } + for (i = 0; i < r; i++) { + arraycopy(BY, Yi + (i * 2) * 16, BY, (i * 16), 16); + } - // proxy certain important events. - for (var n = 0; n < kProxyEvents.length; n++) { - stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); - } + for (i = 0; i < r; i++) { + arraycopy(BY, Yi + (i * 2 + 1) * 16, BY, (i + r) * 16, 16); + } + } - // when we try to consume some more bytes, simply unpause the - // underlying stream. - this._read = function (n) { - debug('wrapped _read', n); - if (paused) { - paused = false; - stream.resume(); + function R(a, b) { + return (a << b) | (a >>> (32 - b)); } - }; - return this; -}; + function salsa20_8(B, x) { + arraycopy(B, 0, x, 0, 16); -Object.defineProperty(Readable.prototype, 'readableHighWaterMark', { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function () { - return this._readableState.highWaterMark; - } -}); + for (let i = 8; i > 0; i -= 2) { + x[ 4] ^= R(x[ 0] + x[12], 7); + x[ 8] ^= R(x[ 4] + x[ 0], 9); + x[12] ^= R(x[ 8] + x[ 4], 13); + x[ 0] ^= R(x[12] + x[ 8], 18); + x[ 9] ^= R(x[ 5] + x[ 1], 7); + x[13] ^= R(x[ 9] + x[ 5], 9); + x[ 1] ^= R(x[13] + x[ 9], 13); + x[ 5] ^= R(x[ 1] + x[13], 18); + x[14] ^= R(x[10] + x[ 6], 7); + x[ 2] ^= R(x[14] + x[10], 9); + x[ 6] ^= R(x[ 2] + x[14], 13); + x[10] ^= R(x[ 6] + x[ 2], 18); + x[ 3] ^= R(x[15] + x[11], 7); + x[ 7] ^= R(x[ 3] + x[15], 9); + x[11] ^= R(x[ 7] + x[ 3], 13); + x[15] ^= R(x[11] + x[ 7], 18); + x[ 1] ^= R(x[ 0] + x[ 3], 7); + x[ 2] ^= R(x[ 1] + x[ 0], 9); + x[ 3] ^= R(x[ 2] + x[ 1], 13); + x[ 0] ^= R(x[ 3] + x[ 2], 18); + x[ 6] ^= R(x[ 5] + x[ 4], 7); + x[ 7] ^= R(x[ 6] + x[ 5], 9); + x[ 4] ^= R(x[ 7] + x[ 6], 13); + x[ 5] ^= R(x[ 4] + x[ 7], 18); + x[11] ^= R(x[10] + x[ 9], 7); + x[ 8] ^= R(x[11] + x[10], 9); + x[ 9] ^= R(x[ 8] + x[11], 13); + x[10] ^= R(x[ 9] + x[ 8], 18); + x[12] ^= R(x[15] + x[14], 7); + x[13] ^= R(x[12] + x[15], 9); + x[14] ^= R(x[13] + x[12], 13); + x[15] ^= R(x[14] + x[13], 18); + } -// exposed for testing purposes only. -Readable._fromList = fromList; + for (let i = 0; i < 16; ++i) { + B[i] += x[i]; + } + } -// Pluck off n bytes from an array of buffers. -// Length is the combined lengths of all the buffers in the list. -// This function is designed to be inlinable, so please take care when making -// changes to the function body. -function fromList(n, state) { - // nothing buffered - if (state.length === 0) return null; + // naive approach... going back to loop unrolling may yield additional performance + function blockxor(S, Si, D, len) { + for (let i = 0; i < len; i++) { + D[i] ^= S[Si + i] + } + } - var ret; - if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { - // read it all, truncate the list - if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length); - state.buffer.clear(); - } else { - // read part of list - ret = fromListPartial(n, state.buffer, state.decoder); - } + function arraycopy(src, srcPos, dest, destPos, length) { + while (length--) { + dest[destPos++] = src[srcPos++]; + } + } - return ret; -} + function checkBufferish(o) { + if (!o || typeof(o.length) !== 'number') { return false; } -// Extracts only enough buffered data to satisfy the amount requested. -// This function is designed to be inlinable, so please take care when making -// changes to the function body. -function fromListPartial(n, list, hasStrings) { - var ret; - if (n < list.head.data.length) { - // slice is the same for buffers and strings - ret = list.head.data.slice(0, n); - list.head.data = list.head.data.slice(n); - } else if (n === list.head.data.length) { - // first chunk is a perfect match - ret = list.shift(); - } else { - // result spans more than one buffer - ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); - } - return ret; -} + for (let i = 0; i < o.length; i++) { + const v = o[i]; + if (typeof(v) !== 'number' || v % 1 || v < 0 || v >= 256) { + return false; + } + } -// Copies a specified amount of characters from the list of buffered data -// chunks. -// This function is designed to be inlinable, so please take care when making -// changes to the function body. -function copyFromBufferString(n, list) { - var p = list.head; - var c = 1; - var ret = p.data; - n -= ret.length; - while (p = p.next) { - var str = p.data; - var nb = n > str.length ? str.length : n; - if (nb === str.length) ret += str;else ret += str.slice(0, n); - n -= nb; - if (n === 0) { - if (nb === str.length) { - ++c; - if (p.next) list.head = p.next;else list.head = list.tail = null; - } else { - list.head = p; - p.data = str.slice(nb); - } - break; + return true; } - ++c; - } - list.length -= c; - return ret; -} -// Copies a specified amount of bytes from the list of buffered data chunks. -// This function is designed to be inlinable, so please take care when making -// changes to the function body. -function copyFromBuffer(n, list) { - var ret = Buffer.allocUnsafe(n); - var p = list.head; - var c = 1; - p.data.copy(ret); - n -= p.data.length; - while (p = p.next) { - var buf = p.data; - var nb = n > buf.length ? buf.length : n; - buf.copy(ret, ret.length - n, 0, nb); - n -= nb; - if (n === 0) { - if (nb === buf.length) { - ++c; - if (p.next) list.head = p.next;else list.head = list.tail = null; - } else { - list.head = p; - p.data = buf.slice(nb); - } - break; + function ensureInteger(value, name) { + if (typeof(value) !== "number" || (value % 1)) { throw new Error('invalid ' + name); } + return value; } - ++c; - } - list.length -= c; - return ret; -} - -function endReadable(stream) { - var state = stream._readableState; - // If we get here before consuming all the bytes, then that is a - // bug in node. Should never happen. - if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); + // N = Cpu cost, r = Memory cost, p = parallelization cost + // callback(error, progress, key) + function _scrypt(password, salt, N, r, p, dkLen, callback) { - if (!state.endEmitted) { - state.ended = true; - pna.nextTick(endReadableNT, state, stream); - } -} + N = ensureInteger(N, 'N'); + r = ensureInteger(r, 'r'); + p = ensureInteger(p, 'p'); -function endReadableNT(state, stream) { - // Check that we didn't get one last unshift. - if (!state.endEmitted && state.length === 0) { - state.endEmitted = true; - stream.readable = false; - stream.emit('end'); - } -} + dkLen = ensureInteger(dkLen, 'dkLen'); -function indexOf(xs, x) { - for (var i = 0, l = xs.length; i < l; i++) { - if (xs[i] === x) return i; - } - return -1; -} -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":265,"./internal/streams/BufferList":270,"./internal/streams/destroy":271,"./internal/streams/stream":272,"_process":253,"core-util-is":157,"events":195,"inherits":230,"isarray":232,"process-nextick-args":252,"safe-buffer":273,"string_decoder/":274,"util":105}],268:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + if (N === 0 || (N & (N - 1)) !== 0) { throw new Error('N must be power of 2'); } -// a transform stream is a readable/writable stream where you do -// something with the data. Sometimes it's called a "filter", -// but that's not a great name for it, since that implies a thing where -// some bits pass through, and others are simply ignored. (That would -// be a valid example of a transform, of course.) -// -// While the output is causally related to the input, it's not a -// necessarily symmetric or synchronous transformation. For example, -// a zlib stream might take multiple plain-text writes(), and then -// emit a single compressed chunk some time in the future. -// -// Here's how this works: -// -// The Transform stream has all the aspects of the readable and writable -// stream classes. When you write(chunk), that calls _write(chunk,cb) -// internally, and returns false if there's a lot of pending writes -// buffered up. When you call read(), that calls _read(n) until -// there's enough pending readable data buffered up. -// -// In a transform stream, the written data is placed in a buffer. When -// _read(n) is called, it transforms the queued up data, calling the -// buffered _write cb's as it consumes chunks. If consuming a single -// written chunk would result in multiple output chunks, then the first -// outputted bit calls the readcb, and subsequent chunks just go into -// the read buffer, and will cause it to emit 'readable' if necessary. -// -// This way, back-pressure is actually determined by the reading side, -// since _read has to be called to start processing a new chunk. However, -// a pathological inflate type of transform can cause excessive buffering -// here. For example, imagine a stream where every byte of input is -// interpreted as an integer from 0-255, and then results in that many -// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in -// 1kb of data being output. In this case, you could write a very small -// amount of input, and end up with a very large amount of output. In -// such a pathological inflating mechanism, there'd be no way to tell -// the system to stop doing the transform. A single 4MB write could -// cause the system to run out of memory. -// -// However, even in such a pathological case, only a single written chunk -// would be consumed, and then the rest would wait (un-transformed) until -// the results of the previous transformed chunk were consumed. + if (N > MAX_VALUE / 128 / r) { throw new Error('N too large'); } + if (r > MAX_VALUE / 128 / p) { throw new Error('r too large'); } -'use strict'; + if (!checkBufferish(password)) { + throw new Error('password must be an array or buffer'); + } + password = Array.prototype.slice.call(password); -module.exports = Transform; + if (!checkBufferish(salt)) { + throw new Error('salt must be an array or buffer'); + } + salt = Array.prototype.slice.call(salt); -var Duplex = require('./_stream_duplex'); + let b = PBKDF2_HMAC_SHA256_OneIter(password, salt, p * 128 * r); + const B = new Uint32Array(p * 32 * r) + for (let i = 0; i < B.length; i++) { + const j = i * 4; + B[i] = ((b[j + 3] & 0xff) << 24) | + ((b[j + 2] & 0xff) << 16) | + ((b[j + 1] & 0xff) << 8) | + ((b[j + 0] & 0xff) << 0); + } -/**/ -var util = Object.create(require('core-util-is')); -util.inherits = require('inherits'); -/**/ + const XY = new Uint32Array(64 * r); + const V = new Uint32Array(32 * r * N); -util.inherits(Transform, Duplex); + const Yi = 32 * r; -function afterTransform(er, data) { - var ts = this._transformState; - ts.transforming = false; + // scratch space + const x = new Uint32Array(16); // salsa20_8 + const _X = new Uint32Array(16); // blockmix_salsa8 - var cb = ts.writecb; + const totalOps = p * N * 2; + let currentOp = 0; + let lastPercent10 = null; - if (!cb) { - return this.emit('error', new Error('write callback called multiple times')); - } + // Set this to true to abandon the scrypt on the next step + let stop = false; - ts.writechunk = null; - ts.writecb = null; + // State information + let state = 0; + let i0 = 0, i1; + let Bi; - if (data != null) // single equals check for both `null` and `undefined` - this.push(data); + // How many blockmix_salsa8 can we do per step? + const limit = callback ? parseInt(1000 / r): 0xffffffff; - cb(er); + // Trick from scrypt-async; if there is a setImmediate shim in place, use it + const nextTick = (typeof(setImmediate) !== 'undefined') ? setImmediate : setTimeout; - var rs = this._readableState; - rs.reading = false; - if (rs.needReadable || rs.length < rs.highWaterMark) { - this._read(rs.highWaterMark); - } -} + // This is really all I changed; making scryptsy a state machine so we occasionally + // stop and give other evnts on the evnt loop a chance to run. ~RicMoo + const incrementalSMix = function() { + if (stop) { + return callback(new Error('cancelled'), currentOp / totalOps); + } -function Transform(options) { - if (!(this instanceof Transform)) return new Transform(options); + let steps; - Duplex.call(this, options); + switch (state) { + case 0: + // for (var i = 0; i < p; i++)... + Bi = i0 * 32 * r; - this._transformState = { - afterTransform: afterTransform.bind(this), - needTransform: false, - transforming: false, - writecb: null, - writechunk: null, - writeencoding: null - }; + arraycopy(B, Bi, XY, 0, Yi); // ROMix - 1 - // start out asking for a readable event once data is transformed. - this._readableState.needReadable = true; + state = 1; // Move to ROMix 2 + i1 = 0; - // we have implemented the _read method, and done the other things - // that Readable wants before the first _read call, so unset the - // sync guard flag. - this._readableState.sync = false; + // Fall through - if (options) { - if (typeof options.transform === 'function') this._transform = options.transform; + case 1: - if (typeof options.flush === 'function') this._flush = options.flush; - } + // Run up to 1000 steps of the first inner smix loop + steps = N - i1; + if (steps > limit) { steps = limit; } + for (let i = 0; i < steps; i++) { // ROMix - 2 + arraycopy(XY, 0, V, (i1 + i) * Yi, Yi) // ROMix - 3 + blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 4 + } - // When the writable side finishes, then flush out anything remaining. - this.on('prefinish', prefinish); -} + // for (var i = 0; i < N; i++) + i1 += steps; + currentOp += steps; -function prefinish() { - var _this = this; + if (callback) { + // Call the callback with the progress (optionally stopping us) + const percent10 = parseInt(1000 * currentOp / totalOps); + if (percent10 !== lastPercent10) { + stop = callback(null, currentOp / totalOps); + if (stop) { break; } + lastPercent10 = percent10; + } + } - if (typeof this._flush === 'function') { - this._flush(function (er, data) { - done(_this, er, data); - }); - } else { - done(this, null, null); - } -} + if (i1 < N) { break; } -Transform.prototype.push = function (chunk, encoding) { - this._transformState.needTransform = false; - return Duplex.prototype.push.call(this, chunk, encoding); -}; + i1 = 0; // Move to ROMix 6 + state = 2; -// This is the part where you do stuff! -// override this function in implementation classes. -// 'chunk' is an input chunk. -// -// Call `push(newChunk)` to pass along transformed output -// to the readable side. You may call 'push' zero or more times. -// -// Call `cb(err)` when you are done with this chunk. If you pass -// an error, then that'll put the hurt on the whole operation. If you -// never call cb(), then you'll never get another chunk. -Transform.prototype._transform = function (chunk, encoding, cb) { - throw new Error('_transform() is not implemented'); -}; + // Fall through -Transform.prototype._write = function (chunk, encoding, cb) { - var ts = this._transformState; - ts.writecb = cb; - ts.writechunk = chunk; - ts.writeencoding = encoding; - if (!ts.transforming) { - var rs = this._readableState; - if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); - } -}; + case 2: -// Doesn't matter what the args are here. -// _transform does all the work. -// That we got here means that the readable side wants more data. -Transform.prototype._read = function (n) { - var ts = this._transformState; + // Run up to 1000 steps of the second inner smix loop + steps = N - i1; + if (steps > limit) { steps = limit; } + for (let i = 0; i < steps; i++) { // ROMix - 6 + const offset = (2 * r - 1) * 16; // ROMix - 7 + const j = XY[offset] & (N - 1); + blockxor(V, j * Yi, XY, Yi); // ROMix - 8 (inner) + blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 9 (outer) + } - if (ts.writechunk !== null && ts.writecb && !ts.transforming) { - ts.transforming = true; - this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); - } else { - // mark that we need a transform, so that any data that comes in - // will get processed, now that we've asked for it. - ts.needTransform = true; - } -}; + // for (var i = 0; i < N; i++)... + i1 += steps; + currentOp += steps; -Transform.prototype._destroy = function (err, cb) { - var _this2 = this; + // Call the callback with the progress (optionally stopping us) + if (callback) { + const percent10 = parseInt(1000 * currentOp / totalOps); + if (percent10 !== lastPercent10) { + stop = callback(null, currentOp / totalOps); + if (stop) { break; } + lastPercent10 = percent10; + } + } - Duplex.prototype._destroy.call(this, err, function (err2) { - cb(err2); - _this2.emit('close'); - }); -}; + if (i1 < N) { break; } -function done(stream, er, data) { - if (er) return stream.emit('error', er); + arraycopy(XY, 0, B, Bi, Yi); // ROMix - 10 - if (data != null) // single equals check for both `null` and `undefined` - stream.push(data); + // for (var i = 0; i < p; i++)... + i0++; + if (i0 < p) { + state = 0; + break; + } - // if there's nothing in the write buffer, then that means - // that nothing more will ever be provided - if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0'); + b = []; + for (let i = 0; i < B.length; i++) { + b.push((B[i] >> 0) & 0xff); + b.push((B[i] >> 8) & 0xff); + b.push((B[i] >> 16) & 0xff); + b.push((B[i] >> 24) & 0xff); + } - if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming'); + const derivedKey = PBKDF2_HMAC_SHA256_OneIter(password, b, dkLen); - return stream.push(null); -} -},{"./_stream_duplex":265,"core-util-is":157,"inherits":230}],269:[function(require,module,exports){ -(function (process,global,setImmediate){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + // Send the result to the callback + if (callback) { callback(null, 1.0, derivedKey); } -// A bit simpler than readable streams. -// Implement an async ._write(chunk, encoding, cb), and it'll handle all -// the drain event emission and buffering. + // Done; don't break (which would reschedule) + return derivedKey; + } -'use strict'; + // Schedule the next steps + if (callback) { nextTick(incrementalSMix); } + } -/**/ + // Run the smix state machine until completion + if (!callback) { + while (true) { + const derivedKey = incrementalSMix(); + if (derivedKey != undefined) { return derivedKey; } + } + } -var pna = require('process-nextick-args'); -/**/ + // Bootstrap the async incremental smix + incrementalSMix(); + } -module.exports = Writable; + const lib = { + scrypt: function(password, salt, N, r, p, dkLen, progressCallback) { + return new Promise(function(resolve, reject) { + let lastProgress = 0; + if (progressCallback) { progressCallback(0); } + _scrypt(password, salt, N, r, p, dkLen, function(error, progress, key) { + if (error) { + reject(error); + } else if (key) { + if (progressCallback && lastProgress !== 1) { + progressCallback(1); + } + resolve(new Uint8Array(key)); + } else if (progressCallback && progress !== lastProgress) { + lastProgress = progress; + return progressCallback(progress); + } + }); + }); + }, + syncScrypt: function(password, salt, N, r, p, dkLen) { + return new Uint8Array(_scrypt(password, salt, N, r, p, dkLen)); + } + }; -/* */ -function WriteReq(chunk, encoding, cb) { - this.chunk = chunk; - this.encoding = encoding; - this.callback = cb; - this.next = null; -} + // node.js + if (typeof(exports) !== 'undefined') { + module.exports = lib; -// It seems a linked list but it is not -// there will be only 2 of these for each stream -function CorkedRequest(state) { - var _this = this; + // RequireJS/AMD + // http://www.requirejs.org/docs/api.html + // https://github.com/amdjs/amdjs-api/wiki/AMD + } else if (typeof(define) === 'function' && define.amd) { + define(lib); - this.next = null; - this.entry = null; - this.finish = function () { - onCorkedFinish(_this, state); - }; -} -/* */ + // Web Browsers + } else if (root) { -/**/ -var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick; -/**/ + // If there was an existing library "scrypt", make sure it is still available + if (root.scrypt) { + root._scrypt = root.scrypt; + } -/**/ -var Duplex; -/**/ + root.scrypt = lib; + } -Writable.WritableState = WritableState; +})(this); -/**/ -var util = Object.create(require('core-util-is')); -util.inherits = require('inherits'); -/**/ +}).call(this)}).call(this,require("timers").setImmediate) +},{"timers":497}],466:[function(require,module,exports){ +const scrypt = require('./scryptSync') +scrypt.async = require('./scrypt') +module.exports = scrypt -/**/ -var internalUtil = { - deprecate: require('util-deprecate') -}; -/**/ +},{"./scrypt":467,"./scryptSync":468}],467:[function(require,module,exports){ +const crypto = require('crypto') +const { + checkAndInit, + smix +} = require('./utils') -/**/ -var Stream = require('./internal/streams/stream'); -/**/ +// N = Cpu cost, r = Memory cost, p = parallelization cost +async function scrypt (key, salt, N, r, p, dkLen, progressCallback, promiseInterval) { + const { + XY, + V, + B32, + x, + _X, + B, + tickCallback + } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback) -/**/ + for (var i = 0; i < p; i++) { + await smix(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) + } -var Buffer = require('safe-buffer').Buffer; -var OurUint8Array = global.Uint8Array || function () {}; -function _uint8ArrayToBuffer(chunk) { - return Buffer.from(chunk); -} -function _isUint8Array(obj) { - return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256') } -/**/ +module.exports = scrypt -var destroyImpl = require('./internal/streams/destroy'); +},{"./utils":469,"crypto":258}],468:[function(require,module,exports){ +const crypto = require('crypto') +const { + checkAndInit, + smixSync +} = require('./utils') -util.inherits(Writable, Stream); +// N = Cpu cost, r = Memory cost, p = parallelization cost +function scrypt (key, salt, N, r, p, dkLen, progressCallback) { + const { + XY, + V, + B32, + x, + _X, + B, + tickCallback + } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback) -function nop() {} + for (var i = 0; i < p; i++) { + smixSync(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback) + } -function WritableState(options, stream) { - Duplex = Duplex || require('./_stream_duplex'); + return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256') +} - options = options || {}; +module.exports = scrypt - // Duplex streams are both readable and writable, but share - // the same options object. - // However, some cases require setting options to different - // values for the readable and the writable sides of the duplex stream. - // These options can be provided separately as readableXXX and writableXXX. - var isDuplex = stream instanceof Duplex; +},{"./utils":469,"crypto":258}],469:[function(require,module,exports){ +(function (Buffer,setImmediate){(function (){ +const crypto = require('crypto') +const MAX_VALUE = 0x7fffffff +const DEFAULT_PROMISE_INTERVAL = 5000 +/* eslint-disable camelcase */ - // object stream flag to indicate whether or not this stream - // contains buffers or objects. - this.objectMode = !!options.objectMode; +function checkAndInit (key, salt, N, r, p, dkLen, progressCallback) { + if (N === 0 || (N & (N - 1)) !== 0) throw Error('N must be > 0 and a power of 2') - if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; + if (N > MAX_VALUE / 128 / r) throw Error('Parameter N is too large') + if (r > MAX_VALUE / 128 / p) throw Error('Parameter r is too large') - // the point at which write() starts returning false - // Note: 0 is a valid value, means that we always return false if - // the entire buffer is not flushed immediately on write() - var hwm = options.highWaterMark; - var writableHwm = options.writableHighWaterMark; - var defaultHwm = this.objectMode ? 16 : 16 * 1024; + let XY = Buffer.alloc(256 * r) + let V = Buffer.alloc(128 * r * N) - if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm; + // pseudo global + let B32 = new Int32Array(16) // salsa20_8 + let x = new Int32Array(16) // salsa20_8 + let _X = Buffer.alloc(64) // blockmix_salsa8 - // cast to ints. - this.highWaterMark = Math.floor(this.highWaterMark); + // pseudo global + let B = crypto.pbkdf2Sync(key, salt, 1, p * 128 * r, 'sha256') - // if _final has been called - this.finalCalled = false; + let tickCallback + if (progressCallback) { + let totalOps = p * N * 2 + let currentOp = 0 - // drain event flag. - this.needDrain = false; - // at the start of calling end() - this.ending = false; - // when end() has been called, and returned - this.ended = false; - // when 'finish' is emitted - this.finished = false; + tickCallback = function () { + ++currentOp - // has it been destroyed - this.destroyed = false; + // send progress notifications once every 1,000 ops + if (currentOp % 1000 === 0) { + progressCallback({ + current: currentOp, + total: totalOps, + percent: (currentOp / totalOps) * 100.0 + }) + } + } + } + return { + XY, + V, + B32, + x, + _X, + B, + tickCallback + } +} - // should we decode strings into buffers before passing to _write? - // this is here so that some node-core streams can optimize string - // handling at a lower level. - var noDecode = options.decodeStrings === false; - this.decodeStrings = !noDecode; +async function smix (B, Bi, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) { + promiseInterval = promiseInterval || DEFAULT_PROMISE_INTERVAL + let Xi = 0 + let Yi = 128 * r + let i - // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - this.defaultEncoding = options.defaultEncoding || 'utf8'; + B.copy(XY, Xi, Bi, Bi + Yi) - // not an actual buffer we keep track of, but a measurement - // of how much we're waiting to get pushed to some underlying - // socket or file. - this.length = 0; + for (i = 0; i < N; i++) { + XY.copy(V, i * Yi, Xi, Xi + Yi) + if (i % promiseInterval === 0) { + await new Promise(resolve => setImmediate(resolve)) + } + blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) - // a flag to see when we're in the middle of a write. - this.writing = false; + if (tickCallback) tickCallback() + } - // when true all writes will be buffered until .uncork() call - this.corked = 0; + for (i = 0; i < N; i++) { + let offset = Xi + (2 * r - 1) * 64 + let j = XY.readUInt32LE(offset) & (N - 1) + blockxor(V, j * Yi, XY, Xi, Yi) + if (i % promiseInterval === 0) { + await new Promise(resolve => setImmediate(resolve)) + } + blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) - // a flag to be able to tell if the onwrite cb is called immediately, - // or on a later tick. We set this to true at first, because any - // actions that shouldn't happen until "later" should generally also - // not happen before the first write call. - this.sync = true; + if (tickCallback) tickCallback() + } - // a flag to know if we're processing previously buffered items, which - // may call the _write() callback in the same tick, so that we don't - // end up in an overlapped onwrite situation. - this.bufferProcessing = false; + XY.copy(B, Bi, Xi, Xi + Yi) +} - // the callback that's passed to _write(chunk,cb) - this.onwrite = function (er) { - onwrite(stream, er); - }; +function smixSync (B, Bi, r, N, V, XY, _X, B32, x, tickCallback) { + let Xi = 0 + let Yi = 128 * r + let i - // the callback that the user supplies to write(chunk,encoding,cb) - this.writecb = null; + B.copy(XY, Xi, Bi, Bi + Yi) - // the amount that is being written when _write is called. - this.writelen = 0; + for (i = 0; i < N; i++) { + XY.copy(V, i * Yi, Xi, Xi + Yi) + blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) - this.bufferedRequest = null; - this.lastBufferedRequest = null; + if (tickCallback) tickCallback() + } - // number of pending user-supplied write callbacks - // this must be 0 before 'finish' can be emitted - this.pendingcb = 0; + for (i = 0; i < N; i++) { + let offset = Xi + (2 * r - 1) * 64 + let j = XY.readUInt32LE(offset) & (N - 1) + blockxor(V, j * Yi, XY, Xi, Yi) + blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) - // emit prefinish if the only thing we're waiting for is _write cbs - // This is relevant for synchronous Transform streams - this.prefinished = false; + if (tickCallback) tickCallback() + } - // True if the error was already emitted and should not be thrown again - this.errorEmitted = false; + XY.copy(B, Bi, Xi, Xi + Yi) +} - // count buffered requests - this.bufferedRequestCount = 0; +function blockmix_salsa8 (BY, Bi, Yi, r, _X, B32, x) { + let i - // allocate the first CorkedRequest, there is always - // one allocated and free to use, and we maintain at most two - this.corkedRequestsFree = new CorkedRequest(this); -} + arraycopy(BY, Bi + (2 * r - 1) * 64, _X, 0, 64) -WritableState.prototype.getBuffer = function getBuffer() { - var current = this.bufferedRequest; - var out = []; - while (current) { - out.push(current); - current = current.next; + for (i = 0; i < 2 * r; i++) { + blockxor(BY, i * 64, _X, 0, 64) + salsa20_8(_X, B32, x) + arraycopy(_X, 0, BY, Yi + (i * 64), 64) } - return out; -}; - -(function () { - try { - Object.defineProperty(WritableState.prototype, 'buffer', { - get: internalUtil.deprecate(function () { - return this.getBuffer(); - }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003') - }); - } catch (_) {} -})(); -// Test _writableState for inheritance to account for Duplex streams, -// whose prototype chain only points to Readable. -var realHasInstance; -if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') { - realHasInstance = Function.prototype[Symbol.hasInstance]; - Object.defineProperty(Writable, Symbol.hasInstance, { - value: function (object) { - if (realHasInstance.call(this, object)) return true; - if (this !== Writable) return false; + for (i = 0; i < r; i++) { + arraycopy(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64) + } - return object && object._writableState instanceof WritableState; - } - }); -} else { - realHasInstance = function (object) { - return object instanceof this; - }; + for (i = 0; i < r; i++) { + arraycopy(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64) + } } -function Writable(options) { - Duplex = Duplex || require('./_stream_duplex'); +function R (a, b) { + return (a << b) | (a >>> (32 - b)) +} - // Writable ctor is applied to Duplexes, too. - // `realHasInstance` is necessary because using plain `instanceof` - // would return false, as no `_writableState` property is attached. +function salsa20_8 (B, B32, x) { + let i - // Trying to use the custom `instanceof` for Writable here will also break the - // Node.js LazyTransform implementation, which has a non-trivial getter for - // `_writableState` that would lead to infinite recursion. - if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) { - return new Writable(options); + for (i = 0; i < 16; i++) { + B32[i] = (B[i * 4 + 0] & 0xff) << 0 + B32[i] |= (B[i * 4 + 1] & 0xff) << 8 + B32[i] |= (B[i * 4 + 2] & 0xff) << 16 + B32[i] |= (B[i * 4 + 3] & 0xff) << 24 + // B32[i] = B.readUInt32LE(i*4) <--- this is signficantly slower even in Node.js } - this._writableState = new WritableState(options, this); - - // legacy. - this.writable = true; - - if (options) { - if (typeof options.write === 'function') this._write = options.write; + arraycopy(B32, 0, x, 0, 16) - if (typeof options.writev === 'function') this._writev = options.writev; + for (i = 8; i > 0; i -= 2) { + x[4] ^= R(x[0] + x[12], 7) + x[8] ^= R(x[4] + x[0], 9) + x[12] ^= R(x[8] + x[4], 13) + x[0] ^= R(x[12] + x[8], 18) + x[9] ^= R(x[5] + x[1], 7) + x[13] ^= R(x[9] + x[5], 9) + x[1] ^= R(x[13] + x[9], 13) + x[5] ^= R(x[1] + x[13], 18) + x[14] ^= R(x[10] + x[6], 7) + x[2] ^= R(x[14] + x[10], 9) + x[6] ^= R(x[2] + x[14], 13) + x[10] ^= R(x[6] + x[2], 18) + x[3] ^= R(x[15] + x[11], 7) + x[7] ^= R(x[3] + x[15], 9) + x[11] ^= R(x[7] + x[3], 13) + x[15] ^= R(x[11] + x[7], 18) + x[1] ^= R(x[0] + x[3], 7) + x[2] ^= R(x[1] + x[0], 9) + x[3] ^= R(x[2] + x[1], 13) + x[0] ^= R(x[3] + x[2], 18) + x[6] ^= R(x[5] + x[4], 7) + x[7] ^= R(x[6] + x[5], 9) + x[4] ^= R(x[7] + x[6], 13) + x[5] ^= R(x[4] + x[7], 18) + x[11] ^= R(x[10] + x[9], 7) + x[8] ^= R(x[11] + x[10], 9) + x[9] ^= R(x[8] + x[11], 13) + x[10] ^= R(x[9] + x[8], 18) + x[12] ^= R(x[15] + x[14], 7) + x[13] ^= R(x[12] + x[15], 9) + x[14] ^= R(x[13] + x[12], 13) + x[15] ^= R(x[14] + x[13], 18) + } - if (typeof options.destroy === 'function') this._destroy = options.destroy; + for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i] - if (typeof options.final === 'function') this._final = options.final; + for (i = 0; i < 16; i++) { + let bi = i * 4 + B[bi + 0] = (B32[i] >> 0 & 0xff) + B[bi + 1] = (B32[i] >> 8 & 0xff) + B[bi + 2] = (B32[i] >> 16 & 0xff) + B[bi + 3] = (B32[i] >> 24 & 0xff) + // B.writeInt32LE(B32[i], i*4) //<--- this is signficantly slower even in Node.js } +} - Stream.call(this); +// naive approach... going back to loop unrolling may yield additional performance +function blockxor (S, Si, D, Di, len) { + for (let i = 0; i < len; i++) { + D[Di + i] ^= S[Si + i] + } } -// Otherwise people can pipe Writable streams, which is just wrong. -Writable.prototype.pipe = function () { - this.emit('error', new Error('Cannot pipe, not readable')); -}; +function arraycopy (src, srcPos, dest, destPos, length) { + if (Buffer.isBuffer(src) && Buffer.isBuffer(dest)) { + src.copy(dest, destPos, srcPos, srcPos + length) + } else { + while (length--) { + dest[destPos++] = src[srcPos++] + } + } +} -function writeAfterEnd(stream, cb) { - var er = new Error('write after end'); - // TODO: defer error events consistently everywhere, not just the cb - stream.emit('error', er); - pna.nextTick(cb, er); +module.exports = { + checkAndInit, + smix, + smixSync } -// Checks that a user-supplied chunk is valid, especially for the particular -// mode the stream is in. Currently this means that `null` is never accepted -// and undefined/non-string values are only allowed in object mode. -function validChunk(stream, state, chunk, cb) { - var valid = true; - var er = false; +}).call(this)}).call(this,require("buffer").Buffer,require("timers").setImmediate) +},{"buffer":249,"crypto":258,"timers":497}],470:[function(require,module,exports){ +// @preserve author Alexander Stetsyuk +// @preserve author Glenn Rempe +// @license MIT - if (chunk === null) { - er = new TypeError('May not write null values to stream'); - } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { - er = new TypeError('Invalid non-string/buffer chunk'); - } - if (er) { - stream.emit('error', er); - pna.nextTick(cb, er); - valid = false; - } - return valid; -} +/*jslint passfail: false, bitwise: true, nomen: true, plusplus: true, todo: false, maxerr: 1000 */ +/*global define, require, module, exports, window, Uint32Array, sjcl */ -Writable.prototype.write = function (chunk, encoding, cb) { - var state = this._writableState; - var ret = false; - var isBuf = !state.objectMode && _isUint8Array(chunk); +// eslint : http://eslint.org/docs/configuring/ +/*eslint-env node, browser, jasmine, sjcl */ +/*eslint no-underscore-dangle:0 */ - if (isBuf && !Buffer.isBuffer(chunk)) { - chunk = _uint8ArrayToBuffer(chunk); - } +// UMD (Universal Module Definition) +// Uses Node, AMD or browser globals to create a module. This module creates +// a global even when AMD is used. This is useful if you have some scripts +// that are loaded by an AMD loader, but they still want access to globals. +// See : https://github.com/umdjs/umd +// See : https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js +// +(function (root, factory) { + "use strict"; - if (typeof encoding === 'function') { - cb = encoding; - encoding = null; - } + if (typeof define === "function" && define.amd) { + // AMD. Register as an anonymous module. + define([], function () { + /*eslint-disable no-return-assign */ + return (root.secrets = factory()); + /*eslint-enable no-return-assign */ + }); + } else if (typeof exports === "object") { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = factory(require("crypto")); + } else { + // Browser globals (root is window) + root.secrets = factory(root.crypto); + } +}(this, function (crypto) { + "use strict"; - if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; + var defaults, + config, + preGenPadding, + runCSPRNGTest, + sjclParanoia, + CSPRNGTypes; - if (typeof cb !== 'function') cb = nop; + function reset() { + defaults = { + bits: 8, // default number of bits + radix: 16, // work with HEX by default + minBits: 3, + maxBits: 20, // this permits 1,048,575 shares, though going this high is NOT recommended in JS! + bytesPerChar: 2, + maxBytesPerChar: 6, // Math.pow(256,7) > Math.pow(2,53) - if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { - state.pendingcb++; - ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); - } + // Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30 + // The index of each term in the array corresponds to the n for that polynomial + // i.e. to get the polynomial for n=16, use primitivePolynomials[16] + primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39, 9, 5, 3, 33, 27, 9, 71, 39, 9, 5, 83] + }; + config = {}; + preGenPadding = new Array(1024).join("0"); // Pre-generate a string of 1024 0's for use by padLeft(). + runCSPRNGTest = true; + sjclParanoia = 10; - return ret; -}; + // WARNING : Never use 'testRandom' except for testing. + CSPRNGTypes = ["nodeCryptoRandomBytes", "browserCryptoGetRandomValues", "browserSJCLRandom", "testRandom"]; + } -Writable.prototype.cork = function () { - var state = this._writableState; + function isSetRNG() { + if (config && config.rng && typeof config.rng === "function") { + return true; + } - state.corked++; -}; + return false; + } -Writable.prototype.uncork = function () { - var state = this._writableState; + // Pads a string `str` with zeros on the left so that its length is a multiple of `bits` + function padLeft(str, multipleOfBits) { + var missing; - if (state.corked) { - state.corked--; + if (multipleOfBits === 0 || multipleOfBits === 1) { + return str; + } - if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); - } -}; + if (multipleOfBits && multipleOfBits > 1024) { + throw new Error("Padding must be multiples of no larger than 1024 bits."); + } -Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { - // node::ParseEncoding() requires lower case. - if (typeof encoding === 'string') encoding = encoding.toLowerCase(); - if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); - this._writableState.defaultEncoding = encoding; - return this; -}; + multipleOfBits = multipleOfBits || config.bits; -function decodeChunk(state, chunk, encoding) { - if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { - chunk = Buffer.from(chunk, encoding); - } - return chunk; -} + if (str) { + missing = str.length % multipleOfBits; + } -Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function () { - return this._writableState.highWaterMark; - } -}); + if (missing) { + return (preGenPadding + str).slice(-(multipleOfBits - missing + str.length)); + } -// if we're already writing something, then just put this -// in the queue, and wait our turn. Otherwise, call _write -// If we return false, then we need a drain event, so set that flag. -function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { - if (!isBuf) { - var newChunk = decodeChunk(state, chunk, encoding); - if (chunk !== newChunk) { - isBuf = true; - encoding = 'buffer'; - chunk = newChunk; + return str; } - } - var len = state.objectMode ? 1 : chunk.length; - state.length += len; - - var ret = state.length < state.highWaterMark; - // we must ensure that previous needDrain will not be reset to false. - if (!ret) state.needDrain = true; - - if (state.writing || state.corked) { - var last = state.lastBufferedRequest; - state.lastBufferedRequest = { - chunk: chunk, - encoding: encoding, - isBuf: isBuf, - callback: cb, - next: null - }; - if (last) { - last.next = state.lastBufferedRequest; - } else { - state.bufferedRequest = state.lastBufferedRequest; - } - state.bufferedRequestCount += 1; - } else { - doWrite(stream, state, false, len, chunk, encoding, cb); - } + function hex2bin(str) { + var bin = "", + num, + i; - return ret; -} + for (i = str.length - 1; i >= 0; i--) { + num = parseInt(str[i], 16); -function doWrite(stream, state, writev, len, chunk, encoding, cb) { - state.writelen = len; - state.writecb = cb; - state.writing = true; - state.sync = true; - if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); - state.sync = false; -} + if (isNaN(num)) { + throw new Error("Invalid hex character."); + } -function onwriteError(stream, state, sync, er, cb) { - --state.pendingcb; + bin = padLeft(num.toString(2), 4) + bin; + } + return bin; + } - if (sync) { - // defer the callback if we are being called synchronously - // to avoid piling up things on the stack - pna.nextTick(cb, er); - // this can emit finish, and it will always happen - // after error - pna.nextTick(finishMaybe, stream, state); - stream._writableState.errorEmitted = true; - stream.emit('error', er); - } else { - // the caller expect this to happen before if - // it is async - cb(er); - stream._writableState.errorEmitted = true; - stream.emit('error', er); - // this can emit finish, but finish must - // always follow error - finishMaybe(stream, state); - } -} + function bin2hex(str) { + var hex = "", + num, + i; -function onwriteStateUpdate(state) { - state.writing = false; - state.writecb = null; - state.length -= state.writelen; - state.writelen = 0; -} + str = padLeft(str, 4); -function onwrite(stream, er) { - var state = stream._writableState; - var sync = state.sync; - var cb = state.writecb; + for (i = str.length; i >= 4; i -= 4) { + num = parseInt(str.slice(i - 4, i), 2); + if (isNaN(num)) { + throw new Error("Invalid binary character."); + } + hex = num.toString(16) + hex; + } - onwriteStateUpdate(state); + return hex; + } - if (er) onwriteError(stream, state, sync, er, cb);else { - // Check if we're actually ready to finish, but don't emit yet - var finished = needFinish(state); + // Returns a pseudo-random number generator of the form function(bits){} + // which should output a random string of 1's and 0's of length `bits`. + // `type` (Optional) : A string representing the CSPRNG that you want to + // force to be loaded, overriding feature detection. Can be one of: + // "nodeCryptoRandomBytes" + // "browserCryptoGetRandomValues" + // "browserSJCLRandom" + // + function getRNG(type) { - if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { - clearBuffer(stream, state); - } + function construct(bits, arr, radix, size) { + var i = 0, + len, + str = "", + parsedInt; - if (sync) { - /**/ - asyncWrite(afterWrite, stream, state, finished, cb); - /**/ - } else { - afterWrite(stream, state, finished, cb); - } - } -} + if (arr) { + len = arr.length - 1; + } -function afterWrite(stream, state, finished, cb) { - if (!finished) onwriteDrain(stream, state); - state.pendingcb--; - cb(); - finishMaybe(stream, state); -} + while (i < len || (str.length < bits)) { + // convert any negative nums to positive with Math.abs() + parsedInt = Math.abs(parseInt(arr[i], radix)); + str = str + padLeft(parsedInt.toString(2), size); + i++; + } -// Must force callback to be called on nextTick, so that we don't -// emit 'drain' before the write() consumer gets the 'false' return -// value, and has a chance to attach a 'drain' listener. -function onwriteDrain(stream, state) { - if (state.length === 0 && state.needDrain) { - state.needDrain = false; - stream.emit('drain'); - } -} + str = str.substr(-bits); -// if there's something in the buffer waiting, then process it -function clearBuffer(stream, state) { - state.bufferProcessing = true; - var entry = state.bufferedRequest; + // return null so this result can be re-processed if the result is all 0's. + if ((str.match(/0/g) || []).length === str.length) { + return null; + } - if (stream._writev && entry && entry.next) { - // Fast case, write everything using _writev() - var l = state.bufferedRequestCount; - var buffer = new Array(l); - var holder = state.corkedRequestsFree; - holder.entry = entry; + return str; + } - var count = 0; - var allBuffers = true; - while (entry) { - buffer[count] = entry; - if (!entry.isBuf) allBuffers = false; - entry = entry.next; - count += 1; - } - buffer.allBuffers = allBuffers; + // Node.js : crypto.randomBytes() + // Note : Node.js and crypto.randomBytes() uses the OpenSSL RAND_bytes() function for its CSPRNG. + // Node.js will need to have been compiled with OpenSSL for this to work. + // See : https://github.com/joyent/node/blob/d8baf8a2a4481940bfed0196308ae6189ca18eee/src/node_crypto.cc#L4696 + // See : https://www.openssl.org/docs/crypto/rand.html + function nodeCryptoRandomBytes(bits) { + var buf, + bytes, + radix, + size, + str = null; - doWrite(stream, state, true, state.length, buffer, '', holder.finish); + radix = 16; + size = 4; + bytes = Math.ceil(bits / 8); - // doWrite is almost always async, defer these to save a bit of time - // as the hot path ends with doWrite - state.pendingcb++; - state.lastBufferedRequest = null; - if (holder.next) { - state.corkedRequestsFree = holder.next; - holder.next = null; - } else { - state.corkedRequestsFree = new CorkedRequest(state); - } - state.bufferedRequestCount = 0; - } else { - // Slow case, write chunks one-by-one - while (entry) { - var chunk = entry.chunk; - var encoding = entry.encoding; - var cb = entry.callback; - var len = state.objectMode ? 1 : chunk.length; + while (str === null) { + buf = crypto.randomBytes(bytes); + str = construct(bits, buf.toString("hex"), radix, size); + } - doWrite(stream, state, false, len, chunk, encoding, cb); - entry = entry.next; - state.bufferedRequestCount--; - // if we didn't call the onwrite immediately, then - // it means that we need to wait until it does. - // also, that means that the chunk and cb are currently - // being processed, so move the buffer counter past them. - if (state.writing) { - break; - } - } + return str; + } - if (entry === null) state.lastBufferedRequest = null; - } + // Browser : window.crypto.getRandomValues() + // See : https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-Crypto + // See : https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues + // Supported Browsers : http://caniuse.com/#search=crypto.getRandomValues + function browserCryptoGetRandomValues(bits) { + var elems, + radix, + size, + str = null; - state.bufferedRequest = entry; - state.bufferProcessing = false; -} + radix = 10; + size = 32; + elems = Math.ceil(bits / 32); + while (str === null) { + str = construct(bits, window.crypto.getRandomValues(new Uint32Array(elems)), radix, size); + } -Writable.prototype._write = function (chunk, encoding, cb) { - cb(new Error('_write() is not implemented')); -}; + return str; + } -Writable.prototype._writev = null; + // Browser SJCL : If the Stanford Javascript Crypto Library (SJCL) is loaded in the browser + // then use it as a fallback CSPRNG when window.crypto.getRandomValues() is not available. + // It may require some time and mouse movements to be fully seeded. Uses a modified version + // of the Fortuna RNG. + // See : https://bitwiseshiftleft.github.io/sjcl/ + function browserSJCLRandom(bits) { + var elems, + radix, + size, + str = null; -Writable.prototype.end = function (chunk, encoding, cb) { - var state = this._writableState; + radix = 10; + size = 32; + elems = Math.ceil(bits / 32); - if (typeof chunk === 'function') { - cb = chunk; - chunk = null; - encoding = null; - } else if (typeof encoding === 'function') { - cb = encoding; - encoding = null; - } + if(sjcl.random.isReady(sjclParanoia)) { + str = construct(bits, sjcl.random.randomWords(elems, sjclParanoia), radix, size); + } else { + throw new Error("SJCL isn't finished seeding the RNG yet."); + } - if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); + return str; + } - // .end() fully uncorks - if (state.corked) { - state.corked = 1; - this.uncork(); - } + // ///////////////////////////////////////////////////////////// + // WARNING : DO NOT USE. For testing purposes only. + // ///////////////////////////////////////////////////////////// + // This function will return repeatable non-random test bits. Can be used + // for testing only. Node.js does not return proper random bytes + // when run within a PhantomJS container. + function testRandom(bits) { + var arr, + elems, + int, + radix, + size, + str = null; - // ignore unnecessary end() calls. - if (!state.ending && !state.finished) endWritable(this, state, cb); -}; + radix = 10; + size = 32; + elems = Math.ceil(bits / 32); + int = 123456789; + arr = new Uint32Array(elems); -function needFinish(state) { - return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; -} -function callFinal(stream, state) { - stream._final(function (err) { - state.pendingcb--; - if (err) { - stream.emit('error', err); - } - state.prefinished = true; - stream.emit('prefinish'); - finishMaybe(stream, state); - }); -} -function prefinish(stream, state) { - if (!state.prefinished && !state.finalCalled) { - if (typeof stream._final === 'function') { - state.pendingcb++; - state.finalCalled = true; - pna.nextTick(callFinal, stream, state); - } else { - state.prefinished = true; - stream.emit('prefinish'); - } - } -} + // Fill every element of the Uint32Array with the same int. + for (var i = 0; i < arr.length; i++) { + arr[i] = int; + } -function finishMaybe(stream, state) { - var need = needFinish(state); - if (need) { - prefinish(stream, state); - if (state.pendingcb === 0) { - state.finished = true; - stream.emit('finish'); - } - } - return need; -} + while (str === null) { + str = construct(bits, arr, radix, size); + } -function endWritable(stream, state, cb) { - state.ending = true; - finishMaybe(stream, state); - if (cb) { - if (state.finished) pna.nextTick(cb);else stream.once('finish', cb); - } - state.ended = true; - stream.writable = false; -} + return str; + } -function onCorkedFinish(corkReq, state, err) { - var entry = corkReq.entry; - corkReq.entry = null; - while (entry) { - var cb = entry.callback; - state.pendingcb--; - cb(err); - entry = entry.next; - } - if (state.corkedRequestsFree) { - state.corkedRequestsFree.next = corkReq; - } else { - state.corkedRequestsFree = corkReq; - } -} + // Return a random generator function for browsers that support HTML5 + // window.crypto.getRandomValues(), Node.js compiled with OpenSSL support. + // or the Stanford Javascript Crypto Library Fortuna RNG. + // WARNING : NEVER use testRandom outside of a testing context. Totally non-random! + if (type && type === "testRandom") { + config.typeCSPRNG = type; + return testRandom; + } else if (type && type === "nodeCryptoRandomBytes") { + config.typeCSPRNG = type; + return nodeCryptoRandomBytes; + } else if (type && type === "browserCryptoGetRandomValues") { + config.typeCSPRNG = type; + return browserCryptoGetRandomValues; + } else if (type && type === "browserSJCLRandom") { + runCSPRNGTest = false; + config.typeCSPRNG = type; + return browserSJCLRandom; + } else if (typeof crypto === "object" && typeof crypto.randomBytes === "function") { + config.typeCSPRNG = "nodeCryptoRandomBytes"; + return nodeCryptoRandomBytes; + } else if (window && window.crypto && (typeof window.crypto.getRandomValues === "function" || typeof window.crypto.getRandomValues === "object") && (typeof Uint32Array === "function" || typeof Uint32Array === "object")) { + config.typeCSPRNG = "browserCryptoGetRandomValues"; + return browserCryptoGetRandomValues; + } else if (window && window.sjcl && typeof window.sjcl === "object" && typeof window.sjcl.random === "object") { + runCSPRNGTest = false; + config.typeCSPRNG = "browserSJCLRandom"; + return browserSJCLRandom; + } -Object.defineProperty(Writable.prototype, 'destroyed', { - get: function () { - if (this._writableState === undefined) { - return false; - } - return this._writableState.destroyed; - }, - set: function (value) { - // we ignore the value if the stream - // has not been initialized yet - if (!this._writableState) { - return; } - // backward compatibility, the user is explicitly - // managing destroyed - this._writableState.destroyed = value; - } -}); - -Writable.prototype.destroy = destroyImpl.destroy; -Writable.prototype._undestroy = destroyImpl.undestroy; -Writable.prototype._destroy = function (err, cb) { - this.end(); - cb(err); -}; -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) -},{"./_stream_duplex":265,"./internal/streams/destroy":271,"./internal/streams/stream":272,"_process":253,"core-util-is":157,"inherits":230,"process-nextick-args":252,"safe-buffer":273,"timers":300,"util-deprecate":327}],270:[function(require,module,exports){ -'use strict'; + // Splits a number string `bits`-length segments, after first + // optionally zero-padding it to a length that is a multiple of `padLength. + // Returns array of integers (each less than 2^bits-1), with each element + // representing a `bits`-length segment of the input string from right to left, + // i.e. parts[0] represents the right-most `bits`-length segment of the input string. + function splitNumStringToIntArray(str, padLength) { + var parts = [], + i; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + if (padLength) { + str = padLeft(str, padLength); + } -var Buffer = require('safe-buffer').Buffer; -var util = require('util'); + for (i = str.length; i > config.bits; i -= config.bits) { + parts.push(parseInt(str.slice(i - config.bits, i), 2)); + } -function copyBuffer(src, target, offset) { - src.copy(target, offset); -} + parts.push(parseInt(str.slice(0, i), 2)); -module.exports = function () { - function BufferList() { - _classCallCheck(this, BufferList); + return parts; + } - this.head = null; - this.tail = null; - this.length = 0; - } + // Polynomial evaluation at `x` using Horner's Method + // NOTE: fx=fx * x + coeff[i] -> exp(log(fx) + log(x)) + coeff[i], + // so if fx===0, just set fx to coeff[i] because + // using the exp/log form will result in incorrect value + function horner(x, coeffs) { + var logx = config.logs[x], + fx = 0, + i; - BufferList.prototype.push = function push(v) { - var entry = { data: v, next: null }; - if (this.length > 0) this.tail.next = entry;else this.head = entry; - this.tail = entry; - ++this.length; - }; + for (i = coeffs.length - 1; i >= 0; i--) { + if (fx !== 0) { + fx = config.exps[(logx + config.logs[fx]) % config.maxShares] ^ coeffs[i]; + } else { + fx = coeffs[i]; + } + } - BufferList.prototype.unshift = function unshift(v) { - var entry = { data: v, next: this.head }; - if (this.length === 0) this.tail = entry; - this.head = entry; - ++this.length; - }; + return fx; + } - BufferList.prototype.shift = function shift() { - if (this.length === 0) return; - var ret = this.head.data; - if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; - --this.length; - return ret; - }; + // Evaluate the Lagrange interpolation polynomial at x = `at` + // using x and y Arrays that are of the same length, with + // corresponding elements constituting points on the polynomial. + function lagrange(at, x, y) { + var sum = 0, + len, + product, + i, + j; - BufferList.prototype.clear = function clear() { - this.head = this.tail = null; - this.length = 0; - }; + for (i = 0, len = x.length; i < len; i++) { + if (y[i]) { - BufferList.prototype.join = function join(s) { - if (this.length === 0) return ''; - var p = this.head; - var ret = '' + p.data; - while (p = p.next) { - ret += s + p.data; - }return ret; - }; + product = config.logs[y[i]]; - BufferList.prototype.concat = function concat(n) { - if (this.length === 0) return Buffer.alloc(0); - if (this.length === 1) return this.head.data; - var ret = Buffer.allocUnsafe(n >>> 0); - var p = this.head; - var i = 0; - while (p) { - copyBuffer(p.data, ret, i); - i += p.data.length; - p = p.next; - } - return ret; - }; + for (j = 0; j < len; j++) { + if (i !== j) { + if (at === x[j]) { // happens when computing a share that is in the list of shares used to compute it + product = -1; // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1 + break; + } + product = (product + config.logs[at ^ x[j]] - config.logs[x[i] ^ x[j]] + config.maxShares) % config.maxShares; // to make sure it's not negative + } + } - return BufferList; -}(); + // though exps[-1]= undefined and undefined ^ anything = anything in + // chrome, this behavior may not hold everywhere, so do the check + sum = product === -1 ? sum : sum ^ config.exps[product]; + } -if (util && util.inspect && util.inspect.custom) { - module.exports.prototype[util.inspect.custom] = function () { - var obj = util.inspect({ length: this.length }); - return this.constructor.name + ' ' + obj; - }; -} -},{"safe-buffer":273,"util":105}],271:[function(require,module,exports){ -'use strict'; + } -/**/ + return sum; + } -var pna = require('process-nextick-args'); -/**/ + // This is the basic polynomial generation and evaluation function + // for a `config.bits`-length secret (NOT an arbitrary length) + // Note: no error-checking at this stage! If `secret` is NOT + // a NUMBER less than 2^bits-1, the output will be incorrect! + function getShares(secret, numShares, threshold) { + var shares = [], + coeffs = [secret], + i, + len; -// undocumented cb() API, needed for core, not for public API -function destroy(err, cb) { - var _this = this; + for (i = 1; i < threshold; i++) { + coeffs[i] = parseInt(config.rng(config.bits), 2); + } - var readableDestroyed = this._readableState && this._readableState.destroyed; - var writableDestroyed = this._writableState && this._writableState.destroyed; + for (i = 1, len = numShares + 1; i < len; i++) { + shares[i - 1] = { + x: i, + y: horner(i, coeffs) + }; + } - if (readableDestroyed || writableDestroyed) { - if (cb) { - cb(err); - } else if (err && (!this._writableState || !this._writableState.errorEmitted)) { - pna.nextTick(emitErrorNT, this, err); + return shares; } - return this; - } - // we set destroyed to true before firing error callbacks in order - // to make it re-entrance safe in case destroy() is called within callbacks + function constructPublicShareString(bits, id, data) { + var bitsBase36, + idHex, + idMax, + idPaddingLen, + newShareString; - if (this._readableState) { - this._readableState.destroyed = true; - } + id = parseInt(id, config.radix); + bits = parseInt(bits, 10) || config.bits; + bitsBase36 = bits.toString(36).toUpperCase(); + idMax = Math.pow(2, bits) - 1; + idPaddingLen = idMax.toString(config.radix).length; + idHex = padLeft(id.toString(config.radix), idPaddingLen); - // if this is a duplex stream mark the writable part as destroyed as well - if (this._writableState) { - this._writableState.destroyed = true; - } + if (typeof id !== "number" || id % 1 !== 0 || id < 1 || id > idMax) { + throw new Error("Share id must be an integer between 1 and " + idMax + ", inclusive."); + } - this._destroy(err || null, function (err) { - if (!cb && err) { - pna.nextTick(emitErrorNT, _this, err); - if (_this._writableState) { - _this._writableState.errorEmitted = true; - } - } else if (cb) { - cb(err); + newShareString = bitsBase36 + idHex + data; + + return newShareString; } - }); - return this; -} + // EXPORTED FUNCTIONS + // ////////////////// -function undestroy() { - if (this._readableState) { - this._readableState.destroyed = false; - this._readableState.reading = false; - this._readableState.ended = false; - this._readableState.endEmitted = false; - } + var secrets = { - if (this._writableState) { - this._writableState.destroyed = false; - this._writableState.ended = false; - this._writableState.ending = false; - this._writableState.finished = false; - this._writableState.errorEmitted = false; - } -} + init: function (bits, rngType) { + var logs = [], + exps = [], + x = 1, + primitive, + i; -function emitErrorNT(self, err) { - self.emit('error', err); -} + // reset all config back to initial state + reset(); -module.exports = { - destroy: destroy, - undestroy: undestroy -}; -},{"process-nextick-args":252}],272:[function(require,module,exports){ -arguments[4][147][0].apply(exports,arguments) -},{"dup":147,"events":195}],273:[function(require,module,exports){ -/* eslint-disable node/no-deprecated-api */ -var buffer = require('buffer') -var Buffer = buffer.Buffer + if (bits && (typeof bits !== "number" || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) { + throw new Error("Number of bits must be an integer between " + defaults.minBits + " and " + defaults.maxBits + ", inclusive."); + } -// alternative to using Object.keys for old browsers -function copyProps (src, dst) { - for (var key in src) { - dst[key] = src[key] - } -} -if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - module.exports = buffer -} else { - // Copy properties from require('buffer') - copyProps(buffer, exports) - exports.Buffer = SafeBuffer -} + if (rngType && CSPRNGTypes.indexOf(rngType) === -1) { + throw new Error("Invalid RNG type argument : '" + rngType + "'"); + } -function SafeBuffer (arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length) -} + config.radix = defaults.radix; + config.bits = bits || defaults.bits; + config.size = Math.pow(2, config.bits); + config.maxShares = config.size - 1; -// Copy static methods from Buffer -copyProps(Buffer, SafeBuffer) + // Construct the exp and log tables for multiplication. + primitive = defaults.primitivePolynomials[config.bits]; -SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === 'number') { - throw new TypeError('Argument must not be a number') - } - return Buffer(arg, encodingOrOffset, length) -} + for (i = 0; i < config.size; i++) { + exps[i] = x; + logs[x] = i; + x = x << 1; // Left shift assignment + if (x >= config.size) { + x = x ^ primitive; // Bitwise XOR assignment + x = x & config.maxShares; // Bitwise AND assignment + } + } -SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - var buf = Buffer(size) - if (fill !== undefined) { - if (typeof encoding === 'string') { - buf.fill(fill, encoding) - } else { - buf.fill(fill) - } - } else { - buf.fill(0) - } - return buf -} + config.logs = logs; + config.exps = exps; -SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return Buffer(size) -} + if (rngType) { + this.setRNG(rngType); + } -SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return buffer.SlowBuffer(size) -} + if (!isSetRNG()) { + this.setRNG(); + } -},{"buffer":155}],274:[function(require,module,exports){ -arguments[4][149][0].apply(exports,arguments) -},{"dup":149,"safe-buffer":273}],275:[function(require,module,exports){ -module.exports = require('./readable').PassThrough + // Setup SJCL and start collecting entropy from mouse movements + if (config.typeCSPRNG === "browserSJCLRandom") { + /*eslint-disable new-cap */ + sjcl.random = new sjcl.prng(sjclParanoia); + /*eslint-enable new-cap */ + sjcl.random.startCollectors(); + } -},{"./readable":276}],276:[function(require,module,exports){ -exports = module.exports = require('./lib/_stream_readable.js'); -exports.Stream = exports; -exports.Readable = exports; -exports.Writable = require('./lib/_stream_writable.js'); -exports.Duplex = require('./lib/_stream_duplex.js'); -exports.Transform = require('./lib/_stream_transform.js'); -exports.PassThrough = require('./lib/_stream_passthrough.js'); + if (!isSetRNG() || !config.bits || !config.size || !config.maxShares || !config.logs || !config.exps || config.logs.length !== config.size || config.exps.length !== config.size) { + throw new Error("Initialization failed."); + } -},{"./lib/_stream_duplex.js":265,"./lib/_stream_passthrough.js":266,"./lib/_stream_readable.js":267,"./lib/_stream_transform.js":268,"./lib/_stream_writable.js":269}],277:[function(require,module,exports){ -module.exports = require('./readable').Transform + }, -},{"./readable":276}],278:[function(require,module,exports){ -module.exports = require('./lib/_stream_writable.js'); + // Evaluates the Lagrange interpolation polynomial at x=`at` for + // individual config.bits-length segments of each share in the `shares` + // Array. Each share is expressed in base `inputRadix`. The output + // is expressed in base `outputRadix'. + combine: function (shares, at) { + var i, + idx, + j, + len, + len2, + result = "", + setBits, + share, + splitShare, + x = [], + y = []; -},{"./lib/_stream_writable.js":269}],279:[function(require,module,exports){ -'use strict' -var Buffer = require('buffer').Buffer -var inherits = require('inherits') -var HashBase = require('hash-base') + at = at || 0; -var ARRAY16 = new Array(16) + for (i = 0, len = shares.length; i < len; i++) { + share = this.extractShareComponents(shares[i]); -var zl = [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, - 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, - 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, - 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 -] + // All shares must have the same bits settings. + if (setBits === undefined) { + setBits = share.bits; + } else if (share.bits !== setBits) { + throw new Error("Mismatched shares: Different bit settings."); + } -var zr = [ - 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, - 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, - 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, - 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, - 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 -] + // Reset everything to the bit settings of the shares. + if (config.bits !== setBits) { + this.init(setBits); + } -var sl = [ - 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, - 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, - 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, - 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, - 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 -] + // Check if this share.id is already in the Array + // and proceed if it is not found. + if (x.indexOf(share.id) === -1) { + idx = x.push(share.id) - 1; + splitShare = splitNumStringToIntArray(hex2bin(share.data)); -var sr = [ - 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, - 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, - 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, - 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, - 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 -] + for (j = 0, len2 = splitShare.length; j < len2; j++) { + y[j] = y[j] || []; + y[j][idx] = splitShare[j]; + } + } -var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e] -var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000] + } -function RIPEMD160 () { - HashBase.call(this, 64) + for (i = 0, len = y.length; i < len; i++) { + result = padLeft(lagrange(at, x, y[i]).toString(2)) + result; + } - // state - this._a = 0x67452301 - this._b = 0xefcdab89 - this._c = 0x98badcfe - this._d = 0x10325476 - this._e = 0xc3d2e1f0 -} + // reconstructing the secret + if (at === 0) { + //find the first 1 + idx = result.indexOf("1"); + return bin2hex(result.slice(idx + 1)); + } -inherits(RIPEMD160, HashBase) + return bin2hex(result); + }, -RIPEMD160.prototype._update = function () { - var words = ARRAY16 - for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4) + getConfig: function () { + var obj = {}; + obj.radix = config.radix; + obj.bits = config.bits; + obj.maxShares = config.maxShares; + obj.hasCSPRNG = isSetRNG(); + obj.typeCSPRNG = config.typeCSPRNG; + return obj; + }, - var al = this._a | 0 - var bl = this._b | 0 - var cl = this._c | 0 - var dl = this._d | 0 - var el = this._e | 0 + // Given a public share, extract the bits (Integer), share ID (Integer), and share data (Hex) + // and return an Object containing those components. + extractShareComponents: function (share) { + var bits, + id, + idLen, + max, + obj = {}, + regexStr, + shareComponents; - var ar = this._a | 0 - var br = this._b | 0 - var cr = this._c | 0 - var dr = this._d | 0 - var er = this._e | 0 + // Extract the first char which represents the bits in Base 36 + bits = parseInt(share.substr(0, 1), 36); - // computation - for (var i = 0; i < 80; i += 1) { - var tl - var tr - if (i < 16) { - tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]) - tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]) - } else if (i < 32) { - tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]) - tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]) - } else if (i < 48) { - tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]) - tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]) - } else if (i < 64) { - tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]) - tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]) - } else { // if (i<80) { - tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]) - tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]) - } + if (bits && (typeof bits !== "number" || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) { + throw new Error("Invalid share : Number of bits must be an integer between " + defaults.minBits + " and " + defaults.maxBits + ", inclusive."); + } - al = el - el = dl - dl = rotl(cl, 10) - cl = bl - bl = tl + // calc the max shares allowed for given bits + max = Math.pow(2, bits) - 1; - ar = er - er = dr - dr = rotl(cr, 10) - cr = br - br = tr - } + // Determine the ID length which is variable and based on the bit count. + idLen = (Math.pow(2, bits) - 1).toString(config.radix).length; - // update state - var t = (this._b + cl + dr) | 0 - this._b = (this._c + dl + er) | 0 - this._c = (this._d + el + ar) | 0 - this._d = (this._e + al + br) | 0 - this._e = (this._a + bl + cr) | 0 - this._a = t -} + // Extract all the parts now that the segment sizes are known. + regexStr = "^([a-kA-K3-9]{1})([a-fA-F0-9]{" + idLen + "})([a-fA-F0-9]+)$"; + shareComponents = new RegExp(regexStr).exec(share); -RIPEMD160.prototype._digest = function () { - // create padding and handle blocks - this._block[this._blockOffset++] = 0x80 - if (this._blockOffset > 56) { - this._block.fill(0, this._blockOffset, 64) - this._update() - this._blockOffset = 0 - } + // The ID is a Hex number and needs to be converted to an Integer + if (shareComponents) { + id = parseInt(shareComponents[2], config.radix); + } - this._block.fill(0, this._blockOffset, 56) - this._block.writeUInt32LE(this._length[0], 56) - this._block.writeUInt32LE(this._length[1], 60) - this._update() + if (typeof id !== "number" || id % 1 !== 0 || id < 1 || id > max) { + throw new Error("Invalid share : Share id must be an integer between 1 and " + config.maxShares + ", inclusive."); + } - // produce result - var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20) - buffer.writeInt32LE(this._a, 0) - buffer.writeInt32LE(this._b, 4) - buffer.writeInt32LE(this._c, 8) - buffer.writeInt32LE(this._d, 12) - buffer.writeInt32LE(this._e, 16) - return buffer -} + if (shareComponents && shareComponents[3]) { + obj.bits = bits; + obj.id = id; + obj.data = shareComponents[3]; + return obj; + } -function rotl (x, n) { - return (x << n) | (x >>> (32 - n)) -} + throw new Error("The share data provided is invalid : " + share); -function fn1 (a, b, c, d, e, m, k, s) { - return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0 -} + }, -function fn2 (a, b, c, d, e, m, k, s) { - return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0 -} + // Set the PRNG to use. If no RNG function is supplied, pick a default using getRNG() + setRNG: function (rng) { -function fn3 (a, b, c, d, e, m, k, s) { - return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0 -} + var errPrefix = "Random number generator is invalid ", + errSuffix = " Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's."; -function fn4 (a, b, c, d, e, m, k, s) { - return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0 -} + if (rng && typeof rng === "string" && CSPRNGTypes.indexOf(rng) === -1) { + throw new Error("Invalid RNG type argument : '" + rng + "'"); + } -function fn5 (a, b, c, d, e, m, k, s) { - return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0 -} + // If RNG was not specified at all, + // try to pick one appropriate for this env. + if (!rng) { + rng = getRNG(); + } -module.exports = RIPEMD160 + // If `rng` is a string, try to forcibly + // set the RNG to the type specified. + if (rng && typeof rng === "string") { + rng = getRNG(rng); + } + + if (runCSPRNGTest) { -},{"buffer":155,"hash-base":199,"inherits":230}],280:[function(require,module,exports){ -/*! safe-buffer. MIT License. Feross Aboukhadijeh */ -/* eslint-disable node/no-deprecated-api */ -var buffer = require('buffer') -var Buffer = buffer.Buffer + if (rng && typeof rng !== "function") { + throw new Error(errPrefix + "(Not a function)." + errSuffix); + } -// alternative to using Object.keys for old browsers -function copyProps (src, dst) { - for (var key in src) { - dst[key] = src[key] - } -} -if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - module.exports = buffer -} else { - // Copy properties from require('buffer') - copyProps(buffer, exports) - exports.Buffer = SafeBuffer -} + if (rng && typeof rng(config.bits) !== "string") { + throw new Error(errPrefix + "(Output is not a string)." + errSuffix); + } -function SafeBuffer (arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length) -} + if (rng && !parseInt(rng(config.bits), 2)) { + throw new Error(errPrefix + "(Binary string output not parseable to an Integer)." + errSuffix); + } -SafeBuffer.prototype = Object.create(Buffer.prototype) + if (rng && rng(config.bits).length > config.bits) { + throw new Error(errPrefix + "(Output length is greater than config.bits)." + errSuffix); + } -// Copy static methods from Buffer -copyProps(Buffer, SafeBuffer) + if (rng && rng(config.bits).length < config.bits) { + throw new Error(errPrefix + "(Output length is less than config.bits)." + errSuffix); + } -SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === 'number') { - throw new TypeError('Argument must not be a number') - } - return Buffer(arg, encodingOrOffset, length) -} + } -SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - var buf = Buffer(size) - if (fill !== undefined) { - if (typeof encoding === 'string') { - buf.fill(fill, encoding) - } else { - buf.fill(fill) - } - } else { - buf.fill(0) - } - return buf -} + config.rng = rng; -SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return Buffer(size) -} + return true; + }, -SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return buffer.SlowBuffer(size) -} + // Converts a given UTF16 character string to the HEX representation. + // Each character of the input string is represented by + // `bytesPerChar` bytes in the output string which defaults to 2. + str2hex: function (str, bytesPerChar) { + var hexChars, + max, + out = "", + neededBytes, + num, + i, + len; -},{"buffer":155}],281:[function(require,module,exports){ -(function (process){ -/* eslint-disable node/no-deprecated-api */ + if (typeof str !== "string") { + throw new Error("Input must be a character string."); + } -'use strict' + if (!bytesPerChar) { + bytesPerChar = defaults.bytesPerChar; + } -var buffer = require('buffer') -var Buffer = buffer.Buffer + if (typeof bytesPerChar !== "number" || bytesPerChar < 1 || bytesPerChar > defaults.maxBytesPerChar || bytesPerChar % 1 !== 0) { + throw new Error("Bytes per character must be an integer between 1 and " + defaults.maxBytesPerChar + ", inclusive."); + } -var safer = {} + hexChars = 2 * bytesPerChar; + max = Math.pow(16, hexChars) - 1; -var key + for (i = 0, len = str.length; i < len; i++) { + num = str[i].charCodeAt(); -for (key in buffer) { - if (!buffer.hasOwnProperty(key)) continue - if (key === 'SlowBuffer' || key === 'Buffer') continue - safer[key] = buffer[key] -} + if (isNaN(num)) { + throw new Error("Invalid character: " + str[i]); + } -var Safer = safer.Buffer = {} -for (key in Buffer) { - if (!Buffer.hasOwnProperty(key)) continue - if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue - Safer[key] = Buffer[key] -} + if (num > max) { + neededBytes = Math.ceil(Math.log(num + 1) / Math.log(256)); + throw new Error("Invalid character code (" + num + "). Maximum allowable is 256^bytes-1 (" + max + "). To convert this character, use at least " + neededBytes + " bytes."); + } -safer.Buffer.prototype = Buffer.prototype + out = padLeft(num.toString(16), hexChars) + out; + } + return out; + }, -if (!Safer.from || Safer.from === Uint8Array.from) { - Safer.from = function (value, encodingOrOffset, length) { - if (typeof value === 'number') { - throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value) - } - if (value && typeof value.length === 'undefined') { - throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value) - } - return Buffer(value, encodingOrOffset, length) - } -} + // Converts a given HEX number string to a UTF16 character string. + hex2str: function (str, bytesPerChar) { + var hexChars, + out = "", + i, + len; -if (!Safer.alloc) { - Safer.alloc = function (size, fill, encoding) { - if (typeof size !== 'number') { - throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size) - } - if (size < 0 || size >= 2 * (1 << 30)) { - throw new RangeError('The value "' + size + '" is invalid for option "size"') - } - var buf = Buffer(size) - if (!fill || fill.length === 0) { - buf.fill(0) - } else if (typeof encoding === 'string') { - buf.fill(fill, encoding) - } else { - buf.fill(fill) - } - return buf - } -} + if (typeof str !== "string") { + throw new Error("Input must be a hexadecimal string."); + } + bytesPerChar = bytesPerChar || defaults.bytesPerChar; -if (!safer.kStringMaxLength) { - try { - safer.kStringMaxLength = process.binding('buffer').kStringMaxLength - } catch (e) { - // we can't determine kStringMaxLength in environments where process.binding - // is unsupported, so let's not set it - } -} + if (typeof bytesPerChar !== "number" || bytesPerChar % 1 !== 0 || bytesPerChar < 1 || bytesPerChar > defaults.maxBytesPerChar) { + throw new Error("Bytes per character must be an integer between 1 and " + defaults.maxBytesPerChar + ", inclusive."); + } -if (!safer.constants) { - safer.constants = { - MAX_LENGTH: safer.kMaxLength - } - if (safer.kStringMaxLength) { - safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength - } -} + hexChars = 2 * bytesPerChar; -module.exports = safer + str = padLeft(str, hexChars); -}).call(this,require('_process')) -},{"_process":253,"buffer":155}],282:[function(require,module,exports){ -(function (setImmediate){ -"use strict"; + for (i = 0, len = str.length; i < len; i += hexChars) { + out = String.fromCharCode(parseInt(str.slice(i, i + hexChars), 16)) + out; + } -(function(root) { - const MAX_VALUE = 0x7fffffff; + return out; + }, - // The SHA256 and PBKDF2 implementation are from scrypt-async-js: - // See: https://github.com/dchest/scrypt-async-js - function SHA256(m) { - const K = new Uint32Array([ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, - 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, - 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, - 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, - 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, - 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, - 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, - 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, - 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, - 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - ]); + // Generates a random bits-length number string using the PRNG + random: function (bits) { - let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a; - let h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19; - const w = new Uint32Array(64); + if (typeof bits !== "number" || bits % 1 !== 0 || bits < 2 || bits > 65536) { + throw new Error("Number of bits must be an Integer between 1 and 65536."); + } - function blocks(p) { - let off = 0, len = p.length; - while (len >= 64) { - let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, u, i, j, t1, t2; + if (config.typeCSPRNG === "browserSJCLRandom" && sjcl.random.isReady(sjclParanoia) < 1) { + throw new Error("SJCL isn't finished seeding the RNG yet. Needs new entropy added or more mouse movement."); + } - for (i = 0; i < 16; i++) { - j = off + i*4; - w[i] = ((p[j] & 0xff)<<24) | ((p[j+1] & 0xff)<<16) | - ((p[j+2] & 0xff)<<8) | (p[j+3] & 0xff); - } + return bin2hex(config.rng(bits)); + }, - for (i = 16; i < 64; i++) { - u = w[i-2]; - t1 = ((u>>>17) | (u<<(32-17))) ^ ((u>>>19) | (u<<(32-19))) ^ (u>>>10); + // Divides a `secret` number String str expressed in radix `inputRadix` (optional, default 16) + // into `numShares` shares, each expressed in radix `outputRadix` (optional, default to `inputRadix`), + // requiring `threshold` number of shares to reconstruct the secret. + // Optionally, zero-pads the secret to a length that is a multiple of padLength before sharing. + share: function (secret, numShares, threshold, padLength) { + var neededBits, + subShares, + x = new Array(numShares), + y = new Array(numShares), + i, + j, + len; - u = w[i-15]; - t2 = ((u>>>7) | (u<<(32-7))) ^ ((u>>>18) | (u<<(32-18))) ^ (u>>>3); + // Security: + // For additional security, pad in multiples of 128 bits by default. + // A small trade-off in larger share size to help prevent leakage of information + // about small-ish secrets and increase the difficulty of attacking them. + padLength = padLength || 128; - w[i] = (((t1 + w[i-7]) | 0) + ((t2 + w[i-16]) | 0)) | 0; - } + if (typeof secret !== "string") { + throw new Error("Secret must be a string."); + } - for (i = 0; i < 64; i++) { - t1 = ((((((e>>>6) | (e<<(32-6))) ^ ((e>>>11) | (e<<(32-11))) ^ - ((e>>>25) | (e<<(32-25)))) + ((e & f) ^ (~e & g))) | 0) + - ((h + ((K[i] + w[i]) | 0)) | 0)) | 0; + if (typeof numShares !== "number" || numShares % 1 !== 0 || numShares < 2) { + throw new Error("Number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive."); + } - t2 = ((((a>>>2) | (a<<(32-2))) ^ ((a>>>13) | (a<<(32-13))) ^ - ((a>>>22) | (a<<(32-22)))) + ((a & b) ^ (a & c) ^ (b & c))) | 0; + if (numShares > config.maxShares) { + neededBits = Math.ceil(Math.log(numShares + 1) / Math.LN2); + throw new Error("Number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive. To create " + numShares + " shares, use at least " + neededBits + " bits."); + } - h = g; - g = f; - f = e; - e = (d + t1) | 0; - d = c; - c = b; - b = a; - a = (t1 + t2) | 0; - } + if (typeof threshold !== "number" || threshold % 1 !== 0 || threshold < 2) { + throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive."); + } - h0 = (h0 + a) | 0; - h1 = (h1 + b) | 0; - h2 = (h2 + c) | 0; - h3 = (h3 + d) | 0; - h4 = (h4 + e) | 0; - h5 = (h5 + f) | 0; - h6 = (h6 + g) | 0; - h7 = (h7 + h) | 0; + if (threshold > config.maxShares) { + neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2); + throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive. To use a threshold of " + threshold + ", use at least " + neededBits + " bits."); + } - off += 64; - len -= 64; + if (threshold > numShares) { + throw new Error("Threshold number of shares was " + threshold + " but must be less than or equal to the " + numShares + " shares specified as the total to generate."); } - } - blocks(m); + if (typeof padLength !== "number" || padLength % 1 !== 0 || padLength < 0 || padLength > 1024) { + throw new Error("Zero-pad length must be an integer between 0 and 1024 inclusive."); + } - let i, bytesLeft = m.length % 64, - bitLenHi = (m.length / 0x20000000) | 0, - bitLenLo = m.length << 3, - numZeros = (bytesLeft < 56) ? 56 : 120, - p = m.slice(m.length - bytesLeft, m.length); + secret = "1" + hex2bin(secret); // append a 1 so that we can preserve the correct number of leading zeros in our secret + secret = splitNumStringToIntArray(secret, padLength); - p.push(0x80); - for (i = bytesLeft + 1; i < numZeros; i++) { p.push(0); } - p.push((bitLenHi >>> 24) & 0xff); - p.push((bitLenHi >>> 16) & 0xff); - p.push((bitLenHi >>> 8) & 0xff); - p.push((bitLenHi >>> 0) & 0xff); - p.push((bitLenLo >>> 24) & 0xff); - p.push((bitLenLo >>> 16) & 0xff); - p.push((bitLenLo >>> 8) & 0xff); - p.push((bitLenLo >>> 0) & 0xff); + for (i = 0, len = secret.length; i < len; i++) { + subShares = getShares(secret[i], numShares, threshold); + for (j = 0; j < numShares; j++) { + x[j] = x[j] || subShares[j].x.toString(config.radix); + y[j] = padLeft(subShares[j].y.toString(2)) + (y[j] || ""); + } + } - blocks(p); + for (i = 0; i < numShares; i++) { + x[i] = constructPublicShareString(config.bits, x[i], bin2hex(y[i])); + } - return [ - (h0 >>> 24) & 0xff, (h0 >>> 16) & 0xff, (h0 >>> 8) & 0xff, (h0 >>> 0) & 0xff, - (h1 >>> 24) & 0xff, (h1 >>> 16) & 0xff, (h1 >>> 8) & 0xff, (h1 >>> 0) & 0xff, - (h2 >>> 24) & 0xff, (h2 >>> 16) & 0xff, (h2 >>> 8) & 0xff, (h2 >>> 0) & 0xff, - (h3 >>> 24) & 0xff, (h3 >>> 16) & 0xff, (h3 >>> 8) & 0xff, (h3 >>> 0) & 0xff, - (h4 >>> 24) & 0xff, (h4 >>> 16) & 0xff, (h4 >>> 8) & 0xff, (h4 >>> 0) & 0xff, - (h5 >>> 24) & 0xff, (h5 >>> 16) & 0xff, (h5 >>> 8) & 0xff, (h5 >>> 0) & 0xff, - (h6 >>> 24) & 0xff, (h6 >>> 16) & 0xff, (h6 >>> 8) & 0xff, (h6 >>> 0) & 0xff, - (h7 >>> 24) & 0xff, (h7 >>> 16) & 0xff, (h7 >>> 8) & 0xff, (h7 >>> 0) & 0xff - ]; - } + return x; + }, - function PBKDF2_HMAC_SHA256_OneIter(password, salt, dkLen) { - // compress password if it's longer than hash block length - password = (password.length <= 64) ? password : SHA256(password); + // Generate a new share with id `id` (a number between 1 and 2^bits-1) + // `id` can be a Number or a String in the default radix (16) + newShare: function (id, shares) { + var share; - const innerLen = 64 + salt.length + 4; - const inner = new Array(innerLen); - const outerKey = new Array(64); + if (id && typeof id === "string") { + id = parseInt(id, config.radix); + } - let i; - let dk = []; + if (id && shares && shares[0]) { + share = this.extractShareComponents(shares[0]); + return constructPublicShareString(share.bits, id, this.combine(shares, id)); + } - // inner = (password ^ ipad) || salt || counter - for (i = 0; i < 64; i++) { inner[i] = 0x36; } - for (i = 0; i < password.length; i++) { inner[i] ^= password[i]; } - for (i = 0; i < salt.length; i++) { inner[64 + i] = salt[i]; } - for (i = innerLen - 4; i < innerLen; i++) { inner[i] = 0; } + throw new Error("Invalid 'id' or 'shares' Array argument to newShare()."); + }, - // outerKey = password ^ opad - for (i = 0; i < 64; i++) outerKey[i] = 0x5c; - for (i = 0; i < password.length; i++) outerKey[i] ^= password[i]; + /* test-code */ + // export private functions so they can be unit tested directly. + _reset: reset, + _padLeft: padLeft, + _hex2bin: hex2bin, + _bin2hex: bin2hex, + _getRNG: getRNG, + _isSetRNG: isSetRNG, + _splitNumStringToIntArray: splitNumStringToIntArray, + _horner: horner, + _lagrange: lagrange, + _getShares: getShares, + _constructPublicShareString: constructPublicShareString + /* end-test-code */ - // increments counter inside inner - function incrementCounter() { - for (let i = innerLen - 1; i >= innerLen - 4; i--) { - inner[i]++; - if (inner[i] <= 0xff) return; - inner[i] = 0; - } - } + }; - // output blocks = SHA256(outerKey || SHA256(inner)) ... - while (dkLen >= 32) { - incrementCounter(); - dk = dk.concat(SHA256(outerKey.concat(SHA256(inner)))); - dkLen -= 32; - } - if (dkLen > 0) { - incrementCounter(); - dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))).slice(0, dkLen)); - } + // Always initialize secrets with default settings. + secrets.init(); - return dk; - } + return secrets; - // The following is an adaptation of scryptsy - // See: https://www.npmjs.com/package/scryptsy - function blockmix_salsa8(BY, Yi, r, x, _X) { - let i; +})); - arraycopy(BY, (2 * r - 1) * 16, _X, 0, 16); - for (i = 0; i < 2 * r; i++) { - blockxor(BY, i * 16, _X, 16); - salsa20_8(_X, x); - arraycopy(_X, 0, BY, Yi + (i * 16), 16); - } +},{"crypto":258}],471:[function(require,module,exports){ +'use strict'; - for (i = 0; i < r; i++) { - arraycopy(BY, Yi + (i * 2) * 16, BY, (i * 16), 16); - } +var GetIntrinsic = require('get-intrinsic'); +var define = require('define-data-property'); +var hasDescriptors = require('has-property-descriptors')(); +var gOPD = require('gopd'); - for (i = 0; i < r; i++) { - arraycopy(BY, Yi + (i * 2 + 1) * 16, BY, (i + r) * 16, 16); - } - } +var $TypeError = require('es-errors/type'); +var $floor = GetIntrinsic('%Math.floor%'); - function R(a, b) { - return (a << b) | (a >>> (32 - b)); - } +/** @type {import('.')} */ +module.exports = function setFunctionLength(fn, length) { + if (typeof fn !== 'function') { + throw new $TypeError('`fn` is not a function'); + } + if (typeof length !== 'number' || length < 0 || length > 0xFFFFFFFF || $floor(length) !== length) { + throw new $TypeError('`length` must be a positive 32-bit integer'); + } - function salsa20_8(B, x) { - arraycopy(B, 0, x, 0, 16); + var loose = arguments.length > 2 && !!arguments[2]; - for (let i = 8; i > 0; i -= 2) { - x[ 4] ^= R(x[ 0] + x[12], 7); - x[ 8] ^= R(x[ 4] + x[ 0], 9); - x[12] ^= R(x[ 8] + x[ 4], 13); - x[ 0] ^= R(x[12] + x[ 8], 18); - x[ 9] ^= R(x[ 5] + x[ 1], 7); - x[13] ^= R(x[ 9] + x[ 5], 9); - x[ 1] ^= R(x[13] + x[ 9], 13); - x[ 5] ^= R(x[ 1] + x[13], 18); - x[14] ^= R(x[10] + x[ 6], 7); - x[ 2] ^= R(x[14] + x[10], 9); - x[ 6] ^= R(x[ 2] + x[14], 13); - x[10] ^= R(x[ 6] + x[ 2], 18); - x[ 3] ^= R(x[15] + x[11], 7); - x[ 7] ^= R(x[ 3] + x[15], 9); - x[11] ^= R(x[ 7] + x[ 3], 13); - x[15] ^= R(x[11] + x[ 7], 18); - x[ 1] ^= R(x[ 0] + x[ 3], 7); - x[ 2] ^= R(x[ 1] + x[ 0], 9); - x[ 3] ^= R(x[ 2] + x[ 1], 13); - x[ 0] ^= R(x[ 3] + x[ 2], 18); - x[ 6] ^= R(x[ 5] + x[ 4], 7); - x[ 7] ^= R(x[ 6] + x[ 5], 9); - x[ 4] ^= R(x[ 7] + x[ 6], 13); - x[ 5] ^= R(x[ 4] + x[ 7], 18); - x[11] ^= R(x[10] + x[ 9], 7); - x[ 8] ^= R(x[11] + x[10], 9); - x[ 9] ^= R(x[ 8] + x[11], 13); - x[10] ^= R(x[ 9] + x[ 8], 18); - x[12] ^= R(x[15] + x[14], 7); - x[13] ^= R(x[12] + x[15], 9); - x[14] ^= R(x[13] + x[12], 13); - x[15] ^= R(x[14] + x[13], 18); - } + var functionLengthIsConfigurable = true; + var functionLengthIsWritable = true; + if ('length' in fn && gOPD) { + var desc = gOPD(fn, 'length'); + if (desc && !desc.configurable) { + functionLengthIsConfigurable = false; + } + if (desc && !desc.writable) { + functionLengthIsWritable = false; + } + } - for (let i = 0; i < 16; ++i) { - B[i] += x[i]; - } - } + if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) { + if (hasDescriptors) { + define(/** @type {Parameters[0]} */ (fn), 'length', length, true, true); + } else { + define(/** @type {Parameters[0]} */ (fn), 'length', length); + } + } + return fn; +}; - // naive approach... going back to loop unrolling may yield additional performance - function blockxor(S, Si, D, len) { - for (let i = 0; i < len; i++) { - D[i] ^= S[Si + i] - } - } +},{"define-data-property":259,"es-errors/type":302,"get-intrinsic":310,"gopd":312,"has-property-descriptors":313}],472:[function(require,module,exports){ +var Buffer = require('safe-buffer').Buffer - function arraycopy(src, srcPos, dest, destPos, length) { - while (length--) { - dest[destPos++] = src[srcPos++]; - } - } +// prototype class for hash functions +function Hash (blockSize, finalSize) { + this._block = Buffer.alloc(blockSize) + this._finalSize = finalSize + this._blockSize = blockSize + this._len = 0 +} - function checkBufferish(o) { - if (!o || typeof(o.length) !== 'number') { return false; } +Hash.prototype.update = function (data, enc) { + if (typeof data === 'string') { + enc = enc || 'utf8' + data = Buffer.from(data, enc) + } - for (let i = 0; i < o.length; i++) { - const v = o[i]; - if (typeof(v) !== 'number' || v % 1 || v < 0 || v >= 256) { - return false; - } - } + var block = this._block + var blockSize = this._blockSize + var length = data.length + var accum = this._len - return true; - } + for (var offset = 0; offset < length;) { + var assigned = accum % blockSize + var remainder = Math.min(length - offset, blockSize - assigned) - function ensureInteger(value, name) { - if (typeof(value) !== "number" || (value % 1)) { throw new Error('invalid ' + name); } - return value; + for (var i = 0; i < remainder; i++) { + block[assigned + i] = data[offset + i] } - // N = Cpu cost, r = Memory cost, p = parallelization cost - // callback(error, progress, key) - function _scrypt(password, salt, N, r, p, dkLen, callback) { - - N = ensureInteger(N, 'N'); - r = ensureInteger(r, 'r'); - p = ensureInteger(p, 'p'); + accum += remainder + offset += remainder - dkLen = ensureInteger(dkLen, 'dkLen'); + if ((accum % blockSize) === 0) { + this._update(block) + } + } - if (N === 0 || (N & (N - 1)) !== 0) { throw new Error('N must be power of 2'); } + this._len += length + return this +} - if (N > MAX_VALUE / 128 / r) { throw new Error('N too large'); } - if (r > MAX_VALUE / 128 / p) { throw new Error('r too large'); } +Hash.prototype.digest = function (enc) { + var rem = this._len % this._blockSize - if (!checkBufferish(password)) { - throw new Error('password must be an array or buffer'); - } - password = Array.prototype.slice.call(password); + this._block[rem] = 0x80 - if (!checkBufferish(salt)) { - throw new Error('salt must be an array or buffer'); - } - salt = Array.prototype.slice.call(salt); + // zero (rem + 1) trailing bits, where (rem + 1) is the smallest + // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize + this._block.fill(0, rem + 1) - let b = PBKDF2_HMAC_SHA256_OneIter(password, salt, p * 128 * r); - const B = new Uint32Array(p * 32 * r) - for (let i = 0; i < B.length; i++) { - const j = i * 4; - B[i] = ((b[j + 3] & 0xff) << 24) | - ((b[j + 2] & 0xff) << 16) | - ((b[j + 1] & 0xff) << 8) | - ((b[j + 0] & 0xff) << 0); - } + if (rem >= this._finalSize) { + this._update(this._block) + this._block.fill(0) + } - const XY = new Uint32Array(64 * r); - const V = new Uint32Array(32 * r * N); + var bits = this._len * 8 - const Yi = 32 * r; + // uint32 + if (bits <= 0xffffffff) { + this._block.writeUInt32BE(bits, this._blockSize - 4) - // scratch space - const x = new Uint32Array(16); // salsa20_8 - const _X = new Uint32Array(16); // blockmix_salsa8 + // uint64 + } else { + var lowBits = (bits & 0xffffffff) >>> 0 + var highBits = (bits - lowBits) / 0x100000000 - const totalOps = p * N * 2; - let currentOp = 0; - let lastPercent10 = null; + this._block.writeUInt32BE(highBits, this._blockSize - 8) + this._block.writeUInt32BE(lowBits, this._blockSize - 4) + } - // Set this to true to abandon the scrypt on the next step - let stop = false; + this._update(this._block) + var hash = this._hash() - // State information - let state = 0; - let i0 = 0, i1; - let Bi; + return enc ? hash.toString(enc) : hash +} - // How many blockmix_salsa8 can we do per step? - const limit = callback ? parseInt(1000 / r): 0xffffffff; +Hash.prototype._update = function () { + throw new Error('_update must be implemented by subclass') +} - // Trick from scrypt-async; if there is a setImmediate shim in place, use it - const nextTick = (typeof(setImmediate) !== 'undefined') ? setImmediate : setTimeout; +module.exports = Hash - // This is really all I changed; making scryptsy a state machine so we occasionally - // stop and give other evnts on the evnt loop a chance to run. ~RicMoo - const incrementalSMix = function() { - if (stop) { - return callback(new Error('cancelled'), currentOp / totalOps); - } +},{"safe-buffer":463}],473:[function(require,module,exports){ +var exports = module.exports = function SHA (algorithm) { + algorithm = algorithm.toLowerCase() - let steps; + var Algorithm = exports[algorithm] + if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)') - switch (state) { - case 0: - // for (var i = 0; i < p; i++)... - Bi = i0 * 32 * r; + return new Algorithm() +} - arraycopy(B, Bi, XY, 0, Yi); // ROMix - 1 +exports.sha = require('./sha') +exports.sha1 = require('./sha1') +exports.sha224 = require('./sha224') +exports.sha256 = require('./sha256') +exports.sha384 = require('./sha384') +exports.sha512 = require('./sha512') - state = 1; // Move to ROMix 2 - i1 = 0; +},{"./sha":474,"./sha1":475,"./sha224":476,"./sha256":477,"./sha384":478,"./sha512":479}],474:[function(require,module,exports){ +/* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined + * in FIPS PUB 180-1 + * This source code is derived from sha1.js of the same repository. + * The difference between SHA-0 and SHA-1 is just a bitwise rotate left + * operation was added. + */ - // Fall through +var inherits = require('inherits') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer - case 1: +var K = [ + 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 +] - // Run up to 1000 steps of the first inner smix loop - steps = N - i1; - if (steps > limit) { steps = limit; } - for (let i = 0; i < steps; i++) { // ROMix - 2 - arraycopy(XY, 0, V, (i1 + i) * Yi, Yi) // ROMix - 3 - blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 4 - } +var W = new Array(80) - // for (var i = 0; i < N; i++) - i1 += steps; - currentOp += steps; +function Sha () { + this.init() + this._w = W - if (callback) { - // Call the callback with the progress (optionally stopping us) - const percent10 = parseInt(1000 * currentOp / totalOps); - if (percent10 !== lastPercent10) { - stop = callback(null, currentOp / totalOps); - if (stop) { break; } - lastPercent10 = percent10; - } - } + Hash.call(this, 64, 56) +} - if (i1 < N) { break; } +inherits(Sha, Hash) - i1 = 0; // Move to ROMix 6 - state = 2; +Sha.prototype.init = function () { + this._a = 0x67452301 + this._b = 0xefcdab89 + this._c = 0x98badcfe + this._d = 0x10325476 + this._e = 0xc3d2e1f0 - // Fall through + return this +} - case 2: +function rotl5 (num) { + return (num << 5) | (num >>> 27) +} - // Run up to 1000 steps of the second inner smix loop - steps = N - i1; - if (steps > limit) { steps = limit; } - for (let i = 0; i < steps; i++) { // ROMix - 6 - const offset = (2 * r - 1) * 16; // ROMix - 7 - const j = XY[offset] & (N - 1); - blockxor(V, j * Yi, XY, Yi); // ROMix - 8 (inner) - blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 9 (outer) - } +function rotl30 (num) { + return (num << 30) | (num >>> 2) +} - // for (var i = 0; i < N; i++)... - i1 += steps; - currentOp += steps; +function ft (s, b, c, d) { + if (s === 0) return (b & c) | ((~b) & d) + if (s === 2) return (b & c) | (b & d) | (c & d) + return b ^ c ^ d +} - // Call the callback with the progress (optionally stopping us) - if (callback) { - const percent10 = parseInt(1000 * currentOp / totalOps); - if (percent10 !== lastPercent10) { - stop = callback(null, currentOp / totalOps); - if (stop) { break; } - lastPercent10 = percent10; - } - } +Sha.prototype._update = function (M) { + var W = this._w - if (i1 < N) { break; } + var a = this._a | 0 + var b = this._b | 0 + var c = this._c | 0 + var d = this._d | 0 + var e = this._e | 0 - arraycopy(XY, 0, B, Bi, Yi); // ROMix - 10 + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) + for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16] - // for (var i = 0; i < p; i++)... - i0++; - if (i0 < p) { - state = 0; - break; - } + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20) + var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 - b = []; - for (let i = 0; i < B.length; i++) { - b.push((B[i] >> 0) & 0xff); - b.push((B[i] >> 8) & 0xff); - b.push((B[i] >> 16) & 0xff); - b.push((B[i] >> 24) & 0xff); - } + e = d + d = c + c = rotl30(b) + b = a + a = t + } - const derivedKey = PBKDF2_HMAC_SHA256_OneIter(password, b, dkLen); + this._a = (a + this._a) | 0 + this._b = (b + this._b) | 0 + this._c = (c + this._c) | 0 + this._d = (d + this._d) | 0 + this._e = (e + this._e) | 0 +} - // Send the result to the callback - if (callback) { callback(null, 1.0, derivedKey); } +Sha.prototype._hash = function () { + var H = Buffer.allocUnsafe(20) - // Done; don't break (which would reschedule) - return derivedKey; - } + H.writeInt32BE(this._a | 0, 0) + H.writeInt32BE(this._b | 0, 4) + H.writeInt32BE(this._c | 0, 8) + H.writeInt32BE(this._d | 0, 12) + H.writeInt32BE(this._e | 0, 16) - // Schedule the next steps - if (callback) { nextTick(incrementalSMix); } - } + return H +} - // Run the smix state machine until completion - if (!callback) { - while (true) { - const derivedKey = incrementalSMix(); - if (derivedKey != undefined) { return derivedKey; } - } - } +module.exports = Sha - // Bootstrap the async incremental smix - incrementalSMix(); - } +},{"./hash":472,"inherits":349,"safe-buffer":463}],475:[function(require,module,exports){ +/* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for details. + */ - const lib = { - scrypt: function(password, salt, N, r, p, dkLen, progressCallback) { - return new Promise(function(resolve, reject) { - let lastProgress = 0; - if (progressCallback) { progressCallback(0); } - _scrypt(password, salt, N, r, p, dkLen, function(error, progress, key) { - if (error) { - reject(error); - } else if (key) { - if (progressCallback && lastProgress !== 1) { - progressCallback(1); - } - resolve(new Uint8Array(key)); - } else if (progressCallback && progress !== lastProgress) { - lastProgress = progress; - return progressCallback(progress); - } - }); - }); - }, - syncScrypt: function(password, salt, N, r, p, dkLen) { - return new Uint8Array(_scrypt(password, salt, N, r, p, dkLen)); - } - }; +var inherits = require('inherits') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer - // node.js - if (typeof(exports) !== 'undefined') { - module.exports = lib; +var K = [ + 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 +] - // RequireJS/AMD - // http://www.requirejs.org/docs/api.html - // https://github.com/amdjs/amdjs-api/wiki/AMD - } else if (typeof(define) === 'function' && define.amd) { - define(lib); +var W = new Array(80) - // Web Browsers - } else if (root) { +function Sha1 () { + this.init() + this._w = W - // If there was an existing library "scrypt", make sure it is still available - if (root.scrypt) { - root._scrypt = root.scrypt; - } + Hash.call(this, 64, 56) +} - root.scrypt = lib; - } +inherits(Sha1, Hash) -})(this); +Sha1.prototype.init = function () { + this._a = 0x67452301 + this._b = 0xefcdab89 + this._c = 0x98badcfe + this._d = 0x10325476 + this._e = 0xc3d2e1f0 -}).call(this,require("timers").setImmediate) -},{"timers":300}],283:[function(require,module,exports){ -const scrypt = require('./scryptSync') -scrypt.async = require('./scrypt') -module.exports = scrypt + return this +} -},{"./scrypt":284,"./scryptSync":285}],284:[function(require,module,exports){ -const crypto = require('crypto') -const { - checkAndInit, - smix -} = require('./utils') +function rotl1 (num) { + return (num << 1) | (num >>> 31) +} -// N = Cpu cost, r = Memory cost, p = parallelization cost -async function scrypt (key, salt, N, r, p, dkLen, progressCallback, promiseInterval) { - const { - XY, - V, - B32, - x, - _X, - B, - tickCallback - } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback) +function rotl5 (num) { + return (num << 5) | (num >>> 27) +} - for (var i = 0; i < p; i++) { - await smix(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) - } +function rotl30 (num) { + return (num << 30) | (num >>> 2) +} - return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256') +function ft (s, b, c, d) { + if (s === 0) return (b & c) | ((~b) & d) + if (s === 2) return (b & c) | (b & d) | (c & d) + return b ^ c ^ d } -module.exports = scrypt +Sha1.prototype._update = function (M) { + var W = this._w -},{"./utils":286,"crypto":163}],285:[function(require,module,exports){ -const crypto = require('crypto') -const { - checkAndInit, - smixSync -} = require('./utils') + var a = this._a | 0 + var b = this._b | 0 + var c = this._c | 0 + var d = this._d | 0 + var e = this._e | 0 -// N = Cpu cost, r = Memory cost, p = parallelization cost -function scrypt (key, salt, N, r, p, dkLen, progressCallback) { - const { - XY, - V, - B32, - x, - _X, - B, - tickCallback - } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback) + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) + for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]) - for (var i = 0; i < p; i++) { - smixSync(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback) + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20) + var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 + + e = d + d = c + c = rotl30(b) + b = a + a = t } - return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256') + this._a = (a + this._a) | 0 + this._b = (b + this._b) | 0 + this._c = (c + this._c) | 0 + this._d = (d + this._d) | 0 + this._e = (e + this._e) | 0 } -module.exports = scrypt +Sha1.prototype._hash = function () { + var H = Buffer.allocUnsafe(20) -},{"./utils":286,"crypto":163}],286:[function(require,module,exports){ -(function (Buffer,setImmediate){ -const crypto = require('crypto') -const MAX_VALUE = 0x7fffffff -const DEFAULT_PROMISE_INTERVAL = 5000 -/* eslint-disable camelcase */ + H.writeInt32BE(this._a | 0, 0) + H.writeInt32BE(this._b | 0, 4) + H.writeInt32BE(this._c | 0, 8) + H.writeInt32BE(this._d | 0, 12) + H.writeInt32BE(this._e | 0, 16) -function checkAndInit (key, salt, N, r, p, dkLen, progressCallback) { - if (N === 0 || (N & (N - 1)) !== 0) throw Error('N must be > 0 and a power of 2') + return H +} - if (N > MAX_VALUE / 128 / r) throw Error('Parameter N is too large') - if (r > MAX_VALUE / 128 / p) throw Error('Parameter r is too large') +module.exports = Sha1 - let XY = Buffer.alloc(256 * r) - let V = Buffer.alloc(128 * r * N) +},{"./hash":472,"inherits":349,"safe-buffer":463}],476:[function(require,module,exports){ +/** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ - // pseudo global - let B32 = new Int32Array(16) // salsa20_8 - let x = new Int32Array(16) // salsa20_8 - let _X = Buffer.alloc(64) // blockmix_salsa8 +var inherits = require('inherits') +var Sha256 = require('./sha256') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer - // pseudo global - let B = crypto.pbkdf2Sync(key, salt, 1, p * 128 * r, 'sha256') +var W = new Array(64) - let tickCallback - if (progressCallback) { - let totalOps = p * N * 2 - let currentOp = 0 +function Sha224 () { + this.init() - tickCallback = function () { - ++currentOp + this._w = W // new Array(64) - // send progress notifications once every 1,000 ops - if (currentOp % 1000 === 0) { - progressCallback({ - current: currentOp, - total: totalOps, - percent: (currentOp / totalOps) * 100.0 - }) - } - } - } - return { - XY, - V, - B32, - x, - _X, - B, - tickCallback - } + Hash.call(this, 64, 56) } -async function smix (B, Bi, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) { - promiseInterval = promiseInterval || DEFAULT_PROMISE_INTERVAL - let Xi = 0 - let Yi = 128 * r - let i - - B.copy(XY, Xi, Bi, Bi + Yi) +inherits(Sha224, Sha256) - for (i = 0; i < N; i++) { - XY.copy(V, i * Yi, Xi, Xi + Yi) - if (i % promiseInterval === 0) { - await new Promise(resolve => setImmediate(resolve)) - } - blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) +Sha224.prototype.init = function () { + this._a = 0xc1059ed8 + this._b = 0x367cd507 + this._c = 0x3070dd17 + this._d = 0xf70e5939 + this._e = 0xffc00b31 + this._f = 0x68581511 + this._g = 0x64f98fa7 + this._h = 0xbefa4fa4 - if (tickCallback) tickCallback() - } + return this +} - for (i = 0; i < N; i++) { - let offset = Xi + (2 * r - 1) * 64 - let j = XY.readUInt32LE(offset) & (N - 1) - blockxor(V, j * Yi, XY, Xi, Yi) - if (i % promiseInterval === 0) { - await new Promise(resolve => setImmediate(resolve)) - } - blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) +Sha224.prototype._hash = function () { + var H = Buffer.allocUnsafe(28) - if (tickCallback) tickCallback() - } + H.writeInt32BE(this._a, 0) + H.writeInt32BE(this._b, 4) + H.writeInt32BE(this._c, 8) + H.writeInt32BE(this._d, 12) + H.writeInt32BE(this._e, 16) + H.writeInt32BE(this._f, 20) + H.writeInt32BE(this._g, 24) - XY.copy(B, Bi, Xi, Xi + Yi) + return H } -function smixSync (B, Bi, r, N, V, XY, _X, B32, x, tickCallback) { - let Xi = 0 - let Yi = 128 * r - let i +module.exports = Sha224 - B.copy(XY, Xi, Bi, Bi + Yi) +},{"./hash":472,"./sha256":477,"inherits":349,"safe-buffer":463}],477:[function(require,module,exports){ +/** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ - for (i = 0; i < N; i++) { - XY.copy(V, i * Yi, Xi, Xi + Yi) - blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) +var inherits = require('inherits') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer - if (tickCallback) tickCallback() - } +var K = [ + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 +] - for (i = 0; i < N; i++) { - let offset = Xi + (2 * r - 1) * 64 - let j = XY.readUInt32LE(offset) & (N - 1) - blockxor(V, j * Yi, XY, Xi, Yi) - blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x) +var W = new Array(64) - if (tickCallback) tickCallback() - } +function Sha256 () { + this.init() - XY.copy(B, Bi, Xi, Xi + Yi) + this._w = W // new Array(64) + + Hash.call(this, 64, 56) } -function blockmix_salsa8 (BY, Bi, Yi, r, _X, B32, x) { - let i +inherits(Sha256, Hash) - arraycopy(BY, Bi + (2 * r - 1) * 64, _X, 0, 64) +Sha256.prototype.init = function () { + this._a = 0x6a09e667 + this._b = 0xbb67ae85 + this._c = 0x3c6ef372 + this._d = 0xa54ff53a + this._e = 0x510e527f + this._f = 0x9b05688c + this._g = 0x1f83d9ab + this._h = 0x5be0cd19 - for (i = 0; i < 2 * r; i++) { - blockxor(BY, i * 64, _X, 0, 64) - salsa20_8(_X, B32, x) - arraycopy(_X, 0, BY, Yi + (i * 64), 64) - } + return this +} - for (i = 0; i < r; i++) { - arraycopy(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64) - } +function ch (x, y, z) { + return z ^ (x & (y ^ z)) +} - for (i = 0; i < r; i++) { - arraycopy(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64) - } +function maj (x, y, z) { + return (x & y) | (z & (x | y)) } -function R (a, b) { - return (a << b) | (a >>> (32 - b)) +function sigma0 (x) { + return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10) } -function salsa20_8 (B, B32, x) { - let i +function sigma1 (x) { + return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7) +} - for (i = 0; i < 16; i++) { - B32[i] = (B[i * 4 + 0] & 0xff) << 0 - B32[i] |= (B[i * 4 + 1] & 0xff) << 8 - B32[i] |= (B[i * 4 + 2] & 0xff) << 16 - B32[i] |= (B[i * 4 + 3] & 0xff) << 24 - // B32[i] = B.readUInt32LE(i*4) <--- this is signficantly slower even in Node.js - } +function gamma0 (x) { + return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3) +} - arraycopy(B32, 0, x, 0, 16) +function gamma1 (x) { + return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10) +} - for (i = 8; i > 0; i -= 2) { - x[4] ^= R(x[0] + x[12], 7) - x[8] ^= R(x[4] + x[0], 9) - x[12] ^= R(x[8] + x[4], 13) - x[0] ^= R(x[12] + x[8], 18) - x[9] ^= R(x[5] + x[1], 7) - x[13] ^= R(x[9] + x[5], 9) - x[1] ^= R(x[13] + x[9], 13) - x[5] ^= R(x[1] + x[13], 18) - x[14] ^= R(x[10] + x[6], 7) - x[2] ^= R(x[14] + x[10], 9) - x[6] ^= R(x[2] + x[14], 13) - x[10] ^= R(x[6] + x[2], 18) - x[3] ^= R(x[15] + x[11], 7) - x[7] ^= R(x[3] + x[15], 9) - x[11] ^= R(x[7] + x[3], 13) - x[15] ^= R(x[11] + x[7], 18) - x[1] ^= R(x[0] + x[3], 7) - x[2] ^= R(x[1] + x[0], 9) - x[3] ^= R(x[2] + x[1], 13) - x[0] ^= R(x[3] + x[2], 18) - x[6] ^= R(x[5] + x[4], 7) - x[7] ^= R(x[6] + x[5], 9) - x[4] ^= R(x[7] + x[6], 13) - x[5] ^= R(x[4] + x[7], 18) - x[11] ^= R(x[10] + x[9], 7) - x[8] ^= R(x[11] + x[10], 9) - x[9] ^= R(x[8] + x[11], 13) - x[10] ^= R(x[9] + x[8], 18) - x[12] ^= R(x[15] + x[14], 7) - x[13] ^= R(x[12] + x[15], 9) - x[14] ^= R(x[13] + x[12], 13) - x[15] ^= R(x[14] + x[13], 18) - } +Sha256.prototype._update = function (M) { + var W = this._w - for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i] + var a = this._a | 0 + var b = this._b | 0 + var c = this._c | 0 + var d = this._d | 0 + var e = this._e | 0 + var f = this._f | 0 + var g = this._g | 0 + var h = this._h | 0 - for (i = 0; i < 16; i++) { - let bi = i * 4 - B[bi + 0] = (B32[i] >> 0 & 0xff) - B[bi + 1] = (B32[i] >> 8 & 0xff) - B[bi + 2] = (B32[i] >> 16 & 0xff) - B[bi + 3] = (B32[i] >> 24 & 0xff) - // B.writeInt32LE(B32[i], i*4) //<--- this is signficantly slower even in Node.js - } -} + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) + for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0 -// naive approach... going back to loop unrolling may yield additional performance -function blockxor (S, Si, D, Di, len) { - for (let i = 0; i < len; i++) { - D[Di + i] ^= S[Si + i] - } -} + for (var j = 0; j < 64; ++j) { + var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0 + var T2 = (sigma0(a) + maj(a, b, c)) | 0 -function arraycopy (src, srcPos, dest, destPos, length) { - if (Buffer.isBuffer(src) && Buffer.isBuffer(dest)) { - src.copy(dest, destPos, srcPos, srcPos + length) - } else { - while (length--) { - dest[destPos++] = src[srcPos++] - } + h = g + g = f + f = e + e = (d + T1) | 0 + d = c + c = b + b = a + a = (T1 + T2) | 0 } + + this._a = (a + this._a) | 0 + this._b = (b + this._b) | 0 + this._c = (c + this._c) | 0 + this._d = (d + this._d) | 0 + this._e = (e + this._e) | 0 + this._f = (f + this._f) | 0 + this._g = (g + this._g) | 0 + this._h = (h + this._h) | 0 } -module.exports = { - checkAndInit, - smix, - smixSync +Sha256.prototype._hash = function () { + var H = Buffer.allocUnsafe(32) + + H.writeInt32BE(this._a, 0) + H.writeInt32BE(this._b, 4) + H.writeInt32BE(this._c, 8) + H.writeInt32BE(this._d, 12) + H.writeInt32BE(this._e, 16) + H.writeInt32BE(this._f, 20) + H.writeInt32BE(this._g, 24) + H.writeInt32BE(this._h, 28) + + return H } -}).call(this,require("buffer").Buffer,require("timers").setImmediate) -},{"buffer":155,"crypto":163,"timers":300}],287:[function(require,module,exports){ -// @preserve author Alexander Stetsyuk -// @preserve author Glenn Rempe -// @license MIT +module.exports = Sha256 -/*jslint passfail: false, bitwise: true, nomen: true, plusplus: true, todo: false, maxerr: 1000 */ -/*global define, require, module, exports, window, Uint32Array, sjcl */ +},{"./hash":472,"inherits":349,"safe-buffer":463}],478:[function(require,module,exports){ +var inherits = require('inherits') +var SHA512 = require('./sha512') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer -// eslint : http://eslint.org/docs/configuring/ -/*eslint-env node, browser, jasmine, sjcl */ -/*eslint no-underscore-dangle:0 */ +var W = new Array(160) -// UMD (Universal Module Definition) -// Uses Node, AMD or browser globals to create a module. This module creates -// a global even when AMD is used. This is useful if you have some scripts -// that are loaded by an AMD loader, but they still want access to globals. -// See : https://github.com/umdjs/umd -// See : https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js -// -(function (root, factory) { - "use strict"; +function Sha384 () { + this.init() + this._w = W - if (typeof define === "function" && define.amd) { - // AMD. Register as an anonymous module. - define([], function () { - /*eslint-disable no-return-assign */ - return (root.secrets = factory()); - /*eslint-enable no-return-assign */ - }); - } else if (typeof exports === "object") { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = factory(require("crypto")); - } else { - // Browser globals (root is window) - root.secrets = factory(root.crypto); - } -}(this, function (crypto) { - "use strict"; + Hash.call(this, 128, 112) +} - var defaults, - config, - preGenPadding, - runCSPRNGTest, - sjclParanoia, - CSPRNGTypes; +inherits(Sha384, SHA512) - function reset() { - defaults = { - bits: 8, // default number of bits - radix: 16, // work with HEX by default - minBits: 3, - maxBits: 20, // this permits 1,048,575 shares, though going this high is NOT recommended in JS! - bytesPerChar: 2, - maxBytesPerChar: 6, // Math.pow(256,7) > Math.pow(2,53) +Sha384.prototype.init = function () { + this._ah = 0xcbbb9d5d + this._bh = 0x629a292a + this._ch = 0x9159015a + this._dh = 0x152fecd8 + this._eh = 0x67332667 + this._fh = 0x8eb44a87 + this._gh = 0xdb0c2e0d + this._hh = 0x47b5481d - // Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30 - // The index of each term in the array corresponds to the n for that polynomial - // i.e. to get the polynomial for n=16, use primitivePolynomials[16] - primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39, 9, 5, 3, 33, 27, 9, 71, 39, 9, 5, 83] - }; - config = {}; - preGenPadding = new Array(1024).join("0"); // Pre-generate a string of 1024 0's for use by padLeft(). - runCSPRNGTest = true; - sjclParanoia = 10; + this._al = 0xc1059ed8 + this._bl = 0x367cd507 + this._cl = 0x3070dd17 + this._dl = 0xf70e5939 + this._el = 0xffc00b31 + this._fl = 0x68581511 + this._gl = 0x64f98fa7 + this._hl = 0xbefa4fa4 - // WARNING : Never use 'testRandom' except for testing. - CSPRNGTypes = ["nodeCryptoRandomBytes", "browserCryptoGetRandomValues", "browserSJCLRandom", "testRandom"]; - } + return this +} - function isSetRNG() { - if (config && config.rng && typeof config.rng === "function") { - return true; - } +Sha384.prototype._hash = function () { + var H = Buffer.allocUnsafe(48) - return false; - } + function writeInt64BE (h, l, offset) { + H.writeInt32BE(h, offset) + H.writeInt32BE(l, offset + 4) + } - // Pads a string `str` with zeros on the left so that its length is a multiple of `bits` - function padLeft(str, multipleOfBits) { - var missing; + writeInt64BE(this._ah, this._al, 0) + writeInt64BE(this._bh, this._bl, 8) + writeInt64BE(this._ch, this._cl, 16) + writeInt64BE(this._dh, this._dl, 24) + writeInt64BE(this._eh, this._el, 32) + writeInt64BE(this._fh, this._fl, 40) - if (multipleOfBits === 0 || multipleOfBits === 1) { - return str; - } + return H +} - if (multipleOfBits && multipleOfBits > 1024) { - throw new Error("Padding must be multiples of no larger than 1024 bits."); - } +module.exports = Sha384 - multipleOfBits = multipleOfBits || config.bits; +},{"./hash":472,"./sha512":479,"inherits":349,"safe-buffer":463}],479:[function(require,module,exports){ +var inherits = require('inherits') +var Hash = require('./hash') +var Buffer = require('safe-buffer').Buffer - if (str) { - missing = str.length % multipleOfBits; - } +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +] - if (missing) { - return (preGenPadding + str).slice(-(multipleOfBits - missing + str.length)); - } +var W = new Array(160) - return str; - } +function Sha512 () { + this.init() + this._w = W - function hex2bin(str) { - var bin = "", - num, - i; + Hash.call(this, 128, 112) +} - for (i = str.length - 1; i >= 0; i--) { - num = parseInt(str[i], 16); +inherits(Sha512, Hash) - if (isNaN(num)) { - throw new Error("Invalid hex character."); - } +Sha512.prototype.init = function () { + this._ah = 0x6a09e667 + this._bh = 0xbb67ae85 + this._ch = 0x3c6ef372 + this._dh = 0xa54ff53a + this._eh = 0x510e527f + this._fh = 0x9b05688c + this._gh = 0x1f83d9ab + this._hh = 0x5be0cd19 - bin = padLeft(num.toString(2), 4) + bin; - } - return bin; - } + this._al = 0xf3bcc908 + this._bl = 0x84caa73b + this._cl = 0xfe94f82b + this._dl = 0x5f1d36f1 + this._el = 0xade682d1 + this._fl = 0x2b3e6c1f + this._gl = 0xfb41bd6b + this._hl = 0x137e2179 - function bin2hex(str) { - var hex = "", - num, - i; + return this +} - str = padLeft(str, 4); +function Ch (x, y, z) { + return z ^ (x & (y ^ z)) +} - for (i = str.length; i >= 4; i -= 4) { - num = parseInt(str.slice(i - 4, i), 2); - if (isNaN(num)) { - throw new Error("Invalid binary character."); - } - hex = num.toString(16) + hex; - } +function maj (x, y, z) { + return (x & y) | (z & (x | y)) +} - return hex; - } +function sigma0 (x, xl) { + return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25) +} - // Returns a pseudo-random number generator of the form function(bits){} - // which should output a random string of 1's and 0's of length `bits`. - // `type` (Optional) : A string representing the CSPRNG that you want to - // force to be loaded, overriding feature detection. Can be one of: - // "nodeCryptoRandomBytes" - // "browserCryptoGetRandomValues" - // "browserSJCLRandom" - // - function getRNG(type) { +function sigma1 (x, xl) { + return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23) +} + +function Gamma0 (x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7) +} + +function Gamma0l (x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25) +} - function construct(bits, arr, radix, size) { - var i = 0, - len, - str = "", - parsedInt; +function Gamma1 (x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6) +} - if (arr) { - len = arr.length - 1; - } +function Gamma1l (x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26) +} - while (i < len || (str.length < bits)) { - // convert any negative nums to positive with Math.abs() - parsedInt = Math.abs(parseInt(arr[i], radix)); - str = str + padLeft(parsedInt.toString(2), size); - i++; - } +function getCarry (a, b) { + return (a >>> 0) < (b >>> 0) ? 1 : 0 +} - str = str.substr(-bits); +Sha512.prototype._update = function (M) { + var W = this._w - // return null so this result can be re-processed if the result is all 0's. - if ((str.match(/0/g) || []).length === str.length) { - return null; - } + var ah = this._ah | 0 + var bh = this._bh | 0 + var ch = this._ch | 0 + var dh = this._dh | 0 + var eh = this._eh | 0 + var fh = this._fh | 0 + var gh = this._gh | 0 + var hh = this._hh | 0 - return str; - } + var al = this._al | 0 + var bl = this._bl | 0 + var cl = this._cl | 0 + var dl = this._dl | 0 + var el = this._el | 0 + var fl = this._fl | 0 + var gl = this._gl | 0 + var hl = this._hl | 0 - // Node.js : crypto.randomBytes() - // Note : Node.js and crypto.randomBytes() uses the OpenSSL RAND_bytes() function for its CSPRNG. - // Node.js will need to have been compiled with OpenSSL for this to work. - // See : https://github.com/joyent/node/blob/d8baf8a2a4481940bfed0196308ae6189ca18eee/src/node_crypto.cc#L4696 - // See : https://www.openssl.org/docs/crypto/rand.html - function nodeCryptoRandomBytes(bits) { - var buf, - bytes, - radix, - size, - str = null; + for (var i = 0; i < 32; i += 2) { + W[i] = M.readInt32BE(i * 4) + W[i + 1] = M.readInt32BE(i * 4 + 4) + } + for (; i < 160; i += 2) { + var xh = W[i - 15 * 2] + var xl = W[i - 15 * 2 + 1] + var gamma0 = Gamma0(xh, xl) + var gamma0l = Gamma0l(xl, xh) - radix = 16; - size = 4; - bytes = Math.ceil(bits / 8); + xh = W[i - 2 * 2] + xl = W[i - 2 * 2 + 1] + var gamma1 = Gamma1(xh, xl) + var gamma1l = Gamma1l(xl, xh) - while (str === null) { - buf = crypto.randomBytes(bytes); - str = construct(bits, buf.toString("hex"), radix, size); - } + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var Wi7h = W[i - 7 * 2] + var Wi7l = W[i - 7 * 2 + 1] - return str; - } + var Wi16h = W[i - 16 * 2] + var Wi16l = W[i - 16 * 2 + 1] - // Browser : window.crypto.getRandomValues() - // See : https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-Crypto - // See : https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues - // Supported Browsers : http://caniuse.com/#search=crypto.getRandomValues - function browserCryptoGetRandomValues(bits) { - var elems, - radix, - size, - str = null; + var Wil = (gamma0l + Wi7l) | 0 + var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0 + Wil = (Wil + gamma1l) | 0 + Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0 + Wil = (Wil + Wi16l) | 0 + Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0 - radix = 10; - size = 32; - elems = Math.ceil(bits / 32); - while (str === null) { - str = construct(bits, window.crypto.getRandomValues(new Uint32Array(elems)), radix, size); - } + W[i] = Wih + W[i + 1] = Wil + } - return str; - } + for (var j = 0; j < 160; j += 2) { + Wih = W[j] + Wil = W[j + 1] - // Browser SJCL : If the Stanford Javascript Crypto Library (SJCL) is loaded in the browser - // then use it as a fallback CSPRNG when window.crypto.getRandomValues() is not available. - // It may require some time and mouse movements to be fully seeded. Uses a modified version - // of the Fortuna RNG. - // See : https://bitwiseshiftleft.github.io/sjcl/ - function browserSJCLRandom(bits) { - var elems, - radix, - size, - str = null; + var majh = maj(ah, bh, ch) + var majl = maj(al, bl, cl) - radix = 10; - size = 32; - elems = Math.ceil(bits / 32); + var sigma0h = sigma0(ah, al) + var sigma0l = sigma0(al, ah) + var sigma1h = sigma1(eh, el) + var sigma1l = sigma1(el, eh) - if(sjcl.random.isReady(sjclParanoia)) { - str = construct(bits, sjcl.random.randomWords(elems, sjclParanoia), radix, size); - } else { - throw new Error("SJCL isn't finished seeding the RNG yet."); - } + // t1 = h + sigma1 + ch + K[j] + W[j] + var Kih = K[j] + var Kil = K[j + 1] - return str; - } + var chh = Ch(eh, fh, gh) + var chl = Ch(el, fl, gl) - // ///////////////////////////////////////////////////////////// - // WARNING : DO NOT USE. For testing purposes only. - // ///////////////////////////////////////////////////////////// - // This function will return repeatable non-random test bits. Can be used - // for testing only. Node.js does not return proper random bytes - // when run within a PhantomJS container. - function testRandom(bits) { - var arr, - elems, - int, - radix, - size, - str = null; + var t1l = (hl + sigma1l) | 0 + var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0 + t1l = (t1l + chl) | 0 + t1h = (t1h + chh + getCarry(t1l, chl)) | 0 + t1l = (t1l + Kil) | 0 + t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0 + t1l = (t1l + Wil) | 0 + t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0 - radix = 10; - size = 32; - elems = Math.ceil(bits / 32); - int = 123456789; - arr = new Uint32Array(elems); + // t2 = sigma0 + maj + var t2l = (sigma0l + majl) | 0 + var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0 - // Fill every element of the Uint32Array with the same int. - for (var i = 0; i < arr.length; i++) { - arr[i] = int; - } + hh = gh + hl = gl + gh = fh + gl = fl + fh = eh + fl = el + el = (dl + t1l) | 0 + eh = (dh + t1h + getCarry(el, dl)) | 0 + dh = ch + dl = cl + ch = bh + cl = bl + bh = ah + bl = al + al = (t1l + t2l) | 0 + ah = (t1h + t2h + getCarry(al, t1l)) | 0 + } - while (str === null) { - str = construct(bits, arr, radix, size); - } + this._al = (this._al + al) | 0 + this._bl = (this._bl + bl) | 0 + this._cl = (this._cl + cl) | 0 + this._dl = (this._dl + dl) | 0 + this._el = (this._el + el) | 0 + this._fl = (this._fl + fl) | 0 + this._gl = (this._gl + gl) | 0 + this._hl = (this._hl + hl) | 0 - return str; - } + this._ah = (this._ah + ah + getCarry(this._al, al)) | 0 + this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0 + this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0 + this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0 + this._eh = (this._eh + eh + getCarry(this._el, el)) | 0 + this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0 + this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0 + this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0 +} - // Return a random generator function for browsers that support HTML5 - // window.crypto.getRandomValues(), Node.js compiled with OpenSSL support. - // or the Stanford Javascript Crypto Library Fortuna RNG. - // WARNING : NEVER use testRandom outside of a testing context. Totally non-random! - if (type && type === "testRandom") { - config.typeCSPRNG = type; - return testRandom; - } else if (type && type === "nodeCryptoRandomBytes") { - config.typeCSPRNG = type; - return nodeCryptoRandomBytes; - } else if (type && type === "browserCryptoGetRandomValues") { - config.typeCSPRNG = type; - return browserCryptoGetRandomValues; - } else if (type && type === "browserSJCLRandom") { - runCSPRNGTest = false; - config.typeCSPRNG = type; - return browserSJCLRandom; - } else if (typeof crypto === "object" && typeof crypto.randomBytes === "function") { - config.typeCSPRNG = "nodeCryptoRandomBytes"; - return nodeCryptoRandomBytes; - } else if (window && window.crypto && (typeof window.crypto.getRandomValues === "function" || typeof window.crypto.getRandomValues === "object") && (typeof Uint32Array === "function" || typeof Uint32Array === "object")) { - config.typeCSPRNG = "browserCryptoGetRandomValues"; - return browserCryptoGetRandomValues; - } else if (window && window.sjcl && typeof window.sjcl === "object" && typeof window.sjcl.random === "object") { - runCSPRNGTest = false; - config.typeCSPRNG = "browserSJCLRandom"; - return browserSJCLRandom; - } +Sha512.prototype._hash = function () { + var H = Buffer.allocUnsafe(64) - } + function writeInt64BE (h, l, offset) { + H.writeInt32BE(h, offset) + H.writeInt32BE(l, offset + 4) + } - // Splits a number string `bits`-length segments, after first - // optionally zero-padding it to a length that is a multiple of `padLength. - // Returns array of integers (each less than 2^bits-1), with each element - // representing a `bits`-length segment of the input string from right to left, - // i.e. parts[0] represents the right-most `bits`-length segment of the input string. - function splitNumStringToIntArray(str, padLength) { - var parts = [], - i; + writeInt64BE(this._ah, this._al, 0) + writeInt64BE(this._bh, this._bl, 8) + writeInt64BE(this._ch, this._cl, 16) + writeInt64BE(this._dh, this._dl, 24) + writeInt64BE(this._eh, this._el, 32) + writeInt64BE(this._fh, this._fl, 40) + writeInt64BE(this._gh, this._gl, 48) + writeInt64BE(this._hh, this._hl, 56) - if (padLength) { - str = padLeft(str, padLength); - } + return H +} - for (i = str.length; i > config.bits; i -= config.bits) { - parts.push(parseInt(str.slice(i - config.bits, i), 2)); - } +module.exports = Sha512 - parts.push(parseInt(str.slice(0, i), 2)); +},{"./hash":472,"inherits":349,"safe-buffer":463}],480:[function(require,module,exports){ +"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}}; +sjcl.cipher.aes=function(a){this.s[0][0][0]||this.O();var b,c,d,e,f=this.s[0][4],g=this.s[1];b=a.length;var h=1;if(4!==b&&6!==b&&8!==b)throw new sjcl.exception.invalid("invalid aes key size");this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=f[c>>>24]<<24^f[c>>16&255]<<16^f[c>>8&255]<<8^f[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:g[0][f[c>>>24]]^g[1][f[c>>16&255]]^g[2][f[c>>8&255]]^g[3][f[c& +255]]}; +sjcl.cipher.aes.prototype={encrypt:function(a){return t(this,a,0)},decrypt:function(a){return t(this,a,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var a=this.s[0],b=this.s[1],c=a[4],d=b[4],e,f,g,h=[],k=[],l,n,m,p;for(e=0;0x100>e;e++)k[(h[e]=e<<1^283*(e>>7))^e]=e;for(f=g=0;!c[f];f^=l||1,g=k[g]||1)for(m=g^g<<1^g<<2^g<<3^g<<4,m=m>>8^m&255^99,c[f]=m,d[m]=f,n=h[e=h[l=h[f]]],p=0x1010101*n^0x10001*e^0x101*l^0x1010100*f,n=0x101*h[m]^0x1010100*m,e=0;4>e;e++)a[e][f]=n=n<<24^n>>>8,b[e][m]=p=p<<24^p>>>8;for(e= +0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}}; +function t(a,b,c){if(4!==b.length)throw new sjcl.exception.invalid("invalid aes block size");var d=a.b[c],e=b[0]^d[0],f=b[c?3:1]^d[1],g=b[2]^d[2];b=b[c?1:3]^d[3];var h,k,l,n=d.length/4-2,m,p=4,r=[0,0,0,0];h=a.s[c];a=h[0];var q=h[1],v=h[2],w=h[3],x=h[4];for(m=0;m>>24]^q[f>>16&255]^v[g>>8&255]^w[b&255]^d[p],k=a[f>>>24]^q[g>>16&255]^v[b>>8&255]^w[e&255]^d[p+1],l=a[g>>>24]^q[b>>16&255]^v[e>>8&255]^w[f&255]^d[p+2],b=a[b>>>24]^q[e>>16&255]^v[f>>8&255]^w[g&255]^d[p+3],p+=4,e=h,f=k,g=l;for(m= +0;4>m;m++)r[c?3&-m:m]=x[e>>>24]<<24^x[f>>16&255]<<16^x[g>>8&255]<<8^x[b&255]^d[p++],h=e,e=f,f=g,g=b,b=h;return r} +sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.$(a.slice(b/32),32-(b&31)).slice(1);return void 0===c?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return!1;var c=0,d;for(d=0;d>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}}; +sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d>>8>>>8>>>8),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c>>g)>>>e),gn){if(!b)try{return sjcl.codec.base32hex.toBits(a)}catch(p){}throw new sjcl.exception.invalid("this isn't "+m+"!");}h>e?(h-=e,f.push(l^n>>>h),l=n<>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,f=sjcl.codec.base64.B,g=0,h;b&&(f=f.substr(0,62)+"-_");for(d=0;dh)throw new sjcl.exception.invalid("this isn't base64!");26>>e),g=h<<32-e):(e+=6,g^=h<<32-e)}e&56&&c.push(sjcl.bitArray.partial(e&56,g,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};sjcl.hash.sha256=function(a){this.b[0]||this.O();a?(this.F=a.F.slice(0),this.A=a.A.slice(0),this.l=a.l):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()}; +sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.F=this.Y.slice(0);this.A=[];this.l=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.A=sjcl.bitArray.concat(this.A,a);b=this.l;a=this.l=b+sjcl.bitArray.bitLength(a);if(0x1fffffffffffffb;c++){e=!0;for(d=2;d*d<=c;d++)if(0===c%d){e= +!1;break}e&&(8>b&&(this.Y[b]=a(Math.pow(c,.5))),this.b[b]=a(Math.pow(c,1/3)),b++)}}}; +function u(a,b){var c,d,e,f=a.F,g=a.b,h=f[0],k=f[1],l=f[2],n=f[3],m=f[4],p=f[5],r=f[6],q=f[7];for(c=0;64>c;c++)16>c?d=b[c]:(d=b[c+1&15],e=b[c+14&15],d=b[c&15]=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+b[c&15]+b[c+9&15]|0),d=d+q+(m>>>6^m>>>11^m>>>25^m<<26^m<<21^m<<7)+(r^m&(p^r))+g[c],q=r,r=p,p=m,m=n+d|0,n=l,l=k,k=h,h=d+(k&l^n&(k^l))+(k>>>2^k>>>13^k>>>22^k<<30^k<<19^k<<10)|0;f[0]=f[0]+h|0;f[1]=f[1]+k|0;f[2]=f[2]+l|0;f[3]=f[3]+n|0;f[4]=f[4]+m|0;f[5]=f[5]+p|0;f[6]=f[6]+r|0;f[7]= +f[7]+q|0} +sjcl.mode.ccm={name:"ccm",G:[],listenProgress:function(a){sjcl.mode.ccm.G.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.G.indexOf(a);-1k)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(f=2;4>f&&l>>>8*f;f++);f<15-k&&(f=15-k);c=h.clamp(c, +8*(15-f));b=sjcl.mode.ccm.V(a,b,c,d,e,f);g=sjcl.mode.ccm.C(a,g,c,b,e,f);return h.concat(g.data,g.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var f=sjcl.bitArray,g=f.bitLength(c)/8,h=f.bitLength(b),k=f.clamp(b,h-e),l=f.bitSlice(b,h-e),h=(h-e)/8;if(7>g)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(b=2;4>b&&h>>>8*b;b++);b<15-g&&(b=15-g);c=f.clamp(c,8*(15-b));k=sjcl.mode.ccm.C(a,k,c,l,e,b);a=sjcl.mode.ccm.V(a,k.data,c,d,e,b);if(!f.equal(k.tag,a))throw new sjcl.exception.corrupt("ccm: tag doesn't match"); +return k.data},na:function(a,b,c,d,e,f){var g=[],h=sjcl.bitArray,k=h.i;d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:0xffffffff>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;be||16n&&(sjcl.mode.ccm.fa(g/ +k),n+=m),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,l)}}}; +sjcl.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,d,e,f){if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("ocb iv must be 128 bits");var g,h=sjcl.mode.ocb2.S,k=sjcl.bitArray,l=k.i,n=[0,0,0,0];c=h(a.encrypt(c));var m,p=[];d=d||[];e=e||64;for(g=0;g+4e.bitLength(c)&&(h=f(h,d(h)),c=e.concat(c,[-2147483648,0,0,0]));g=f(g,c); +return a.encrypt(f(d(f(h,d(h))),g))},S:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}}; +sjcl.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var f=b.slice(0);b=sjcl.bitArray;d=d||[];a=sjcl.mode.gcm.C(!0,a,f,d,c,e||128);return b.concat(a.data,a.tag)},decrypt:function(a,b,c,d,e){var f=b.slice(0),g=sjcl.bitArray,h=g.bitLength(f);e=e||128;d=d||[];e<=h?(b=g.bitSlice(f,h-e),f=g.bitSlice(f,0,h-e)):(b=f,f=[]);a=sjcl.mode.gcm.C(!1,a,f,d,c,e);if(!g.equal(a.tag,b))throw new sjcl.exception.corrupt("gcm: tag doesn't match");return a.data},ka:function(a,b){var c,d,e,f,g,h=sjcl.bitArray.i;e=[0,0, +0,0];f=b.slice(0);for(c=0;128>c;c++){(d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,f));g=0!==(f[3]&1);for(d=3;0>>1|(f[d-1]&1)<<31;f[0]>>>=1;g&&(f[0]^=-0x1f000000)}return e},j:function(a,b,c){var d,e=c.length;b=b.slice(0);for(d=0;de&&(a=b.hash(a));for(d=0;dd||0>c)throw new sjcl.exception.invalid("invalid params to pbkdf2");"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));e=e||sjcl.misc.hmac;a=new e(a);var f,g,h,k,l=[],n=sjcl.bitArray;for(k=1;32*l.length<(d||1);k++){e=f=a.encrypt(n.concat(b,[k]));for(g=1;gg;g++)e.push(0x100000000*Math.random()|0);for(g=0;g=1<this.o&&(this.o= +f);this.P++;this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.L=new sjcl.cipher.aes(this.b);for(d=0;4>d&&(this.h[d]=this.h[d]+1|0,!this.h[d]);d++);}for(d=0;d>>1;this.c[g].update([d,this.N++,2,b,f,a.length].concat(a))}break;case "string":void 0===b&&(b=a.length);this.c[g].update([d,this.N++,3,b,f,a.length]);this.c[g].update(a);break;default:k=1}if(k)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[g]+=b;this.f+=b;h===this.u&&(this.isReady()!==this.u&&A("seeded",Math.max(this.o,this.f)),A("progress",this.getProgress()))}, +isReady:function(a){a=this.T[void 0!==a?a:this.M];return this.o&&this.o>=a?this.m[0]>this.ba&&(new Date).valueOf()>this.Z?this.J|this.I:this.I:this.f>=a?this.J|this.u:this.u},getProgress:function(a){a=this.T[a?a:this.M];return this.o>=a?1:this.f>a?1:this.f/a},startCollectors:function(){if(!this.D){this.a={loadTimeCollector:B(this,this.ma),mouseCollector:B(this,this.oa),keyboardCollector:B(this,this.la),accelerometerCollector:B(this,this.ea),touchCollector:B(this,this.qa)};if(window.addEventListener)window.addEventListener("load", +this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new sjcl.exception.bug("can't attach event"); +this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove", +this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(a,b){this.K[a][this.ga++]=b},removeEventListener:function(a,b){var c,d,e=this.K[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;cb&&(a.h[b]=a.h[b]+1|0,!a.h[b]);b++);return a.L.encrypt(a.h)} +function B(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6); +a:try{var D,E,F,G;if(G="undefined"!==typeof module&&module.exports){var H;try{H=require("crypto")}catch(a){H=null}G=E=H}if(G&&E.randomBytes)D=E.randomBytes(128),D=new Uint32Array((new Uint8Array(D)).buffer),sjcl.random.addEntropy(D,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){F=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F); +else break a;sjcl.random.addEntropy(F,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))} +sjcl.json={defaults:{v:1,iter:1E4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json,f=e.g({iv:sjcl.random.randomWords(4,0)},e.defaults),g;e.g(f,c);c=f.adata;"string"===typeof f.salt&&(f.salt=sjcl.codec.base64.toBits(f.salt));"string"===typeof f.iv&&(f.iv=sjcl.codec.base64.toBits(f.iv));if(!sjcl.mode[f.mode]||!sjcl.cipher[f.cipher]||"string"===typeof a&&100>=f.iter||64!==f.ts&&96!==f.ts&&128!==f.ts||128!==f.ks&&192!==f.ks&&0x100!==f.ks||2>f.iv.length|| +4=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&0x100!==b.ks||!b.iv||2>b.iv.length||4 exp(log(fx) + log(x)) + coeff[i], - // so if fx===0, just set fx to coeff[i] because - // using the exp/log form will result in incorrect value - function horner(x, coeffs) { - var logx = config.logs[x], - fx = 0, - i; +module.exports = Stream; - for (i = coeffs.length - 1; i >= 0; i--) { - if (fx !== 0) { - fx = config.exps[(logx + config.logs[fx]) % config.maxShares] ^ coeffs[i]; - } else { - fx = coeffs[i]; - } - } +var EE = require('events').EventEmitter; +var inherits = require('inherits'); - return fx; - } +inherits(Stream, EE); +Stream.Readable = require('readable-stream/lib/_stream_readable.js'); +Stream.Writable = require('readable-stream/lib/_stream_writable.js'); +Stream.Duplex = require('readable-stream/lib/_stream_duplex.js'); +Stream.Transform = require('readable-stream/lib/_stream_transform.js'); +Stream.PassThrough = require('readable-stream/lib/_stream_passthrough.js'); +Stream.finished = require('readable-stream/lib/internal/streams/end-of-stream.js') +Stream.pipeline = require('readable-stream/lib/internal/streams/pipeline.js') - // Evaluate the Lagrange interpolation polynomial at x = `at` - // using x and y Arrays that are of the same length, with - // corresponding elements constituting points on the polynomial. - function lagrange(at, x, y) { - var sum = 0, - len, - product, - i, - j; +// Backwards-compat with node 0.4.x +Stream.Stream = Stream; - for (i = 0, len = x.length; i < len; i++) { - if (y[i]) { - product = config.logs[y[i]]; - for (j = 0; j < len; j++) { - if (i !== j) { - if (at === x[j]) { // happens when computing a share that is in the list of shares used to compute it - product = -1; // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1 - break; - } - product = (product + config.logs[at ^ x[j]] - config.logs[x[i] ^ x[j]] + config.maxShares) % config.maxShares; // to make sure it's not negative - } - } +// old-style streams. Note that the pipe method (the only relevant +// part of this class) is overridden in the Readable class. - // though exps[-1]= undefined and undefined ^ anything = anything in - // chrome, this behavior may not hold everywhere, so do the check - sum = product === -1 ? sum : sum ^ config.exps[product]; - } +function Stream() { + EE.call(this); +} - } +Stream.prototype.pipe = function(dest, options) { + var source = this; - return sum; + function ondata(chunk) { + if (dest.writable) { + if (false === dest.write(chunk) && source.pause) { + source.pause(); + } } + } - // This is the basic polynomial generation and evaluation function - // for a `config.bits`-length secret (NOT an arbitrary length) - // Note: no error-checking at this stage! If `secret` is NOT - // a NUMBER less than 2^bits-1, the output will be incorrect! - function getShares(secret, numShares, threshold) { - var shares = [], - coeffs = [secret], - i, - len; + source.on('data', ondata); - for (i = 1; i < threshold; i++) { - coeffs[i] = parseInt(config.rng(config.bits), 2); - } + function ondrain() { + if (source.readable && source.resume) { + source.resume(); + } + } - for (i = 1, len = numShares + 1; i < len; i++) { - shares[i - 1] = { - x: i, - y: horner(i, coeffs) - }; - } + dest.on('drain', ondrain); - return shares; - } + // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + if (!dest._isStdio && (!options || options.end !== false)) { + source.on('end', onend); + source.on('close', onclose); + } - function constructPublicShareString(bits, id, data) { - var bitsBase36, - idHex, - idMax, - idPaddingLen, - newShareString; + var didOnEnd = false; + function onend() { + if (didOnEnd) return; + didOnEnd = true; - id = parseInt(id, config.radix); - bits = parseInt(bits, 10) || config.bits; - bitsBase36 = bits.toString(36).toUpperCase(); - idMax = Math.pow(2, bits) - 1; - idPaddingLen = idMax.toString(config.radix).length; - idHex = padLeft(id.toString(config.radix), idPaddingLen); + dest.end(); + } - if (typeof id !== "number" || id % 1 !== 0 || id < 1 || id > idMax) { - throw new Error("Share id must be an integer between 1 and " + idMax + ", inclusive."); - } - newShareString = bitsBase36 + idHex + data; + function onclose() { + if (didOnEnd) return; + didOnEnd = true; - return newShareString; + if (typeof dest.destroy === 'function') dest.destroy(); + } + + // don't leave dangling pipes when there are errors. + function onerror(er) { + cleanup(); + if (EE.listenerCount(this, 'error') === 0) { + throw er; // Unhandled stream error in pipe. } + } - // EXPORTED FUNCTIONS - // ////////////////// + source.on('error', onerror); + dest.on('error', onerror); - var secrets = { + // remove all the event listeners that were added. + function cleanup() { + source.removeListener('data', ondata); + dest.removeListener('drain', ondrain); - init: function (bits, rngType) { - var logs = [], - exps = [], - x = 1, - primitive, - i; + source.removeListener('end', onend); + source.removeListener('close', onclose); + + source.removeListener('error', onerror); + dest.removeListener('error', onerror); - // reset all config back to initial state - reset(); + source.removeListener('end', cleanup); + source.removeListener('close', cleanup); - if (bits && (typeof bits !== "number" || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) { - throw new Error("Number of bits must be an integer between " + defaults.minBits + " and " + defaults.maxBits + ", inclusive."); - } + dest.removeListener('close', cleanup); + } - if (rngType && CSPRNGTypes.indexOf(rngType) === -1) { - throw new Error("Invalid RNG type argument : '" + rngType + "'"); - } + source.on('end', cleanup); + source.on('close', cleanup); - config.radix = defaults.radix; - config.bits = bits || defaults.bits; - config.size = Math.pow(2, config.bits); - config.maxShares = config.size - 1; + dest.on('close', cleanup); - // Construct the exp and log tables for multiplication. - primitive = defaults.primitivePolynomials[config.bits]; + dest.emit('pipe', source); - for (i = 0; i < config.size; i++) { - exps[i] = x; - logs[x] = i; - x = x << 1; // Left shift assignment - if (x >= config.size) { - x = x ^ primitive; // Bitwise XOR assignment - x = x & config.maxShares; // Bitwise AND assignment - } - } + // Allow for unix-like usage: A.pipe(B).pipe(C) + return dest; +}; - config.logs = logs; - config.exps = exps; +},{"events":304,"inherits":349,"readable-stream/lib/_stream_duplex.js":483,"readable-stream/lib/_stream_passthrough.js":484,"readable-stream/lib/_stream_readable.js":485,"readable-stream/lib/_stream_transform.js":486,"readable-stream/lib/_stream_writable.js":487,"readable-stream/lib/internal/streams/end-of-stream.js":491,"readable-stream/lib/internal/streams/pipeline.js":493}],482:[function(require,module,exports){ +arguments[4][229][0].apply(exports,arguments) +},{"dup":229}],483:[function(require,module,exports){ +(function (process){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - if (rngType) { - this.setRNG(rngType); - } +// a duplex stream is just a stream that is both readable and writable. +// Since JS doesn't have multiple prototypal inheritance, this class +// prototypally inherits from Readable, and then parasitically from +// Writable. - if (!isSetRNG()) { - this.setRNG(); - } +'use strict'; - // Setup SJCL and start collecting entropy from mouse movements - if (config.typeCSPRNG === "browserSJCLRandom") { - /*eslint-disable new-cap */ - sjcl.random = new sjcl.prng(sjclParanoia); - /*eslint-enable new-cap */ - sjcl.random.startCollectors(); - } +/**/ +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) keys.push(key); + return keys; +}; +/**/ - if (!isSetRNG() || !config.bits || !config.size || !config.maxShares || !config.logs || !config.exps || config.logs.length !== config.size || config.exps.length !== config.size) { - throw new Error("Initialization failed."); - } +module.exports = Duplex; +var Readable = require('./_stream_readable'); +var Writable = require('./_stream_writable'); +require('inherits')(Duplex, Readable); +{ + // Allow the keys array to be GC'ed. + var keys = objectKeys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } +} +function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + this.allowHalfOpen = true; + if (options) { + if (options.readable === false) this.readable = false; + if (options.writable === false) this.writable = false; + if (options.allowHalfOpen === false) { + this.allowHalfOpen = false; + this.once('end', onend); + } + } +} +Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } +}); +Object.defineProperty(Duplex.prototype, 'writableBuffer', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } +}); +Object.defineProperty(Duplex.prototype, 'writableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } +}); - }, +// the no-half-open enforcer +function onend() { + // If the writable side ended, then we're ok. + if (this._writableState.ended) return; - // Evaluates the Lagrange interpolation polynomial at x=`at` for - // individual config.bits-length segments of each share in the `shares` - // Array. Each share is expressed in base `inputRadix`. The output - // is expressed in base `outputRadix'. - combine: function (shares, at) { - var i, - idx, - j, - len, - len2, - result = "", - setBits, - share, - splitShare, - x = [], - y = []; + // no more data can be written. + // But allow more writes to happen in this tick. + process.nextTick(onEndNT, this); +} +function onEndNT(self) { + self.end(); +} +Object.defineProperty(Duplex.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined || this._writableState === undefined) { + return false; + } + return this._readableState.destroyed && this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (this._readableState === undefined || this._writableState === undefined) { + return; + } - at = at || 0; + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + this._writableState.destroyed = value; + } +}); +}).call(this)}).call(this,require('_process')) +},{"./_stream_readable":485,"./_stream_writable":487,"_process":451,"inherits":349}],484:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - for (i = 0, len = shares.length; i < len; i++) { - share = this.extractShareComponents(shares[i]); +// a passthrough stream. +// basically just the most minimal sort of Transform stream. +// Every written chunk gets output as-is. - // All shares must have the same bits settings. - if (setBits === undefined) { - setBits = share.bits; - } else if (share.bits !== setBits) { - throw new Error("Mismatched shares: Different bit settings."); - } +'use strict'; - // Reset everything to the bit settings of the shares. - if (config.bits !== setBits) { - this.init(setBits); - } +module.exports = PassThrough; +var Transform = require('./_stream_transform'); +require('inherits')(PassThrough, Transform); +function PassThrough(options) { + if (!(this instanceof PassThrough)) return new PassThrough(options); + Transform.call(this, options); +} +PassThrough.prototype._transform = function (chunk, encoding, cb) { + cb(null, chunk); +}; +},{"./_stream_transform":486,"inherits":349}],485:[function(require,module,exports){ +(function (process,global){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - // Check if this share.id is already in the Array - // and proceed if it is not found. - if (x.indexOf(share.id) === -1) { - idx = x.push(share.id) - 1; - splitShare = splitNumStringToIntArray(hex2bin(share.data)); +'use strict'; - for (j = 0, len2 = splitShare.length; j < len2; j++) { - y[j] = y[j] || []; - y[j][idx] = splitShare[j]; - } - } +module.exports = Readable; - } +/**/ +var Duplex; +/**/ - for (i = 0, len = y.length; i < len; i++) { - result = padLeft(lagrange(at, x, y[i]).toString(2)) + result; - } +Readable.ReadableState = ReadableState; - // reconstructing the secret - if (at === 0) { - //find the first 1 - idx = result.indexOf("1"); - return bin2hex(result.slice(idx + 1)); - } +/**/ +var EE = require('events').EventEmitter; +var EElistenerCount = function EElistenerCount(emitter, type) { + return emitter.listeners(type).length; +}; +/**/ - return bin2hex(result); - }, +/**/ +var Stream = require('./internal/streams/stream'); +/**/ - getConfig: function () { - var obj = {}; - obj.radix = config.radix; - obj.bits = config.bits; - obj.maxShares = config.maxShares; - obj.hasCSPRNG = isSetRNG(); - obj.typeCSPRNG = config.typeCSPRNG; - return obj; - }, +var Buffer = require('buffer').Buffer; +var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; +function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); +} +function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; +} - // Given a public share, extract the bits (Integer), share ID (Integer), and share data (Hex) - // and return an Object containing those components. - extractShareComponents: function (share) { - var bits, - id, - idLen, - max, - obj = {}, - regexStr, - shareComponents; +/**/ +var debugUtil = require('util'); +var debug; +if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); +} else { + debug = function debug() {}; +} +/**/ - // Extract the first char which represents the bits in Base 36 - bits = parseInt(share.substr(0, 1), 36); +var BufferList = require('./internal/streams/buffer_list'); +var destroyImpl = require('./internal/streams/destroy'); +var _require = require('./internal/streams/state'), + getHighWaterMark = _require.getHighWaterMark; +var _require$codes = require('../errors').codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; - if (bits && (typeof bits !== "number" || bits % 1 !== 0 || bits < defaults.minBits || bits > defaults.maxBits)) { - throw new Error("Invalid share : Number of bits must be an integer between " + defaults.minBits + " and " + defaults.maxBits + ", inclusive."); - } +// Lazy loaded to improve the startup performance. +var StringDecoder; +var createReadableStreamAsyncIterator; +var from; +require('inherits')(Readable, Stream); +var errorOrDestroy = destroyImpl.errorOrDestroy; +var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; +function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); - // calc the max shares allowed for given bits - max = Math.pow(2, bits) - 1; + // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; +} +function ReadableState(options, stream, isDuplex) { + Duplex = Duplex || require('./_stream_duplex'); + options = options || {}; - // Determine the ID length which is variable and based on the bit count. - idLen = (Math.pow(2, bits) - 1).toString(config.radix).length; + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; - // Extract all the parts now that the segment sizes are known. - regexStr = "^([a-kA-K3-9]{1})([a-fA-F0-9]{" + idLen + "})([a-fA-F0-9]+)$"; - shareComponents = new RegExp(regexStr).exec(share); + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; - // The ID is a Hex number and needs to be converted to an Integer - if (shareComponents) { - id = parseInt(shareComponents[2], config.radix); - } + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); - if (typeof id !== "number" || id % 1 !== 0 || id < 1 || id > max) { - throw new Error("Invalid share : Share id must be an integer between 1 and " + config.maxShares + ", inclusive."); - } + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + this.buffer = new BufferList(); + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; - if (shareComponents && shareComponents[3]) { - obj.bits = bits; - obj.id = id; - obj.data = shareComponents[3]; - return obj; - } + // a flag to be able to tell if the event 'readable'/'data' is emitted + // immediately, or on a later tick. We set this to true at first, because + // any actions that shouldn't happen until "later" should generally also + // not happen before the first read call. + this.sync = true; - throw new Error("The share data provided is invalid : " + share); + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; + this.paused = true; - }, + // Should close be emitted on destroy. Defaults to true. + this.emitClose = options.emitClose !== false; - // Set the PRNG to use. If no RNG function is supplied, pick a default using getRNG() - setRNG: function (rng) { + // Should .destroy() be called after 'end' (and potentially 'finish') + this.autoDestroy = !!options.autoDestroy; - var errPrefix = "Random number generator is invalid ", - errSuffix = " Supply an CSPRNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's."; + // has it been destroyed + this.destroyed = false; - if (rng && typeof rng === "string" && CSPRNGTypes.indexOf(rng) === -1) { - throw new Error("Invalid RNG type argument : '" + rng + "'"); - } + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; - // If RNG was not specified at all, - // try to pick one appropriate for this env. - if (!rng) { - rng = getRNG(); - } + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; - // If `rng` is a string, try to forcibly - // set the RNG to the type specified. - if (rng && typeof rng === "string") { - rng = getRNG(rng); - } + // if true, a maybeReadMore has been scheduled + this.readingMore = false; + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } +} +function Readable(options) { + Duplex = Duplex || require('./_stream_duplex'); + if (!(this instanceof Readable)) return new Readable(options); - if (runCSPRNGTest) { + // Checking for a Stream.Duplex instance is faster here instead of inside + // the ReadableState constructor, at least with V8 6.5 + var isDuplex = this instanceof Duplex; + this._readableState = new ReadableState(options, this, isDuplex); - if (rng && typeof rng !== "function") { - throw new Error(errPrefix + "(Not a function)." + errSuffix); - } + // legacy + this.readable = true; + if (options) { + if (typeof options.read === 'function') this._read = options.read; + if (typeof options.destroy === 'function') this._destroy = options.destroy; + } + Stream.call(this); +} +Object.defineProperty(Readable.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined) { + return false; + } + return this._readableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._readableState) { + return; + } - if (rng && typeof rng(config.bits) !== "string") { - throw new Error(errPrefix + "(Output is not a string)." + errSuffix); - } + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + } +}); +Readable.prototype.destroy = destroyImpl.destroy; +Readable.prototype._undestroy = destroyImpl.undestroy; +Readable.prototype._destroy = function (err, cb) { + cb(err); +}; - if (rng && !parseInt(rng(config.bits), 2)) { - throw new Error(errPrefix + "(Binary string output not parseable to an Integer)." + errSuffix); - } +// Manually shove something into the read() buffer. +// This returns true if the highWaterMark has not been hit yet, +// similar to how Writable.write() returns true if you should +// write() some more. +Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + var skipChunkCheck; + if (!state.objectMode) { + if (typeof chunk === 'string') { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = Buffer.from(chunk, encoding); + encoding = ''; + } + skipChunkCheck = true; + } + } else { + skipChunkCheck = true; + } + return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); +}; - if (rng && rng(config.bits).length > config.bits) { - throw new Error(errPrefix + "(Output length is greater than config.bits)." + errSuffix); - } +// Unshift should *always* be something directly out of read() +Readable.prototype.unshift = function (chunk) { + return readableAddChunk(this, chunk, null, true, false); +}; +function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { + debug('readableAddChunk', chunk); + var state = stream._readableState; + if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else { + var er; + if (!skipChunkCheck) er = chunkInvalid(state, chunk); + if (er) { + errorOrDestroy(stream, er); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (addToFront) { + if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true); + } else if (state.ended) { + errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF()); + } else if (state.destroyed) { + return false; + } else { + state.reading = false; + if (state.decoder && !encoding) { + chunk = state.decoder.write(chunk); + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); + } else { + addChunk(stream, state, chunk, false); + } + } + } else if (!addToFront) { + state.reading = false; + maybeReadMore(stream, state); + } + } - if (rng && rng(config.bits).length < config.bits) { - throw new Error(errPrefix + "(Output length is less than config.bits)." + errSuffix); - } + // We can push more data if we are below the highWaterMark. + // Also, if we have no data yet, we can stand some more bytes. + // This is to work around cases where hwm=0, such as the repl. + return !state.ended && (state.length < state.highWaterMark || state.length === 0); +} +function addChunk(stream, state, chunk, addToFront) { + if (state.flowing && state.length === 0 && !state.sync) { + state.awaitDrain = 0; + stream.emit('data', chunk); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + if (state.needReadable) emitReadable(stream); + } + maybeReadMore(stream, state); +} +function chunkInvalid(state, chunk) { + var er; + if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk); + } + return er; +} +Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; +}; - } +// backwards compatibility. +Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; + var decoder = new StringDecoder(enc); + this._readableState.decoder = decoder; + // If setEncoding(null), decoder.encoding equals utf8 + this._readableState.encoding = this._readableState.decoder.encoding; - config.rng = rng; + // Iterate over current buffer to convert already stored Buffers: + var p = this._readableState.buffer.head; + var content = ''; + while (p !== null) { + content += decoder.write(p.data); + p = p.next; + } + this._readableState.buffer.clear(); + if (content !== '') this._readableState.buffer.push(content); + this._readableState.length = content.length; + return this; +}; - return true; - }, +// Don't raise the hwm > 1GB +var MAX_HWM = 0x40000000; +function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE. + n = MAX_HWM; + } else { + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; +} - // Converts a given UTF16 character string to the HEX representation. - // Each character of the input string is represented by - // `bytesPerChar` bytes in the output string which defaults to 2. - str2hex: function (str, bytesPerChar) { - var hexChars, - max, - out = "", - neededBytes, - num, - i, - len; +// This function is designed to be inlinable, so please take care when making +// changes to the function body. +function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; + } + // If we're asking for more than the current hwm, then raise the hwm. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n <= state.length) return n; + // Don't have enough + if (!state.ended) { + state.needReadable = true; + return 0; + } + return state.length; +} - if (typeof str !== "string") { - throw new Error("Input must be a character string."); - } +// you can override either this method, or the async _read(n) below. +Readable.prototype.read = function (n) { + debug('read', n); + n = parseInt(n, 10); + var state = this._readableState; + var nOrig = n; + if (n !== 0) state.emittedReadable = false; - if (!bytesPerChar) { - bytesPerChar = defaults.bytesPerChar; - } + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } + n = howMuchToRead(n, state); - if (typeof bytesPerChar !== "number" || bytesPerChar < 1 || bytesPerChar > defaults.maxBytesPerChar || bytesPerChar % 1 !== 0) { - throw new Error("Bytes per character must be an integer between 1 and " + defaults.maxBytesPerChar + ", inclusive."); - } + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } - hexChars = 2 * bytesPerChar; - max = Math.pow(16, hexChars) - 1; + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. - for (i = 0, len = str.length; i < len; i++) { - num = str[i].charCodeAt(); + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); - if (isNaN(num)) { - throw new Error("Invalid character: " + str[i]); - } + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); + } - if (num > max) { - neededBytes = Math.ceil(Math.log(num + 1) / Math.log(256)); - throw new Error("Invalid character code (" + num + "). Maximum allowable is 256^bytes-1 (" + max + "). To convert this character, use at least " + neededBytes + " bytes."); - } + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } else if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (!state.reading) n = howMuchToRead(nOrig, state); + } + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; + if (ret === null) { + state.needReadable = state.length <= state.highWaterMark; + n = 0; + } else { + state.length -= n; + state.awaitDrain = 0; + } + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; - out = padLeft(num.toString(16), hexChars) + out; - } - return out; - }, + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this); + } + if (ret !== null) this.emit('data', ret); + return ret; +}; +function onEofChunk(stream, state) { + debug('onEofChunk'); + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + if (state.sync) { + // if we are sync, wait until next tick to emit the data. + // Otherwise we risk emitting data in the flow() + // the readable code triggers during a read() call + emitReadable(stream); + } else { + // emit 'readable' now to make sure it gets picked up. + state.needReadable = false; + if (!state.emittedReadable) { + state.emittedReadable = true; + emitReadable_(stream); + } + } +} - // Converts a given HEX number string to a UTF16 character string. - hex2str: function (str, bytesPerChar) { - var hexChars, - out = "", - i, - len; +// Don't emit readable right away in sync mode, because this can trigger +// another read() call => stack overflow. This way, it might trigger +// a nextTick recursion warning, but that's not so bad. +function emitReadable(stream) { + var state = stream._readableState; + debug('emitReadable', state.needReadable, state.emittedReadable); + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + process.nextTick(emitReadable_, stream); + } +} +function emitReadable_(stream) { + var state = stream._readableState; + debug('emitReadable_', state.destroyed, state.length, state.ended); + if (!state.destroyed && (state.length || state.ended)) { + stream.emit('readable'); + state.emittedReadable = false; + } - if (typeof str !== "string") { - throw new Error("Input must be a hexadecimal string."); - } - bytesPerChar = bytesPerChar || defaults.bytesPerChar; + // The stream needs another readable event if + // 1. It is not flowing, as the flow mechanism will take + // care of it. + // 2. It is not ended. + // 3. It is below the highWaterMark, so we can schedule + // another readable later. + state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark; + flow(stream); +} - if (typeof bytesPerChar !== "number" || bytesPerChar % 1 !== 0 || bytesPerChar < 1 || bytesPerChar > defaults.maxBytesPerChar) { - throw new Error("Bytes per character must be an integer between 1 and " + defaults.maxBytesPerChar + ", inclusive."); - } +// at this point, the user has presumably seen the 'readable' event, +// and called read() to consume some data. that may have triggered +// in turn another _read(n) call, in which case reading = true if +// it's in progress. +// However, if we're not ended, or reading, and the length < hwm, +// then go ahead and try to read some more preemptively. +function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + process.nextTick(maybeReadMore_, stream, state); + } +} +function maybeReadMore_(stream, state) { + // Attempt to read more data if we should. + // + // The conditions for reading more data are (one of): + // - Not enough data buffered (state.length < state.highWaterMark). The loop + // is responsible for filling the buffer with enough data if such data + // is available. If highWaterMark is 0 and we are not in the flowing mode + // we should _not_ attempt to buffer any extra data. We'll get more data + // when the stream consumer calls read() instead. + // - No data in the buffer, and the stream is in flowing mode. In this mode + // the loop below is responsible for ensuring read() is called. Failing to + // call read here would abort the flow and there's no other mechanism for + // continuing the flow if the stream consumer has just subscribed to the + // 'data' event. + // + // In addition to the above conditions to keep reading data, the following + // conditions prevent the data from being read: + // - The stream has ended (state.ended). + // - There is already a pending 'read' operation (state.reading). This is a + // case where the the stream has called the implementation defined _read() + // method, but they are processing the call asynchronously and have _not_ + // called push() with new data. In this case we skip performing more + // read()s. The execution ends in this method again after the _read() ends + // up calling push() with more data. + while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { + var len = state.length; + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break; + } + state.readingMore = false; +} - hexChars = 2 * bytesPerChar; +// abstract method. to be overridden in specific implementation classes. +// call cb(er, data) where data is <= n in length. +// for virtual (non-string, non-buffer) streams, "length" is somewhat +// arbitrary, and perhaps not very meaningful. +Readable.prototype._read = function (n) { + errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()')); +}; +Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; + var endFn = doEnd ? onend : unpipe; + if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn); + dest.on('unpipe', onunpipe); + function onunpipe(readable, unpipeInfo) { + debug('onunpipe'); + if (readable === src) { + if (unpipeInfo && unpipeInfo.hasUnpiped === false) { + unpipeInfo.hasUnpiped = true; + cleanup(); + } + } + } + function onend() { + debug('onend'); + dest.end(); + } - str = padLeft(str, hexChars); + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); + var cleanedUp = false; + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', unpipe); + src.removeListener('data', ondata); + cleanedUp = true; - for (i = 0, len = str.length; i < len; i += hexChars) { - out = String.fromCharCode(parseInt(str.slice(i, i + hexChars), 16)) + out; - } + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + var ret = dest.write(chunk); + debug('dest.write', ret); + if (ret === false) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { + debug('false write response, pause', state.awaitDrain); + state.awaitDrain++; + } + src.pause(); + } + } - return out; - }, + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er); + } - // Generates a random bits-length number string using the PRNG - random: function (bits) { + // Make sure our error handler is attached before userland ones. + prependListener(dest, 'error', onerror); - if (typeof bits !== "number" || bits % 1 !== 0 || bits < 2 || bits > 65536) { - throw new Error("Number of bits must be an Integer between 1 and 65536."); - } + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } - if (config.typeCSPRNG === "browserSJCLRandom" && sjcl.random.isReady(sjclParanoia) < 1) { - throw new Error("SJCL isn't finished seeding the RNG yet. Needs new entropy added or more mouse movement."); - } + // tell the dest that it's being piped to + dest.emit('pipe', src); - return bin2hex(config.rng(bits)); - }, + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); + } + return dest; +}; +function pipeOnDrain(src) { + return function pipeOnDrainFunctionResult() { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { + state.flowing = true; + flow(src); + } + }; +} +Readable.prototype.unpipe = function (dest) { + var state = this._readableState; + var unpipeInfo = { + hasUnpiped: false + }; - // Divides a `secret` number String str expressed in radix `inputRadix` (optional, default 16) - // into `numShares` shares, each expressed in radix `outputRadix` (optional, default to `inputRadix`), - // requiring `threshold` number of shares to reconstruct the secret. - // Optionally, zero-pads the secret to a length that is a multiple of padLength before sharing. - share: function (secret, numShares, threshold, padLength) { - var neededBits, - subShares, - x = new Array(numShares), - y = new Array(numShares), - i, - j, - len; + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; - // Security: - // For additional security, pad in multiples of 128 bits by default. - // A small trade-off in larger share size to help prevent leakage of information - // about small-ish secrets and increase the difficulty of attacking them. - padLength = padLength || 128; + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; + if (!dest) dest = state.pipes; - if (typeof secret !== "string") { - throw new Error("Secret must be a string."); - } + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit('unpipe', this, unpipeInfo); + return this; + } - if (typeof numShares !== "number" || numShares % 1 !== 0 || numShares < 2) { - throw new Error("Number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive."); - } + // slow case. multiple pipe destinations. - if (numShares > config.maxShares) { - neededBits = Math.ceil(Math.log(numShares + 1) / Math.LN2); - throw new Error("Number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive. To create " + numShares + " shares, use at least " + neededBits + " bits."); - } + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + for (var i = 0; i < len; i++) dests[i].emit('unpipe', this, { + hasUnpiped: false + }); + return this; + } - if (typeof threshold !== "number" || threshold % 1 !== 0 || threshold < 2) { - throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive."); - } + // try to find the right one. + var index = indexOf(state.pipes, dest); + if (index === -1) return this; + state.pipes.splice(index, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; + dest.emit('unpipe', this, unpipeInfo); + return this; +}; - if (threshold > config.maxShares) { - neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2); - throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 (" + config.maxShares + "), inclusive. To use a threshold of " + threshold + ", use at least " + neededBits + " bits."); - } +// set up data events if they are asked for +// Ensure readable listeners eventually get something +Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + var state = this._readableState; + if (ev === 'data') { + // update readableListening so that resume() may be a no-op + // a few lines down. This is needed to support once('readable'). + state.readableListening = this.listenerCount('readable') > 0; - if (threshold > numShares) { - throw new Error("Threshold number of shares was " + threshold + " but must be less than or equal to the " + numShares + " shares specified as the total to generate."); - } + // Try start flowing on next tick if stream isn't explicitly paused + if (state.flowing !== false) this.resume(); + } else if (ev === 'readable') { + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.flowing = false; + state.emittedReadable = false; + debug('on readable', state.length, state.reading); + if (state.length) { + emitReadable(this); + } else if (!state.reading) { + process.nextTick(nReadingNextTick, this); + } + } + } + return res; +}; +Readable.prototype.addListener = Readable.prototype.on; +Readable.prototype.removeListener = function (ev, fn) { + var res = Stream.prototype.removeListener.call(this, ev, fn); + if (ev === 'readable') { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process.nextTick(updateReadableListening, this); + } + return res; +}; +Readable.prototype.removeAllListeners = function (ev) { + var res = Stream.prototype.removeAllListeners.apply(this, arguments); + if (ev === 'readable' || ev === undefined) { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process.nextTick(updateReadableListening, this); + } + return res; +}; +function updateReadableListening(self) { + var state = self._readableState; + state.readableListening = self.listenerCount('readable') > 0; + if (state.resumeScheduled && !state.paused) { + // flowing needs to be set to true now, otherwise + // the upcoming resume will not flow. + state.flowing = true; - if (typeof padLength !== "number" || padLength % 1 !== 0 || padLength < 0 || padLength > 1024) { - throw new Error("Zero-pad length must be an integer between 0 and 1024 inclusive."); - } + // crude way to check if we should resume + } else if (self.listenerCount('data') > 0) { + self.resume(); + } +} +function nReadingNextTick(self) { + debug('readable nexttick read 0'); + self.read(0); +} - secret = "1" + hex2bin(secret); // append a 1 so that we can preserve the correct number of leading zeros in our secret - secret = splitNumStringToIntArray(secret, padLength); +// pause() and resume() are remnants of the legacy readable stream API +// If the user uses them, then switch into old mode. +Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + // we flow only if there is no one listening + // for readable, but we still have to call + // resume() + state.flowing = !state.readableListening; + resume(this, state); + } + state.paused = false; + return this; +}; +function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + process.nextTick(resume_, stream, state); + } +} +function resume_(stream, state) { + debug('resume', state.reading); + if (!state.reading) { + stream.read(0); + } + state.resumeScheduled = false; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); +} +Readable.prototype.pause = function () { + debug('call pause flowing=%j', this._readableState.flowing); + if (this._readableState.flowing !== false) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + this._readableState.paused = true; + return this; +}; +function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + while (state.flowing && stream.read() !== null); +} - for (i = 0, len = secret.length; i < len; i++) { - subShares = getShares(secret[i], numShares, threshold); - for (j = 0; j < numShares; j++) { - x[j] = x[j] || subShares[j].x.toString(config.radix); - y[j] = padLeft(subShares[j].y.toString(2)) + (y[j] || ""); - } - } +// wrap an old-style stream as the async data source. +// This is *not* part of the readable stream interface. +// It is an ugly unfortunate mess of history. +Readable.prototype.wrap = function (stream) { + var _this = this; + var state = this._readableState; + var paused = false; + stream.on('end', function () { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) _this.push(chunk); + } + _this.push(null); + }); + stream.on('data', function (chunk) { + debug('wrapped data'); + if (state.decoder) chunk = state.decoder.write(chunk); - for (i = 0; i < numShares; i++) { - x[i] = constructPublicShareString(config.bits, x[i], bin2hex(y[i])); - } + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + var ret = _this.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); - return x; - }, + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === 'function') { + this[i] = function methodWrap(method) { + return function methodWrapReturnFunction() { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } - // Generate a new share with id `id` (a number between 1 and 2^bits-1) - // `id` can be a Number or a String in the default radix (16) - newShare: function (id, shares) { - var share; + // proxy certain important events. + for (var n = 0; n < kProxyEvents.length; n++) { + stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); + } - if (id && typeof id === "string") { - id = parseInt(id, config.radix); - } + // when we try to consume some more bytes, simply unpause the + // underlying stream. + this._read = function (n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; + return this; +}; +if (typeof Symbol === 'function') { + Readable.prototype[Symbol.asyncIterator] = function () { + if (createReadableStreamAsyncIterator === undefined) { + createReadableStreamAsyncIterator = require('./internal/streams/async_iterator'); + } + return createReadableStreamAsyncIterator(this); + }; +} +Object.defineProperty(Readable.prototype, 'readableHighWaterMark', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.highWaterMark; + } +}); +Object.defineProperty(Readable.prototype, 'readableBuffer', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState && this._readableState.buffer; + } +}); +Object.defineProperty(Readable.prototype, 'readableFlowing', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.flowing; + }, + set: function set(state) { + if (this._readableState) { + this._readableState.flowing = state; + } + } +}); - if (id && shares && shares[0]) { - share = this.extractShareComponents(shares[0]); - return constructPublicShareString(share.bits, id, this.combine(shares, id)); - } +// exposed for testing purposes only. +Readable._fromList = fromList; +Object.defineProperty(Readable.prototype, 'readableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.length; + } +}); - throw new Error("Invalid 'id' or 'shares' Array argument to newShare()."); - }, +// Pluck off n bytes from an array of buffers. +// Length is the combined lengths of all the buffers in the list. +// This function is designed to be inlinable, so please take care when making +// changes to the function body. +function fromList(n, state) { + // nothing buffered + if (state.length === 0) return null; + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length); + state.buffer.clear(); + } else { + // read part of list + ret = state.buffer.consume(n, state.decoder); + } + return ret; +} +function endReadable(stream) { + var state = stream._readableState; + debug('endReadable', state.endEmitted); + if (!state.endEmitted) { + state.ended = true; + process.nextTick(endReadableNT, state, stream); + } +} +function endReadableNT(state, stream) { + debug('endReadableNT', state.endEmitted, state.length); - /* test-code */ - // export private functions so they can be unit tested directly. - _reset: reset, - _padLeft: padLeft, - _hex2bin: hex2bin, - _bin2hex: bin2hex, - _getRNG: getRNG, - _isSetRNG: isSetRNG, - _splitNumStringToIntArray: splitNumStringToIntArray, - _horner: horner, - _lagrange: lagrange, - _getShares: getShares, - _constructPublicShareString: constructPublicShareString - /* end-test-code */ + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the writable side is ready for autoDestroy as well + var wState = stream._writableState; + if (!wState || wState.autoDestroy && wState.finished) { + stream.destroy(); + } + } + } +} +if (typeof Symbol === 'function') { + Readable.from = function (iterable, opts) { + if (from === undefined) { + from = require('./internal/streams/from'); + } + return from(Readable, iterable, opts); + }; +} +function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; +} +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../errors":482,"./_stream_duplex":483,"./internal/streams/async_iterator":488,"./internal/streams/buffer_list":489,"./internal/streams/destroy":490,"./internal/streams/from":492,"./internal/streams/state":494,"./internal/streams/stream":495,"_process":451,"buffer":249,"events":304,"inherits":349,"string_decoder/":496,"util":200}],486:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - }; +// a transform stream is a readable/writable stream where you do +// something with the data. Sometimes it's called a "filter", +// but that's not a great name for it, since that implies a thing where +// some bits pass through, and others are simply ignored. (That would +// be a valid example of a transform, of course.) +// +// While the output is causally related to the input, it's not a +// necessarily symmetric or synchronous transformation. For example, +// a zlib stream might take multiple plain-text writes(), and then +// emit a single compressed chunk some time in the future. +// +// Here's how this works: +// +// The Transform stream has all the aspects of the readable and writable +// stream classes. When you write(chunk), that calls _write(chunk,cb) +// internally, and returns false if there's a lot of pending writes +// buffered up. When you call read(), that calls _read(n) until +// there's enough pending readable data buffered up. +// +// In a transform stream, the written data is placed in a buffer. When +// _read(n) is called, it transforms the queued up data, calling the +// buffered _write cb's as it consumes chunks. If consuming a single +// written chunk would result in multiple output chunks, then the first +// outputted bit calls the readcb, and subsequent chunks just go into +// the read buffer, and will cause it to emit 'readable' if necessary. +// +// This way, back-pressure is actually determined by the reading side, +// since _read has to be called to start processing a new chunk. However, +// a pathological inflate type of transform can cause excessive buffering +// here. For example, imagine a stream where every byte of input is +// interpreted as an integer from 0-255, and then results in that many +// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in +// 1kb of data being output. In this case, you could write a very small +// amount of input, and end up with a very large amount of output. In +// such a pathological inflating mechanism, there'd be no way to tell +// the system to stop doing the transform. A single 4MB write could +// cause the system to run out of memory. +// +// However, even in such a pathological case, only a single written chunk +// would be consumed, and then the rest would wait (un-transformed) until +// the results of the previous transformed chunk were consumed. - // Always initialize secrets with default settings. - secrets.init(); +'use strict'; - return secrets; +module.exports = Transform; +var _require$codes = require('../errors').codes, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, + ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; +var Duplex = require('./_stream_duplex'); +require('inherits')(Transform, Duplex); +function afterTransform(er, data) { + var ts = this._transformState; + ts.transforming = false; + var cb = ts.writecb; + if (cb === null) { + return this.emit('error', new ERR_MULTIPLE_CALLBACK()); + } + ts.writechunk = null; + ts.writecb = null; + if (data != null) + // single equals check for both `null` and `undefined` + this.push(data); + cb(er); + var rs = this._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + this._read(rs.highWaterMark); + } +} +function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + Duplex.call(this, options); + this._transformState = { + afterTransform: afterTransform.bind(this), + needTransform: false, + transforming: false, + writecb: null, + writechunk: null, + writeencoding: null + }; -})); + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; -},{"crypto":163}],288:[function(require,module,exports){ -var Buffer = require('safe-buffer').Buffer + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + if (options) { + if (typeof options.transform === 'function') this._transform = options.transform; + if (typeof options.flush === 'function') this._flush = options.flush; + } -// prototype class for hash functions -function Hash (blockSize, finalSize) { - this._block = Buffer.alloc(blockSize) - this._finalSize = finalSize - this._blockSize = blockSize - this._len = 0 + // When the writable side finishes, then flush out anything remaining. + this.on('prefinish', prefinish); +} +function prefinish() { + var _this = this; + if (typeof this._flush === 'function' && !this._readableState.destroyed) { + this._flush(function (er, data) { + done(_this, er, data); + }); + } else { + done(this, null, null); + } } +Transform.prototype.push = function (chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); +}; -Hash.prototype.update = function (data, enc) { - if (typeof data === 'string') { - enc = enc || 'utf8' - data = Buffer.from(data, enc) +// This is the part where you do stuff! +// override this function in implementation classes. +// 'chunk' is an input chunk. +// +// Call `push(newChunk)` to pass along transformed output +// to the readable side. You may call 'push' zero or more times. +// +// Call `cb(err)` when you are done with this chunk. If you pass +// an error, then that'll put the hurt on the whole operation. If you +// never call cb(), then you'll never get another chunk. +Transform.prototype._transform = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()')); +}; +Transform.prototype._write = function (chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); } +}; - var block = this._block - var blockSize = this._blockSize - var length = data.length - var accum = this._len - - for (var offset = 0; offset < length;) { - var assigned = accum % blockSize - var remainder = Math.min(length - offset, blockSize - assigned) - - for (var i = 0; i < remainder; i++) { - block[assigned + i] = data[offset + i] - } - - accum += remainder - offset += remainder - - if ((accum % blockSize) === 0) { - this._update(block) - } +// Doesn't matter what the args are here. +// _transform does all the work. +// That we got here means that the readable side wants more data. +Transform.prototype._read = function (n) { + var ts = this._transformState; + if (ts.writechunk !== null && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; } +}; +Transform.prototype._destroy = function (err, cb) { + Duplex.prototype._destroy.call(this, err, function (err2) { + cb(err2); + }); +}; +function done(stream, er, data) { + if (er) return stream.emit('error', er); + if (data != null) + // single equals check for both `null` and `undefined` + stream.push(data); - this._len += length - return this + // TODO(BridgeAR): Write a test for these two error cases + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0(); + if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING(); + return stream.push(null); } +},{"../errors":482,"./_stream_duplex":483,"inherits":349}],487:[function(require,module,exports){ +(function (process,global){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. -Hash.prototype.digest = function (enc) { - var rem = this._len % this._blockSize +// A bit simpler than readable streams. +// Implement an async ._write(chunk, encoding, cb), and it'll handle all +// the drain event emission and buffering. - this._block[rem] = 0x80 +'use strict'; - // zero (rem + 1) trailing bits, where (rem + 1) is the smallest - // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize - this._block.fill(0, rem + 1) +module.exports = Writable; - if (rem >= this._finalSize) { - this._update(this._block) - this._block.fill(0) - } +/* */ +function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; + this.next = null; +} - var bits = this._len * 8 +// It seems a linked list but it is not +// there will be only 2 of these for each stream +function CorkedRequest(state) { + var _this = this; + this.next = null; + this.entry = null; + this.finish = function () { + onCorkedFinish(_this, state); + }; +} +/* */ - // uint32 - if (bits <= 0xffffffff) { - this._block.writeUInt32BE(bits, this._blockSize - 4) +/**/ +var Duplex; +/**/ - // uint64 - } else { - var lowBits = (bits & 0xffffffff) >>> 0 - var highBits = (bits - lowBits) / 0x100000000 +Writable.WritableState = WritableState; - this._block.writeUInt32BE(highBits, this._blockSize - 8) - this._block.writeUInt32BE(lowBits, this._blockSize - 4) - } +/**/ +var internalUtil = { + deprecate: require('util-deprecate') +}; +/**/ - this._update(this._block) - var hash = this._hash() +/**/ +var Stream = require('./internal/streams/stream'); +/**/ - return enc ? hash.toString(enc) : hash +var Buffer = require('buffer').Buffer; +var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; +function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); } - -Hash.prototype._update = function () { - throw new Error('_update must be implemented by subclass') +function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; } +var destroyImpl = require('./internal/streams/destroy'); +var _require = require('./internal/streams/state'), + getHighWaterMark = _require.getHighWaterMark; +var _require$codes = require('../errors').codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, + ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, + ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, + ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; +var errorOrDestroy = destroyImpl.errorOrDestroy; +require('inherits')(Writable, Stream); +function nop() {} +function WritableState(options, stream, isDuplex) { + Duplex = Duplex || require('./_stream_duplex'); + options = options || {}; -module.exports = Hash + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream, + // e.g. options.readableObjectMode vs. options.writableObjectMode, etc. + if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; -},{"safe-buffer":280}],289:[function(require,module,exports){ -var exports = module.exports = function SHA (algorithm) { - algorithm = algorithm.toLowerCase() + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; - var Algorithm = exports[algorithm] - if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)') + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); - return new Algorithm() -} + // if _final has been called + this.finalCalled = false; -exports.sha = require('./sha') -exports.sha1 = require('./sha1') -exports.sha224 = require('./sha224') -exports.sha256 = require('./sha256') -exports.sha384 = require('./sha384') -exports.sha512 = require('./sha512') + // drain event flag. + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; -},{"./sha":290,"./sha1":291,"./sha224":292,"./sha256":293,"./sha384":294,"./sha512":295}],290:[function(require,module,exports){ -/* - * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined - * in FIPS PUB 180-1 - * This source code is derived from sha1.js of the same repository. - * The difference between SHA-0 and SHA-1 is just a bitwise rotate left - * operation was added. - */ + // has it been destroyed + this.destroyed = false; -var inherits = require('inherits') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; -var K = [ - 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 -] + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; -var W = new Array(80) + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; -function Sha () { - this.init() - this._w = W + // a flag to see when we're in the middle of a write. + this.writing = false; - Hash.call(this, 64, 56) -} + // when true all writes will be buffered until .uncork() call + this.corked = 0; -inherits(Sha, Hash) + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; -Sha.prototype.init = function () { - this._a = 0x67452301 - this._b = 0xefcdab89 - this._c = 0x98badcfe - this._d = 0x10325476 - this._e = 0xc3d2e1f0 + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; - return this -} + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; -function rotl5 (num) { - return (num << 5) | (num >>> 27) -} + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; -function rotl30 (num) { - return (num << 30) | (num >>> 2) -} + // the amount that is being written when _write is called. + this.writelen = 0; + this.bufferedRequest = null; + this.lastBufferedRequest = null; -function ft (s, b, c, d) { - if (s === 0) return (b & c) | ((~b) & d) - if (s === 2) return (b & c) | (b & d) | (c & d) - return b ^ c ^ d -} + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; -Sha.prototype._update = function (M) { - var W = this._w + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; - var a = this._a | 0 - var b = this._b | 0 - var c = this._c | 0 - var d = this._d | 0 - var e = this._e | 0 + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) - for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16] + // Should close be emitted on destroy. Defaults to true. + this.emitClose = options.emitClose !== false; - for (var j = 0; j < 80; ++j) { - var s = ~~(j / 20) - var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 + // Should .destroy() be called after 'finish' (and potentially 'end') + this.autoDestroy = !!options.autoDestroy; - e = d - d = c - c = rotl30(b) - b = a - a = t - } + // count buffered requests + this.bufferedRequestCount = 0; - this._a = (a + this._a) | 0 - this._b = (b + this._b) | 0 - this._c = (c + this._c) | 0 - this._d = (d + this._d) | 0 - this._e = (e + this._e) | 0 + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + this.corkedRequestsFree = new CorkedRequest(this); } +WritableState.prototype.getBuffer = function getBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; +}; +(function () { + try { + Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function writableStateBufferGetter() { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003') + }); + } catch (_) {} +})(); -Sha.prototype._hash = function () { - var H = Buffer.allocUnsafe(20) - - H.writeInt32BE(this._a | 0, 0) - H.writeInt32BE(this._b | 0, 4) - H.writeInt32BE(this._c | 0, 8) - H.writeInt32BE(this._d | 0, 12) - H.writeInt32BE(this._e | 0, 16) - - return H +// Test _writableState for inheritance to account for Duplex streams, +// whose prototype chain only points to Readable. +var realHasInstance; +if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') { + realHasInstance = Function.prototype[Symbol.hasInstance]; + Object.defineProperty(Writable, Symbol.hasInstance, { + value: function value(object) { + if (realHasInstance.call(this, object)) return true; + if (this !== Writable) return false; + return object && object._writableState instanceof WritableState; + } + }); +} else { + realHasInstance = function realHasInstance(object) { + return object instanceof this; + }; } +function Writable(options) { + Duplex = Duplex || require('./_stream_duplex'); -module.exports = Sha + // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. -},{"./hash":288,"inherits":230,"safe-buffer":280}],291:[function(require,module,exports){ -/* - * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Version 2.1a Copyright Paul Johnston 2000 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for details. - */ + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. -var inherits = require('inherits') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer + // Checking for a Stream.Duplex instance is faster here instead of inside + // the WritableState constructor, at least with V8 6.5 + var isDuplex = this instanceof Duplex; + if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); + this._writableState = new WritableState(options, this, isDuplex); -var K = [ - 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 -] + // legacy. + this.writable = true; + if (options) { + if (typeof options.write === 'function') this._write = options.write; + if (typeof options.writev === 'function') this._writev = options.writev; + if (typeof options.destroy === 'function') this._destroy = options.destroy; + if (typeof options.final === 'function') this._final = options.final; + } + Stream.call(this); +} -var W = new Array(80) +// Otherwise people can pipe Writable streams, which is just wrong. +Writable.prototype.pipe = function () { + errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE()); +}; +function writeAfterEnd(stream, cb) { + var er = new ERR_STREAM_WRITE_AFTER_END(); + // TODO: defer error events consistently everywhere, not just the cb + errorOrDestroy(stream, er); + process.nextTick(cb, er); +} -function Sha1 () { - this.init() - this._w = W +// Checks that a user-supplied chunk is valid, especially for the particular +// mode the stream is in. Currently this means that `null` is never accepted +// and undefined/non-string values are only allowed in object mode. +function validChunk(stream, state, chunk, cb) { + var er; + if (chunk === null) { + er = new ERR_STREAM_NULL_VALUES(); + } else if (typeof chunk !== 'string' && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk); + } + if (er) { + errorOrDestroy(stream, er); + process.nextTick(cb, er); + return false; + } + return true; +} +Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + var isBuf = !state.objectMode && _isUint8Array(chunk); + if (isBuf && !Buffer.isBuffer(chunk)) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; + if (typeof cb !== 'function') cb = nop; + if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); + } + return ret; +}; +Writable.prototype.cork = function () { + this._writableState.corked++; +}; +Writable.prototype.uncork = function () { + var state = this._writableState; + if (state.corked) { + state.corked--; + if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } +}; +Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === 'string') encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding); + this._writableState.defaultEncoding = encoding; + return this; +}; +Object.defineProperty(Writable.prototype, 'writableBuffer', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } +}); +function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { + chunk = Buffer.from(chunk, encoding); + } + return chunk; +} +Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } +}); - Hash.call(this, 64, 56) +// if we're already writing something, then just put this +// in the queue, and wait our turn. Otherwise, call _write +// If we return false, then we need a drain event, so set that flag. +function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + var newChunk = decodeChunk(state, chunk, encoding); + if (chunk !== newChunk) { + isBuf = true; + encoding = 'buffer'; + chunk = newChunk; + } + } + var len = state.objectMode ? 1 : chunk.length; + state.length += len; + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = { + chunk: chunk, + encoding: encoding, + isBuf: isBuf, + callback: cb, + next: null + }; + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + return ret; } - -inherits(Sha1, Hash) - -Sha1.prototype.init = function () { - this._a = 0x67452301 - this._b = 0xefcdab89 - this._c = 0x98badcfe - this._d = 0x10325476 - this._e = 0xc3d2e1f0 - - return this +function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; } - -function rotl1 (num) { - return (num << 1) | (num >>> 31) +function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) { + // defer the callback if we are being called synchronously + // to avoid piling up things on the stack + process.nextTick(cb, er); + // this can emit finish, and it will always happen + // after error + process.nextTick(finishMaybe, stream, state); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); + } else { + // the caller expect this to happen before if + // it is async + cb(er); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); + // this can emit finish, but finish must + // always follow error + finishMaybe(stream, state); + } } - -function rotl5 (num) { - return (num << 5) | (num >>> 27) +function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; } - -function rotl30 (num) { - return (num << 30) | (num >>> 2) +function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK(); + onwriteStateUpdate(state); + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state) || stream.destroyed; + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); + } + if (sync) { + process.nextTick(afterWrite, stream, state, finished, cb); + } else { + afterWrite(stream, state, finished, cb); + } + } } - -function ft (s, b, c, d) { - if (s === 0) return (b & c) | ((~b) & d) - if (s === 2) return (b & c) | (b & d) | (c & d) - return b ^ c ^ d +function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); } -Sha1.prototype._update = function (M) { - var W = this._w - - var a = this._a | 0 - var b = this._b | 0 - var c = this._c | 0 - var d = this._d | 0 - var e = this._e | 0 - - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) - for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]) - - for (var j = 0; j < 80; ++j) { - var s = ~~(j / 20) - var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0 - - e = d - d = c - c = rotl30(b) - b = a - a = t +// Must force callback to be called on nextTick, so that we don't +// emit 'drain' before the write() consumer gets the 'false' return +// value, and has a chance to attach a 'drain' listener. +function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); } - - this._a = (a + this._a) | 0 - this._b = (b + this._b) | 0 - this._c = (c + this._c) | 0 - this._d = (d + this._d) | 0 - this._e = (e + this._e) | 0 } -Sha1.prototype._hash = function () { - var H = Buffer.allocUnsafe(20) - - H.writeInt32BE(this._a | 0, 0) - H.writeInt32BE(this._b | 0, 4) - H.writeInt32BE(this._c | 0, 8) - H.writeInt32BE(this._d | 0, 12) - H.writeInt32BE(this._e | 0, 16) +// if there's something in the buffer waiting, then process it +function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + var count = 0; + var allBuffers = true; + while (entry) { + buffer[count] = entry; + if (!entry.isBuf) allBuffers = false; + entry = entry.next; + count += 1; + } + buffer.allBuffers = allBuffers; + doWrite(stream, state, true, state.length, buffer, '', holder.finish); - return H + // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } + state.bufferedRequestCount = 0; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + state.bufferedRequestCount--; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } + if (entry === null) state.lastBufferedRequest = null; + } + state.bufferedRequest = entry; + state.bufferProcessing = false; } +Writable.prototype._write = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()')); +}; +Writable.prototype._writev = null; +Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; + if (typeof chunk === 'function') { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); -module.exports = Sha1 - -},{"./hash":288,"inherits":230,"safe-buffer":280}],292:[function(require,module,exports){ -/** - * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined - * in FIPS 180-2 - * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - */ - -var inherits = require('inherits') -var Sha256 = require('./sha256') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer - -var W = new Array(64) - -function Sha224 () { - this.init() - - this._w = W // new Array(64) + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } - Hash.call(this, 64, 56) + // ignore unnecessary end() calls. + if (!state.ending) endWritable(this, state, cb); + return this; +}; +Object.defineProperty(Writable.prototype, 'writableLength', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } +}); +function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; } - -inherits(Sha224, Sha256) - -Sha224.prototype.init = function () { - this._a = 0xc1059ed8 - this._b = 0x367cd507 - this._c = 0x3070dd17 - this._d = 0xf70e5939 - this._e = 0xffc00b31 - this._f = 0x68581511 - this._g = 0x64f98fa7 - this._h = 0xbefa4fa4 - - return this +function callFinal(stream, state) { + stream._final(function (err) { + state.pendingcb--; + if (err) { + errorOrDestroy(stream, err); + } + state.prefinished = true; + stream.emit('prefinish'); + finishMaybe(stream, state); + }); } - -Sha224.prototype._hash = function () { - var H = Buffer.allocUnsafe(28) - - H.writeInt32BE(this._a, 0) - H.writeInt32BE(this._b, 4) - H.writeInt32BE(this._c, 8) - H.writeInt32BE(this._d, 12) - H.writeInt32BE(this._e, 16) - H.writeInt32BE(this._f, 20) - H.writeInt32BE(this._g, 24) - - return H +function prefinish(stream, state) { + if (!state.prefinished && !state.finalCalled) { + if (typeof stream._final === 'function' && !state.destroyed) { + state.pendingcb++; + state.finalCalled = true; + process.nextTick(callFinal, stream, state); + } else { + state.prefinished = true; + stream.emit('prefinish'); + } + } } - -module.exports = Sha224 - -},{"./hash":288,"./sha256":293,"inherits":230,"safe-buffer":280}],293:[function(require,module,exports){ -/** - * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined - * in FIPS 180-2 - * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - */ - -var inherits = require('inherits') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer - -var K = [ - 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, - 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, - 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, - 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, - 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, - 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, - 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, - 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, - 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, - 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, - 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, - 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, - 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, - 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, - 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, - 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 -] - -var W = new Array(64) - -function Sha256 () { - this.init() - - this._w = W // new Array(64) - - Hash.call(this, 64, 56) +function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + prefinish(stream, state); + if (state.pendingcb === 0) { + state.finished = true; + stream.emit('finish'); + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the readable side is ready for autoDestroy as well + var rState = stream._readableState; + if (!rState || rState.autoDestroy && rState.endEmitted) { + stream.destroy(); + } + } + } + } + return need; } - -inherits(Sha256, Hash) - -Sha256.prototype.init = function () { - this._a = 0x6a09e667 - this._b = 0xbb67ae85 - this._c = 0x3c6ef372 - this._d = 0xa54ff53a - this._e = 0x510e527f - this._f = 0x9b05688c - this._g = 0x1f83d9ab - this._h = 0x5be0cd19 - - return this +function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) process.nextTick(cb);else stream.once('finish', cb); + } + state.ended = true; + stream.writable = false; } +function onCorkedFinish(corkReq, state, err) { + var entry = corkReq.entry; + corkReq.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } -function ch (x, y, z) { - return z ^ (x & (y ^ z)) + // reuse the free corkReq. + state.corkedRequestsFree.next = corkReq; } +Object.defineProperty(Writable.prototype, 'destroyed', { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._writableState === undefined) { + return false; + } + return this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._writableState) { + return; + } -function maj (x, y, z) { - return (x & y) | (z & (x | y)) -} + // backward compatibility, the user is explicitly + // managing destroyed + this._writableState.destroyed = value; + } +}); +Writable.prototype.destroy = destroyImpl.destroy; +Writable.prototype._undestroy = destroyImpl.undestroy; +Writable.prototype._destroy = function (err, cb) { + cb(err); +}; +}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../errors":482,"./_stream_duplex":483,"./internal/streams/destroy":490,"./internal/streams/state":494,"./internal/streams/stream":495,"_process":451,"buffer":249,"inherits":349,"util-deprecate":524}],488:[function(require,module,exports){ +(function (process){(function (){ +'use strict'; -function sigma0 (x) { - return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10) +var _Object$setPrototypeO; +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var finished = require('./end-of-stream'); +var kLastResolve = Symbol('lastResolve'); +var kLastReject = Symbol('lastReject'); +var kError = Symbol('error'); +var kEnded = Symbol('ended'); +var kLastPromise = Symbol('lastPromise'); +var kHandlePromise = Symbol('handlePromise'); +var kStream = Symbol('stream'); +function createIterResult(value, done) { + return { + value: value, + done: done + }; } - -function sigma1 (x) { - return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7) +function readAndResolve(iter) { + var resolve = iter[kLastResolve]; + if (resolve !== null) { + var data = iter[kStream].read(); + // we defer if data is null + // we can be expecting either 'end' or + // 'error' + if (data !== null) { + iter[kLastPromise] = null; + iter[kLastResolve] = null; + iter[kLastReject] = null; + resolve(createIterResult(data, false)); + } + } } - -function gamma0 (x) { - return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3) +function onReadable(iter) { + // we wait for the next tick, because it might + // emit an error with process.nextTick + process.nextTick(readAndResolve, iter); } - -function gamma1 (x) { - return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10) +function wrapForNext(lastPromise, iter) { + return function (resolve, reject) { + lastPromise.then(function () { + if (iter[kEnded]) { + resolve(createIterResult(undefined, true)); + return; + } + iter[kHandlePromise](resolve, reject); + }, reject); + }; } +var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); +var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { + get stream() { + return this[kStream]; + }, + next: function next() { + var _this = this; + // if we have detected an error in the meanwhile + // reject straight away + var error = this[kError]; + if (error !== null) { + return Promise.reject(error); + } + if (this[kEnded]) { + return Promise.resolve(createIterResult(undefined, true)); + } + if (this[kStream].destroyed) { + // We need to defer via nextTick because if .destroy(err) is + // called, the error will be emitted via nextTick, and + // we cannot guarantee that there is no error lingering around + // waiting to be emitted. + return new Promise(function (resolve, reject) { + process.nextTick(function () { + if (_this[kError]) { + reject(_this[kError]); + } else { + resolve(createIterResult(undefined, true)); + } + }); + }); + } -Sha256.prototype._update = function (M) { - var W = this._w - - var a = this._a | 0 - var b = this._b | 0 - var c = this._c | 0 - var d = this._d | 0 - var e = this._e | 0 - var f = this._f | 0 - var g = this._g | 0 - var h = this._h | 0 - - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4) - for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0 - - for (var j = 0; j < 64; ++j) { - var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0 - var T2 = (sigma0(a) + maj(a, b, c)) | 0 - - h = g - g = f - f = e - e = (d + T1) | 0 - d = c - c = b - b = a - a = (T1 + T2) | 0 + // if we have multiple next() calls + // we will wait for the previous Promise to finish + // this logic is optimized to support for await loops, + // where next() is only called once at a time + var lastPromise = this[kLastPromise]; + var promise; + if (lastPromise) { + promise = new Promise(wrapForNext(lastPromise, this)); + } else { + // fast path needed to support multiple this.push() + // without triggering the next() queue + var data = this[kStream].read(); + if (data !== null) { + return Promise.resolve(createIterResult(data, false)); + } + promise = new Promise(this[kHandlePromise]); + } + this[kLastPromise] = promise; + return promise; } +}, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { + return this; +}), _defineProperty(_Object$setPrototypeO, "return", function _return() { + var _this2 = this; + // destroy(err, cb) is a private API + // we can guarantee we have that here, because we control the + // Readable class this is attached to + return new Promise(function (resolve, reject) { + _this2[kStream].destroy(null, function (err) { + if (err) { + reject(err); + return; + } + resolve(createIterResult(undefined, true)); + }); + }); +}), _Object$setPrototypeO), AsyncIteratorPrototype); +var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { + var _Object$create; + var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { + value: stream, + writable: true + }), _defineProperty(_Object$create, kLastResolve, { + value: null, + writable: true + }), _defineProperty(_Object$create, kLastReject, { + value: null, + writable: true + }), _defineProperty(_Object$create, kError, { + value: null, + writable: true + }), _defineProperty(_Object$create, kEnded, { + value: stream._readableState.endEmitted, + writable: true + }), _defineProperty(_Object$create, kHandlePromise, { + value: function value(resolve, reject) { + var data = iterator[kStream].read(); + if (data) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(data, false)); + } else { + iterator[kLastResolve] = resolve; + iterator[kLastReject] = reject; + } + }, + writable: true + }), _Object$create)); + iterator[kLastPromise] = null; + finished(stream, function (err) { + if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { + var reject = iterator[kLastReject]; + // reject if we are waiting for data in the Promise + // returned by next() and store the error + if (reject !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + reject(err); + } + iterator[kError] = err; + return; + } + var resolve = iterator[kLastResolve]; + if (resolve !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(undefined, true)); + } + iterator[kEnded] = true; + }); + stream.on('readable', onReadable.bind(null, iterator)); + return iterator; +}; +module.exports = createReadableStreamAsyncIterator; +}).call(this)}).call(this,require('_process')) +},{"./end-of-stream":491,"_process":451}],489:[function(require,module,exports){ +'use strict'; - this._a = (a + this._a) | 0 - this._b = (b + this._b) | 0 - this._c = (c + this._c) | 0 - this._d = (d + this._d) | 0 - this._e = (e + this._e) | 0 - this._f = (f + this._f) | 0 - this._g = (g + this._g) | 0 - this._h = (h + this._h) | 0 +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } +function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } +function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } +var _require = require('buffer'), + Buffer = _require.Buffer; +var _require2 = require('util'), + inspect = _require2.inspect; +var custom = inspect && inspect.custom || 'inspect'; +function copyBuffer(src, target, offset) { + Buffer.prototype.copy.call(src, target, offset); } +module.exports = /*#__PURE__*/function () { + function BufferList() { + _classCallCheck(this, BufferList); + this.head = null; + this.tail = null; + this.length = 0; + } + _createClass(BufferList, [{ + key: "push", + value: function push(v) { + var entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + } + }, { + key: "unshift", + value: function unshift(v) { + var entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + } + }, { + key: "shift", + value: function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + } + }, { + key: "clear", + value: function clear() { + this.head = this.tail = null; + this.length = 0; + } + }, { + key: "join", + value: function join(s) { + if (this.length === 0) return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) ret += s + p.data; + return ret; + } + }, { + key: "concat", + value: function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; + } + return ret; + } -Sha256.prototype._hash = function () { - var H = Buffer.allocUnsafe(32) + // Consumes a specified amount of bytes or characters from the buffered data. + }, { + key: "consume", + value: function consume(n, hasStrings) { + var ret; + if (n < this.head.data.length) { + // `slice` is the same for buffers and strings. + ret = this.head.data.slice(0, n); + this.head.data = this.head.data.slice(n); + } else if (n === this.head.data.length) { + // First chunk is a perfect match. + ret = this.shift(); + } else { + // Result spans more than one buffer. + ret = hasStrings ? this._getString(n) : this._getBuffer(n); + } + return ret; + } + }, { + key: "first", + value: function first() { + return this.head.data; + } - H.writeInt32BE(this._a, 0) - H.writeInt32BE(this._b, 4) - H.writeInt32BE(this._c, 8) - H.writeInt32BE(this._d, 12) - H.writeInt32BE(this._e, 16) - H.writeInt32BE(this._f, 20) - H.writeInt32BE(this._g, 24) - H.writeInt32BE(this._h, 28) + // Consumes a specified amount of characters from the buffered data. + }, { + key: "_getString", + value: function _getString(n) { + var p = this.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = str.slice(nb); + } + break; + } + ++c; + } + this.length -= c; + return ret; + } - return H -} + // Consumes a specified amount of bytes from the buffered data. + }, { + key: "_getBuffer", + value: function _getBuffer(n) { + var ret = Buffer.allocUnsafe(n); + var p = this.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = buf.slice(nb); + } + break; + } + ++c; + } + this.length -= c; + return ret; + } -module.exports = Sha256 + // Make sure the linked list only shows the minimal necessary information. + }, { + key: custom, + value: function value(_, options) { + return inspect(this, _objectSpread(_objectSpread({}, options), {}, { + // Only inspect one level. + depth: 0, + // It should not recurse. + customInspect: false + })); + } + }]); + return BufferList; +}(); +},{"buffer":249,"util":200}],490:[function(require,module,exports){ +(function (process){(function (){ +'use strict'; -},{"./hash":288,"inherits":230,"safe-buffer":280}],294:[function(require,module,exports){ -var inherits = require('inherits') -var SHA512 = require('./sha512') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer +// undocumented cb() API, needed for core, not for public API +function destroy(err, cb) { + var _this = this; + var readableDestroyed = this._readableState && this._readableState.destroyed; + var writableDestroyed = this._writableState && this._writableState.destroyed; + if (readableDestroyed || writableDestroyed) { + if (cb) { + cb(err); + } else if (err) { + if (!this._writableState) { + process.nextTick(emitErrorNT, this, err); + } else if (!this._writableState.errorEmitted) { + this._writableState.errorEmitted = true; + process.nextTick(emitErrorNT, this, err); + } + } + return this; + } -var W = new Array(160) + // we set destroyed to true before firing error callbacks in order + // to make it re-entrance safe in case destroy() is called within callbacks -function Sha384 () { - this.init() - this._w = W + if (this._readableState) { + this._readableState.destroyed = true; + } - Hash.call(this, 128, 112) + // if this is a duplex stream mark the writable part as destroyed as well + if (this._writableState) { + this._writableState.destroyed = true; + } + this._destroy(err || null, function (err) { + if (!cb && err) { + if (!_this._writableState) { + process.nextTick(emitErrorAndCloseNT, _this, err); + } else if (!_this._writableState.errorEmitted) { + _this._writableState.errorEmitted = true; + process.nextTick(emitErrorAndCloseNT, _this, err); + } else { + process.nextTick(emitCloseNT, _this); + } + } else if (cb) { + process.nextTick(emitCloseNT, _this); + cb(err); + } else { + process.nextTick(emitCloseNT, _this); + } + }); + return this; } - -inherits(Sha384, SHA512) - -Sha384.prototype.init = function () { - this._ah = 0xcbbb9d5d - this._bh = 0x629a292a - this._ch = 0x9159015a - this._dh = 0x152fecd8 - this._eh = 0x67332667 - this._fh = 0x8eb44a87 - this._gh = 0xdb0c2e0d - this._hh = 0x47b5481d - - this._al = 0xc1059ed8 - this._bl = 0x367cd507 - this._cl = 0x3070dd17 - this._dl = 0xf70e5939 - this._el = 0xffc00b31 - this._fl = 0x68581511 - this._gl = 0x64f98fa7 - this._hl = 0xbefa4fa4 - - return this +function emitErrorAndCloseNT(self, err) { + emitErrorNT(self, err); + emitCloseNT(self); } - -Sha384.prototype._hash = function () { - var H = Buffer.allocUnsafe(48) - - function writeInt64BE (h, l, offset) { - H.writeInt32BE(h, offset) - H.writeInt32BE(l, offset + 4) +function emitCloseNT(self) { + if (self._writableState && !self._writableState.emitClose) return; + if (self._readableState && !self._readableState.emitClose) return; + self.emit('close'); +} +function undestroy() { + if (this._readableState) { + this._readableState.destroyed = false; + this._readableState.reading = false; + this._readableState.ended = false; + this._readableState.endEmitted = false; + } + if (this._writableState) { + this._writableState.destroyed = false; + this._writableState.ended = false; + this._writableState.ending = false; + this._writableState.finalCalled = false; + this._writableState.prefinished = false; + this._writableState.finished = false; + this._writableState.errorEmitted = false; } - - writeInt64BE(this._ah, this._al, 0) - writeInt64BE(this._bh, this._bl, 8) - writeInt64BE(this._ch, this._cl, 16) - writeInt64BE(this._dh, this._dl, 24) - writeInt64BE(this._eh, this._el, 32) - writeInt64BE(this._fh, this._fl, 40) - - return H } - -module.exports = Sha384 - -},{"./hash":288,"./sha512":295,"inherits":230,"safe-buffer":280}],295:[function(require,module,exports){ -var inherits = require('inherits') -var Hash = require('./hash') -var Buffer = require('safe-buffer').Buffer - -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -] - -var W = new Array(160) - -function Sha512 () { - this.init() - this._w = W - - Hash.call(this, 128, 112) +function emitErrorNT(self, err) { + self.emit('error', err); } +function errorOrDestroy(stream, err) { + // We have tests that rely on errors being emitted + // in the same tick, so changing this is semver major. + // For now when you opt-in to autoDestroy we allow + // the error to be emitted nextTick. In a future + // semver major update we should change the default to this. -inherits(Sha512, Hash) - -Sha512.prototype.init = function () { - this._ah = 0x6a09e667 - this._bh = 0xbb67ae85 - this._ch = 0x3c6ef372 - this._dh = 0xa54ff53a - this._eh = 0x510e527f - this._fh = 0x9b05688c - this._gh = 0x1f83d9ab - this._hh = 0x5be0cd19 + var rState = stream._readableState; + var wState = stream._writableState; + if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err); +} +module.exports = { + destroy: destroy, + undestroy: undestroy, + errorOrDestroy: errorOrDestroy +}; +}).call(this)}).call(this,require('_process')) +},{"_process":451}],491:[function(require,module,exports){ +// Ported from https://github.com/mafintosh/end-of-stream with +// permission from the author, Mathias Buus (@mafintosh). - this._al = 0xf3bcc908 - this._bl = 0x84caa73b - this._cl = 0xfe94f82b - this._dl = 0x5f1d36f1 - this._el = 0xade682d1 - this._fl = 0x2b3e6c1f - this._gl = 0xfb41bd6b - this._hl = 0x137e2179 +'use strict'; - return this +var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE; +function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + callback.apply(this, args); + }; } - -function Ch (x, y, z) { - return z ^ (x & (y ^ z)) +function noop() {} +function isRequest(stream) { + return stream.setHeader && typeof stream.abort === 'function'; } - -function maj (x, y, z) { - return (x & y) | (z & (x | y)) +function eos(stream, opts, callback) { + if (typeof opts === 'function') return eos(stream, null, opts); + if (!opts) opts = {}; + callback = once(callback || noop); + var readable = opts.readable || opts.readable !== false && stream.readable; + var writable = opts.writable || opts.writable !== false && stream.writable; + var onlegacyfinish = function onlegacyfinish() { + if (!stream.writable) onfinish(); + }; + var writableEnded = stream._writableState && stream._writableState.finished; + var onfinish = function onfinish() { + writable = false; + writableEnded = true; + if (!readable) callback.call(stream); + }; + var readableEnded = stream._readableState && stream._readableState.endEmitted; + var onend = function onend() { + readable = false; + readableEnded = true; + if (!writable) callback.call(stream); + }; + var onerror = function onerror(err) { + callback.call(stream, err); + }; + var onclose = function onclose() { + var err; + if (readable && !readableEnded) { + if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + if (writable && !writableEnded) { + if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + }; + var onrequest = function onrequest() { + stream.req.on('finish', onfinish); + }; + if (isRequest(stream)) { + stream.on('complete', onfinish); + stream.on('abort', onclose); + if (stream.req) onrequest();else stream.on('request', onrequest); + } else if (writable && !stream._writableState) { + // legacy streams + stream.on('end', onlegacyfinish); + stream.on('close', onlegacyfinish); + } + stream.on('end', onend); + stream.on('finish', onfinish); + if (opts.error !== false) stream.on('error', onerror); + stream.on('close', onclose); + return function () { + stream.removeListener('complete', onfinish); + stream.removeListener('abort', onclose); + stream.removeListener('request', onrequest); + if (stream.req) stream.req.removeListener('finish', onfinish); + stream.removeListener('end', onlegacyfinish); + stream.removeListener('close', onlegacyfinish); + stream.removeListener('finish', onfinish); + stream.removeListener('end', onend); + stream.removeListener('error', onerror); + stream.removeListener('close', onclose); + }; } +module.exports = eos; +},{"../../../errors":482}],492:[function(require,module,exports){ +arguments[4][239][0].apply(exports,arguments) +},{"dup":239}],493:[function(require,module,exports){ +// Ported from https://github.com/mafintosh/pump with +// permission from the author, Mathias Buus (@mafintosh). -function sigma0 (x, xl) { - return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25) -} +'use strict'; -function sigma1 (x, xl) { - return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23) +var eos; +function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + callback.apply(void 0, arguments); + }; } - -function Gamma0 (x, xl) { - return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7) +var _require$codes = require('../../../errors').codes, + ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; +function noop(err) { + // Rethrow the error if it exists to avoid swallowing it + if (err) throw err; } - -function Gamma0l (x, xl) { - return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25) +function isRequest(stream) { + return stream.setHeader && typeof stream.abort === 'function'; } +function destroyer(stream, reading, writing, callback) { + callback = once(callback); + var closed = false; + stream.on('close', function () { + closed = true; + }); + if (eos === undefined) eos = require('./end-of-stream'); + eos(stream, { + readable: reading, + writable: writing + }, function (err) { + if (err) return callback(err); + closed = true; + callback(); + }); + var destroyed = false; + return function (err) { + if (closed) return; + if (destroyed) return; + destroyed = true; -function Gamma1 (x, xl) { - return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6) + // request.destroy just do .end - .abort is what we want + if (isRequest(stream)) return stream.abort(); + if (typeof stream.destroy === 'function') return stream.destroy(); + callback(err || new ERR_STREAM_DESTROYED('pipe')); + }; } - -function Gamma1l (x, xl) { - return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26) +function call(fn) { + fn(); } - -function getCarry (a, b) { - return (a >>> 0) < (b >>> 0) ? 1 : 0 +function pipe(from, to) { + return from.pipe(to); } - -Sha512.prototype._update = function (M) { - var W = this._w - - var ah = this._ah | 0 - var bh = this._bh | 0 - var ch = this._ch | 0 - var dh = this._dh | 0 - var eh = this._eh | 0 - var fh = this._fh | 0 - var gh = this._gh | 0 - var hh = this._hh | 0 - - var al = this._al | 0 - var bl = this._bl | 0 - var cl = this._cl | 0 - var dl = this._dl | 0 - var el = this._el | 0 - var fl = this._fl | 0 - var gl = this._gl | 0 - var hl = this._hl | 0 - - for (var i = 0; i < 32; i += 2) { - W[i] = M.readInt32BE(i * 4) - W[i + 1] = M.readInt32BE(i * 4 + 4) - } - for (; i < 160; i += 2) { - var xh = W[i - 15 * 2] - var xl = W[i - 15 * 2 + 1] - var gamma0 = Gamma0(xh, xl) - var gamma0l = Gamma0l(xl, xh) - - xh = W[i - 2 * 2] - xl = W[i - 2 * 2 + 1] - var gamma1 = Gamma1(xh, xl) - var gamma1l = Gamma1l(xl, xh) - - // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] - var Wi7h = W[i - 7 * 2] - var Wi7l = W[i - 7 * 2 + 1] - - var Wi16h = W[i - 16 * 2] - var Wi16l = W[i - 16 * 2 + 1] - - var Wil = (gamma0l + Wi7l) | 0 - var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0 - Wil = (Wil + gamma1l) | 0 - Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0 - Wil = (Wil + Wi16l) | 0 - Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0 - - W[i] = Wih - W[i + 1] = Wil +function popCallback(streams) { + if (!streams.length) return noop; + if (typeof streams[streams.length - 1] !== 'function') return noop; + return streams.pop(); +} +function pipeline() { + for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { + streams[_key] = arguments[_key]; } - - for (var j = 0; j < 160; j += 2) { - Wih = W[j] - Wil = W[j + 1] - - var majh = maj(ah, bh, ch) - var majl = maj(al, bl, cl) - - var sigma0h = sigma0(ah, al) - var sigma0l = sigma0(al, ah) - var sigma1h = sigma1(eh, el) - var sigma1l = sigma1(el, eh) - - // t1 = h + sigma1 + ch + K[j] + W[j] - var Kih = K[j] - var Kil = K[j + 1] - - var chh = Ch(eh, fh, gh) - var chl = Ch(el, fl, gl) - - var t1l = (hl + sigma1l) | 0 - var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0 - t1l = (t1l + chl) | 0 - t1h = (t1h + chh + getCarry(t1l, chl)) | 0 - t1l = (t1l + Kil) | 0 - t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0 - t1l = (t1l + Wil) | 0 - t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0 - - // t2 = sigma0 + maj - var t2l = (sigma0l + majl) | 0 - var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0 - - hh = gh - hl = gl - gh = fh - gl = fl - fh = eh - fl = el - el = (dl + t1l) | 0 - eh = (dh + t1h + getCarry(el, dl)) | 0 - dh = ch - dl = cl - ch = bh - cl = bl - bh = ah - bl = al - al = (t1l + t2l) | 0 - ah = (t1h + t2h + getCarry(al, t1l)) | 0 + var callback = popCallback(streams); + if (Array.isArray(streams[0])) streams = streams[0]; + if (streams.length < 2) { + throw new ERR_MISSING_ARGS('streams'); } - - this._al = (this._al + al) | 0 - this._bl = (this._bl + bl) | 0 - this._cl = (this._cl + cl) | 0 - this._dl = (this._dl + dl) | 0 - this._el = (this._el + el) | 0 - this._fl = (this._fl + fl) | 0 - this._gl = (this._gl + gl) | 0 - this._hl = (this._hl + hl) | 0 - - this._ah = (this._ah + ah + getCarry(this._al, al)) | 0 - this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0 - this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0 - this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0 - this._eh = (this._eh + eh + getCarry(this._el, el)) | 0 - this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0 - this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0 - this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0 + var error; + var destroys = streams.map(function (stream, i) { + var reading = i < streams.length - 1; + var writing = i > 0; + return destroyer(stream, reading, writing, function (err) { + if (!error) error = err; + if (err) destroys.forEach(call); + if (reading) return; + destroys.forEach(call); + callback(error); + }); + }); + return streams.reduce(pipe); } +module.exports = pipeline; +},{"../../../errors":482,"./end-of-stream":491}],494:[function(require,module,exports){ +'use strict'; -Sha512.prototype._hash = function () { - var H = Buffer.allocUnsafe(64) - - function writeInt64BE (h, l, offset) { - H.writeInt32BE(h, offset) - H.writeInt32BE(l, offset + 4) +var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; +function highWaterMarkFrom(options, isDuplex, duplexKey) { + return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; +} +function getHighWaterMark(state, options, duplexKey, isDuplex) { + var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); + if (hwm != null) { + if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { + var name = isDuplex ? duplexKey : 'highWaterMark'; + throw new ERR_INVALID_OPT_VALUE(name, hwm); + } + return Math.floor(hwm); } - writeInt64BE(this._ah, this._al, 0) - writeInt64BE(this._bh, this._bl, 8) - writeInt64BE(this._ch, this._cl, 16) - writeInt64BE(this._dh, this._dl, 24) - writeInt64BE(this._eh, this._el, 32) - writeInt64BE(this._fh, this._fl, 40) - writeInt64BE(this._gh, this._gl, 48) - writeInt64BE(this._hh, this._hl, 56) - - return H + // Default value + return state.objectMode ? 16 : 16 * 1024; } - -module.exports = Sha512 - -},{"./hash":288,"inherits":230,"safe-buffer":280}],296:[function(require,module,exports){ -"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}}; -sjcl.cipher.aes=function(a){this.s[0][0][0]||this.O();var b,c,d,e,f=this.s[0][4],g=this.s[1];b=a.length;var h=1;if(4!==b&&6!==b&&8!==b)throw new sjcl.exception.invalid("invalid aes key size");this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=f[c>>>24]<<24^f[c>>16&255]<<16^f[c>>8&255]<<8^f[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:g[0][f[c>>>24]]^g[1][f[c>>16&255]]^g[2][f[c>>8&255]]^g[3][f[c& -255]]}; -sjcl.cipher.aes.prototype={encrypt:function(a){return t(this,a,0)},decrypt:function(a){return t(this,a,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var a=this.s[0],b=this.s[1],c=a[4],d=b[4],e,f,g,h=[],k=[],l,n,m,p;for(e=0;0x100>e;e++)k[(h[e]=e<<1^283*(e>>7))^e]=e;for(f=g=0;!c[f];f^=l||1,g=k[g]||1)for(m=g^g<<1^g<<2^g<<3^g<<4,m=m>>8^m&255^99,c[f]=m,d[m]=f,n=h[e=h[l=h[f]]],p=0x1010101*n^0x10001*e^0x101*l^0x1010100*f,n=0x101*h[m]^0x1010100*m,e=0;4>e;e++)a[e][f]=n=n<<24^n>>>8,b[e][m]=p=p<<24^p>>>8;for(e= -0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}}; -function t(a,b,c){if(4!==b.length)throw new sjcl.exception.invalid("invalid aes block size");var d=a.b[c],e=b[0]^d[0],f=b[c?3:1]^d[1],g=b[2]^d[2];b=b[c?1:3]^d[3];var h,k,l,n=d.length/4-2,m,p=4,r=[0,0,0,0];h=a.s[c];a=h[0];var q=h[1],v=h[2],w=h[3],x=h[4];for(m=0;m>>24]^q[f>>16&255]^v[g>>8&255]^w[b&255]^d[p],k=a[f>>>24]^q[g>>16&255]^v[b>>8&255]^w[e&255]^d[p+1],l=a[g>>>24]^q[b>>16&255]^v[e>>8&255]^w[f&255]^d[p+2],b=a[b>>>24]^q[e>>16&255]^v[f>>8&255]^w[g&255]^d[p+3],p+=4,e=h,f=k,g=l;for(m= -0;4>m;m++)r[c?3&-m:m]=x[e>>>24]<<24^x[f>>16&255]<<16^x[g>>8&255]<<8^x[b&255]^d[p++],h=e,e=f,f=g,g=b,b=h;return r} -sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.$(a.slice(b/32),32-(b&31)).slice(1);return void 0===c?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return!1;var c=0,d;for(d=0;d>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}}; -sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d>>8>>>8>>>8),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c>>g)>>>e),gn){if(!b)try{return sjcl.codec.base32hex.toBits(a)}catch(p){}throw new sjcl.exception.invalid("this isn't "+m+"!");}h>e?(h-=e,f.push(l^n>>>h),l=n<>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,f=sjcl.codec.base64.B,g=0,h;b&&(f=f.substr(0,62)+"-_");for(d=0;dh)throw new sjcl.exception.invalid("this isn't base64!");26>>e),g=h<<32-e):(e+=6,g^=h<<32-e)}e&56&&c.push(sjcl.bitArray.partial(e&56,g,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};sjcl.hash.sha256=function(a){this.b[0]||this.O();a?(this.F=a.F.slice(0),this.A=a.A.slice(0),this.l=a.l):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()}; -sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.F=this.Y.slice(0);this.A=[];this.l=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.A=sjcl.bitArray.concat(this.A,a);b=this.l;a=this.l=b+sjcl.bitArray.bitLength(a);if(0x1fffffffffffffb;c++){e=!0;for(d=2;d*d<=c;d++)if(0===c%d){e= -!1;break}e&&(8>b&&(this.Y[b]=a(Math.pow(c,.5))),this.b[b]=a(Math.pow(c,1/3)),b++)}}}; -function u(a,b){var c,d,e,f=a.F,g=a.b,h=f[0],k=f[1],l=f[2],n=f[3],m=f[4],p=f[5],r=f[6],q=f[7];for(c=0;64>c;c++)16>c?d=b[c]:(d=b[c+1&15],e=b[c+14&15],d=b[c&15]=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+b[c&15]+b[c+9&15]|0),d=d+q+(m>>>6^m>>>11^m>>>25^m<<26^m<<21^m<<7)+(r^m&(p^r))+g[c],q=r,r=p,p=m,m=n+d|0,n=l,l=k,k=h,h=d+(k&l^n&(k^l))+(k>>>2^k>>>13^k>>>22^k<<30^k<<19^k<<10)|0;f[0]=f[0]+h|0;f[1]=f[1]+k|0;f[2]=f[2]+l|0;f[3]=f[3]+n|0;f[4]=f[4]+m|0;f[5]=f[5]+p|0;f[6]=f[6]+r|0;f[7]= -f[7]+q|0} -sjcl.mode.ccm={name:"ccm",G:[],listenProgress:function(a){sjcl.mode.ccm.G.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.G.indexOf(a);-1k)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(f=2;4>f&&l>>>8*f;f++);f<15-k&&(f=15-k);c=h.clamp(c, -8*(15-f));b=sjcl.mode.ccm.V(a,b,c,d,e,f);g=sjcl.mode.ccm.C(a,g,c,b,e,f);return h.concat(g.data,g.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var f=sjcl.bitArray,g=f.bitLength(c)/8,h=f.bitLength(b),k=f.clamp(b,h-e),l=f.bitSlice(b,h-e),h=(h-e)/8;if(7>g)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(b=2;4>b&&h>>>8*b;b++);b<15-g&&(b=15-g);c=f.clamp(c,8*(15-b));k=sjcl.mode.ccm.C(a,k,c,l,e,b);a=sjcl.mode.ccm.V(a,k.data,c,d,e,b);if(!f.equal(k.tag,a))throw new sjcl.exception.corrupt("ccm: tag doesn't match"); -return k.data},na:function(a,b,c,d,e,f){var g=[],h=sjcl.bitArray,k=h.i;d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:0xffffffff>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;be||16n&&(sjcl.mode.ccm.fa(g/ -k),n+=m),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,l)}}}; -sjcl.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,d,e,f){if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("ocb iv must be 128 bits");var g,h=sjcl.mode.ocb2.S,k=sjcl.bitArray,l=k.i,n=[0,0,0,0];c=h(a.encrypt(c));var m,p=[];d=d||[];e=e||64;for(g=0;g+4e.bitLength(c)&&(h=f(h,d(h)),c=e.concat(c,[-2147483648,0,0,0]));g=f(g,c); -return a.encrypt(f(d(f(h,d(h))),g))},S:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}}; -sjcl.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var f=b.slice(0);b=sjcl.bitArray;d=d||[];a=sjcl.mode.gcm.C(!0,a,f,d,c,e||128);return b.concat(a.data,a.tag)},decrypt:function(a,b,c,d,e){var f=b.slice(0),g=sjcl.bitArray,h=g.bitLength(f);e=e||128;d=d||[];e<=h?(b=g.bitSlice(f,h-e),f=g.bitSlice(f,0,h-e)):(b=f,f=[]);a=sjcl.mode.gcm.C(!1,a,f,d,c,e);if(!g.equal(a.tag,b))throw new sjcl.exception.corrupt("gcm: tag doesn't match");return a.data},ka:function(a,b){var c,d,e,f,g,h=sjcl.bitArray.i;e=[0,0, -0,0];f=b.slice(0);for(c=0;128>c;c++){(d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,f));g=0!==(f[3]&1);for(d=3;0>>1|(f[d-1]&1)<<31;f[0]>>>=1;g&&(f[0]^=-0x1f000000)}return e},j:function(a,b,c){var d,e=c.length;b=b.slice(0);for(d=0;de&&(a=b.hash(a));for(d=0;dd||0>c)throw new sjcl.exception.invalid("invalid params to pbkdf2");"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));e=e||sjcl.misc.hmac;a=new e(a);var f,g,h,k,l=[],n=sjcl.bitArray;for(k=1;32*l.length<(d||1);k++){e=f=a.encrypt(n.concat(b,[k]));for(g=1;gg;g++)e.push(0x100000000*Math.random()|0);for(g=0;g=1<this.o&&(this.o= -f);this.P++;this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.L=new sjcl.cipher.aes(this.b);for(d=0;4>d&&(this.h[d]=this.h[d]+1|0,!this.h[d]);d++);}for(d=0;d>>1;this.c[g].update([d,this.N++,2,b,f,a.length].concat(a))}break;case "string":void 0===b&&(b=a.length);this.c[g].update([d,this.N++,3,b,f,a.length]);this.c[g].update(a);break;default:k=1}if(k)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[g]+=b;this.f+=b;h===this.u&&(this.isReady()!==this.u&&A("seeded",Math.max(this.o,this.f)),A("progress",this.getProgress()))}, -isReady:function(a){a=this.T[void 0!==a?a:this.M];return this.o&&this.o>=a?this.m[0]>this.ba&&(new Date).valueOf()>this.Z?this.J|this.I:this.I:this.f>=a?this.J|this.u:this.u},getProgress:function(a){a=this.T[a?a:this.M];return this.o>=a?1:this.f>a?1:this.f/a},startCollectors:function(){if(!this.D){this.a={loadTimeCollector:B(this,this.ma),mouseCollector:B(this,this.oa),keyboardCollector:B(this,this.la),accelerometerCollector:B(this,this.ea),touchCollector:B(this,this.qa)};if(window.addEventListener)window.addEventListener("load", -this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new sjcl.exception.bug("can't attach event"); -this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove", -this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(a,b){this.K[a][this.ga++]=b},removeEventListener:function(a,b){var c,d,e=this.K[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;cb&&(a.h[b]=a.h[b]+1|0,!a.h[b]);b++);return a.L.encrypt(a.h)} -function B(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6); -a:try{var D,E,F,G;if(G="undefined"!==typeof module&&module.exports){var H;try{H=require("crypto")}catch(a){H=null}G=E=H}if(G&&E.randomBytes)D=E.randomBytes(128),D=new Uint32Array((new Uint8Array(D)).buffer),sjcl.random.addEntropy(D,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){F=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F); -else break a;sjcl.random.addEntropy(F,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))} -sjcl.json={defaults:{v:1,iter:1E4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json,f=e.g({iv:sjcl.random.randomWords(4,0)},e.defaults),g;e.g(f,c);c=f.adata;"string"===typeof f.salt&&(f.salt=sjcl.codec.base64.toBits(f.salt));"string"===typeof f.iv&&(f.iv=sjcl.codec.base64.toBits(f.iv));if(!sjcl.mode[f.mode]||!sjcl.cipher[f.cipher]||"string"===typeof a&&100>=f.iter||64!==f.ts&&96!==f.ts&&128!==f.ts||128!==f.ks&&192!==f.ks&&0x100!==f.ks||2>f.iv.length|| -4=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&0x100!==b.ks||!b.iv||2>b.iv.length||4*/ + var Buffer = require('safe-buffer').Buffer; +/**/ var isEncoding = Buffer.isEncoding || function (encoding) { encoding = '' + encoding; @@ -60503,10 +81243,10 @@ StringDecoder.prototype.fillLast = function (buf) { }; // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a -// continuation byte. +// continuation byte. If an invalid byte is detected, -2 is returned. function utf8CheckByte(byte) { if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4; - return -1; + return byte >> 6 === 0x02 ? -1 : -2; } // Checks at most 3 bytes at the end of a Buffer in order to detect an @@ -60520,13 +81260,13 @@ function utf8CheckIncomplete(self, buf, i) { if (nb > 0) self.lastNeed = nb - 1; return nb; } - if (--j < i) return 0; + if (--j < i || nb === -2) return 0; nb = utf8CheckByte(buf[j]); if (nb >= 0) { if (nb > 0) self.lastNeed = nb - 2; return nb; } - if (--j < i) return 0; + if (--j < i || nb === -2) return 0; nb = utf8CheckByte(buf[j]); if (nb >= 0) { if (nb > 0) { @@ -60540,7 +81280,7 @@ function utf8CheckIncomplete(self, buf, i) { // Validates as many continuation bytes for a multi-byte UTF-8 character as // needed or are available. If we see a non-continuation byte where we expect // one, we "replace" the validated continuation bytes we've seen so far with -// UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding +// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding // behavior. The continuation byte check is included three times in the case // where all of the continuation bytes for a character exist in the same buffer. // It is also done this way as a slight performance increase instead of using a @@ -60548,17 +81288,17 @@ function utf8CheckIncomplete(self, buf, i) { function utf8CheckExtraBytes(self, buf, p) { if ((buf[0] & 0xC0) !== 0x80) { self.lastNeed = 0; - return '\ufffd'.repeat(p); + return '\ufffd'; } if (self.lastNeed > 1 && buf.length > 1) { if ((buf[1] & 0xC0) !== 0x80) { self.lastNeed = 1; - return '\ufffd'.repeat(p + 1); + return '\ufffd'; } if (self.lastNeed > 2 && buf.length > 2) { if ((buf[2] & 0xC0) !== 0x80) { self.lastNeed = 2; - return '\ufffd'.repeat(p + 2); + return '\ufffd'; } } } @@ -60589,11 +81329,11 @@ function utf8Text(buf, i) { return buf.toString('utf8', i, end); } -// For UTF-8, a replacement character for each buffered byte of a (partial) -// character needs to be added to the output. +// For UTF-8, a replacement character is added when ending on a partial +// character. function utf8End(buf) { var r = buf && buf.length ? this.write(buf) : ''; - if (this.lastNeed) return r + '\ufffd'.repeat(this.lastTotal - this.lastNeed); + if (this.lastNeed) return r + '\ufffd'; return r; } @@ -60661,10 +81401,8 @@ function simpleWrite(buf) { function simpleEnd(buf) { return buf && buf.length ? this.write(buf) : ''; } -},{"safe-buffer":299}],299:[function(require,module,exports){ -arguments[4][273][0].apply(exports,arguments) -},{"buffer":155,"dup":273}],300:[function(require,module,exports){ -(function (setImmediate,clearImmediate){ +},{"safe-buffer":463}],497:[function(require,module,exports){ +(function (setImmediate,clearImmediate){(function (){ var nextTick = require('process/browser.js').nextTick; var apply = Function.prototype.apply; var slice = Array.prototype.slice; @@ -60741,9 +81479,9 @@ exports.setImmediate = typeof setImmediate === "function" ? setImmediate : funct exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) { delete immediateIds[id]; }; -}).call(this,require("timers").setImmediate,require("timers").clearImmediate) -},{"process/browser.js":253,"timers":300}],301:[function(require,module,exports){ -(function (Buffer){ +}).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate) +},{"process/browser.js":451,"timers":497}],498:[function(require,module,exports){ +(function (Buffer){(function (){ const BN = require('bn.js') const EC = require('elliptic').ec const secp256k1 = new EC('secp256k1') @@ -61027,8 +81765,8 @@ module.exports = { verify } -}).call(this,require("buffer").Buffer) -},{"./rfc6979":319,"bn.js":302,"buffer":155,"elliptic":303}],302:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"./rfc6979":516,"bn.js":499,"buffer":249,"elliptic":500}],499:[function(require,module,exports){ (function (module, exports) { 'use strict'; @@ -64476,9 +85214,9 @@ module.exports = { }; })(typeof module === 'undefined' || module, this); -},{"buffer":105}],303:[function(require,module,exports){ -arguments[4][179][0].apply(exports,arguments) -},{"../package.json":318,"./elliptic/curve":306,"./elliptic/curves":309,"./elliptic/ec":310,"./elliptic/eddsa":313,"./elliptic/utils":317,"brorand":104,"dup":179}],304:[function(require,module,exports){ +},{"buffer":200}],500:[function(require,module,exports){ +arguments[4][280][0].apply(exports,arguments) +},{"../package.json":515,"./elliptic/curve":503,"./elliptic/curves":506,"./elliptic/ec":507,"./elliptic/eddsa":510,"./elliptic/utils":514,"brorand":199,"dup":280}],501:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -64861,7 +85599,7 @@ BasePoint.prototype.dblp = function dblp(k) { return r; }; -},{"../utils":317,"bn.js":302}],305:[function(require,module,exports){ +},{"../utils":514,"bn.js":499}],502:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -65298,11 +86036,11 @@ Point.prototype.eqXToP = function eqXToP(x) { Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; -},{"../utils":317,"./base":304,"bn.js":302,"inherits":230}],306:[function(require,module,exports){ -arguments[4][182][0].apply(exports,arguments) -},{"./base":304,"./edwards":305,"./mont":307,"./short":308,"dup":182}],307:[function(require,module,exports){ -arguments[4][183][0].apply(exports,arguments) -},{"../utils":317,"./base":304,"bn.js":302,"dup":183,"inherits":230}],308:[function(require,module,exports){ +},{"../utils":514,"./base":501,"bn.js":499,"inherits":349}],503:[function(require,module,exports){ +arguments[4][283][0].apply(exports,arguments) +},{"./base":501,"./edwards":502,"./mont":504,"./short":505,"dup":283}],504:[function(require,module,exports){ +arguments[4][284][0].apply(exports,arguments) +},{"../utils":514,"./base":501,"bn.js":499,"dup":284,"inherits":349}],505:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); @@ -66242,7 +86980,7 @@ JPoint.prototype.isInfinity = function isInfinity() { return this.z.cmpn(0) === 0; }; -},{"../utils":317,"./base":304,"bn.js":302,"inherits":230}],309:[function(require,module,exports){ +},{"../utils":514,"./base":501,"bn.js":499,"inherits":349}],506:[function(require,module,exports){ 'use strict'; var curves = exports; @@ -66450,7 +87188,7 @@ defineCurve('secp256k1', { ], }); -},{"./curve":306,"./precomputed/secp256k1":316,"./utils":317,"hash.js":216}],310:[function(require,module,exports){ +},{"./curve":503,"./precomputed/secp256k1":513,"./utils":514,"hash.js":334}],507:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -66695,7 +87433,7 @@ EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) { throw new Error('Unable to find valid recovery factor'); }; -},{"../curves":309,"../utils":317,"./key":311,"./signature":312,"bn.js":302,"brorand":104,"hmac-drbg":228}],311:[function(require,module,exports){ +},{"../curves":506,"../utils":514,"./key":508,"./signature":509,"bn.js":499,"brorand":199,"hmac-drbg":347}],508:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -66818,9 +87556,9 @@ KeyPair.prototype.inspect = function inspect() { ' pub: ' + (this.pub && this.pub.inspect()) + ' >'; }; -},{"../utils":317,"bn.js":302}],312:[function(require,module,exports){ -arguments[4][188][0].apply(exports,arguments) -},{"../utils":317,"bn.js":302,"dup":188}],313:[function(require,module,exports){ +},{"../utils":514,"bn.js":499}],509:[function(require,module,exports){ +arguments[4][289][0].apply(exports,arguments) +},{"../utils":514,"bn.js":499,"dup":289}],510:[function(require,module,exports){ 'use strict'; var hash = require('hash.js'); @@ -66940,9 +87678,9 @@ EDDSA.prototype.isPoint = function isPoint(val) { return val instanceof this.pointClass; }; -},{"../curves":309,"../utils":317,"./key":314,"./signature":315,"hash.js":216}],314:[function(require,module,exports){ -arguments[4][190][0].apply(exports,arguments) -},{"../utils":317,"dup":190}],315:[function(require,module,exports){ +},{"../curves":506,"../utils":514,"./key":511,"./signature":512,"hash.js":334}],511:[function(require,module,exports){ +arguments[4][291][0].apply(exports,arguments) +},{"../utils":514,"dup":291}],512:[function(require,module,exports){ 'use strict'; var BN = require('bn.js'); @@ -67009,7 +87747,7 @@ Signature.prototype.toHex = function toHex() { module.exports = Signature; -},{"../utils":317,"bn.js":302}],316:[function(require,module,exports){ +},{"../utils":514,"bn.js":499}],513:[function(require,module,exports){ module.exports = { doubles: { step: 4, @@ -67791,3753 +88529,4804 @@ module.exports = { }, }; -},{}],317:[function(require,module,exports){ -'use strict'; +},{}],514:[function(require,module,exports){ +'use strict'; + +var utils = exports; +var BN = require('bn.js'); +var minAssert = require('minimalistic-assert'); +var minUtils = require('minimalistic-crypto-utils'); + +utils.assert = minAssert; +utils.toArray = minUtils.toArray; +utils.zero2 = minUtils.zero2; +utils.toHex = minUtils.toHex; +utils.encode = minUtils.encode; + +// Represent num in a w-NAF form +function getNAF(num, w, bits) { + var naf = new Array(Math.max(num.bitLength(), bits) + 1); + naf.fill(0); + + var ws = 1 << (w + 1); + var k = num.clone(); + + for (var i = 0; i < naf.length; i++) { + var z; + var mod = k.andln(ws - 1); + if (k.isOdd()) { + if (mod > (ws >> 1) - 1) + z = (ws >> 1) - mod; + else + z = mod; + k.isubn(z); + } else { + z = 0; + } + + naf[i] = z; + k.iushrn(1); + } + + return naf; +} +utils.getNAF = getNAF; + +// Represent k1, k2 in a Joint Sparse Form +function getJSF(k1, k2) { + var jsf = [ + [], + [], + ]; + + k1 = k1.clone(); + k2 = k2.clone(); + var d1 = 0; + var d2 = 0; + var m8; + while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { + // First phase + var m14 = (k1.andln(3) + d1) & 3; + var m24 = (k2.andln(3) + d2) & 3; + if (m14 === 3) + m14 = -1; + if (m24 === 3) + m24 = -1; + var u1; + if ((m14 & 1) === 0) { + u1 = 0; + } else { + m8 = (k1.andln(7) + d1) & 7; + if ((m8 === 3 || m8 === 5) && m24 === 2) + u1 = -m14; + else + u1 = m14; + } + jsf[0].push(u1); + + var u2; + if ((m24 & 1) === 0) { + u2 = 0; + } else { + m8 = (k2.andln(7) + d2) & 7; + if ((m8 === 3 || m8 === 5) && m14 === 2) + u2 = -m24; + else + u2 = m24; + } + jsf[1].push(u2); + + // Second phase + if (2 * d1 === u1 + 1) + d1 = 1 - d1; + if (2 * d2 === u2 + 1) + d2 = 1 - d2; + k1.iushrn(1); + k2.iushrn(1); + } + + return jsf; +} +utils.getJSF = getJSF; + +function cachedProperty(obj, name, computer) { + var key = '_' + name; + obj.prototype[name] = function cachedProperty() { + return this[key] !== undefined ? this[key] : + this[key] = computer.call(this); + }; +} +utils.cachedProperty = cachedProperty; + +function parseBytes(bytes) { + return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : + bytes; +} +utils.parseBytes = parseBytes; + +function intFromLE(bytes) { + return new BN(bytes, 'hex', 'le'); +} +utils.intFromLE = intFromLE; + + +},{"bn.js":499,"minimalistic-assert":436,"minimalistic-crypto-utils":437}],515:[function(require,module,exports){ +module.exports={ + "name": "elliptic", + "version": "6.5.4", + "description": "EC cryptography", + "main": "lib/elliptic.js", + "files": [ + "lib" + ], + "scripts": { + "lint": "eslint lib test", + "lint:fix": "npm run lint -- --fix", + "unit": "istanbul test _mocha --reporter=spec test/index.js", + "test": "npm run lint && npm run unit", + "version": "grunt dist && git add dist/" + }, + "repository": { + "type": "git", + "url": "git@github.com:indutny/elliptic" + }, + "keywords": [ + "EC", + "Elliptic", + "curve", + "Cryptography" + ], + "author": "Fedor Indutny ", + "license": "MIT", + "bugs": { + "url": "https://github.com/indutny/elliptic/issues" + }, + "homepage": "https://github.com/indutny/elliptic", + "devDependencies": { + "brfs": "^2.0.2", + "coveralls": "^3.1.0", + "eslint": "^7.6.0", + "grunt": "^1.2.1", + "grunt-browserify": "^5.3.0", + "grunt-cli": "^1.3.2", + "grunt-contrib-connect": "^3.0.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^5.0.0", + "grunt-mocha-istanbul": "^5.0.2", + "grunt-saucelabs": "^9.0.1", + "istanbul": "^0.4.5", + "mocha": "^8.0.1" + }, + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } +} + +},{}],516:[function(require,module,exports){ +(function (Buffer){(function (){ +const createHmac = require('create-hmac') + +const ONE1 = Buffer.alloc(1, 1) +const ZERO1 = Buffer.alloc(1, 0) + +// https://tools.ietf.org/html/rfc6979#section-3.2 +function deterministicGenerateK (hash, x, checkSig, isPrivate, extraEntropy) { + // Step A, ignored as hash already provided + // Step B + // Step C + let k = Buffer.alloc(32, 0) + let v = Buffer.alloc(32, 1) + + // Step D + k = createHmac('sha256', k) + .update(v) + .update(ZERO1) + .update(x) + .update(hash) + .update(extraEntropy || '') + .digest() + + // Step E + v = createHmac('sha256', k).update(v).digest() + + // Step F + k = createHmac('sha256', k) + .update(v) + .update(ONE1) + .update(x) + .update(hash) + .update(extraEntropy || '') + .digest() + + // Step G + v = createHmac('sha256', k).update(v).digest() + + // Step H1/H2a, ignored as tlen === qlen (256 bit) + // Step H2b + v = createHmac('sha256', k).update(v).digest() + + let T = v + + // Step H3, repeat until T is within the interval [1, n - 1] and is suitable for ECDSA + while (!isPrivate(T) || !checkSig(T)) { + k = createHmac('sha256', k) + .update(v) + .update(ZERO1) + .digest() + + v = createHmac('sha256', k).update(v).digest() + + // Step H1/H2a, again, ignored as tlen === qlen (256 bit) + // Step H2b again + v = createHmac('sha256', k).update(v).digest() + T = v + } + + return T +} + +module.exports = deterministicGenerateK + +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":249,"create-hmac":256}],517:[function(require,module,exports){ +(function (Buffer){(function (){ +// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +(function(root, f) { + 'use strict'; + if (typeof module !== 'undefined' && module.exports) module.exports = f(); + else if (root.nacl) root.nacl.util = f(); + else { + root.nacl = {}; + root.nacl.util = f(); + } +}(this, function() { + 'use strict'; + + var util = {}; + + function validateBase64(s) { + if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) { + throw new TypeError('invalid encoding'); + } + } + + util.decodeUTF8 = function(s) { + if (typeof s !== 'string') throw new TypeError('expected string'); + var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; + + util.encodeUTF8 = function(arr) { + var i, s = []; + for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); + return decodeURIComponent(escape(s.join(''))); + }; + + if (typeof atob === 'undefined') { + // Node.js + + if (typeof Buffer.from !== 'undefined') { + // Node v6 and later + util.encodeBase64 = function (arr) { // v6 and later + return Buffer.from(arr).toString('base64'); + }; + + util.decodeBase64 = function (s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); + }; + + } else { + // Node earlier than v6 + util.encodeBase64 = function (arr) { // v6 and later + return (new Buffer(arr)).toString('base64'); + }; + + util.decodeBase64 = function(s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); + }; + } + + } else { + // Browsers + + util.encodeBase64 = function(arr) { + var i, s = [], len = arr.length; + for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); + return btoa(s.join('')); + }; + + util.decodeBase64 = function(s) { + validateBase64(s); + var i, d = atob(s), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; + + } + + return util; + +})); + +}).call(this)}).call(this,require("buffer").Buffer) +},{"buffer":200}],518:[function(require,module,exports){ +(function(nacl) { +'use strict'; + +// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +// +// Implementation derived from TweetNaCl version 20140427. +// See for details: http://tweetnacl.cr.yp.to/ + +var gf = function(init) { + var i, r = new Float64Array(16); + if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; + return r; +}; + +// Pluggable, initialized in high-level API below. +var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; + +var _0 = new Uint8Array(16); +var _9 = new Uint8Array(32); _9[0] = 9; + +var gf0 = gf(), + gf1 = gf([1]), + _121665 = gf([0xdb41, 1]), + D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); + +function ts64(x, i, h, l) { + x[i] = (h >> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} + +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} + +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} + +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} + +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; + + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; + + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; + + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; + + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; + + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; + + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; + + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; + + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; + + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; + + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; + + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; + + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; + + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; + + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} + +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; + + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; + + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; + + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; + + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; + + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; + + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} + +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} + +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} + +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" + +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} + +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} + +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} + +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} + +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ + +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; + + var t0, t1, t2, t3, t4, t5, t6, t7; + + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; + + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; + +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; + + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; + + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; + + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; + + c = 0; + + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; + + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; + + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; + + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; + + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; + + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; + + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; + + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; + + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; + + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; + + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; + + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; + + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; + +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; + + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } + + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; + + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); + + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; + + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; + + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } + + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; + +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; + + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } + + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } + + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } +}; + +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} + +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} + +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} + +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} + +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} + +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} + +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} + +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; + } + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} + +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} + +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} + +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} + +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} + +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} + +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; + + v = a[0]; + t0 += v * b0; + t1 += v * b1; + t2 += v * b2; + t3 += v * b3; + t4 += v * b4; + t5 += v * b5; + t6 += v * b6; + t7 += v * b7; + t8 += v * b8; + t9 += v * b9; + t10 += v * b10; + t11 += v * b11; + t12 += v * b12; + t13 += v * b13; + t14 += v * b14; + t15 += v * b15; + v = a[1]; + t1 += v * b0; + t2 += v * b1; + t3 += v * b2; + t4 += v * b3; + t5 += v * b4; + t6 += v * b5; + t7 += v * b6; + t8 += v * b7; + t9 += v * b8; + t10 += v * b9; + t11 += v * b10; + t12 += v * b11; + t13 += v * b12; + t14 += v * b13; + t15 += v * b14; + t16 += v * b15; + v = a[2]; + t2 += v * b0; + t3 += v * b1; + t4 += v * b2; + t5 += v * b3; + t6 += v * b4; + t7 += v * b5; + t8 += v * b6; + t9 += v * b7; + t10 += v * b8; + t11 += v * b9; + t12 += v * b10; + t13 += v * b11; + t14 += v * b12; + t15 += v * b13; + t16 += v * b14; + t17 += v * b15; + v = a[3]; + t3 += v * b0; + t4 += v * b1; + t5 += v * b2; + t6 += v * b3; + t7 += v * b4; + t8 += v * b5; + t9 += v * b6; + t10 += v * b7; + t11 += v * b8; + t12 += v * b9; + t13 += v * b10; + t14 += v * b11; + t15 += v * b12; + t16 += v * b13; + t17 += v * b14; + t18 += v * b15; + v = a[4]; + t4 += v * b0; + t5 += v * b1; + t6 += v * b2; + t7 += v * b3; + t8 += v * b4; + t9 += v * b5; + t10 += v * b6; + t11 += v * b7; + t12 += v * b8; + t13 += v * b9; + t14 += v * b10; + t15 += v * b11; + t16 += v * b12; + t17 += v * b13; + t18 += v * b14; + t19 += v * b15; + v = a[5]; + t5 += v * b0; + t6 += v * b1; + t7 += v * b2; + t8 += v * b3; + t9 += v * b4; + t10 += v * b5; + t11 += v * b6; + t12 += v * b7; + t13 += v * b8; + t14 += v * b9; + t15 += v * b10; + t16 += v * b11; + t17 += v * b12; + t18 += v * b13; + t19 += v * b14; + t20 += v * b15; + v = a[6]; + t6 += v * b0; + t7 += v * b1; + t8 += v * b2; + t9 += v * b3; + t10 += v * b4; + t11 += v * b5; + t12 += v * b6; + t13 += v * b7; + t14 += v * b8; + t15 += v * b9; + t16 += v * b10; + t17 += v * b11; + t18 += v * b12; + t19 += v * b13; + t20 += v * b14; + t21 += v * b15; + v = a[7]; + t7 += v * b0; + t8 += v * b1; + t9 += v * b2; + t10 += v * b3; + t11 += v * b4; + t12 += v * b5; + t13 += v * b6; + t14 += v * b7; + t15 += v * b8; + t16 += v * b9; + t17 += v * b10; + t18 += v * b11; + t19 += v * b12; + t20 += v * b13; + t21 += v * b14; + t22 += v * b15; + v = a[8]; + t8 += v * b0; + t9 += v * b1; + t10 += v * b2; + t11 += v * b3; + t12 += v * b4; + t13 += v * b5; + t14 += v * b6; + t15 += v * b7; + t16 += v * b8; + t17 += v * b9; + t18 += v * b10; + t19 += v * b11; + t20 += v * b12; + t21 += v * b13; + t22 += v * b14; + t23 += v * b15; + v = a[9]; + t9 += v * b0; + t10 += v * b1; + t11 += v * b2; + t12 += v * b3; + t13 += v * b4; + t14 += v * b5; + t15 += v * b6; + t16 += v * b7; + t17 += v * b8; + t18 += v * b9; + t19 += v * b10; + t20 += v * b11; + t21 += v * b12; + t22 += v * b13; + t23 += v * b14; + t24 += v * b15; + v = a[10]; + t10 += v * b0; + t11 += v * b1; + t12 += v * b2; + t13 += v * b3; + t14 += v * b4; + t15 += v * b5; + t16 += v * b6; + t17 += v * b7; + t18 += v * b8; + t19 += v * b9; + t20 += v * b10; + t21 += v * b11; + t22 += v * b12; + t23 += v * b13; + t24 += v * b14; + t25 += v * b15; + v = a[11]; + t11 += v * b0; + t12 += v * b1; + t13 += v * b2; + t14 += v * b3; + t15 += v * b4; + t16 += v * b5; + t17 += v * b6; + t18 += v * b7; + t19 += v * b8; + t20 += v * b9; + t21 += v * b10; + t22 += v * b11; + t23 += v * b12; + t24 += v * b13; + t25 += v * b14; + t26 += v * b15; + v = a[12]; + t12 += v * b0; + t13 += v * b1; + t14 += v * b2; + t15 += v * b3; + t16 += v * b4; + t17 += v * b5; + t18 += v * b6; + t19 += v * b7; + t20 += v * b8; + t21 += v * b9; + t22 += v * b10; + t23 += v * b11; + t24 += v * b12; + t25 += v * b13; + t26 += v * b14; + t27 += v * b15; + v = a[13]; + t13 += v * b0; + t14 += v * b1; + t15 += v * b2; + t16 += v * b3; + t17 += v * b4; + t18 += v * b5; + t19 += v * b6; + t20 += v * b7; + t21 += v * b8; + t22 += v * b9; + t23 += v * b10; + t24 += v * b11; + t25 += v * b12; + t26 += v * b13; + t27 += v * b14; + t28 += v * b15; + v = a[14]; + t14 += v * b0; + t15 += v * b1; + t16 += v * b2; + t17 += v * b3; + t18 += v * b4; + t19 += v * b5; + t20 += v * b6; + t21 += v * b7; + t22 += v * b8; + t23 += v * b9; + t24 += v * b10; + t25 += v * b11; + t26 += v * b12; + t27 += v * b13; + t28 += v * b14; + t29 += v * b15; + v = a[15]; + t15 += v * b0; + t16 += v * b1; + t17 += v * b2; + t18 += v * b3; + t19 += v * b4; + t20 += v * b5; + t21 += v * b6; + t22 += v * b7; + t23 += v * b8; + t24 += v * b9; + t25 += v * b10; + t26 += v * b11; + t27 += v * b12; + t28 += v * b13; + t29 += v * b14; + t30 += v * b15; -var utils = exports; -var BN = require('bn.js'); -var minAssert = require('minimalistic-assert'); -var minUtils = require('minimalistic-crypto-utils'); + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is -utils.assert = minAssert; -utils.toArray = minUtils.toArray; -utils.zero2 = minUtils.zero2; -utils.toHex = minUtils.toHex; -utils.encode = minUtils.encode; + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); -// Represent num in a w-NAF form -function getNAF(num, w, bits) { - var naf = new Array(Math.max(num.bitLength(), bits) + 1); - naf.fill(0); + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); - var ws = 1 << (w + 1); - var k = num.clone(); + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} - for (var i = 0; i < naf.length; i++) { - var z; - var mod = k.andln(ws - 1); - if (k.isOdd()) { - if (mod > (ws >> 1) - 1) - z = (ws >> 1) - mod; - else - z = mod; - k.isubn(z); - } else { - z = 0; - } +function S(o, a) { + M(o, a, a); +} - naf[i] = z; - k.iushrn(1); +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); } - - return naf; + for (a = 0; a < 16; a++) o[a] = c[a]; } -utils.getNAF = getNAF; - -// Represent k1, k2 in a Joint Sparse Form -function getJSF(k1, k2) { - var jsf = [ - [], - [], - ]; - - k1 = k1.clone(); - k2 = k2.clone(); - var d1 = 0; - var d2 = 0; - var m8; - while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { - // First phase - var m14 = (k1.andln(3) + d1) & 3; - var m24 = (k2.andln(3) + d2) & 3; - if (m14 === 3) - m14 = -1; - if (m24 === 3) - m24 = -1; - var u1; - if ((m14 & 1) === 0) { - u1 = 0; - } else { - m8 = (k1.andln(7) + d1) & 7; - if ((m8 === 3 || m8 === 5) && m24 === 2) - u1 = -m14; - else - u1 = m14; - } - jsf[0].push(u1); - - var u2; - if ((m24 & 1) === 0) { - u2 = 0; - } else { - m8 = (k2.andln(7) + d2) & 7; - if ((m8 === 3 || m8 === 5) && m14 === 2) - u2 = -m24; - else - u2 = m24; - } - jsf[1].push(u2); - // Second phase - if (2 * d1 === u1 + 1) - d1 = 1 - d1; - if (2 * d2 === u2 + 1) - d2 = 1 - d2; - k1.iushrn(1); - k2.iushrn(1); +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); } - - return jsf; + for (a = 0; a < 16; a++) o[a] = c[a]; } -utils.getJSF = getJSF; -function cachedProperty(obj, name, computer) { - var key = '_' + name; - obj.prototype[name] = function cachedProperty() { - return this[key] !== undefined ? this[key] : - this[key] = computer.call(this); - }; +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; } -utils.cachedProperty = cachedProperty; -function parseBytes(bytes) { - return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : - bytes; +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); } -utils.parseBytes = parseBytes; -function intFromLE(bytes) { - return new BN(bytes, 'hex', 'le'); +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); } -utils.intFromLE = intFromLE; - -},{"bn.js":302,"minimalistic-assert":238,"minimalistic-crypto-utils":239}],318:[function(require,module,exports){ -module.exports={ - "name": "elliptic", - "version": "6.5.4", - "description": "EC cryptography", - "main": "lib/elliptic.js", - "files": [ - "lib" - ], - "scripts": { - "lint": "eslint lib test", - "lint:fix": "npm run lint -- --fix", - "unit": "istanbul test _mocha --reporter=spec test/index.js", - "test": "npm run lint && npm run unit", - "version": "grunt dist && git add dist/" - }, - "repository": { - "type": "git", - "url": "git@github.com:indutny/elliptic" - }, - "keywords": [ - "EC", - "Elliptic", - "curve", - "Cryptography" - ], - "author": "Fedor Indutny ", - "license": "MIT", - "bugs": { - "url": "https://github.com/indutny/elliptic/issues" - }, - "homepage": "https://github.com/indutny/elliptic", - "devDependencies": { - "brfs": "^2.0.2", - "coveralls": "^3.1.0", - "eslint": "^7.6.0", - "grunt": "^1.2.1", - "grunt-browserify": "^5.3.0", - "grunt-cli": "^1.3.2", - "grunt-contrib-connect": "^3.0.0", - "grunt-contrib-copy": "^1.0.0", - "grunt-contrib-uglify": "^5.0.0", - "grunt-mocha-istanbul": "^5.0.2", - "grunt-saucelabs": "^9.0.1", - "istanbul": "^0.4.5", - "mocha": "^8.0.1" - }, - "dependencies": { - "bn.js": "^4.11.9", - "brorand": "^1.1.0", - "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.1", - "inherits": "^2.0.4", - "minimalistic-assert": "^1.0.1", - "minimalistic-crypto-utils": "^1.0.1" - } +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); } -},{}],319:[function(require,module,exports){ -(function (Buffer){ -const createHmac = require('create-hmac') - -const ONE1 = Buffer.alloc(1, 1) -const ZERO1 = Buffer.alloc(1, 0) - -// https://tools.ietf.org/html/rfc6979#section-3.2 -function deterministicGenerateK (hash, x, checkSig, isPrivate, extraEntropy) { - // Step A, ignored as hash already provided - // Step B - // Step C - let k = Buffer.alloc(32, 0) - let v = Buffer.alloc(32, 1) - - // Step D - k = createHmac('sha256', k) - .update(v) - .update(ZERO1) - .update(x) - .update(hash) - .update(extraEntropy || '') - .digest() - - // Step E - v = createHmac('sha256', k).update(v).digest() - - // Step F - k = createHmac('sha256', k) - .update(v) - .update(ONE1) - .update(x) - .update(hash) - .update(extraEntropy || '') - .digest() - - // Step G - v = createHmac('sha256', k).update(v).digest() - - // Step H1/H2a, ignored as tlen === qlen (256 bit) - // Step H2b - v = createHmac('sha256', k).update(v).digest() - - let T = v - - // Step H3, repeat until T is within the interval [1, n - 1] and is suitable for ECDSA - while (!isPrivate(T) || !checkSig(T)) { - k = createHmac('sha256', k) - .update(v) - .update(ZERO1) - .digest() - - v = createHmac('sha256', k).update(v).digest() - - // Step H1/H2a, again, ignored as tlen === qlen (256 bit) - // Step H2b again - v = createHmac('sha256', k).update(v).digest() - T = v - } +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; - return T +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); } -module.exports = deterministicGenerateK - -}).call(this,require("buffer").Buffer) -},{"buffer":155,"create-hmac":161}],320:[function(require,module,exports){ -(function (Buffer){ -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if (typeof module !== 'undefined' && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; - - var util = {}; - - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); - } - } - - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; - - if (typeof atob === 'undefined') { - // Node.js - - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; - - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; - - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; - } - - } else { - // Browsers - - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - } - - return util; - -})); - -}).call(this,require("buffer").Buffer) -},{"buffer":105}],321:[function(require,module,exports){ -(function(nacl) { -'use strict'; - -// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -// -// Implementation derived from TweetNaCl version 20140427. -// See for details: http://tweetnacl.cr.yp.to/ - -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; - return r; -}; +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} -// Pluggable, initialized in high-level API below. -var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; -var _0 = new Uint8Array(16); -var _9 = new Uint8Array(32); _9[0] = 9; +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; -var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], -function ts64(x, i, h, l) { - x[i] = (h >> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} + // add + h = ah7; + l = al7; -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); + // K + h = K[i*2]; + l = K[i*2+1]; - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); + // w + h = wh[i%16]; + l = wl[i%16]; - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; + // add + h = th; + l = tl; - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; + // add + h = bh3; + l = bl3; - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; + h = th; + l = tl; - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; + // add + h = ah0; + l = al0; - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; + h = hh[0]; + l = hl[0]; - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} + h = ah1; + l = al1; -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} + h = hh[1]; + l = hl[1]; -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; -} + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; -} + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); -} + h = ah2; + l = al2; -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); -} + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ + h = hh[2]; + l = hl[2]; -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - var t0, t1, t2, t3, t4, t5, t6, t7; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; + h = ah3; + l = al3; -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; + h = hh[3]; + l = hl[3]; - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - c = 0; + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; + h = ah4; + l = al4; - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; + h = hh[4]; + l = hl[4]; - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; + h = ah5; + l = al5; - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; + h = hh[5]; + l = hl[5]; - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; -}; + h = ah6; + l = al6; -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } + h = hh[6]; + l = hl[6]; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; + h = ah7; + l = al7; - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; -}; + h = hh[7]; + l = hl[7]; -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; + pos += 128; + n -= 128; } -}; -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; + return n; } -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } + return 0; } -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); } -function unpack25519(o, n) { +function cswap(p, q, b) { var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } } -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; } -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } } -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; - - v = a[0]; - t0 += v * b0; - t1 += v * b1; - t2 += v * b2; - t3 += v * b3; - t4 += v * b4; - t5 += v * b5; - t6 += v * b6; - t7 += v * b7; - t8 += v * b8; - t9 += v * b9; - t10 += v * b10; - t11 += v * b11; - t12 += v * b12; - t13 += v * b13; - t14 += v * b14; - t15 += v * b15; - v = a[1]; - t1 += v * b0; - t2 += v * b1; - t3 += v * b2; - t4 += v * b3; - t5 += v * b4; - t6 += v * b5; - t7 += v * b6; - t8 += v * b7; - t9 += v * b8; - t10 += v * b9; - t11 += v * b10; - t12 += v * b11; - t13 += v * b12; - t14 += v * b13; - t15 += v * b14; - t16 += v * b15; - v = a[2]; - t2 += v * b0; - t3 += v * b1; - t4 += v * b2; - t5 += v * b3; - t6 += v * b4; - t7 += v * b5; - t8 += v * b6; - t9 += v * b7; - t10 += v * b8; - t11 += v * b9; - t12 += v * b10; - t13 += v * b11; - t14 += v * b12; - t15 += v * b13; - t16 += v * b14; - t17 += v * b15; - v = a[3]; - t3 += v * b0; - t4 += v * b1; - t5 += v * b2; - t6 += v * b3; - t7 += v * b4; - t8 += v * b5; - t9 += v * b6; - t10 += v * b7; - t11 += v * b8; - t12 += v * b9; - t13 += v * b10; - t14 += v * b11; - t15 += v * b12; - t16 += v * b13; - t17 += v * b14; - t18 += v * b15; - v = a[4]; - t4 += v * b0; - t5 += v * b1; - t6 += v * b2; - t7 += v * b3; - t8 += v * b4; - t9 += v * b5; - t10 += v * b6; - t11 += v * b7; - t12 += v * b8; - t13 += v * b9; - t14 += v * b10; - t15 += v * b11; - t16 += v * b12; - t17 += v * b13; - t18 += v * b14; - t19 += v * b15; - v = a[5]; - t5 += v * b0; - t6 += v * b1; - t7 += v * b2; - t8 += v * b3; - t9 += v * b4; - t10 += v * b5; - t11 += v * b6; - t12 += v * b7; - t13 += v * b8; - t14 += v * b9; - t15 += v * b10; - t16 += v * b11; - t17 += v * b12; - t18 += v * b13; - t19 += v * b14; - t20 += v * b15; - v = a[6]; - t6 += v * b0; - t7 += v * b1; - t8 += v * b2; - t9 += v * b3; - t10 += v * b4; - t11 += v * b5; - t12 += v * b6; - t13 += v * b7; - t14 += v * b8; - t15 += v * b9; - t16 += v * b10; - t17 += v * b11; - t18 += v * b12; - t19 += v * b13; - t20 += v * b14; - t21 += v * b15; - v = a[7]; - t7 += v * b0; - t8 += v * b1; - t9 += v * b2; - t10 += v * b3; - t11 += v * b4; - t12 += v * b5; - t13 += v * b6; - t14 += v * b7; - t15 += v * b8; - t16 += v * b9; - t17 += v * b10; - t18 += v * b11; - t19 += v * b12; - t20 += v * b13; - t21 += v * b14; - t22 += v * b15; - v = a[8]; - t8 += v * b0; - t9 += v * b1; - t10 += v * b2; - t11 += v * b3; - t12 += v * b4; - t13 += v * b5; - t14 += v * b6; - t15 += v * b7; - t16 += v * b8; - t17 += v * b9; - t18 += v * b10; - t19 += v * b11; - t20 += v * b12; - t21 += v * b13; - t22 += v * b14; - t23 += v * b15; - v = a[9]; - t9 += v * b0; - t10 += v * b1; - t11 += v * b2; - t12 += v * b3; - t13 += v * b4; - t14 += v * b5; - t15 += v * b6; - t16 += v * b7; - t17 += v * b8; - t18 += v * b9; - t19 += v * b10; - t20 += v * b11; - t21 += v * b12; - t22 += v * b13; - t23 += v * b14; - t24 += v * b15; - v = a[10]; - t10 += v * b0; - t11 += v * b1; - t12 += v * b2; - t13 += v * b3; - t14 += v * b4; - t15 += v * b5; - t16 += v * b6; - t17 += v * b7; - t18 += v * b8; - t19 += v * b9; - t20 += v * b10; - t21 += v * b11; - t22 += v * b12; - t23 += v * b13; - t24 += v * b14; - t25 += v * b15; - v = a[11]; - t11 += v * b0; - t12 += v * b1; - t13 += v * b2; - t14 += v * b3; - t15 += v * b4; - t16 += v * b5; - t17 += v * b6; - t18 += v * b7; - t19 += v * b8; - t20 += v * b9; - t21 += v * b10; - t22 += v * b11; - t23 += v * b12; - t24 += v * b13; - t25 += v * b14; - t26 += v * b15; - v = a[12]; - t12 += v * b0; - t13 += v * b1; - t14 += v * b2; - t15 += v * b3; - t16 += v * b4; - t17 += v * b5; - t18 += v * b6; - t19 += v * b7; - t20 += v * b8; - t21 += v * b9; - t22 += v * b10; - t23 += v * b11; - t24 += v * b12; - t25 += v * b13; - t26 += v * b14; - t27 += v * b15; - v = a[13]; - t13 += v * b0; - t14 += v * b1; - t15 += v * b2; - t16 += v * b3; - t17 += v * b4; - t18 += v * b5; - t19 += v * b6; - t20 += v * b7; - t21 += v * b8; - t22 += v * b9; - t23 += v * b10; - t24 += v * b11; - t25 += v * b12; - t26 += v * b13; - t27 += v * b14; - t28 += v * b15; - v = a[14]; - t14 += v * b0; - t15 += v * b1; - t16 += v * b2; - t17 += v * b3; - t18 += v * b4; - t19 += v * b5; - t20 += v * b6; - t21 += v * b7; - t22 += v * b8; - t23 += v * b9; - t24 += v * b10; - t25 += v * b11; - t26 += v * b12; - t27 += v * b13; - t28 += v * b14; - t29 += v * b15; - v = a[15]; - t15 += v * b0; - t16 += v * b1; - t17 += v * b2; - t18 += v * b3; - t19 += v * b4; - t20 += v * b5; - t21 += v * b6; - t22 += v * b7; - t23 += v * b8; - t24 += v * b9; - t25 += v * b10; - t26 += v * b11; - t27 += v * b12; - t28 += v * b13; - t29 += v * b14; - t30 += v * b15; - - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is - - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; -function S(o, a) { - M(o, a, a); -} + scalarbase(p, d); + pack(pk, p); -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; } -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = Math.floor((x[j] + 128) / 256); + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; } -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); } -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; + + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; + + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); + + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); + + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } + + modL(sm.subarray(32), x); + return smlen; } -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); + + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); + + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); + + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; + + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); + + M(r[3], r[0], r[1]); + return 0; } -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; +function crypto_sign_open(m, sm, n, pk) { + var i; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); + if (n < 64) return -1; + + if (unpackneg(q, pk)) return -1; + + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); + + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); + + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } + + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + return n; } -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; + +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, + + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES, + + gf: gf, + D: D, + L: L, + pack25519: pack25519, + unpack25519: unpack25519, + M: M, + A: A, + S: S, + Z: Z, + pow2523: pow2523, + add: add, + set25519: set25519, + modL: modL, + scalarmult: scalarmult, + scalarbase: scalarbase, +}; + +/* High-level API */ + +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); } -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; - // add - h = ah7; - l = al7; +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; - // K - h = K[i*2]; - l = K[i*2+1]; +nacl.box.after = nacl.secretbox; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; - // w - h = wh[i%16]; - l = wl[i%16]; +nacl.box.open.after = nacl.secretbox.open; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; + +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; - // add - h = th; - l = tl; +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; - // add - h = bh3; - l = bl3; +nacl.hash.hashLength = crypto_hash_BYTES; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; - h = th; - l = tl; +nacl.setPRNG = function(fn) { + randombytes = fn; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (typeof require !== 'undefined') { + // Node.js. + crypto = require('crypto'); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } +})(); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {})); - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); +},{"crypto":200}],519:[function(require,module,exports){ +var native = require('./native') - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; +function getTypeName (fn) { + return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1] +} - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; +function getValueTypeName (value) { + return native.Nil(value) ? '' : getTypeName(value.constructor) +} - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; +function getValue (value) { + if (native.Function(value)) return '' + if (native.String(value)) return JSON.stringify(value) + if (value && native.Object(value)) return '' + return value +} - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +function captureStackTrace (e, t) { + if (Error.captureStackTrace) { + Error.captureStackTrace(e, t) + } +} - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; +function tfJSON (type) { + if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type) + if (native.Array(type)) return 'Array' + if (type && native.Object(type)) return 'Object' - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + return type !== undefined ? type : '' +} - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); +function tfErrorString (type, value, valueTypeName) { + var valueJson = getValue(value) - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + return 'Expected ' + tfJSON(type) + ', got' + + (valueTypeName !== '' ? ' ' + valueTypeName : '') + + (valueJson !== '' ? ' ' + valueJson : '') +} - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); +function TfTypeError (type, value, valueTypeName) { + valueTypeName = valueTypeName || getValueTypeName(value) + this.message = tfErrorString(type, value, valueTypeName) - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + captureStackTrace(this, TfTypeError) + this.__type = type + this.__value = value + this.__valueTypeName = valueTypeName +} - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +TfTypeError.prototype = Object.create(Error.prototype) +TfTypeError.prototype.constructor = TfTypeError - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); - } - } - } +function tfPropertyErrorString (type, label, name, value, valueTypeName) { + var description = '" of type ' + if (label === 'key') description = '" with key type ' - // add - h = ah0; - l = al0; + return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName) +} - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +function TfPropertyTypeError (type, property, label, value, valueTypeName) { + if (type) { + valueTypeName = valueTypeName || getValueTypeName(value) + this.message = tfPropertyErrorString(type, label, property, value, valueTypeName) + } else { + this.message = 'Unexpected property "' + property + '"' + } - h = hh[0]; - l = hl[0]; + captureStackTrace(this, TfTypeError) + this.__label = label + this.__property = property + this.__type = type + this.__value = value + this.__valueTypeName = valueTypeName +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +TfPropertyTypeError.prototype = Object.create(Error.prototype) +TfPropertyTypeError.prototype.constructor = TfTypeError - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +function tfCustomError (expected, actual) { + return new TfTypeError(expected, {}, actual) +} - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); +function tfSubError (e, property, label) { + // sub child? + if (e instanceof TfPropertyTypeError) { + property = property + '.' + e.__property - h = ah1; - l = al1; + e = new TfPropertyTypeError( + e.__type, property, e.__label, e.__value, e.__valueTypeName + ) - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + // child? + } else if (e instanceof TfTypeError) { + e = new TfPropertyTypeError( + e.__type, property, label, e.__value, e.__valueTypeName + ) + } - h = hh[1]; - l = hl[1]; + captureStackTrace(e) + return e +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +module.exports = { + TfTypeError: TfTypeError, + TfPropertyTypeError: TfPropertyTypeError, + tfCustomError: tfCustomError, + tfSubError: tfSubError, + tfJSON: tfJSON, + getValueTypeName: getValueTypeName +} - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +},{"./native":522}],520:[function(require,module,exports){ +(function (Buffer){(function (){ +var NATIVE = require('./native') +var ERRORS = require('./errors') - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); +function _Buffer (value) { + return Buffer.isBuffer(value) +} - h = ah2; - l = al2; +function Hex (value) { + return typeof value === 'string' && /^([0-9a-f]{2})+$/i.test(value) +} - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +function _LengthN (type, length) { + var name = type.toJSON() - h = hh[2]; - l = hl[2]; + function Length (value) { + if (!type(value)) return false + if (value.length === length) return true - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + throw ERRORS.tfCustomError(name + '(Length: ' + length + ')', name + '(Length: ' + value.length + ')') + } + Length.toJSON = function () { return name } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + return Length +} - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); +var _ArrayN = _LengthN.bind(null, NATIVE.Array) +var _BufferN = _LengthN.bind(null, _Buffer) +var _HexN = _LengthN.bind(null, Hex) +var _StringN = _LengthN.bind(null, NATIVE.String) - h = ah3; - l = al3; +function Range (a, b, f) { + f = f || NATIVE.Number + function _range (value, strict) { + return f(value, strict) && (value > a) && (value < b) + } + _range.toJSON = function () { + return `${f.toJSON()} between [${a}, ${b}]` + } + return _range +} - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +var INT53_MAX = Math.pow(2, 53) - 1 - h = hh[3]; - l = hl[3]; +function Finite (value) { + return typeof value === 'number' && isFinite(value) +} +function Int8 (value) { return ((value << 24) >> 24) === value } +function Int16 (value) { return ((value << 16) >> 16) === value } +function Int32 (value) { return (value | 0) === value } +function Int53 (value) { + return typeof value === 'number' && + value >= -INT53_MAX && + value <= INT53_MAX && + Math.floor(value) === value +} +function UInt8 (value) { return (value & 0xff) === value } +function UInt16 (value) { return (value & 0xffff) === value } +function UInt32 (value) { return (value >>> 0) === value } +function UInt53 (value) { + return typeof value === 'number' && + value >= 0 && + value <= INT53_MAX && + Math.floor(value) === value +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +var types = { + ArrayN: _ArrayN, + Buffer: _Buffer, + BufferN: _BufferN, + Finite: Finite, + Hex: Hex, + HexN: _HexN, + Int8: Int8, + Int16: Int16, + Int32: Int32, + Int53: Int53, + Range: Range, + StringN: _StringN, + UInt8: UInt8, + UInt16: UInt16, + UInt32: UInt32, + UInt53: UInt53 +} - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +for (var typeName in types) { + types[typeName].toJSON = function (t) { + return t + }.bind(null, typeName) +} - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); +module.exports = types - h = ah4; - l = al4; +}).call(this)}).call(this,{"isBuffer":require("../is-buffer/index.js")}) +},{"../is-buffer/index.js":351,"./errors":519,"./native":522}],521:[function(require,module,exports){ +var ERRORS = require('./errors') +var NATIVE = require('./native') - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +// short-hand +var tfJSON = ERRORS.tfJSON +var TfTypeError = ERRORS.TfTypeError +var TfPropertyTypeError = ERRORS.TfPropertyTypeError +var tfSubError = ERRORS.tfSubError +var getValueTypeName = ERRORS.getValueTypeName - h = hh[4]; - l = hl[4]; +var TYPES = { + arrayOf: function arrayOf (type, options) { + type = compile(type) + options = options || {} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + function _arrayOf (array, strict) { + if (!NATIVE.Array(array)) return false + if (NATIVE.Nil(array)) return false + if (options.minLength !== undefined && array.length < options.minLength) return false + if (options.maxLength !== undefined && array.length > options.maxLength) return false + if (options.length !== undefined && array.length !== options.length) return false - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + return array.every(function (value, i) { + try { + return typeforce(type, value, strict) + } catch (e) { + throw tfSubError(e, i) + } + }) + } + _arrayOf.toJSON = function () { + var str = '[' + tfJSON(type) + ']' + if (options.length !== undefined) { + str += '{' + options.length + '}' + } else if (options.minLength !== undefined || options.maxLength !== undefined) { + str += '{' + + (options.minLength === undefined ? 0 : options.minLength) + ',' + + (options.maxLength === undefined ? Infinity : options.maxLength) + '}' + } + return str + } - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); + return _arrayOf + }, - h = ah5; - l = al5; + maybe: function maybe (type) { + type = compile(type) - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + function _maybe (value, strict) { + return NATIVE.Nil(value) || type(value, strict, maybe) + } + _maybe.toJSON = function () { return '?' + tfJSON(type) } - h = hh[5]; - l = hl[5]; + return _maybe + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + map: function map (propertyType, propertyKeyType) { + propertyType = compile(propertyType) + if (propertyKeyType) propertyKeyType = compile(propertyKeyType) - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + function _map (value, strict) { + if (!NATIVE.Object(value)) return false + if (NATIVE.Nil(value)) return false - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); + for (var propertyName in value) { + try { + if (propertyKeyType) { + typeforce(propertyKeyType, propertyName, strict) + } + } catch (e) { + throw tfSubError(e, propertyName, 'key') + } - h = ah6; - l = al6; + try { + var propertyValue = value[propertyName] + typeforce(propertyType, propertyValue, strict) + } catch (e) { + throw tfSubError(e, propertyName) + } + } - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + return true + } - h = hh[6]; - l = hl[6]; + if (propertyKeyType) { + _map.toJSON = function () { + return '{' + tfJSON(propertyKeyType) + ': ' + tfJSON(propertyType) + '}' + } + } else { + _map.toJSON = function () { return '{' + tfJSON(propertyType) + '}' } + } - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + return _map + }, - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + object: function object (uncompiled) { + var type = {} - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); + for (var typePropertyName in uncompiled) { + type[typePropertyName] = compile(uncompiled[typePropertyName]) + } - h = ah7; - l = al7; + function _object (value, strict) { + if (!NATIVE.Object(value)) return false + if (NATIVE.Nil(value)) return false - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + var propertyName - h = hh[7]; - l = hl[7]; + try { + for (propertyName in type) { + var propertyType = type[propertyName] + var propertyValue = value[propertyName] - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + typeforce(propertyType, propertyValue, strict) + } + } catch (e) { + throw tfSubError(e, propertyName) + } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (strict) { + for (propertyName in value) { + if (type[propertyName]) continue - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); + throw new TfPropertyTypeError(undefined, propertyName) + } + } - pos += 128; - n -= 128; - } + return true + } + _object.toJSON = function () { return tfJSON(type) } - return n; -} + return _object + }, -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; + anyOf: function anyOf () { + var types = [].slice.call(arguments).map(compile) - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; + function _anyOf (value, strict) { + return types.some(function (type) { + try { + return typeforce(type, value, strict) + } catch (e) { + return false + } + }) + } + _anyOf.toJSON = function () { return types.map(tfJSON).join('|') } - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; + return _anyOf + }, - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; + allOf: function allOf () { + var types = [].slice.call(arguments).map(compile) - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; + function _allOf (value, strict) { + return types.every(function (type) { + try { + return typeforce(type, value, strict) + } catch (e) { + return false + } + }) + } + _allOf.toJSON = function () { return types.map(tfJSON).join(' & ') } - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); + return _allOf + }, - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + quacksLike: function quacksLike (type) { + function _quacksLike (value) { + return type === getValueTypeName(value) + } + _quacksLike.toJSON = function () { return type } - return 0; -} + return _quacksLike + }, -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); + tuple: function tuple () { + var types = [].slice.call(arguments).map(compile) - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); + function _tuple (values, strict) { + if (NATIVE.Nil(values)) return false + if (NATIVE.Nil(values.length)) return false + if (strict && (values.length !== types.length)) return false - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} + return types.every(function (type, i) { + try { + return typeforce(type, values[i], strict) + } catch (e) { + throw tfSubError(e, i) + } + }) + } + _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' } -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} + return _tuple + }, -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} + value: function value (expected) { + function _value (actual) { + return actual === expected + } + _value.toJSON = function () { return expected } -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); + return _value } } -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} +// TODO: deprecate +TYPES.oneOf = TYPES.anyOf -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; +function compile (type) { + if (NATIVE.String(type)) { + if (type[0] === '?') return TYPES.maybe(type.slice(1)) - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; + return NATIVE[type] || TYPES.quacksLike(type) + } else if (type && NATIVE.Object(type)) { + if (NATIVE.Array(type)) { + if (type.length !== 1) throw new TypeError('Expected compile() parameter of type Array of length 1') + return TYPES.arrayOf(type[0]) + } - scalarbase(p, d); - pack(pk, p); + return TYPES.object(type) + } else if (NATIVE.Function(type)) { + return type + } - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; + return TYPES.value(type) } -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); +function typeforce (type, value, strict, surrogate) { + if (NATIVE.Function(type)) { + if (type(value, strict)) return true -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = Math.floor((x[j] + 128) / 256); - x[j] -= carry * 256; - } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; + throw new TfTypeError(surrogate || type, value) } -} -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); + // JIT + return typeforce(compile(type), value, strict) } -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; - - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; +// assign types to typeforce function +for (var typeName in NATIVE) { + typeforce[typeName] = NATIVE[typeName] +} - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; +for (typeName in TYPES) { + typeforce[typeName] = TYPES[typeName] +} - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); +var EXTRA = require('./extra') +for (typeName in EXTRA) { + typeforce[typeName] = EXTRA[typeName] +} - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); +typeforce.compile = compile +typeforce.TfTypeError = TfTypeError +typeforce.TfPropertyTypeError = TfPropertyTypeError - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; - } - } +module.exports = typeforce - modL(sm.subarray(32), x); - return smlen; +},{"./errors":519,"./extra":520,"./native":522}],522:[function(require,module,exports){ +var types = { + Array: function (value) { return value !== null && value !== undefined && value.constructor === Array }, + Boolean: function (value) { return typeof value === 'boolean' }, + Function: function (value) { return typeof value === 'function' }, + Nil: function (value) { return value === undefined || value === null }, + Number: function (value) { return typeof value === 'number' }, + Object: function (value) { return typeof value === 'object' }, + String: function (value) { return typeof value === 'string' }, + '': function () { return true } } -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); - - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); +// TODO: deprecate +types.Null = types.Nil - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); +for (var typeName in types) { + types[typeName].toJSON = function (t) { + return t + }.bind(null, typeName) +} - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); +module.exports = types - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; +},{}],523:[function(require,module,exports){ +(function (root) { + "use strict"; - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); +/***** unorm.js *****/ - M(r[3], r[0], r[1]); - return 0; -} +/* + * UnicodeNormalizer 1.0.0 + * Copyright (c) 2008 Matsuza + * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. + * $Date: 2008-06-05 16:44:17 +0200 (Thu, 05 Jun 2008) $ + * $Rev: 13309 $ + */ -function crypto_sign_open(m, sm, n, pk) { - var i; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; + var DEFAULT_FEATURE = [null, 0, {}]; + var CACHE_THRESHOLD = 10; + var SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7, LCount = 19, VCount = 21, TCount = 28; + var NCount = VCount * TCount; // 588 + var SCount = LCount * NCount; // 11172 - if (n < 64) return -1; + var UChar = function(cp, feature){ + this.codepoint = cp; + this.feature = feature; + }; - if (unpackneg(q, pk)) return -1; + // Strategies + var cache = {}; + var cacheCounter = []; + for (var i = 0; i <= 0xFF; ++i){ + cacheCounter[i] = 0; + } - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); + function fromCache(next, cp, needFeature){ + var ret = cache[cp]; + if(!ret){ + ret = next(cp, needFeature); + if(!!ret.feature && ++cacheCounter[(cp >> 8) & 0xFF] > CACHE_THRESHOLD){ + cache[cp] = ret; + } + } + return ret; + } - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); + function fromData(next, cp, needFeature){ + var hash = cp & 0xFF00; + var dunit = UChar.udata[hash] || {}; + var f = dunit[cp]; + return f ? new UChar(cp, f) : new UChar(cp, DEFAULT_FEATURE); + } + function fromCpOnly(next, cp, needFeature){ + return !!needFeature ? next(cp, needFeature) : new UChar(cp, null); + } + function fromRuleBasedJamo(next, cp, needFeature){ + var j; + if(cp < LBase || (LBase + LCount <= cp && cp < SBase) || (SBase + SCount < cp)){ + return next(cp, needFeature); + } + if(LBase <= cp && cp < LBase + LCount){ + var c = {}; + var base = (cp - LBase) * VCount; + for (j = 0; j < VCount; ++j){ + c[VBase + j] = SBase + TCount * (j + base); + } + return new UChar(cp, [,,c]); + } - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } + var SIndex = cp - SBase; + var TIndex = SIndex % TCount; + var feature = []; + if(TIndex !== 0){ + feature[0] = [SBase + SIndex - TIndex, TBase + TIndex]; + } else { + feature[0] = [LBase + Math.floor(SIndex / NCount), VBase + Math.floor((SIndex % NCount) / TCount)]; + feature[2] = {}; + for (j = 1; j < TCount; ++j){ + feature[2][TBase + j] = cp + j; + } + } + return new UChar(cp, feature); + } + function fromCpFilter(next, cp, needFeature){ + return cp < 60 || 13311 < cp && cp < 42607 ? new UChar(cp, DEFAULT_FEATURE) : next(cp, needFeature); + } - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - return n; -} + var strategies = [fromCpFilter, fromCache, fromCpOnly, fromRuleBasedJamo, fromData]; -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; + UChar.fromCharCode = strategies.reduceRight(function (next, strategy) { + return function (cp, needFeature) { + return strategy(next, cp, needFeature); + }; + }, null); -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, + UChar.isHighSurrogate = function(cp){ + return cp >= 0xD800 && cp <= 0xDBFF; + }; + UChar.isLowSurrogate = function(cp){ + return cp >= 0xDC00 && cp <= 0xDFFF; + }; - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES, + UChar.prototype.prepFeature = function(){ + if(!this.feature){ + this.feature = UChar.fromCharCode(this.codepoint, true).feature; + } + }; - gf: gf, - D: D, - L: L, - pack25519: pack25519, - unpack25519: unpack25519, - M: M, - A: A, - S: S, - Z: Z, - pow2523: pow2523, - add: add, - set25519: set25519, - modL: modL, - scalarmult: scalarmult, - scalarbase: scalarbase, -}; + UChar.prototype.toString = function(){ + if(this.codepoint < 0x10000){ + return String.fromCharCode(this.codepoint); + } else { + var x = this.codepoint - 0x10000; + return String.fromCharCode(Math.floor(x / 0x400) + 0xD800, x % 0x400 + 0xDC00); + } + }; -/* High-level API */ + UChar.prototype.getDecomp = function(){ + this.prepFeature(); + return this.feature[0] || null; + }; -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} + UChar.prototype.isCompatibility = function(){ + this.prepFeature(); + return !!this.feature[1] && (this.feature[1] & (1 << 8)); + }; + UChar.prototype.isExclude = function(){ + this.prepFeature(); + return !!this.feature[1] && (this.feature[1] & (1 << 9)); + }; + UChar.prototype.getCanonicalClass = function(){ + this.prepFeature(); + return !!this.feature[1] ? (this.feature[1] & 0xff) : 0; + }; + UChar.prototype.getComposite = function(following){ + this.prepFeature(); + if(!this.feature[2]){ + return null; + } + var cp = this.feature[2][following.codepoint]; + return cp ? UChar.fromCharCode(cp) : null; + }; -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} + var UCharIterator = function(str){ + this.str = str; + this.cursor = 0; + }; + UCharIterator.prototype.next = function(){ + if(!!this.str && this.cursor < this.str.length){ + var cp = this.str.charCodeAt(this.cursor++); + var d; + if(UChar.isHighSurrogate(cp) && this.cursor < this.str.length && UChar.isLowSurrogate((d = this.str.charCodeAt(this.cursor)))){ + cp = (cp - 0xD800) * 0x400 + (d -0xDC00) + 0x10000; + ++this.cursor; + } + return UChar.fromCharCode(cp); + } else { + this.str = null; + return null; + } + }; -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} + var RecursDecompIterator = function(it, cano){ + this.it = it; + this.canonical = cano; + this.resBuf = []; + }; -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} + RecursDecompIterator.prototype.next = function(){ + function recursiveDecomp(cano, uchar){ + var decomp = uchar.getDecomp(); + if(!!decomp && !(cano && uchar.isCompatibility())){ + var ret = []; + for(var i = 0; i < decomp.length; ++i){ + var a = recursiveDecomp(cano, UChar.fromCharCode(decomp[i])); + ret = ret.concat(a); + } + return ret; + } else { + return [uchar]; + } + } + if(this.resBuf.length === 0){ + var uchar = this.it.next(); + if(!uchar){ + return null; + } + this.resBuf = recursiveDecomp(this.canonical, uchar); + } + return this.resBuf.shift(); + }; -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; -}; + var DecompIterator = function(it){ + this.it = it; + this.resBuf = []; + }; -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); -}; + DecompIterator.prototype.next = function(){ + var cc; + if(this.resBuf.length === 0){ + do{ + var uchar = this.it.next(); + if(!uchar){ + break; + } + cc = uchar.getCanonicalClass(); + var inspt = this.resBuf.length; + if(cc !== 0){ + for(; inspt > 0; --inspt){ + var uchar2 = this.resBuf[inspt - 1]; + var cc2 = uchar2.getCanonicalClass(); + if(cc2 <= cc){ + break; + } + } + } + this.resBuf.splice(inspt, 0, uchar); + } while(cc !== 0); + } + return this.resBuf.shift(); + }; -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; + var CompIterator = function(it){ + this.it = it; + this.procBuf = []; + this.resBuf = []; + this.lastClass = null; + }; -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + CompIterator.prototype.next = function(){ + while(this.resBuf.length === 0){ + var uchar = this.it.next(); + if(!uchar){ + this.resBuf = this.procBuf; + this.procBuf = []; + break; + } + if(this.procBuf.length === 0){ + this.lastClass = uchar.getCanonicalClass(); + this.procBuf.push(uchar); + } else { + var starter = this.procBuf[0]; + var composite = starter.getComposite(uchar); + var cc = uchar.getCanonicalClass(); + if(!!composite && (this.lastClass < cc || this.lastClass === 0)){ + this.procBuf[0] = composite; + } else { + if(cc === 0){ + this.resBuf = this.procBuf; + this.procBuf = []; + } + this.lastClass = cc; + this.procBuf.push(uchar); + } + } + } + return this.resBuf.shift(); + }; -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; + var createIterator = function(mode, str){ + switch(mode){ + case "NFD": + return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true)); + case "NFKD": + return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false)); + case "NFC": + return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true))); + case "NFKC": + return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false))); + } + throw mode + " is invalid"; + }; + var normalize = function(mode, str){ + var it = createIterator(mode, str); + var ret = ""; + var uchar; + while(!!(uchar = it.next())){ + ret += uchar.toString(); + } + return ret; + }; -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; + /* API functions */ + function nfd(str){ + return normalize("NFD", str); + } -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; + function nfkd(str){ + return normalize("NFKD", str); + } -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; + function nfc(str){ + return normalize("NFC", str); + } -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; + function nfkc(str){ + return normalize("NFKC", str); + } -nacl.box.after = nacl.secretbox; +/* Unicode data */ +UChar.udata={ +0:{60:[,,{824:8814}],61:[,,{824:8800}],62:[,,{824:8815}],65:[,,{768:192,769:193,770:194,771:195,772:256,774:258,775:550,776:196,777:7842,778:197,780:461,783:512,785:514,803:7840,805:7680,808:260}],66:[,,{775:7682,803:7684,817:7686}],67:[,,{769:262,770:264,775:266,780:268,807:199}],68:[,,{775:7690,780:270,803:7692,807:7696,813:7698,817:7694}],69:[,,{768:200,769:201,770:202,771:7868,772:274,774:276,775:278,776:203,777:7866,780:282,783:516,785:518,803:7864,807:552,808:280,813:7704,816:7706}],70:[,,{775:7710}],71:[,,{769:500,770:284,772:7712,774:286,775:288,780:486,807:290}],72:[,,{770:292,775:7714,776:7718,780:542,803:7716,807:7720,814:7722}],73:[,,{768:204,769:205,770:206,771:296,772:298,774:300,775:304,776:207,777:7880,780:463,783:520,785:522,803:7882,808:302,816:7724}],74:[,,{770:308}],75:[,,{769:7728,780:488,803:7730,807:310,817:7732}],76:[,,{769:313,780:317,803:7734,807:315,813:7740,817:7738}],77:[,,{769:7742,775:7744,803:7746}],78:[,,{768:504,769:323,771:209,775:7748,780:327,803:7750,807:325,813:7754,817:7752}],79:[,,{768:210,769:211,770:212,771:213,772:332,774:334,775:558,776:214,777:7886,779:336,780:465,783:524,785:526,795:416,803:7884,808:490}],80:[,,{769:7764,775:7766}],82:[,,{769:340,775:7768,780:344,783:528,785:530,803:7770,807:342,817:7774}],83:[,,{769:346,770:348,775:7776,780:352,803:7778,806:536,807:350}],84:[,,{775:7786,780:356,803:7788,806:538,807:354,813:7792,817:7790}],85:[,,{768:217,769:218,770:219,771:360,772:362,774:364,776:220,777:7910,778:366,779:368,780:467,783:532,785:534,795:431,803:7908,804:7794,808:370,813:7798,816:7796}],86:[,,{771:7804,803:7806}],87:[,,{768:7808,769:7810,770:372,775:7814,776:7812,803:7816}],88:[,,{775:7818,776:7820}],89:[,,{768:7922,769:221,770:374,771:7928,772:562,775:7822,776:376,777:7926,803:7924}],90:[,,{769:377,770:7824,775:379,780:381,803:7826,817:7828}],97:[,,{768:224,769:225,770:226,771:227,772:257,774:259,775:551,776:228,777:7843,778:229,780:462,783:513,785:515,803:7841,805:7681,808:261}],98:[,,{775:7683,803:7685,817:7687}],99:[,,{769:263,770:265,775:267,780:269,807:231}],100:[,,{775:7691,780:271,803:7693,807:7697,813:7699,817:7695}],101:[,,{768:232,769:233,770:234,771:7869,772:275,774:277,775:279,776:235,777:7867,780:283,783:517,785:519,803:7865,807:553,808:281,813:7705,816:7707}],102:[,,{775:7711}],103:[,,{769:501,770:285,772:7713,774:287,775:289,780:487,807:291}],104:[,,{770:293,775:7715,776:7719,780:543,803:7717,807:7721,814:7723,817:7830}],105:[,,{768:236,769:237,770:238,771:297,772:299,774:301,776:239,777:7881,780:464,783:521,785:523,803:7883,808:303,816:7725}],106:[,,{770:309,780:496}],107:[,,{769:7729,780:489,803:7731,807:311,817:7733}],108:[,,{769:314,780:318,803:7735,807:316,813:7741,817:7739}],109:[,,{769:7743,775:7745,803:7747}],110:[,,{768:505,769:324,771:241,775:7749,780:328,803:7751,807:326,813:7755,817:7753}],111:[,,{768:242,769:243,770:244,771:245,772:333,774:335,775:559,776:246,777:7887,779:337,780:466,783:525,785:527,795:417,803:7885,808:491}],112:[,,{769:7765,775:7767}],114:[,,{769:341,775:7769,780:345,783:529,785:531,803:7771,807:343,817:7775}],115:[,,{769:347,770:349,775:7777,780:353,803:7779,806:537,807:351}],116:[,,{775:7787,776:7831,780:357,803:7789,806:539,807:355,813:7793,817:7791}],117:[,,{768:249,769:250,770:251,771:361,772:363,774:365,776:252,777:7911,778:367,779:369,780:468,783:533,785:535,795:432,803:7909,804:7795,808:371,813:7799,816:7797}],118:[,,{771:7805,803:7807}],119:[,,{768:7809,769:7811,770:373,775:7815,776:7813,778:7832,803:7817}],120:[,,{775:7819,776:7821}],121:[,,{768:7923,769:253,770:375,771:7929,772:563,775:7823,776:255,777:7927,778:7833,803:7925}],122:[,,{769:378,770:7825,775:380,780:382,803:7827,817:7829}],160:[[32],256],168:[[32,776],256,{768:8173,769:901,834:8129}],170:[[97],256],175:[[32,772],256],178:[[50],256],179:[[51],256],180:[[32,769],256],181:[[956],256],184:[[32,807],256],185:[[49],256],186:[[111],256],188:[[49,8260,52],256],189:[[49,8260,50],256],190:[[51,8260,52],256],192:[[65,768]],193:[[65,769]],194:[[65,770],,{768:7846,769:7844,771:7850,777:7848}],195:[[65,771]],196:[[65,776],,{772:478}],197:[[65,778],,{769:506}],198:[,,{769:508,772:482}],199:[[67,807],,{769:7688}],200:[[69,768]],201:[[69,769]],202:[[69,770],,{768:7872,769:7870,771:7876,777:7874}],203:[[69,776]],204:[[73,768]],205:[[73,769]],206:[[73,770]],207:[[73,776],,{769:7726}],209:[[78,771]],210:[[79,768]],211:[[79,769]],212:[[79,770],,{768:7890,769:7888,771:7894,777:7892}],213:[[79,771],,{769:7756,772:556,776:7758}],214:[[79,776],,{772:554}],216:[,,{769:510}],217:[[85,768]],218:[[85,769]],219:[[85,770]],220:[[85,776],,{768:475,769:471,772:469,780:473}],221:[[89,769]],224:[[97,768]],225:[[97,769]],226:[[97,770],,{768:7847,769:7845,771:7851,777:7849}],227:[[97,771]],228:[[97,776],,{772:479}],229:[[97,778],,{769:507}],230:[,,{769:509,772:483}],231:[[99,807],,{769:7689}],232:[[101,768]],233:[[101,769]],234:[[101,770],,{768:7873,769:7871,771:7877,777:7875}],235:[[101,776]],236:[[105,768]],237:[[105,769]],238:[[105,770]],239:[[105,776],,{769:7727}],241:[[110,771]],242:[[111,768]],243:[[111,769]],244:[[111,770],,{768:7891,769:7889,771:7895,777:7893}],245:[[111,771],,{769:7757,772:557,776:7759}],246:[[111,776],,{772:555}],248:[,,{769:511}],249:[[117,768]],250:[[117,769]],251:[[117,770]],252:[[117,776],,{768:476,769:472,772:470,780:474}],253:[[121,769]],255:[[121,776]]}, +256:{256:[[65,772]],257:[[97,772]],258:[[65,774],,{768:7856,769:7854,771:7860,777:7858}],259:[[97,774],,{768:7857,769:7855,771:7861,777:7859}],260:[[65,808]],261:[[97,808]],262:[[67,769]],263:[[99,769]],264:[[67,770]],265:[[99,770]],266:[[67,775]],267:[[99,775]],268:[[67,780]],269:[[99,780]],270:[[68,780]],271:[[100,780]],274:[[69,772],,{768:7700,769:7702}],275:[[101,772],,{768:7701,769:7703}],276:[[69,774]],277:[[101,774]],278:[[69,775]],279:[[101,775]],280:[[69,808]],281:[[101,808]],282:[[69,780]],283:[[101,780]],284:[[71,770]],285:[[103,770]],286:[[71,774]],287:[[103,774]],288:[[71,775]],289:[[103,775]],290:[[71,807]],291:[[103,807]],292:[[72,770]],293:[[104,770]],296:[[73,771]],297:[[105,771]],298:[[73,772]],299:[[105,772]],300:[[73,774]],301:[[105,774]],302:[[73,808]],303:[[105,808]],304:[[73,775]],306:[[73,74],256],307:[[105,106],256],308:[[74,770]],309:[[106,770]],310:[[75,807]],311:[[107,807]],313:[[76,769]],314:[[108,769]],315:[[76,807]],316:[[108,807]],317:[[76,780]],318:[[108,780]],319:[[76,183],256],320:[[108,183],256],323:[[78,769]],324:[[110,769]],325:[[78,807]],326:[[110,807]],327:[[78,780]],328:[[110,780]],329:[[700,110],256],332:[[79,772],,{768:7760,769:7762}],333:[[111,772],,{768:7761,769:7763}],334:[[79,774]],335:[[111,774]],336:[[79,779]],337:[[111,779]],340:[[82,769]],341:[[114,769]],342:[[82,807]],343:[[114,807]],344:[[82,780]],345:[[114,780]],346:[[83,769],,{775:7780}],347:[[115,769],,{775:7781}],348:[[83,770]],349:[[115,770]],350:[[83,807]],351:[[115,807]],352:[[83,780],,{775:7782}],353:[[115,780],,{775:7783}],354:[[84,807]],355:[[116,807]],356:[[84,780]],357:[[116,780]],360:[[85,771],,{769:7800}],361:[[117,771],,{769:7801}],362:[[85,772],,{776:7802}],363:[[117,772],,{776:7803}],364:[[85,774]],365:[[117,774]],366:[[85,778]],367:[[117,778]],368:[[85,779]],369:[[117,779]],370:[[85,808]],371:[[117,808]],372:[[87,770]],373:[[119,770]],374:[[89,770]],375:[[121,770]],376:[[89,776]],377:[[90,769]],378:[[122,769]],379:[[90,775]],380:[[122,775]],381:[[90,780]],382:[[122,780]],383:[[115],256,{775:7835}],416:[[79,795],,{768:7900,769:7898,771:7904,777:7902,803:7906}],417:[[111,795],,{768:7901,769:7899,771:7905,777:7903,803:7907}],431:[[85,795],,{768:7914,769:7912,771:7918,777:7916,803:7920}],432:[[117,795],,{768:7915,769:7913,771:7919,777:7917,803:7921}],439:[,,{780:494}],452:[[68,381],256],453:[[68,382],256],454:[[100,382],256],455:[[76,74],256],456:[[76,106],256],457:[[108,106],256],458:[[78,74],256],459:[[78,106],256],460:[[110,106],256],461:[[65,780]],462:[[97,780]],463:[[73,780]],464:[[105,780]],465:[[79,780]],466:[[111,780]],467:[[85,780]],468:[[117,780]],469:[[220,772]],470:[[252,772]],471:[[220,769]],472:[[252,769]],473:[[220,780]],474:[[252,780]],475:[[220,768]],476:[[252,768]],478:[[196,772]],479:[[228,772]],480:[[550,772]],481:[[551,772]],482:[[198,772]],483:[[230,772]],486:[[71,780]],487:[[103,780]],488:[[75,780]],489:[[107,780]],490:[[79,808],,{772:492}],491:[[111,808],,{772:493}],492:[[490,772]],493:[[491,772]],494:[[439,780]],495:[[658,780]],496:[[106,780]],497:[[68,90],256],498:[[68,122],256],499:[[100,122],256],500:[[71,769]],501:[[103,769]],504:[[78,768]],505:[[110,768]],506:[[197,769]],507:[[229,769]],508:[[198,769]],509:[[230,769]],510:[[216,769]],511:[[248,769]],66045:[,220]}, +512:{512:[[65,783]],513:[[97,783]],514:[[65,785]],515:[[97,785]],516:[[69,783]],517:[[101,783]],518:[[69,785]],519:[[101,785]],520:[[73,783]],521:[[105,783]],522:[[73,785]],523:[[105,785]],524:[[79,783]],525:[[111,783]],526:[[79,785]],527:[[111,785]],528:[[82,783]],529:[[114,783]],530:[[82,785]],531:[[114,785]],532:[[85,783]],533:[[117,783]],534:[[85,785]],535:[[117,785]],536:[[83,806]],537:[[115,806]],538:[[84,806]],539:[[116,806]],542:[[72,780]],543:[[104,780]],550:[[65,775],,{772:480}],551:[[97,775],,{772:481}],552:[[69,807],,{774:7708}],553:[[101,807],,{774:7709}],554:[[214,772]],555:[[246,772]],556:[[213,772]],557:[[245,772]],558:[[79,775],,{772:560}],559:[[111,775],,{772:561}],560:[[558,772]],561:[[559,772]],562:[[89,772]],563:[[121,772]],658:[,,{780:495}],688:[[104],256],689:[[614],256],690:[[106],256],691:[[114],256],692:[[633],256],693:[[635],256],694:[[641],256],695:[[119],256],696:[[121],256],728:[[32,774],256],729:[[32,775],256],730:[[32,778],256],731:[[32,808],256],732:[[32,771],256],733:[[32,779],256],736:[[611],256],737:[[108],256],738:[[115],256],739:[[120],256],740:[[661],256],66272:[,220]}, +768:{768:[,230],769:[,230],770:[,230],771:[,230],772:[,230],773:[,230],774:[,230],775:[,230],776:[,230,{769:836}],777:[,230],778:[,230],779:[,230],780:[,230],781:[,230],782:[,230],783:[,230],784:[,230],785:[,230],786:[,230],787:[,230],788:[,230],789:[,232],790:[,220],791:[,220],792:[,220],793:[,220],794:[,232],795:[,216],796:[,220],797:[,220],798:[,220],799:[,220],800:[,220],801:[,202],802:[,202],803:[,220],804:[,220],805:[,220],806:[,220],807:[,202],808:[,202],809:[,220],810:[,220],811:[,220],812:[,220],813:[,220],814:[,220],815:[,220],816:[,220],817:[,220],818:[,220],819:[,220],820:[,1],821:[,1],822:[,1],823:[,1],824:[,1],825:[,220],826:[,220],827:[,220],828:[,220],829:[,230],830:[,230],831:[,230],832:[[768],230],833:[[769],230],834:[,230],835:[[787],230],836:[[776,769],230],837:[,240],838:[,230],839:[,220],840:[,220],841:[,220],842:[,230],843:[,230],844:[,230],845:[,220],846:[,220],848:[,230],849:[,230],850:[,230],851:[,220],852:[,220],853:[,220],854:[,220],855:[,230],856:[,232],857:[,220],858:[,220],859:[,230],860:[,233],861:[,234],862:[,234],863:[,233],864:[,234],865:[,234],866:[,233],867:[,230],868:[,230],869:[,230],870:[,230],871:[,230],872:[,230],873:[,230],874:[,230],875:[,230],876:[,230],877:[,230],878:[,230],879:[,230],884:[[697]],890:[[32,837],256],894:[[59]],900:[[32,769],256],901:[[168,769]],902:[[913,769]],903:[[183]],904:[[917,769]],905:[[919,769]],906:[[921,769]],908:[[927,769]],910:[[933,769]],911:[[937,769]],912:[[970,769]],913:[,,{768:8122,769:902,772:8121,774:8120,787:7944,788:7945,837:8124}],917:[,,{768:8136,769:904,787:7960,788:7961}],919:[,,{768:8138,769:905,787:7976,788:7977,837:8140}],921:[,,{768:8154,769:906,772:8153,774:8152,776:938,787:7992,788:7993}],927:[,,{768:8184,769:908,787:8008,788:8009}],929:[,,{788:8172}],933:[,,{768:8170,769:910,772:8169,774:8168,776:939,788:8025}],937:[,,{768:8186,769:911,787:8040,788:8041,837:8188}],938:[[921,776]],939:[[933,776]],940:[[945,769],,{837:8116}],941:[[949,769]],942:[[951,769],,{837:8132}],943:[[953,769]],944:[[971,769]],945:[,,{768:8048,769:940,772:8113,774:8112,787:7936,788:7937,834:8118,837:8115}],949:[,,{768:8050,769:941,787:7952,788:7953}],951:[,,{768:8052,769:942,787:7968,788:7969,834:8134,837:8131}],953:[,,{768:8054,769:943,772:8145,774:8144,776:970,787:7984,788:7985,834:8150}],959:[,,{768:8056,769:972,787:8000,788:8001}],961:[,,{787:8164,788:8165}],965:[,,{768:8058,769:973,772:8161,774:8160,776:971,787:8016,788:8017,834:8166}],969:[,,{768:8060,769:974,787:8032,788:8033,834:8182,837:8179}],970:[[953,776],,{768:8146,769:912,834:8151}],971:[[965,776],,{768:8162,769:944,834:8167}],972:[[959,769]],973:[[965,769]],974:[[969,769],,{837:8180}],976:[[946],256],977:[[952],256],978:[[933],256,{769:979,776:980}],979:[[978,769]],980:[[978,776]],981:[[966],256],982:[[960],256],1008:[[954],256],1009:[[961],256],1010:[[962],256],1012:[[920],256],1013:[[949],256],1017:[[931],256],66422:[,230],66423:[,230],66424:[,230],66425:[,230],66426:[,230]}, +1024:{1024:[[1045,768]],1025:[[1045,776]],1027:[[1043,769]],1030:[,,{776:1031}],1031:[[1030,776]],1036:[[1050,769]],1037:[[1048,768]],1038:[[1059,774]],1040:[,,{774:1232,776:1234}],1043:[,,{769:1027}],1045:[,,{768:1024,774:1238,776:1025}],1046:[,,{774:1217,776:1244}],1047:[,,{776:1246}],1048:[,,{768:1037,772:1250,774:1049,776:1252}],1049:[[1048,774]],1050:[,,{769:1036}],1054:[,,{776:1254}],1059:[,,{772:1262,774:1038,776:1264,779:1266}],1063:[,,{776:1268}],1067:[,,{776:1272}],1069:[,,{776:1260}],1072:[,,{774:1233,776:1235}],1075:[,,{769:1107}],1077:[,,{768:1104,774:1239,776:1105}],1078:[,,{774:1218,776:1245}],1079:[,,{776:1247}],1080:[,,{768:1117,772:1251,774:1081,776:1253}],1081:[[1080,774]],1082:[,,{769:1116}],1086:[,,{776:1255}],1091:[,,{772:1263,774:1118,776:1265,779:1267}],1095:[,,{776:1269}],1099:[,,{776:1273}],1101:[,,{776:1261}],1104:[[1077,768]],1105:[[1077,776]],1107:[[1075,769]],1110:[,,{776:1111}],1111:[[1110,776]],1116:[[1082,769]],1117:[[1080,768]],1118:[[1091,774]],1140:[,,{783:1142}],1141:[,,{783:1143}],1142:[[1140,783]],1143:[[1141,783]],1155:[,230],1156:[,230],1157:[,230],1158:[,230],1159:[,230],1217:[[1046,774]],1218:[[1078,774]],1232:[[1040,774]],1233:[[1072,774]],1234:[[1040,776]],1235:[[1072,776]],1238:[[1045,774]],1239:[[1077,774]],1240:[,,{776:1242}],1241:[,,{776:1243}],1242:[[1240,776]],1243:[[1241,776]],1244:[[1046,776]],1245:[[1078,776]],1246:[[1047,776]],1247:[[1079,776]],1250:[[1048,772]],1251:[[1080,772]],1252:[[1048,776]],1253:[[1080,776]],1254:[[1054,776]],1255:[[1086,776]],1256:[,,{776:1258}],1257:[,,{776:1259}],1258:[[1256,776]],1259:[[1257,776]],1260:[[1069,776]],1261:[[1101,776]],1262:[[1059,772]],1263:[[1091,772]],1264:[[1059,776]],1265:[[1091,776]],1266:[[1059,779]],1267:[[1091,779]],1268:[[1063,776]],1269:[[1095,776]],1272:[[1067,776]],1273:[[1099,776]]}, +1280:{1415:[[1381,1410],256],1425:[,220],1426:[,230],1427:[,230],1428:[,230],1429:[,230],1430:[,220],1431:[,230],1432:[,230],1433:[,230],1434:[,222],1435:[,220],1436:[,230],1437:[,230],1438:[,230],1439:[,230],1440:[,230],1441:[,230],1442:[,220],1443:[,220],1444:[,220],1445:[,220],1446:[,220],1447:[,220],1448:[,230],1449:[,230],1450:[,220],1451:[,230],1452:[,230],1453:[,222],1454:[,228],1455:[,230],1456:[,10],1457:[,11],1458:[,12],1459:[,13],1460:[,14],1461:[,15],1462:[,16],1463:[,17],1464:[,18],1465:[,19],1466:[,19],1467:[,20],1468:[,21],1469:[,22],1471:[,23],1473:[,24],1474:[,25],1476:[,230],1477:[,220],1479:[,18]}, +1536:{1552:[,230],1553:[,230],1554:[,230],1555:[,230],1556:[,230],1557:[,230],1558:[,230],1559:[,230],1560:[,30],1561:[,31],1562:[,32],1570:[[1575,1619]],1571:[[1575,1620]],1572:[[1608,1620]],1573:[[1575,1621]],1574:[[1610,1620]],1575:[,,{1619:1570,1620:1571,1621:1573}],1608:[,,{1620:1572}],1610:[,,{1620:1574}],1611:[,27],1612:[,28],1613:[,29],1614:[,30],1615:[,31],1616:[,32],1617:[,33],1618:[,34],1619:[,230],1620:[,230],1621:[,220],1622:[,220],1623:[,230],1624:[,230],1625:[,230],1626:[,230],1627:[,230],1628:[,220],1629:[,230],1630:[,230],1631:[,220],1648:[,35],1653:[[1575,1652],256],1654:[[1608,1652],256],1655:[[1735,1652],256],1656:[[1610,1652],256],1728:[[1749,1620]],1729:[,,{1620:1730}],1730:[[1729,1620]],1746:[,,{1620:1747}],1747:[[1746,1620]],1749:[,,{1620:1728}],1750:[,230],1751:[,230],1752:[,230],1753:[,230],1754:[,230],1755:[,230],1756:[,230],1759:[,230],1760:[,230],1761:[,230],1762:[,230],1763:[,220],1764:[,230],1767:[,230],1768:[,230],1770:[,220],1771:[,230],1772:[,230],1773:[,220]}, +1792:{1809:[,36],1840:[,230],1841:[,220],1842:[,230],1843:[,230],1844:[,220],1845:[,230],1846:[,230],1847:[,220],1848:[,220],1849:[,220],1850:[,230],1851:[,220],1852:[,220],1853:[,230],1854:[,220],1855:[,230],1856:[,230],1857:[,230],1858:[,220],1859:[,230],1860:[,220],1861:[,230],1862:[,220],1863:[,230],1864:[,220],1865:[,230],1866:[,230],2027:[,230],2028:[,230],2029:[,230],2030:[,230],2031:[,230],2032:[,230],2033:[,230],2034:[,220],2035:[,230]}, +2048:{2070:[,230],2071:[,230],2072:[,230],2073:[,230],2075:[,230],2076:[,230],2077:[,230],2078:[,230],2079:[,230],2080:[,230],2081:[,230],2082:[,230],2083:[,230],2085:[,230],2086:[,230],2087:[,230],2089:[,230],2090:[,230],2091:[,230],2092:[,230],2093:[,230],2137:[,220],2138:[,220],2139:[,220],2276:[,230],2277:[,230],2278:[,220],2279:[,230],2280:[,230],2281:[,220],2282:[,230],2283:[,230],2284:[,230],2285:[,220],2286:[,220],2287:[,220],2288:[,27],2289:[,28],2290:[,29],2291:[,230],2292:[,230],2293:[,230],2294:[,220],2295:[,230],2296:[,230],2297:[,220],2298:[,220],2299:[,230],2300:[,230],2301:[,230],2302:[,230],2303:[,230]}, +2304:{2344:[,,{2364:2345}],2345:[[2344,2364]],2352:[,,{2364:2353}],2353:[[2352,2364]],2355:[,,{2364:2356}],2356:[[2355,2364]],2364:[,7],2381:[,9],2385:[,230],2386:[,220],2387:[,230],2388:[,230],2392:[[2325,2364],512],2393:[[2326,2364],512],2394:[[2327,2364],512],2395:[[2332,2364],512],2396:[[2337,2364],512],2397:[[2338,2364],512],2398:[[2347,2364],512],2399:[[2351,2364],512],2492:[,7],2503:[,,{2494:2507,2519:2508}],2507:[[2503,2494]],2508:[[2503,2519]],2509:[,9],2524:[[2465,2492],512],2525:[[2466,2492],512],2527:[[2479,2492],512]}, +2560:{2611:[[2610,2620],512],2614:[[2616,2620],512],2620:[,7],2637:[,9],2649:[[2582,2620],512],2650:[[2583,2620],512],2651:[[2588,2620],512],2654:[[2603,2620],512],2748:[,7],2765:[,9],68109:[,220],68111:[,230],68152:[,230],68153:[,1],68154:[,220],68159:[,9],68325:[,230],68326:[,220]}, +2816:{2876:[,7],2887:[,,{2878:2891,2902:2888,2903:2892}],2888:[[2887,2902]],2891:[[2887,2878]],2892:[[2887,2903]],2893:[,9],2908:[[2849,2876],512],2909:[[2850,2876],512],2962:[,,{3031:2964}],2964:[[2962,3031]],3014:[,,{3006:3018,3031:3020}],3015:[,,{3006:3019}],3018:[[3014,3006]],3019:[[3015,3006]],3020:[[3014,3031]],3021:[,9]}, +3072:{3142:[,,{3158:3144}],3144:[[3142,3158]],3149:[,9],3157:[,84],3158:[,91],3260:[,7],3263:[,,{3285:3264}],3264:[[3263,3285]],3270:[,,{3266:3274,3285:3271,3286:3272}],3271:[[3270,3285]],3272:[[3270,3286]],3274:[[3270,3266],,{3285:3275}],3275:[[3274,3285]],3277:[,9]}, +3328:{3398:[,,{3390:3402,3415:3404}],3399:[,,{3390:3403}],3402:[[3398,3390]],3403:[[3399,3390]],3404:[[3398,3415]],3405:[,9],3530:[,9],3545:[,,{3530:3546,3535:3548,3551:3550}],3546:[[3545,3530]],3548:[[3545,3535],,{3530:3549}],3549:[[3548,3530]],3550:[[3545,3551]]}, +3584:{3635:[[3661,3634],256],3640:[,103],3641:[,103],3642:[,9],3656:[,107],3657:[,107],3658:[,107],3659:[,107],3763:[[3789,3762],256],3768:[,118],3769:[,118],3784:[,122],3785:[,122],3786:[,122],3787:[,122],3804:[[3755,3737],256],3805:[[3755,3745],256]}, +3840:{3852:[[3851],256],3864:[,220],3865:[,220],3893:[,220],3895:[,220],3897:[,216],3907:[[3906,4023],512],3917:[[3916,4023],512],3922:[[3921,4023],512],3927:[[3926,4023],512],3932:[[3931,4023],512],3945:[[3904,4021],512],3953:[,129],3954:[,130],3955:[[3953,3954],512],3956:[,132],3957:[[3953,3956],512],3958:[[4018,3968],512],3959:[[4018,3969],256],3960:[[4019,3968],512],3961:[[4019,3969],256],3962:[,130],3963:[,130],3964:[,130],3965:[,130],3968:[,130],3969:[[3953,3968],512],3970:[,230],3971:[,230],3972:[,9],3974:[,230],3975:[,230],3987:[[3986,4023],512],3997:[[3996,4023],512],4002:[[4001,4023],512],4007:[[4006,4023],512],4012:[[4011,4023],512],4025:[[3984,4021],512],4038:[,220]}, +4096:{4133:[,,{4142:4134}],4134:[[4133,4142]],4151:[,7],4153:[,9],4154:[,9],4237:[,220],4348:[[4316],256],69702:[,9],69759:[,9],69785:[,,{69818:69786}],69786:[[69785,69818]],69787:[,,{69818:69788}],69788:[[69787,69818]],69797:[,,{69818:69803}],69803:[[69797,69818]],69817:[,9],69818:[,7]}, +4352:{69888:[,230],69889:[,230],69890:[,230],69934:[[69937,69927]],69935:[[69938,69927]],69937:[,,{69927:69934}],69938:[,,{69927:69935}],69939:[,9],69940:[,9],70003:[,7],70080:[,9]}, +4608:{70197:[,9],70198:[,7],70377:[,7],70378:[,9]}, +4864:{4957:[,230],4958:[,230],4959:[,230],70460:[,7],70471:[,,{70462:70475,70487:70476}],70475:[[70471,70462]],70476:[[70471,70487]],70477:[,9],70502:[,230],70503:[,230],70504:[,230],70505:[,230],70506:[,230],70507:[,230],70508:[,230],70512:[,230],70513:[,230],70514:[,230],70515:[,230],70516:[,230]}, +5120:{70841:[,,{70832:70844,70842:70843,70845:70846}],70843:[[70841,70842]],70844:[[70841,70832]],70846:[[70841,70845]],70850:[,9],70851:[,7]}, +5376:{71096:[,,{71087:71098}],71097:[,,{71087:71099}],71098:[[71096,71087]],71099:[[71097,71087]],71103:[,9],71104:[,7]}, +5632:{71231:[,9],71350:[,9],71351:[,7]}, +5888:{5908:[,9],5940:[,9],6098:[,9],6109:[,230]}, +6144:{6313:[,228]}, +6400:{6457:[,222],6458:[,230],6459:[,220]}, +6656:{6679:[,230],6680:[,220],6752:[,9],6773:[,230],6774:[,230],6775:[,230],6776:[,230],6777:[,230],6778:[,230],6779:[,230],6780:[,230],6783:[,220],6832:[,230],6833:[,230],6834:[,230],6835:[,230],6836:[,230],6837:[,220],6838:[,220],6839:[,220],6840:[,220],6841:[,220],6842:[,220],6843:[,230],6844:[,230],6845:[,220]}, +6912:{6917:[,,{6965:6918}],6918:[[6917,6965]],6919:[,,{6965:6920}],6920:[[6919,6965]],6921:[,,{6965:6922}],6922:[[6921,6965]],6923:[,,{6965:6924}],6924:[[6923,6965]],6925:[,,{6965:6926}],6926:[[6925,6965]],6929:[,,{6965:6930}],6930:[[6929,6965]],6964:[,7],6970:[,,{6965:6971}],6971:[[6970,6965]],6972:[,,{6965:6973}],6973:[[6972,6965]],6974:[,,{6965:6976}],6975:[,,{6965:6977}],6976:[[6974,6965]],6977:[[6975,6965]],6978:[,,{6965:6979}],6979:[[6978,6965]],6980:[,9],7019:[,230],7020:[,220],7021:[,230],7022:[,230],7023:[,230],7024:[,230],7025:[,230],7026:[,230],7027:[,230],7082:[,9],7083:[,9],7142:[,7],7154:[,9],7155:[,9]}, +7168:{7223:[,7],7376:[,230],7377:[,230],7378:[,230],7380:[,1],7381:[,220],7382:[,220],7383:[,220],7384:[,220],7385:[,220],7386:[,230],7387:[,230],7388:[,220],7389:[,220],7390:[,220],7391:[,220],7392:[,230],7394:[,1],7395:[,1],7396:[,1],7397:[,1],7398:[,1],7399:[,1],7400:[,1],7405:[,220],7412:[,230],7416:[,230],7417:[,230]}, +7424:{7468:[[65],256],7469:[[198],256],7470:[[66],256],7472:[[68],256],7473:[[69],256],7474:[[398],256],7475:[[71],256],7476:[[72],256],7477:[[73],256],7478:[[74],256],7479:[[75],256],7480:[[76],256],7481:[[77],256],7482:[[78],256],7484:[[79],256],7485:[[546],256],7486:[[80],256],7487:[[82],256],7488:[[84],256],7489:[[85],256],7490:[[87],256],7491:[[97],256],7492:[[592],256],7493:[[593],256],7494:[[7426],256],7495:[[98],256],7496:[[100],256],7497:[[101],256],7498:[[601],256],7499:[[603],256],7500:[[604],256],7501:[[103],256],7503:[[107],256],7504:[[109],256],7505:[[331],256],7506:[[111],256],7507:[[596],256],7508:[[7446],256],7509:[[7447],256],7510:[[112],256],7511:[[116],256],7512:[[117],256],7513:[[7453],256],7514:[[623],256],7515:[[118],256],7516:[[7461],256],7517:[[946],256],7518:[[947],256],7519:[[948],256],7520:[[966],256],7521:[[967],256],7522:[[105],256],7523:[[114],256],7524:[[117],256],7525:[[118],256],7526:[[946],256],7527:[[947],256],7528:[[961],256],7529:[[966],256],7530:[[967],256],7544:[[1085],256],7579:[[594],256],7580:[[99],256],7581:[[597],256],7582:[[240],256],7583:[[604],256],7584:[[102],256],7585:[[607],256],7586:[[609],256],7587:[[613],256],7588:[[616],256],7589:[[617],256],7590:[[618],256],7591:[[7547],256],7592:[[669],256],7593:[[621],256],7594:[[7557],256],7595:[[671],256],7596:[[625],256],7597:[[624],256],7598:[[626],256],7599:[[627],256],7600:[[628],256],7601:[[629],256],7602:[[632],256],7603:[[642],256],7604:[[643],256],7605:[[427],256],7606:[[649],256],7607:[[650],256],7608:[[7452],256],7609:[[651],256],7610:[[652],256],7611:[[122],256],7612:[[656],256],7613:[[657],256],7614:[[658],256],7615:[[952],256],7616:[,230],7617:[,230],7618:[,220],7619:[,230],7620:[,230],7621:[,230],7622:[,230],7623:[,230],7624:[,230],7625:[,230],7626:[,220],7627:[,230],7628:[,230],7629:[,234],7630:[,214],7631:[,220],7632:[,202],7633:[,230],7634:[,230],7635:[,230],7636:[,230],7637:[,230],7638:[,230],7639:[,230],7640:[,230],7641:[,230],7642:[,230],7643:[,230],7644:[,230],7645:[,230],7646:[,230],7647:[,230],7648:[,230],7649:[,230],7650:[,230],7651:[,230],7652:[,230],7653:[,230],7654:[,230],7655:[,230],7656:[,230],7657:[,230],7658:[,230],7659:[,230],7660:[,230],7661:[,230],7662:[,230],7663:[,230],7664:[,230],7665:[,230],7666:[,230],7667:[,230],7668:[,230],7669:[,230],7676:[,233],7677:[,220],7678:[,230],7679:[,220]}, +7680:{7680:[[65,805]],7681:[[97,805]],7682:[[66,775]],7683:[[98,775]],7684:[[66,803]],7685:[[98,803]],7686:[[66,817]],7687:[[98,817]],7688:[[199,769]],7689:[[231,769]],7690:[[68,775]],7691:[[100,775]],7692:[[68,803]],7693:[[100,803]],7694:[[68,817]],7695:[[100,817]],7696:[[68,807]],7697:[[100,807]],7698:[[68,813]],7699:[[100,813]],7700:[[274,768]],7701:[[275,768]],7702:[[274,769]],7703:[[275,769]],7704:[[69,813]],7705:[[101,813]],7706:[[69,816]],7707:[[101,816]],7708:[[552,774]],7709:[[553,774]],7710:[[70,775]],7711:[[102,775]],7712:[[71,772]],7713:[[103,772]],7714:[[72,775]],7715:[[104,775]],7716:[[72,803]],7717:[[104,803]],7718:[[72,776]],7719:[[104,776]],7720:[[72,807]],7721:[[104,807]],7722:[[72,814]],7723:[[104,814]],7724:[[73,816]],7725:[[105,816]],7726:[[207,769]],7727:[[239,769]],7728:[[75,769]],7729:[[107,769]],7730:[[75,803]],7731:[[107,803]],7732:[[75,817]],7733:[[107,817]],7734:[[76,803],,{772:7736}],7735:[[108,803],,{772:7737}],7736:[[7734,772]],7737:[[7735,772]],7738:[[76,817]],7739:[[108,817]],7740:[[76,813]],7741:[[108,813]],7742:[[77,769]],7743:[[109,769]],7744:[[77,775]],7745:[[109,775]],7746:[[77,803]],7747:[[109,803]],7748:[[78,775]],7749:[[110,775]],7750:[[78,803]],7751:[[110,803]],7752:[[78,817]],7753:[[110,817]],7754:[[78,813]],7755:[[110,813]],7756:[[213,769]],7757:[[245,769]],7758:[[213,776]],7759:[[245,776]],7760:[[332,768]],7761:[[333,768]],7762:[[332,769]],7763:[[333,769]],7764:[[80,769]],7765:[[112,769]],7766:[[80,775]],7767:[[112,775]],7768:[[82,775]],7769:[[114,775]],7770:[[82,803],,{772:7772}],7771:[[114,803],,{772:7773}],7772:[[7770,772]],7773:[[7771,772]],7774:[[82,817]],7775:[[114,817]],7776:[[83,775]],7777:[[115,775]],7778:[[83,803],,{775:7784}],7779:[[115,803],,{775:7785}],7780:[[346,775]],7781:[[347,775]],7782:[[352,775]],7783:[[353,775]],7784:[[7778,775]],7785:[[7779,775]],7786:[[84,775]],7787:[[116,775]],7788:[[84,803]],7789:[[116,803]],7790:[[84,817]],7791:[[116,817]],7792:[[84,813]],7793:[[116,813]],7794:[[85,804]],7795:[[117,804]],7796:[[85,816]],7797:[[117,816]],7798:[[85,813]],7799:[[117,813]],7800:[[360,769]],7801:[[361,769]],7802:[[362,776]],7803:[[363,776]],7804:[[86,771]],7805:[[118,771]],7806:[[86,803]],7807:[[118,803]],7808:[[87,768]],7809:[[119,768]],7810:[[87,769]],7811:[[119,769]],7812:[[87,776]],7813:[[119,776]],7814:[[87,775]],7815:[[119,775]],7816:[[87,803]],7817:[[119,803]],7818:[[88,775]],7819:[[120,775]],7820:[[88,776]],7821:[[120,776]],7822:[[89,775]],7823:[[121,775]],7824:[[90,770]],7825:[[122,770]],7826:[[90,803]],7827:[[122,803]],7828:[[90,817]],7829:[[122,817]],7830:[[104,817]],7831:[[116,776]],7832:[[119,778]],7833:[[121,778]],7834:[[97,702],256],7835:[[383,775]],7840:[[65,803],,{770:7852,774:7862}],7841:[[97,803],,{770:7853,774:7863}],7842:[[65,777]],7843:[[97,777]],7844:[[194,769]],7845:[[226,769]],7846:[[194,768]],7847:[[226,768]],7848:[[194,777]],7849:[[226,777]],7850:[[194,771]],7851:[[226,771]],7852:[[7840,770]],7853:[[7841,770]],7854:[[258,769]],7855:[[259,769]],7856:[[258,768]],7857:[[259,768]],7858:[[258,777]],7859:[[259,777]],7860:[[258,771]],7861:[[259,771]],7862:[[7840,774]],7863:[[7841,774]],7864:[[69,803],,{770:7878}],7865:[[101,803],,{770:7879}],7866:[[69,777]],7867:[[101,777]],7868:[[69,771]],7869:[[101,771]],7870:[[202,769]],7871:[[234,769]],7872:[[202,768]],7873:[[234,768]],7874:[[202,777]],7875:[[234,777]],7876:[[202,771]],7877:[[234,771]],7878:[[7864,770]],7879:[[7865,770]],7880:[[73,777]],7881:[[105,777]],7882:[[73,803]],7883:[[105,803]],7884:[[79,803],,{770:7896}],7885:[[111,803],,{770:7897}],7886:[[79,777]],7887:[[111,777]],7888:[[212,769]],7889:[[244,769]],7890:[[212,768]],7891:[[244,768]],7892:[[212,777]],7893:[[244,777]],7894:[[212,771]],7895:[[244,771]],7896:[[7884,770]],7897:[[7885,770]],7898:[[416,769]],7899:[[417,769]],7900:[[416,768]],7901:[[417,768]],7902:[[416,777]],7903:[[417,777]],7904:[[416,771]],7905:[[417,771]],7906:[[416,803]],7907:[[417,803]],7908:[[85,803]],7909:[[117,803]],7910:[[85,777]],7911:[[117,777]],7912:[[431,769]],7913:[[432,769]],7914:[[431,768]],7915:[[432,768]],7916:[[431,777]],7917:[[432,777]],7918:[[431,771]],7919:[[432,771]],7920:[[431,803]],7921:[[432,803]],7922:[[89,768]],7923:[[121,768]],7924:[[89,803]],7925:[[121,803]],7926:[[89,777]],7927:[[121,777]],7928:[[89,771]],7929:[[121,771]]}, +7936:{7936:[[945,787],,{768:7938,769:7940,834:7942,837:8064}],7937:[[945,788],,{768:7939,769:7941,834:7943,837:8065}],7938:[[7936,768],,{837:8066}],7939:[[7937,768],,{837:8067}],7940:[[7936,769],,{837:8068}],7941:[[7937,769],,{837:8069}],7942:[[7936,834],,{837:8070}],7943:[[7937,834],,{837:8071}],7944:[[913,787],,{768:7946,769:7948,834:7950,837:8072}],7945:[[913,788],,{768:7947,769:7949,834:7951,837:8073}],7946:[[7944,768],,{837:8074}],7947:[[7945,768],,{837:8075}],7948:[[7944,769],,{837:8076}],7949:[[7945,769],,{837:8077}],7950:[[7944,834],,{837:8078}],7951:[[7945,834],,{837:8079}],7952:[[949,787],,{768:7954,769:7956}],7953:[[949,788],,{768:7955,769:7957}],7954:[[7952,768]],7955:[[7953,768]],7956:[[7952,769]],7957:[[7953,769]],7960:[[917,787],,{768:7962,769:7964}],7961:[[917,788],,{768:7963,769:7965}],7962:[[7960,768]],7963:[[7961,768]],7964:[[7960,769]],7965:[[7961,769]],7968:[[951,787],,{768:7970,769:7972,834:7974,837:8080}],7969:[[951,788],,{768:7971,769:7973,834:7975,837:8081}],7970:[[7968,768],,{837:8082}],7971:[[7969,768],,{837:8083}],7972:[[7968,769],,{837:8084}],7973:[[7969,769],,{837:8085}],7974:[[7968,834],,{837:8086}],7975:[[7969,834],,{837:8087}],7976:[[919,787],,{768:7978,769:7980,834:7982,837:8088}],7977:[[919,788],,{768:7979,769:7981,834:7983,837:8089}],7978:[[7976,768],,{837:8090}],7979:[[7977,768],,{837:8091}],7980:[[7976,769],,{837:8092}],7981:[[7977,769],,{837:8093}],7982:[[7976,834],,{837:8094}],7983:[[7977,834],,{837:8095}],7984:[[953,787],,{768:7986,769:7988,834:7990}],7985:[[953,788],,{768:7987,769:7989,834:7991}],7986:[[7984,768]],7987:[[7985,768]],7988:[[7984,769]],7989:[[7985,769]],7990:[[7984,834]],7991:[[7985,834]],7992:[[921,787],,{768:7994,769:7996,834:7998}],7993:[[921,788],,{768:7995,769:7997,834:7999}],7994:[[7992,768]],7995:[[7993,768]],7996:[[7992,769]],7997:[[7993,769]],7998:[[7992,834]],7999:[[7993,834]],8000:[[959,787],,{768:8002,769:8004}],8001:[[959,788],,{768:8003,769:8005}],8002:[[8000,768]],8003:[[8001,768]],8004:[[8000,769]],8005:[[8001,769]],8008:[[927,787],,{768:8010,769:8012}],8009:[[927,788],,{768:8011,769:8013}],8010:[[8008,768]],8011:[[8009,768]],8012:[[8008,769]],8013:[[8009,769]],8016:[[965,787],,{768:8018,769:8020,834:8022}],8017:[[965,788],,{768:8019,769:8021,834:8023}],8018:[[8016,768]],8019:[[8017,768]],8020:[[8016,769]],8021:[[8017,769]],8022:[[8016,834]],8023:[[8017,834]],8025:[[933,788],,{768:8027,769:8029,834:8031}],8027:[[8025,768]],8029:[[8025,769]],8031:[[8025,834]],8032:[[969,787],,{768:8034,769:8036,834:8038,837:8096}],8033:[[969,788],,{768:8035,769:8037,834:8039,837:8097}],8034:[[8032,768],,{837:8098}],8035:[[8033,768],,{837:8099}],8036:[[8032,769],,{837:8100}],8037:[[8033,769],,{837:8101}],8038:[[8032,834],,{837:8102}],8039:[[8033,834],,{837:8103}],8040:[[937,787],,{768:8042,769:8044,834:8046,837:8104}],8041:[[937,788],,{768:8043,769:8045,834:8047,837:8105}],8042:[[8040,768],,{837:8106}],8043:[[8041,768],,{837:8107}],8044:[[8040,769],,{837:8108}],8045:[[8041,769],,{837:8109}],8046:[[8040,834],,{837:8110}],8047:[[8041,834],,{837:8111}],8048:[[945,768],,{837:8114}],8049:[[940]],8050:[[949,768]],8051:[[941]],8052:[[951,768],,{837:8130}],8053:[[942]],8054:[[953,768]],8055:[[943]],8056:[[959,768]],8057:[[972]],8058:[[965,768]],8059:[[973]],8060:[[969,768],,{837:8178}],8061:[[974]],8064:[[7936,837]],8065:[[7937,837]],8066:[[7938,837]],8067:[[7939,837]],8068:[[7940,837]],8069:[[7941,837]],8070:[[7942,837]],8071:[[7943,837]],8072:[[7944,837]],8073:[[7945,837]],8074:[[7946,837]],8075:[[7947,837]],8076:[[7948,837]],8077:[[7949,837]],8078:[[7950,837]],8079:[[7951,837]],8080:[[7968,837]],8081:[[7969,837]],8082:[[7970,837]],8083:[[7971,837]],8084:[[7972,837]],8085:[[7973,837]],8086:[[7974,837]],8087:[[7975,837]],8088:[[7976,837]],8089:[[7977,837]],8090:[[7978,837]],8091:[[7979,837]],8092:[[7980,837]],8093:[[7981,837]],8094:[[7982,837]],8095:[[7983,837]],8096:[[8032,837]],8097:[[8033,837]],8098:[[8034,837]],8099:[[8035,837]],8100:[[8036,837]],8101:[[8037,837]],8102:[[8038,837]],8103:[[8039,837]],8104:[[8040,837]],8105:[[8041,837]],8106:[[8042,837]],8107:[[8043,837]],8108:[[8044,837]],8109:[[8045,837]],8110:[[8046,837]],8111:[[8047,837]],8112:[[945,774]],8113:[[945,772]],8114:[[8048,837]],8115:[[945,837]],8116:[[940,837]],8118:[[945,834],,{837:8119}],8119:[[8118,837]],8120:[[913,774]],8121:[[913,772]],8122:[[913,768]],8123:[[902]],8124:[[913,837]],8125:[[32,787],256],8126:[[953]],8127:[[32,787],256,{768:8141,769:8142,834:8143}],8128:[[32,834],256],8129:[[168,834]],8130:[[8052,837]],8131:[[951,837]],8132:[[942,837]],8134:[[951,834],,{837:8135}],8135:[[8134,837]],8136:[[917,768]],8137:[[904]],8138:[[919,768]],8139:[[905]],8140:[[919,837]],8141:[[8127,768]],8142:[[8127,769]],8143:[[8127,834]],8144:[[953,774]],8145:[[953,772]],8146:[[970,768]],8147:[[912]],8150:[[953,834]],8151:[[970,834]],8152:[[921,774]],8153:[[921,772]],8154:[[921,768]],8155:[[906]],8157:[[8190,768]],8158:[[8190,769]],8159:[[8190,834]],8160:[[965,774]],8161:[[965,772]],8162:[[971,768]],8163:[[944]],8164:[[961,787]],8165:[[961,788]],8166:[[965,834]],8167:[[971,834]],8168:[[933,774]],8169:[[933,772]],8170:[[933,768]],8171:[[910]],8172:[[929,788]],8173:[[168,768]],8174:[[901]],8175:[[96]],8178:[[8060,837]],8179:[[969,837]],8180:[[974,837]],8182:[[969,834],,{837:8183}],8183:[[8182,837]],8184:[[927,768]],8185:[[908]],8186:[[937,768]],8187:[[911]],8188:[[937,837]],8189:[[180]],8190:[[32,788],256,{768:8157,769:8158,834:8159}]}, +8192:{8192:[[8194]],8193:[[8195]],8194:[[32],256],8195:[[32],256],8196:[[32],256],8197:[[32],256],8198:[[32],256],8199:[[32],256],8200:[[32],256],8201:[[32],256],8202:[[32],256],8209:[[8208],256],8215:[[32,819],256],8228:[[46],256],8229:[[46,46],256],8230:[[46,46,46],256],8239:[[32],256],8243:[[8242,8242],256],8244:[[8242,8242,8242],256],8246:[[8245,8245],256],8247:[[8245,8245,8245],256],8252:[[33,33],256],8254:[[32,773],256],8263:[[63,63],256],8264:[[63,33],256],8265:[[33,63],256],8279:[[8242,8242,8242,8242],256],8287:[[32],256],8304:[[48],256],8305:[[105],256],8308:[[52],256],8309:[[53],256],8310:[[54],256],8311:[[55],256],8312:[[56],256],8313:[[57],256],8314:[[43],256],8315:[[8722],256],8316:[[61],256],8317:[[40],256],8318:[[41],256],8319:[[110],256],8320:[[48],256],8321:[[49],256],8322:[[50],256],8323:[[51],256],8324:[[52],256],8325:[[53],256],8326:[[54],256],8327:[[55],256],8328:[[56],256],8329:[[57],256],8330:[[43],256],8331:[[8722],256],8332:[[61],256],8333:[[40],256],8334:[[41],256],8336:[[97],256],8337:[[101],256],8338:[[111],256],8339:[[120],256],8340:[[601],256],8341:[[104],256],8342:[[107],256],8343:[[108],256],8344:[[109],256],8345:[[110],256],8346:[[112],256],8347:[[115],256],8348:[[116],256],8360:[[82,115],256],8400:[,230],8401:[,230],8402:[,1],8403:[,1],8404:[,230],8405:[,230],8406:[,230],8407:[,230],8408:[,1],8409:[,1],8410:[,1],8411:[,230],8412:[,230],8417:[,230],8421:[,1],8422:[,1],8423:[,230],8424:[,220],8425:[,230],8426:[,1],8427:[,1],8428:[,220],8429:[,220],8430:[,220],8431:[,220],8432:[,230]}, +8448:{8448:[[97,47,99],256],8449:[[97,47,115],256],8450:[[67],256],8451:[[176,67],256],8453:[[99,47,111],256],8454:[[99,47,117],256],8455:[[400],256],8457:[[176,70],256],8458:[[103],256],8459:[[72],256],8460:[[72],256],8461:[[72],256],8462:[[104],256],8463:[[295],256],8464:[[73],256],8465:[[73],256],8466:[[76],256],8467:[[108],256],8469:[[78],256],8470:[[78,111],256],8473:[[80],256],8474:[[81],256],8475:[[82],256],8476:[[82],256],8477:[[82],256],8480:[[83,77],256],8481:[[84,69,76],256],8482:[[84,77],256],8484:[[90],256],8486:[[937]],8488:[[90],256],8490:[[75]],8491:[[197]],8492:[[66],256],8493:[[67],256],8495:[[101],256],8496:[[69],256],8497:[[70],256],8499:[[77],256],8500:[[111],256],8501:[[1488],256],8502:[[1489],256],8503:[[1490],256],8504:[[1491],256],8505:[[105],256],8507:[[70,65,88],256],8508:[[960],256],8509:[[947],256],8510:[[915],256],8511:[[928],256],8512:[[8721],256],8517:[[68],256],8518:[[100],256],8519:[[101],256],8520:[[105],256],8521:[[106],256],8528:[[49,8260,55],256],8529:[[49,8260,57],256],8530:[[49,8260,49,48],256],8531:[[49,8260,51],256],8532:[[50,8260,51],256],8533:[[49,8260,53],256],8534:[[50,8260,53],256],8535:[[51,8260,53],256],8536:[[52,8260,53],256],8537:[[49,8260,54],256],8538:[[53,8260,54],256],8539:[[49,8260,56],256],8540:[[51,8260,56],256],8541:[[53,8260,56],256],8542:[[55,8260,56],256],8543:[[49,8260],256],8544:[[73],256],8545:[[73,73],256],8546:[[73,73,73],256],8547:[[73,86],256],8548:[[86],256],8549:[[86,73],256],8550:[[86,73,73],256],8551:[[86,73,73,73],256],8552:[[73,88],256],8553:[[88],256],8554:[[88,73],256],8555:[[88,73,73],256],8556:[[76],256],8557:[[67],256],8558:[[68],256],8559:[[77],256],8560:[[105],256],8561:[[105,105],256],8562:[[105,105,105],256],8563:[[105,118],256],8564:[[118],256],8565:[[118,105],256],8566:[[118,105,105],256],8567:[[118,105,105,105],256],8568:[[105,120],256],8569:[[120],256],8570:[[120,105],256],8571:[[120,105,105],256],8572:[[108],256],8573:[[99],256],8574:[[100],256],8575:[[109],256],8585:[[48,8260,51],256],8592:[,,{824:8602}],8594:[,,{824:8603}],8596:[,,{824:8622}],8602:[[8592,824]],8603:[[8594,824]],8622:[[8596,824]],8653:[[8656,824]],8654:[[8660,824]],8655:[[8658,824]],8656:[,,{824:8653}],8658:[,,{824:8655}],8660:[,,{824:8654}]}, +8704:{8707:[,,{824:8708}],8708:[[8707,824]],8712:[,,{824:8713}],8713:[[8712,824]],8715:[,,{824:8716}],8716:[[8715,824]],8739:[,,{824:8740}],8740:[[8739,824]],8741:[,,{824:8742}],8742:[[8741,824]],8748:[[8747,8747],256],8749:[[8747,8747,8747],256],8751:[[8750,8750],256],8752:[[8750,8750,8750],256],8764:[,,{824:8769}],8769:[[8764,824]],8771:[,,{824:8772}],8772:[[8771,824]],8773:[,,{824:8775}],8775:[[8773,824]],8776:[,,{824:8777}],8777:[[8776,824]],8781:[,,{824:8813}],8800:[[61,824]],8801:[,,{824:8802}],8802:[[8801,824]],8804:[,,{824:8816}],8805:[,,{824:8817}],8813:[[8781,824]],8814:[[60,824]],8815:[[62,824]],8816:[[8804,824]],8817:[[8805,824]],8818:[,,{824:8820}],8819:[,,{824:8821}],8820:[[8818,824]],8821:[[8819,824]],8822:[,,{824:8824}],8823:[,,{824:8825}],8824:[[8822,824]],8825:[[8823,824]],8826:[,,{824:8832}],8827:[,,{824:8833}],8828:[,,{824:8928}],8829:[,,{824:8929}],8832:[[8826,824]],8833:[[8827,824]],8834:[,,{824:8836}],8835:[,,{824:8837}],8836:[[8834,824]],8837:[[8835,824]],8838:[,,{824:8840}],8839:[,,{824:8841}],8840:[[8838,824]],8841:[[8839,824]],8849:[,,{824:8930}],8850:[,,{824:8931}],8866:[,,{824:8876}],8872:[,,{824:8877}],8873:[,,{824:8878}],8875:[,,{824:8879}],8876:[[8866,824]],8877:[[8872,824]],8878:[[8873,824]],8879:[[8875,824]],8882:[,,{824:8938}],8883:[,,{824:8939}],8884:[,,{824:8940}],8885:[,,{824:8941}],8928:[[8828,824]],8929:[[8829,824]],8930:[[8849,824]],8931:[[8850,824]],8938:[[8882,824]],8939:[[8883,824]],8940:[[8884,824]],8941:[[8885,824]]}, +8960:{9001:[[12296]],9002:[[12297]]}, +9216:{9312:[[49],256],9313:[[50],256],9314:[[51],256],9315:[[52],256],9316:[[53],256],9317:[[54],256],9318:[[55],256],9319:[[56],256],9320:[[57],256],9321:[[49,48],256],9322:[[49,49],256],9323:[[49,50],256],9324:[[49,51],256],9325:[[49,52],256],9326:[[49,53],256],9327:[[49,54],256],9328:[[49,55],256],9329:[[49,56],256],9330:[[49,57],256],9331:[[50,48],256],9332:[[40,49,41],256],9333:[[40,50,41],256],9334:[[40,51,41],256],9335:[[40,52,41],256],9336:[[40,53,41],256],9337:[[40,54,41],256],9338:[[40,55,41],256],9339:[[40,56,41],256],9340:[[40,57,41],256],9341:[[40,49,48,41],256],9342:[[40,49,49,41],256],9343:[[40,49,50,41],256],9344:[[40,49,51,41],256],9345:[[40,49,52,41],256],9346:[[40,49,53,41],256],9347:[[40,49,54,41],256],9348:[[40,49,55,41],256],9349:[[40,49,56,41],256],9350:[[40,49,57,41],256],9351:[[40,50,48,41],256],9352:[[49,46],256],9353:[[50,46],256],9354:[[51,46],256],9355:[[52,46],256],9356:[[53,46],256],9357:[[54,46],256],9358:[[55,46],256],9359:[[56,46],256],9360:[[57,46],256],9361:[[49,48,46],256],9362:[[49,49,46],256],9363:[[49,50,46],256],9364:[[49,51,46],256],9365:[[49,52,46],256],9366:[[49,53,46],256],9367:[[49,54,46],256],9368:[[49,55,46],256],9369:[[49,56,46],256],9370:[[49,57,46],256],9371:[[50,48,46],256],9372:[[40,97,41],256],9373:[[40,98,41],256],9374:[[40,99,41],256],9375:[[40,100,41],256],9376:[[40,101,41],256],9377:[[40,102,41],256],9378:[[40,103,41],256],9379:[[40,104,41],256],9380:[[40,105,41],256],9381:[[40,106,41],256],9382:[[40,107,41],256],9383:[[40,108,41],256],9384:[[40,109,41],256],9385:[[40,110,41],256],9386:[[40,111,41],256],9387:[[40,112,41],256],9388:[[40,113,41],256],9389:[[40,114,41],256],9390:[[40,115,41],256],9391:[[40,116,41],256],9392:[[40,117,41],256],9393:[[40,118,41],256],9394:[[40,119,41],256],9395:[[40,120,41],256],9396:[[40,121,41],256],9397:[[40,122,41],256],9398:[[65],256],9399:[[66],256],9400:[[67],256],9401:[[68],256],9402:[[69],256],9403:[[70],256],9404:[[71],256],9405:[[72],256],9406:[[73],256],9407:[[74],256],9408:[[75],256],9409:[[76],256],9410:[[77],256],9411:[[78],256],9412:[[79],256],9413:[[80],256],9414:[[81],256],9415:[[82],256],9416:[[83],256],9417:[[84],256],9418:[[85],256],9419:[[86],256],9420:[[87],256],9421:[[88],256],9422:[[89],256],9423:[[90],256],9424:[[97],256],9425:[[98],256],9426:[[99],256],9427:[[100],256],9428:[[101],256],9429:[[102],256],9430:[[103],256],9431:[[104],256],9432:[[105],256],9433:[[106],256],9434:[[107],256],9435:[[108],256],9436:[[109],256],9437:[[110],256],9438:[[111],256],9439:[[112],256],9440:[[113],256],9441:[[114],256],9442:[[115],256],9443:[[116],256],9444:[[117],256],9445:[[118],256],9446:[[119],256],9447:[[120],256],9448:[[121],256],9449:[[122],256],9450:[[48],256]}, +10752:{10764:[[8747,8747,8747,8747],256],10868:[[58,58,61],256],10869:[[61,61],256],10870:[[61,61,61],256],10972:[[10973,824],512]}, +11264:{11388:[[106],256],11389:[[86],256],11503:[,230],11504:[,230],11505:[,230]}, +11520:{11631:[[11617],256],11647:[,9],11744:[,230],11745:[,230],11746:[,230],11747:[,230],11748:[,230],11749:[,230],11750:[,230],11751:[,230],11752:[,230],11753:[,230],11754:[,230],11755:[,230],11756:[,230],11757:[,230],11758:[,230],11759:[,230],11760:[,230],11761:[,230],11762:[,230],11763:[,230],11764:[,230],11765:[,230],11766:[,230],11767:[,230],11768:[,230],11769:[,230],11770:[,230],11771:[,230],11772:[,230],11773:[,230],11774:[,230],11775:[,230]}, +11776:{11935:[[27597],256],12019:[[40863],256]}, +12032:{12032:[[19968],256],12033:[[20008],256],12034:[[20022],256],12035:[[20031],256],12036:[[20057],256],12037:[[20101],256],12038:[[20108],256],12039:[[20128],256],12040:[[20154],256],12041:[[20799],256],12042:[[20837],256],12043:[[20843],256],12044:[[20866],256],12045:[[20886],256],12046:[[20907],256],12047:[[20960],256],12048:[[20981],256],12049:[[20992],256],12050:[[21147],256],12051:[[21241],256],12052:[[21269],256],12053:[[21274],256],12054:[[21304],256],12055:[[21313],256],12056:[[21340],256],12057:[[21353],256],12058:[[21378],256],12059:[[21430],256],12060:[[21448],256],12061:[[21475],256],12062:[[22231],256],12063:[[22303],256],12064:[[22763],256],12065:[[22786],256],12066:[[22794],256],12067:[[22805],256],12068:[[22823],256],12069:[[22899],256],12070:[[23376],256],12071:[[23424],256],12072:[[23544],256],12073:[[23567],256],12074:[[23586],256],12075:[[23608],256],12076:[[23662],256],12077:[[23665],256],12078:[[24027],256],12079:[[24037],256],12080:[[24049],256],12081:[[24062],256],12082:[[24178],256],12083:[[24186],256],12084:[[24191],256],12085:[[24308],256],12086:[[24318],256],12087:[[24331],256],12088:[[24339],256],12089:[[24400],256],12090:[[24417],256],12091:[[24435],256],12092:[[24515],256],12093:[[25096],256],12094:[[25142],256],12095:[[25163],256],12096:[[25903],256],12097:[[25908],256],12098:[[25991],256],12099:[[26007],256],12100:[[26020],256],12101:[[26041],256],12102:[[26080],256],12103:[[26085],256],12104:[[26352],256],12105:[[26376],256],12106:[[26408],256],12107:[[27424],256],12108:[[27490],256],12109:[[27513],256],12110:[[27571],256],12111:[[27595],256],12112:[[27604],256],12113:[[27611],256],12114:[[27663],256],12115:[[27668],256],12116:[[27700],256],12117:[[28779],256],12118:[[29226],256],12119:[[29238],256],12120:[[29243],256],12121:[[29247],256],12122:[[29255],256],12123:[[29273],256],12124:[[29275],256],12125:[[29356],256],12126:[[29572],256],12127:[[29577],256],12128:[[29916],256],12129:[[29926],256],12130:[[29976],256],12131:[[29983],256],12132:[[29992],256],12133:[[30000],256],12134:[[30091],256],12135:[[30098],256],12136:[[30326],256],12137:[[30333],256],12138:[[30382],256],12139:[[30399],256],12140:[[30446],256],12141:[[30683],256],12142:[[30690],256],12143:[[30707],256],12144:[[31034],256],12145:[[31160],256],12146:[[31166],256],12147:[[31348],256],12148:[[31435],256],12149:[[31481],256],12150:[[31859],256],12151:[[31992],256],12152:[[32566],256],12153:[[32593],256],12154:[[32650],256],12155:[[32701],256],12156:[[32769],256],12157:[[32780],256],12158:[[32786],256],12159:[[32819],256],12160:[[32895],256],12161:[[32905],256],12162:[[33251],256],12163:[[33258],256],12164:[[33267],256],12165:[[33276],256],12166:[[33292],256],12167:[[33307],256],12168:[[33311],256],12169:[[33390],256],12170:[[33394],256],12171:[[33400],256],12172:[[34381],256],12173:[[34411],256],12174:[[34880],256],12175:[[34892],256],12176:[[34915],256],12177:[[35198],256],12178:[[35211],256],12179:[[35282],256],12180:[[35328],256],12181:[[35895],256],12182:[[35910],256],12183:[[35925],256],12184:[[35960],256],12185:[[35997],256],12186:[[36196],256],12187:[[36208],256],12188:[[36275],256],12189:[[36523],256],12190:[[36554],256],12191:[[36763],256],12192:[[36784],256],12193:[[36789],256],12194:[[37009],256],12195:[[37193],256],12196:[[37318],256],12197:[[37324],256],12198:[[37329],256],12199:[[38263],256],12200:[[38272],256],12201:[[38428],256],12202:[[38582],256],12203:[[38585],256],12204:[[38632],256],12205:[[38737],256],12206:[[38750],256],12207:[[38754],256],12208:[[38761],256],12209:[[38859],256],12210:[[38893],256],12211:[[38899],256],12212:[[38913],256],12213:[[39080],256],12214:[[39131],256],12215:[[39135],256],12216:[[39318],256],12217:[[39321],256],12218:[[39340],256],12219:[[39592],256],12220:[[39640],256],12221:[[39647],256],12222:[[39717],256],12223:[[39727],256],12224:[[39730],256],12225:[[39740],256],12226:[[39770],256],12227:[[40165],256],12228:[[40565],256],12229:[[40575],256],12230:[[40613],256],12231:[[40635],256],12232:[[40643],256],12233:[[40653],256],12234:[[40657],256],12235:[[40697],256],12236:[[40701],256],12237:[[40718],256],12238:[[40723],256],12239:[[40736],256],12240:[[40763],256],12241:[[40778],256],12242:[[40786],256],12243:[[40845],256],12244:[[40860],256],12245:[[40864],256]}, +12288:{12288:[[32],256],12330:[,218],12331:[,228],12332:[,232],12333:[,222],12334:[,224],12335:[,224],12342:[[12306],256],12344:[[21313],256],12345:[[21316],256],12346:[[21317],256],12358:[,,{12441:12436}],12363:[,,{12441:12364}],12364:[[12363,12441]],12365:[,,{12441:12366}],12366:[[12365,12441]],12367:[,,{12441:12368}],12368:[[12367,12441]],12369:[,,{12441:12370}],12370:[[12369,12441]],12371:[,,{12441:12372}],12372:[[12371,12441]],12373:[,,{12441:12374}],12374:[[12373,12441]],12375:[,,{12441:12376}],12376:[[12375,12441]],12377:[,,{12441:12378}],12378:[[12377,12441]],12379:[,,{12441:12380}],12380:[[12379,12441]],12381:[,,{12441:12382}],12382:[[12381,12441]],12383:[,,{12441:12384}],12384:[[12383,12441]],12385:[,,{12441:12386}],12386:[[12385,12441]],12388:[,,{12441:12389}],12389:[[12388,12441]],12390:[,,{12441:12391}],12391:[[12390,12441]],12392:[,,{12441:12393}],12393:[[12392,12441]],12399:[,,{12441:12400,12442:12401}],12400:[[12399,12441]],12401:[[12399,12442]],12402:[,,{12441:12403,12442:12404}],12403:[[12402,12441]],12404:[[12402,12442]],12405:[,,{12441:12406,12442:12407}],12406:[[12405,12441]],12407:[[12405,12442]],12408:[,,{12441:12409,12442:12410}],12409:[[12408,12441]],12410:[[12408,12442]],12411:[,,{12441:12412,12442:12413}],12412:[[12411,12441]],12413:[[12411,12442]],12436:[[12358,12441]],12441:[,8],12442:[,8],12443:[[32,12441],256],12444:[[32,12442],256],12445:[,,{12441:12446}],12446:[[12445,12441]],12447:[[12424,12426],256],12454:[,,{12441:12532}],12459:[,,{12441:12460}],12460:[[12459,12441]],12461:[,,{12441:12462}],12462:[[12461,12441]],12463:[,,{12441:12464}],12464:[[12463,12441]],12465:[,,{12441:12466}],12466:[[12465,12441]],12467:[,,{12441:12468}],12468:[[12467,12441]],12469:[,,{12441:12470}],12470:[[12469,12441]],12471:[,,{12441:12472}],12472:[[12471,12441]],12473:[,,{12441:12474}],12474:[[12473,12441]],12475:[,,{12441:12476}],12476:[[12475,12441]],12477:[,,{12441:12478}],12478:[[12477,12441]],12479:[,,{12441:12480}],12480:[[12479,12441]],12481:[,,{12441:12482}],12482:[[12481,12441]],12484:[,,{12441:12485}],12485:[[12484,12441]],12486:[,,{12441:12487}],12487:[[12486,12441]],12488:[,,{12441:12489}],12489:[[12488,12441]],12495:[,,{12441:12496,12442:12497}],12496:[[12495,12441]],12497:[[12495,12442]],12498:[,,{12441:12499,12442:12500}],12499:[[12498,12441]],12500:[[12498,12442]],12501:[,,{12441:12502,12442:12503}],12502:[[12501,12441]],12503:[[12501,12442]],12504:[,,{12441:12505,12442:12506}],12505:[[12504,12441]],12506:[[12504,12442]],12507:[,,{12441:12508,12442:12509}],12508:[[12507,12441]],12509:[[12507,12442]],12527:[,,{12441:12535}],12528:[,,{12441:12536}],12529:[,,{12441:12537}],12530:[,,{12441:12538}],12532:[[12454,12441]],12535:[[12527,12441]],12536:[[12528,12441]],12537:[[12529,12441]],12538:[[12530,12441]],12541:[,,{12441:12542}],12542:[[12541,12441]],12543:[[12467,12488],256]}, +12544:{12593:[[4352],256],12594:[[4353],256],12595:[[4522],256],12596:[[4354],256],12597:[[4524],256],12598:[[4525],256],12599:[[4355],256],12600:[[4356],256],12601:[[4357],256],12602:[[4528],256],12603:[[4529],256],12604:[[4530],256],12605:[[4531],256],12606:[[4532],256],12607:[[4533],256],12608:[[4378],256],12609:[[4358],256],12610:[[4359],256],12611:[[4360],256],12612:[[4385],256],12613:[[4361],256],12614:[[4362],256],12615:[[4363],256],12616:[[4364],256],12617:[[4365],256],12618:[[4366],256],12619:[[4367],256],12620:[[4368],256],12621:[[4369],256],12622:[[4370],256],12623:[[4449],256],12624:[[4450],256],12625:[[4451],256],12626:[[4452],256],12627:[[4453],256],12628:[[4454],256],12629:[[4455],256],12630:[[4456],256],12631:[[4457],256],12632:[[4458],256],12633:[[4459],256],12634:[[4460],256],12635:[[4461],256],12636:[[4462],256],12637:[[4463],256],12638:[[4464],256],12639:[[4465],256],12640:[[4466],256],12641:[[4467],256],12642:[[4468],256],12643:[[4469],256],12644:[[4448],256],12645:[[4372],256],12646:[[4373],256],12647:[[4551],256],12648:[[4552],256],12649:[[4556],256],12650:[[4558],256],12651:[[4563],256],12652:[[4567],256],12653:[[4569],256],12654:[[4380],256],12655:[[4573],256],12656:[[4575],256],12657:[[4381],256],12658:[[4382],256],12659:[[4384],256],12660:[[4386],256],12661:[[4387],256],12662:[[4391],256],12663:[[4393],256],12664:[[4395],256],12665:[[4396],256],12666:[[4397],256],12667:[[4398],256],12668:[[4399],256],12669:[[4402],256],12670:[[4406],256],12671:[[4416],256],12672:[[4423],256],12673:[[4428],256],12674:[[4593],256],12675:[[4594],256],12676:[[4439],256],12677:[[4440],256],12678:[[4441],256],12679:[[4484],256],12680:[[4485],256],12681:[[4488],256],12682:[[4497],256],12683:[[4498],256],12684:[[4500],256],12685:[[4510],256],12686:[[4513],256],12690:[[19968],256],12691:[[20108],256],12692:[[19977],256],12693:[[22235],256],12694:[[19978],256],12695:[[20013],256],12696:[[19979],256],12697:[[30002],256],12698:[[20057],256],12699:[[19993],256],12700:[[19969],256],12701:[[22825],256],12702:[[22320],256],12703:[[20154],256]}, +12800:{12800:[[40,4352,41],256],12801:[[40,4354,41],256],12802:[[40,4355,41],256],12803:[[40,4357,41],256],12804:[[40,4358,41],256],12805:[[40,4359,41],256],12806:[[40,4361,41],256],12807:[[40,4363,41],256],12808:[[40,4364,41],256],12809:[[40,4366,41],256],12810:[[40,4367,41],256],12811:[[40,4368,41],256],12812:[[40,4369,41],256],12813:[[40,4370,41],256],12814:[[40,4352,4449,41],256],12815:[[40,4354,4449,41],256],12816:[[40,4355,4449,41],256],12817:[[40,4357,4449,41],256],12818:[[40,4358,4449,41],256],12819:[[40,4359,4449,41],256],12820:[[40,4361,4449,41],256],12821:[[40,4363,4449,41],256],12822:[[40,4364,4449,41],256],12823:[[40,4366,4449,41],256],12824:[[40,4367,4449,41],256],12825:[[40,4368,4449,41],256],12826:[[40,4369,4449,41],256],12827:[[40,4370,4449,41],256],12828:[[40,4364,4462,41],256],12829:[[40,4363,4457,4364,4453,4523,41],256],12830:[[40,4363,4457,4370,4462,41],256],12832:[[40,19968,41],256],12833:[[40,20108,41],256],12834:[[40,19977,41],256],12835:[[40,22235,41],256],12836:[[40,20116,41],256],12837:[[40,20845,41],256],12838:[[40,19971,41],256],12839:[[40,20843,41],256],12840:[[40,20061,41],256],12841:[[40,21313,41],256],12842:[[40,26376,41],256],12843:[[40,28779,41],256],12844:[[40,27700,41],256],12845:[[40,26408,41],256],12846:[[40,37329,41],256],12847:[[40,22303,41],256],12848:[[40,26085,41],256],12849:[[40,26666,41],256],12850:[[40,26377,41],256],12851:[[40,31038,41],256],12852:[[40,21517,41],256],12853:[[40,29305,41],256],12854:[[40,36001,41],256],12855:[[40,31069,41],256],12856:[[40,21172,41],256],12857:[[40,20195,41],256],12858:[[40,21628,41],256],12859:[[40,23398,41],256],12860:[[40,30435,41],256],12861:[[40,20225,41],256],12862:[[40,36039,41],256],12863:[[40,21332,41],256],12864:[[40,31085,41],256],12865:[[40,20241,41],256],12866:[[40,33258,41],256],12867:[[40,33267,41],256],12868:[[21839],256],12869:[[24188],256],12870:[[25991],256],12871:[[31631],256],12880:[[80,84,69],256],12881:[[50,49],256],12882:[[50,50],256],12883:[[50,51],256],12884:[[50,52],256],12885:[[50,53],256],12886:[[50,54],256],12887:[[50,55],256],12888:[[50,56],256],12889:[[50,57],256],12890:[[51,48],256],12891:[[51,49],256],12892:[[51,50],256],12893:[[51,51],256],12894:[[51,52],256],12895:[[51,53],256],12896:[[4352],256],12897:[[4354],256],12898:[[4355],256],12899:[[4357],256],12900:[[4358],256],12901:[[4359],256],12902:[[4361],256],12903:[[4363],256],12904:[[4364],256],12905:[[4366],256],12906:[[4367],256],12907:[[4368],256],12908:[[4369],256],12909:[[4370],256],12910:[[4352,4449],256],12911:[[4354,4449],256],12912:[[4355,4449],256],12913:[[4357,4449],256],12914:[[4358,4449],256],12915:[[4359,4449],256],12916:[[4361,4449],256],12917:[[4363,4449],256],12918:[[4364,4449],256],12919:[[4366,4449],256],12920:[[4367,4449],256],12921:[[4368,4449],256],12922:[[4369,4449],256],12923:[[4370,4449],256],12924:[[4366,4449,4535,4352,4457],256],12925:[[4364,4462,4363,4468],256],12926:[[4363,4462],256],12928:[[19968],256],12929:[[20108],256],12930:[[19977],256],12931:[[22235],256],12932:[[20116],256],12933:[[20845],256],12934:[[19971],256],12935:[[20843],256],12936:[[20061],256],12937:[[21313],256],12938:[[26376],256],12939:[[28779],256],12940:[[27700],256],12941:[[26408],256],12942:[[37329],256],12943:[[22303],256],12944:[[26085],256],12945:[[26666],256],12946:[[26377],256],12947:[[31038],256],12948:[[21517],256],12949:[[29305],256],12950:[[36001],256],12951:[[31069],256],12952:[[21172],256],12953:[[31192],256],12954:[[30007],256],12955:[[22899],256],12956:[[36969],256],12957:[[20778],256],12958:[[21360],256],12959:[[27880],256],12960:[[38917],256],12961:[[20241],256],12962:[[20889],256],12963:[[27491],256],12964:[[19978],256],12965:[[20013],256],12966:[[19979],256],12967:[[24038],256],12968:[[21491],256],12969:[[21307],256],12970:[[23447],256],12971:[[23398],256],12972:[[30435],256],12973:[[20225],256],12974:[[36039],256],12975:[[21332],256],12976:[[22812],256],12977:[[51,54],256],12978:[[51,55],256],12979:[[51,56],256],12980:[[51,57],256],12981:[[52,48],256],12982:[[52,49],256],12983:[[52,50],256],12984:[[52,51],256],12985:[[52,52],256],12986:[[52,53],256],12987:[[52,54],256],12988:[[52,55],256],12989:[[52,56],256],12990:[[52,57],256],12991:[[53,48],256],12992:[[49,26376],256],12993:[[50,26376],256],12994:[[51,26376],256],12995:[[52,26376],256],12996:[[53,26376],256],12997:[[54,26376],256],12998:[[55,26376],256],12999:[[56,26376],256],13000:[[57,26376],256],13001:[[49,48,26376],256],13002:[[49,49,26376],256],13003:[[49,50,26376],256],13004:[[72,103],256],13005:[[101,114,103],256],13006:[[101,86],256],13007:[[76,84,68],256],13008:[[12450],256],13009:[[12452],256],13010:[[12454],256],13011:[[12456],256],13012:[[12458],256],13013:[[12459],256],13014:[[12461],256],13015:[[12463],256],13016:[[12465],256],13017:[[12467],256],13018:[[12469],256],13019:[[12471],256],13020:[[12473],256],13021:[[12475],256],13022:[[12477],256],13023:[[12479],256],13024:[[12481],256],13025:[[12484],256],13026:[[12486],256],13027:[[12488],256],13028:[[12490],256],13029:[[12491],256],13030:[[12492],256],13031:[[12493],256],13032:[[12494],256],13033:[[12495],256],13034:[[12498],256],13035:[[12501],256],13036:[[12504],256],13037:[[12507],256],13038:[[12510],256],13039:[[12511],256],13040:[[12512],256],13041:[[12513],256],13042:[[12514],256],13043:[[12516],256],13044:[[12518],256],13045:[[12520],256],13046:[[12521],256],13047:[[12522],256],13048:[[12523],256],13049:[[12524],256],13050:[[12525],256],13051:[[12527],256],13052:[[12528],256],13053:[[12529],256],13054:[[12530],256]}, +13056:{13056:[[12450,12497,12540,12488],256],13057:[[12450,12523,12501,12449],256],13058:[[12450,12531,12506,12450],256],13059:[[12450,12540,12523],256],13060:[[12452,12491,12531,12464],256],13061:[[12452,12531,12481],256],13062:[[12454,12457,12531],256],13063:[[12456,12473,12463,12540,12489],256],13064:[[12456,12540,12459,12540],256],13065:[[12458,12531,12473],256],13066:[[12458,12540,12512],256],13067:[[12459,12452,12522],256],13068:[[12459,12521,12483,12488],256],13069:[[12459,12525,12522,12540],256],13070:[[12460,12525,12531],256],13071:[[12460,12531,12510],256],13072:[[12462,12460],256],13073:[[12462,12491,12540],256],13074:[[12461,12517,12522,12540],256],13075:[[12462,12523,12480,12540],256],13076:[[12461,12525],256],13077:[[12461,12525,12464,12521,12512],256],13078:[[12461,12525,12513,12540,12488,12523],256],13079:[[12461,12525,12527,12483,12488],256],13080:[[12464,12521,12512],256],13081:[[12464,12521,12512,12488,12531],256],13082:[[12463,12523,12476,12452,12525],256],13083:[[12463,12525,12540,12493],256],13084:[[12465,12540,12473],256],13085:[[12467,12523,12490],256],13086:[[12467,12540,12509],256],13087:[[12469,12452,12463,12523],256],13088:[[12469,12531,12481,12540,12512],256],13089:[[12471,12522,12531,12464],256],13090:[[12475,12531,12481],256],13091:[[12475,12531,12488],256],13092:[[12480,12540,12473],256],13093:[[12487,12471],256],13094:[[12489,12523],256],13095:[[12488,12531],256],13096:[[12490,12494],256],13097:[[12494,12483,12488],256],13098:[[12495,12452,12484],256],13099:[[12497,12540,12475,12531,12488],256],13100:[[12497,12540,12484],256],13101:[[12496,12540,12524,12523],256],13102:[[12500,12450,12473,12488,12523],256],13103:[[12500,12463,12523],256],13104:[[12500,12467],256],13105:[[12499,12523],256],13106:[[12501,12449,12521,12483,12489],256],13107:[[12501,12451,12540,12488],256],13108:[[12502,12483,12471,12455,12523],256],13109:[[12501,12521,12531],256],13110:[[12504,12463,12479,12540,12523],256],13111:[[12506,12477],256],13112:[[12506,12491,12498],256],13113:[[12504,12523,12484],256],13114:[[12506,12531,12473],256],13115:[[12506,12540,12472],256],13116:[[12505,12540,12479],256],13117:[[12509,12452,12531,12488],256],13118:[[12508,12523,12488],256],13119:[[12507,12531],256],13120:[[12509,12531,12489],256],13121:[[12507,12540,12523],256],13122:[[12507,12540,12531],256],13123:[[12510,12452,12463,12525],256],13124:[[12510,12452,12523],256],13125:[[12510,12483,12495],256],13126:[[12510,12523,12463],256],13127:[[12510,12531,12471,12519,12531],256],13128:[[12511,12463,12525,12531],256],13129:[[12511,12522],256],13130:[[12511,12522,12496,12540,12523],256],13131:[[12513,12460],256],13132:[[12513,12460,12488,12531],256],13133:[[12513,12540,12488,12523],256],13134:[[12516,12540,12489],256],13135:[[12516,12540,12523],256],13136:[[12518,12450,12531],256],13137:[[12522,12483,12488,12523],256],13138:[[12522,12521],256],13139:[[12523,12500,12540],256],13140:[[12523,12540,12502,12523],256],13141:[[12524,12512],256],13142:[[12524,12531,12488,12466,12531],256],13143:[[12527,12483,12488],256],13144:[[48,28857],256],13145:[[49,28857],256],13146:[[50,28857],256],13147:[[51,28857],256],13148:[[52,28857],256],13149:[[53,28857],256],13150:[[54,28857],256],13151:[[55,28857],256],13152:[[56,28857],256],13153:[[57,28857],256],13154:[[49,48,28857],256],13155:[[49,49,28857],256],13156:[[49,50,28857],256],13157:[[49,51,28857],256],13158:[[49,52,28857],256],13159:[[49,53,28857],256],13160:[[49,54,28857],256],13161:[[49,55,28857],256],13162:[[49,56,28857],256],13163:[[49,57,28857],256],13164:[[50,48,28857],256],13165:[[50,49,28857],256],13166:[[50,50,28857],256],13167:[[50,51,28857],256],13168:[[50,52,28857],256],13169:[[104,80,97],256],13170:[[100,97],256],13171:[[65,85],256],13172:[[98,97,114],256],13173:[[111,86],256],13174:[[112,99],256],13175:[[100,109],256],13176:[[100,109,178],256],13177:[[100,109,179],256],13178:[[73,85],256],13179:[[24179,25104],256],13180:[[26157,21644],256],13181:[[22823,27491],256],13182:[[26126,27835],256],13183:[[26666,24335,20250,31038],256],13184:[[112,65],256],13185:[[110,65],256],13186:[[956,65],256],13187:[[109,65],256],13188:[[107,65],256],13189:[[75,66],256],13190:[[77,66],256],13191:[[71,66],256],13192:[[99,97,108],256],13193:[[107,99,97,108],256],13194:[[112,70],256],13195:[[110,70],256],13196:[[956,70],256],13197:[[956,103],256],13198:[[109,103],256],13199:[[107,103],256],13200:[[72,122],256],13201:[[107,72,122],256],13202:[[77,72,122],256],13203:[[71,72,122],256],13204:[[84,72,122],256],13205:[[956,8467],256],13206:[[109,8467],256],13207:[[100,8467],256],13208:[[107,8467],256],13209:[[102,109],256],13210:[[110,109],256],13211:[[956,109],256],13212:[[109,109],256],13213:[[99,109],256],13214:[[107,109],256],13215:[[109,109,178],256],13216:[[99,109,178],256],13217:[[109,178],256],13218:[[107,109,178],256],13219:[[109,109,179],256],13220:[[99,109,179],256],13221:[[109,179],256],13222:[[107,109,179],256],13223:[[109,8725,115],256],13224:[[109,8725,115,178],256],13225:[[80,97],256],13226:[[107,80,97],256],13227:[[77,80,97],256],13228:[[71,80,97],256],13229:[[114,97,100],256],13230:[[114,97,100,8725,115],256],13231:[[114,97,100,8725,115,178],256],13232:[[112,115],256],13233:[[110,115],256],13234:[[956,115],256],13235:[[109,115],256],13236:[[112,86],256],13237:[[110,86],256],13238:[[956,86],256],13239:[[109,86],256],13240:[[107,86],256],13241:[[77,86],256],13242:[[112,87],256],13243:[[110,87],256],13244:[[956,87],256],13245:[[109,87],256],13246:[[107,87],256],13247:[[77,87],256],13248:[[107,937],256],13249:[[77,937],256],13250:[[97,46,109,46],256],13251:[[66,113],256],13252:[[99,99],256],13253:[[99,100],256],13254:[[67,8725,107,103],256],13255:[[67,111,46],256],13256:[[100,66],256],13257:[[71,121],256],13258:[[104,97],256],13259:[[72,80],256],13260:[[105,110],256],13261:[[75,75],256],13262:[[75,77],256],13263:[[107,116],256],13264:[[108,109],256],13265:[[108,110],256],13266:[[108,111,103],256],13267:[[108,120],256],13268:[[109,98],256],13269:[[109,105,108],256],13270:[[109,111,108],256],13271:[[80,72],256],13272:[[112,46,109,46],256],13273:[[80,80,77],256],13274:[[80,82],256],13275:[[115,114],256],13276:[[83,118],256],13277:[[87,98],256],13278:[[86,8725,109],256],13279:[[65,8725,109],256],13280:[[49,26085],256],13281:[[50,26085],256],13282:[[51,26085],256],13283:[[52,26085],256],13284:[[53,26085],256],13285:[[54,26085],256],13286:[[55,26085],256],13287:[[56,26085],256],13288:[[57,26085],256],13289:[[49,48,26085],256],13290:[[49,49,26085],256],13291:[[49,50,26085],256],13292:[[49,51,26085],256],13293:[[49,52,26085],256],13294:[[49,53,26085],256],13295:[[49,54,26085],256],13296:[[49,55,26085],256],13297:[[49,56,26085],256],13298:[[49,57,26085],256],13299:[[50,48,26085],256],13300:[[50,49,26085],256],13301:[[50,50,26085],256],13302:[[50,51,26085],256],13303:[[50,52,26085],256],13304:[[50,53,26085],256],13305:[[50,54,26085],256],13306:[[50,55,26085],256],13307:[[50,56,26085],256],13308:[[50,57,26085],256],13309:[[51,48,26085],256],13310:[[51,49,26085],256],13311:[[103,97,108],256]}, +27136:{92912:[,1],92913:[,1],92914:[,1],92915:[,1],92916:[,1]}, +27392:{92976:[,230],92977:[,230],92978:[,230],92979:[,230],92980:[,230],92981:[,230],92982:[,230]}, +42496:{42607:[,230],42612:[,230],42613:[,230],42614:[,230],42615:[,230],42616:[,230],42617:[,230],42618:[,230],42619:[,230],42620:[,230],42621:[,230],42652:[[1098],256],42653:[[1100],256],42655:[,230],42736:[,230],42737:[,230]}, +42752:{42864:[[42863],256],43000:[[294],256],43001:[[339],256]}, +43008:{43014:[,9],43204:[,9],43232:[,230],43233:[,230],43234:[,230],43235:[,230],43236:[,230],43237:[,230],43238:[,230],43239:[,230],43240:[,230],43241:[,230],43242:[,230],43243:[,230],43244:[,230],43245:[,230],43246:[,230],43247:[,230],43248:[,230],43249:[,230]}, +43264:{43307:[,220],43308:[,220],43309:[,220],43347:[,9],43443:[,7],43456:[,9]}, +43520:{43696:[,230],43698:[,230],43699:[,230],43700:[,220],43703:[,230],43704:[,230],43710:[,230],43711:[,230],43713:[,230],43766:[,9]}, +43776:{43868:[[42791],256],43869:[[43831],256],43870:[[619],256],43871:[[43858],256],44013:[,9]}, +48128:{113822:[,1]}, +53504:{119134:[[119127,119141],512],119135:[[119128,119141],512],119136:[[119135,119150],512],119137:[[119135,119151],512],119138:[[119135,119152],512],119139:[[119135,119153],512],119140:[[119135,119154],512],119141:[,216],119142:[,216],119143:[,1],119144:[,1],119145:[,1],119149:[,226],119150:[,216],119151:[,216],119152:[,216],119153:[,216],119154:[,216],119163:[,220],119164:[,220],119165:[,220],119166:[,220],119167:[,220],119168:[,220],119169:[,220],119170:[,220],119173:[,230],119174:[,230],119175:[,230],119176:[,230],119177:[,230],119178:[,220],119179:[,220],119210:[,230],119211:[,230],119212:[,230],119213:[,230],119227:[[119225,119141],512],119228:[[119226,119141],512],119229:[[119227,119150],512],119230:[[119228,119150],512],119231:[[119227,119151],512],119232:[[119228,119151],512]}, +53760:{119362:[,230],119363:[,230],119364:[,230]}, +54272:{119808:[[65],256],119809:[[66],256],119810:[[67],256],119811:[[68],256],119812:[[69],256],119813:[[70],256],119814:[[71],256],119815:[[72],256],119816:[[73],256],119817:[[74],256],119818:[[75],256],119819:[[76],256],119820:[[77],256],119821:[[78],256],119822:[[79],256],119823:[[80],256],119824:[[81],256],119825:[[82],256],119826:[[83],256],119827:[[84],256],119828:[[85],256],119829:[[86],256],119830:[[87],256],119831:[[88],256],119832:[[89],256],119833:[[90],256],119834:[[97],256],119835:[[98],256],119836:[[99],256],119837:[[100],256],119838:[[101],256],119839:[[102],256],119840:[[103],256],119841:[[104],256],119842:[[105],256],119843:[[106],256],119844:[[107],256],119845:[[108],256],119846:[[109],256],119847:[[110],256],119848:[[111],256],119849:[[112],256],119850:[[113],256],119851:[[114],256],119852:[[115],256],119853:[[116],256],119854:[[117],256],119855:[[118],256],119856:[[119],256],119857:[[120],256],119858:[[121],256],119859:[[122],256],119860:[[65],256],119861:[[66],256],119862:[[67],256],119863:[[68],256],119864:[[69],256],119865:[[70],256],119866:[[71],256],119867:[[72],256],119868:[[73],256],119869:[[74],256],119870:[[75],256],119871:[[76],256],119872:[[77],256],119873:[[78],256],119874:[[79],256],119875:[[80],256],119876:[[81],256],119877:[[82],256],119878:[[83],256],119879:[[84],256],119880:[[85],256],119881:[[86],256],119882:[[87],256],119883:[[88],256],119884:[[89],256],119885:[[90],256],119886:[[97],256],119887:[[98],256],119888:[[99],256],119889:[[100],256],119890:[[101],256],119891:[[102],256],119892:[[103],256],119894:[[105],256],119895:[[106],256],119896:[[107],256],119897:[[108],256],119898:[[109],256],119899:[[110],256],119900:[[111],256],119901:[[112],256],119902:[[113],256],119903:[[114],256],119904:[[115],256],119905:[[116],256],119906:[[117],256],119907:[[118],256],119908:[[119],256],119909:[[120],256],119910:[[121],256],119911:[[122],256],119912:[[65],256],119913:[[66],256],119914:[[67],256],119915:[[68],256],119916:[[69],256],119917:[[70],256],119918:[[71],256],119919:[[72],256],119920:[[73],256],119921:[[74],256],119922:[[75],256],119923:[[76],256],119924:[[77],256],119925:[[78],256],119926:[[79],256],119927:[[80],256],119928:[[81],256],119929:[[82],256],119930:[[83],256],119931:[[84],256],119932:[[85],256],119933:[[86],256],119934:[[87],256],119935:[[88],256],119936:[[89],256],119937:[[90],256],119938:[[97],256],119939:[[98],256],119940:[[99],256],119941:[[100],256],119942:[[101],256],119943:[[102],256],119944:[[103],256],119945:[[104],256],119946:[[105],256],119947:[[106],256],119948:[[107],256],119949:[[108],256],119950:[[109],256],119951:[[110],256],119952:[[111],256],119953:[[112],256],119954:[[113],256],119955:[[114],256],119956:[[115],256],119957:[[116],256],119958:[[117],256],119959:[[118],256],119960:[[119],256],119961:[[120],256],119962:[[121],256],119963:[[122],256],119964:[[65],256],119966:[[67],256],119967:[[68],256],119970:[[71],256],119973:[[74],256],119974:[[75],256],119977:[[78],256],119978:[[79],256],119979:[[80],256],119980:[[81],256],119982:[[83],256],119983:[[84],256],119984:[[85],256],119985:[[86],256],119986:[[87],256],119987:[[88],256],119988:[[89],256],119989:[[90],256],119990:[[97],256],119991:[[98],256],119992:[[99],256],119993:[[100],256],119995:[[102],256],119997:[[104],256],119998:[[105],256],119999:[[106],256],120000:[[107],256],120001:[[108],256],120002:[[109],256],120003:[[110],256],120005:[[112],256],120006:[[113],256],120007:[[114],256],120008:[[115],256],120009:[[116],256],120010:[[117],256],120011:[[118],256],120012:[[119],256],120013:[[120],256],120014:[[121],256],120015:[[122],256],120016:[[65],256],120017:[[66],256],120018:[[67],256],120019:[[68],256],120020:[[69],256],120021:[[70],256],120022:[[71],256],120023:[[72],256],120024:[[73],256],120025:[[74],256],120026:[[75],256],120027:[[76],256],120028:[[77],256],120029:[[78],256],120030:[[79],256],120031:[[80],256],120032:[[81],256],120033:[[82],256],120034:[[83],256],120035:[[84],256],120036:[[85],256],120037:[[86],256],120038:[[87],256],120039:[[88],256],120040:[[89],256],120041:[[90],256],120042:[[97],256],120043:[[98],256],120044:[[99],256],120045:[[100],256],120046:[[101],256],120047:[[102],256],120048:[[103],256],120049:[[104],256],120050:[[105],256],120051:[[106],256],120052:[[107],256],120053:[[108],256],120054:[[109],256],120055:[[110],256],120056:[[111],256],120057:[[112],256],120058:[[113],256],120059:[[114],256],120060:[[115],256],120061:[[116],256],120062:[[117],256],120063:[[118],256]}, +54528:{120064:[[119],256],120065:[[120],256],120066:[[121],256],120067:[[122],256],120068:[[65],256],120069:[[66],256],120071:[[68],256],120072:[[69],256],120073:[[70],256],120074:[[71],256],120077:[[74],256],120078:[[75],256],120079:[[76],256],120080:[[77],256],120081:[[78],256],120082:[[79],256],120083:[[80],256],120084:[[81],256],120086:[[83],256],120087:[[84],256],120088:[[85],256],120089:[[86],256],120090:[[87],256],120091:[[88],256],120092:[[89],256],120094:[[97],256],120095:[[98],256],120096:[[99],256],120097:[[100],256],120098:[[101],256],120099:[[102],256],120100:[[103],256],120101:[[104],256],120102:[[105],256],120103:[[106],256],120104:[[107],256],120105:[[108],256],120106:[[109],256],120107:[[110],256],120108:[[111],256],120109:[[112],256],120110:[[113],256],120111:[[114],256],120112:[[115],256],120113:[[116],256],120114:[[117],256],120115:[[118],256],120116:[[119],256],120117:[[120],256],120118:[[121],256],120119:[[122],256],120120:[[65],256],120121:[[66],256],120123:[[68],256],120124:[[69],256],120125:[[70],256],120126:[[71],256],120128:[[73],256],120129:[[74],256],120130:[[75],256],120131:[[76],256],120132:[[77],256],120134:[[79],256],120138:[[83],256],120139:[[84],256],120140:[[85],256],120141:[[86],256],120142:[[87],256],120143:[[88],256],120144:[[89],256],120146:[[97],256],120147:[[98],256],120148:[[99],256],120149:[[100],256],120150:[[101],256],120151:[[102],256],120152:[[103],256],120153:[[104],256],120154:[[105],256],120155:[[106],256],120156:[[107],256],120157:[[108],256],120158:[[109],256],120159:[[110],256],120160:[[111],256],120161:[[112],256],120162:[[113],256],120163:[[114],256],120164:[[115],256],120165:[[116],256],120166:[[117],256],120167:[[118],256],120168:[[119],256],120169:[[120],256],120170:[[121],256],120171:[[122],256],120172:[[65],256],120173:[[66],256],120174:[[67],256],120175:[[68],256],120176:[[69],256],120177:[[70],256],120178:[[71],256],120179:[[72],256],120180:[[73],256],120181:[[74],256],120182:[[75],256],120183:[[76],256],120184:[[77],256],120185:[[78],256],120186:[[79],256],120187:[[80],256],120188:[[81],256],120189:[[82],256],120190:[[83],256],120191:[[84],256],120192:[[85],256],120193:[[86],256],120194:[[87],256],120195:[[88],256],120196:[[89],256],120197:[[90],256],120198:[[97],256],120199:[[98],256],120200:[[99],256],120201:[[100],256],120202:[[101],256],120203:[[102],256],120204:[[103],256],120205:[[104],256],120206:[[105],256],120207:[[106],256],120208:[[107],256],120209:[[108],256],120210:[[109],256],120211:[[110],256],120212:[[111],256],120213:[[112],256],120214:[[113],256],120215:[[114],256],120216:[[115],256],120217:[[116],256],120218:[[117],256],120219:[[118],256],120220:[[119],256],120221:[[120],256],120222:[[121],256],120223:[[122],256],120224:[[65],256],120225:[[66],256],120226:[[67],256],120227:[[68],256],120228:[[69],256],120229:[[70],256],120230:[[71],256],120231:[[72],256],120232:[[73],256],120233:[[74],256],120234:[[75],256],120235:[[76],256],120236:[[77],256],120237:[[78],256],120238:[[79],256],120239:[[80],256],120240:[[81],256],120241:[[82],256],120242:[[83],256],120243:[[84],256],120244:[[85],256],120245:[[86],256],120246:[[87],256],120247:[[88],256],120248:[[89],256],120249:[[90],256],120250:[[97],256],120251:[[98],256],120252:[[99],256],120253:[[100],256],120254:[[101],256],120255:[[102],256],120256:[[103],256],120257:[[104],256],120258:[[105],256],120259:[[106],256],120260:[[107],256],120261:[[108],256],120262:[[109],256],120263:[[110],256],120264:[[111],256],120265:[[112],256],120266:[[113],256],120267:[[114],256],120268:[[115],256],120269:[[116],256],120270:[[117],256],120271:[[118],256],120272:[[119],256],120273:[[120],256],120274:[[121],256],120275:[[122],256],120276:[[65],256],120277:[[66],256],120278:[[67],256],120279:[[68],256],120280:[[69],256],120281:[[70],256],120282:[[71],256],120283:[[72],256],120284:[[73],256],120285:[[74],256],120286:[[75],256],120287:[[76],256],120288:[[77],256],120289:[[78],256],120290:[[79],256],120291:[[80],256],120292:[[81],256],120293:[[82],256],120294:[[83],256],120295:[[84],256],120296:[[85],256],120297:[[86],256],120298:[[87],256],120299:[[88],256],120300:[[89],256],120301:[[90],256],120302:[[97],256],120303:[[98],256],120304:[[99],256],120305:[[100],256],120306:[[101],256],120307:[[102],256],120308:[[103],256],120309:[[104],256],120310:[[105],256],120311:[[106],256],120312:[[107],256],120313:[[108],256],120314:[[109],256],120315:[[110],256],120316:[[111],256],120317:[[112],256],120318:[[113],256],120319:[[114],256]}, +54784:{120320:[[115],256],120321:[[116],256],120322:[[117],256],120323:[[118],256],120324:[[119],256],120325:[[120],256],120326:[[121],256],120327:[[122],256],120328:[[65],256],120329:[[66],256],120330:[[67],256],120331:[[68],256],120332:[[69],256],120333:[[70],256],120334:[[71],256],120335:[[72],256],120336:[[73],256],120337:[[74],256],120338:[[75],256],120339:[[76],256],120340:[[77],256],120341:[[78],256],120342:[[79],256],120343:[[80],256],120344:[[81],256],120345:[[82],256],120346:[[83],256],120347:[[84],256],120348:[[85],256],120349:[[86],256],120350:[[87],256],120351:[[88],256],120352:[[89],256],120353:[[90],256],120354:[[97],256],120355:[[98],256],120356:[[99],256],120357:[[100],256],120358:[[101],256],120359:[[102],256],120360:[[103],256],120361:[[104],256],120362:[[105],256],120363:[[106],256],120364:[[107],256],120365:[[108],256],120366:[[109],256],120367:[[110],256],120368:[[111],256],120369:[[112],256],120370:[[113],256],120371:[[114],256],120372:[[115],256],120373:[[116],256],120374:[[117],256],120375:[[118],256],120376:[[119],256],120377:[[120],256],120378:[[121],256],120379:[[122],256],120380:[[65],256],120381:[[66],256],120382:[[67],256],120383:[[68],256],120384:[[69],256],120385:[[70],256],120386:[[71],256],120387:[[72],256],120388:[[73],256],120389:[[74],256],120390:[[75],256],120391:[[76],256],120392:[[77],256],120393:[[78],256],120394:[[79],256],120395:[[80],256],120396:[[81],256],120397:[[82],256],120398:[[83],256],120399:[[84],256],120400:[[85],256],120401:[[86],256],120402:[[87],256],120403:[[88],256],120404:[[89],256],120405:[[90],256],120406:[[97],256],120407:[[98],256],120408:[[99],256],120409:[[100],256],120410:[[101],256],120411:[[102],256],120412:[[103],256],120413:[[104],256],120414:[[105],256],120415:[[106],256],120416:[[107],256],120417:[[108],256],120418:[[109],256],120419:[[110],256],120420:[[111],256],120421:[[112],256],120422:[[113],256],120423:[[114],256],120424:[[115],256],120425:[[116],256],120426:[[117],256],120427:[[118],256],120428:[[119],256],120429:[[120],256],120430:[[121],256],120431:[[122],256],120432:[[65],256],120433:[[66],256],120434:[[67],256],120435:[[68],256],120436:[[69],256],120437:[[70],256],120438:[[71],256],120439:[[72],256],120440:[[73],256],120441:[[74],256],120442:[[75],256],120443:[[76],256],120444:[[77],256],120445:[[78],256],120446:[[79],256],120447:[[80],256],120448:[[81],256],120449:[[82],256],120450:[[83],256],120451:[[84],256],120452:[[85],256],120453:[[86],256],120454:[[87],256],120455:[[88],256],120456:[[89],256],120457:[[90],256],120458:[[97],256],120459:[[98],256],120460:[[99],256],120461:[[100],256],120462:[[101],256],120463:[[102],256],120464:[[103],256],120465:[[104],256],120466:[[105],256],120467:[[106],256],120468:[[107],256],120469:[[108],256],120470:[[109],256],120471:[[110],256],120472:[[111],256],120473:[[112],256],120474:[[113],256],120475:[[114],256],120476:[[115],256],120477:[[116],256],120478:[[117],256],120479:[[118],256],120480:[[119],256],120481:[[120],256],120482:[[121],256],120483:[[122],256],120484:[[305],256],120485:[[567],256],120488:[[913],256],120489:[[914],256],120490:[[915],256],120491:[[916],256],120492:[[917],256],120493:[[918],256],120494:[[919],256],120495:[[920],256],120496:[[921],256],120497:[[922],256],120498:[[923],256],120499:[[924],256],120500:[[925],256],120501:[[926],256],120502:[[927],256],120503:[[928],256],120504:[[929],256],120505:[[1012],256],120506:[[931],256],120507:[[932],256],120508:[[933],256],120509:[[934],256],120510:[[935],256],120511:[[936],256],120512:[[937],256],120513:[[8711],256],120514:[[945],256],120515:[[946],256],120516:[[947],256],120517:[[948],256],120518:[[949],256],120519:[[950],256],120520:[[951],256],120521:[[952],256],120522:[[953],256],120523:[[954],256],120524:[[955],256],120525:[[956],256],120526:[[957],256],120527:[[958],256],120528:[[959],256],120529:[[960],256],120530:[[961],256],120531:[[962],256],120532:[[963],256],120533:[[964],256],120534:[[965],256],120535:[[966],256],120536:[[967],256],120537:[[968],256],120538:[[969],256],120539:[[8706],256],120540:[[1013],256],120541:[[977],256],120542:[[1008],256],120543:[[981],256],120544:[[1009],256],120545:[[982],256],120546:[[913],256],120547:[[914],256],120548:[[915],256],120549:[[916],256],120550:[[917],256],120551:[[918],256],120552:[[919],256],120553:[[920],256],120554:[[921],256],120555:[[922],256],120556:[[923],256],120557:[[924],256],120558:[[925],256],120559:[[926],256],120560:[[927],256],120561:[[928],256],120562:[[929],256],120563:[[1012],256],120564:[[931],256],120565:[[932],256],120566:[[933],256],120567:[[934],256],120568:[[935],256],120569:[[936],256],120570:[[937],256],120571:[[8711],256],120572:[[945],256],120573:[[946],256],120574:[[947],256],120575:[[948],256]}, +55040:{120576:[[949],256],120577:[[950],256],120578:[[951],256],120579:[[952],256],120580:[[953],256],120581:[[954],256],120582:[[955],256],120583:[[956],256],120584:[[957],256],120585:[[958],256],120586:[[959],256],120587:[[960],256],120588:[[961],256],120589:[[962],256],120590:[[963],256],120591:[[964],256],120592:[[965],256],120593:[[966],256],120594:[[967],256],120595:[[968],256],120596:[[969],256],120597:[[8706],256],120598:[[1013],256],120599:[[977],256],120600:[[1008],256],120601:[[981],256],120602:[[1009],256],120603:[[982],256],120604:[[913],256],120605:[[914],256],120606:[[915],256],120607:[[916],256],120608:[[917],256],120609:[[918],256],120610:[[919],256],120611:[[920],256],120612:[[921],256],120613:[[922],256],120614:[[923],256],120615:[[924],256],120616:[[925],256],120617:[[926],256],120618:[[927],256],120619:[[928],256],120620:[[929],256],120621:[[1012],256],120622:[[931],256],120623:[[932],256],120624:[[933],256],120625:[[934],256],120626:[[935],256],120627:[[936],256],120628:[[937],256],120629:[[8711],256],120630:[[945],256],120631:[[946],256],120632:[[947],256],120633:[[948],256],120634:[[949],256],120635:[[950],256],120636:[[951],256],120637:[[952],256],120638:[[953],256],120639:[[954],256],120640:[[955],256],120641:[[956],256],120642:[[957],256],120643:[[958],256],120644:[[959],256],120645:[[960],256],120646:[[961],256],120647:[[962],256],120648:[[963],256],120649:[[964],256],120650:[[965],256],120651:[[966],256],120652:[[967],256],120653:[[968],256],120654:[[969],256],120655:[[8706],256],120656:[[1013],256],120657:[[977],256],120658:[[1008],256],120659:[[981],256],120660:[[1009],256],120661:[[982],256],120662:[[913],256],120663:[[914],256],120664:[[915],256],120665:[[916],256],120666:[[917],256],120667:[[918],256],120668:[[919],256],120669:[[920],256],120670:[[921],256],120671:[[922],256],120672:[[923],256],120673:[[924],256],120674:[[925],256],120675:[[926],256],120676:[[927],256],120677:[[928],256],120678:[[929],256],120679:[[1012],256],120680:[[931],256],120681:[[932],256],120682:[[933],256],120683:[[934],256],120684:[[935],256],120685:[[936],256],120686:[[937],256],120687:[[8711],256],120688:[[945],256],120689:[[946],256],120690:[[947],256],120691:[[948],256],120692:[[949],256],120693:[[950],256],120694:[[951],256],120695:[[952],256],120696:[[953],256],120697:[[954],256],120698:[[955],256],120699:[[956],256],120700:[[957],256],120701:[[958],256],120702:[[959],256],120703:[[960],256],120704:[[961],256],120705:[[962],256],120706:[[963],256],120707:[[964],256],120708:[[965],256],120709:[[966],256],120710:[[967],256],120711:[[968],256],120712:[[969],256],120713:[[8706],256],120714:[[1013],256],120715:[[977],256],120716:[[1008],256],120717:[[981],256],120718:[[1009],256],120719:[[982],256],120720:[[913],256],120721:[[914],256],120722:[[915],256],120723:[[916],256],120724:[[917],256],120725:[[918],256],120726:[[919],256],120727:[[920],256],120728:[[921],256],120729:[[922],256],120730:[[923],256],120731:[[924],256],120732:[[925],256],120733:[[926],256],120734:[[927],256],120735:[[928],256],120736:[[929],256],120737:[[1012],256],120738:[[931],256],120739:[[932],256],120740:[[933],256],120741:[[934],256],120742:[[935],256],120743:[[936],256],120744:[[937],256],120745:[[8711],256],120746:[[945],256],120747:[[946],256],120748:[[947],256],120749:[[948],256],120750:[[949],256],120751:[[950],256],120752:[[951],256],120753:[[952],256],120754:[[953],256],120755:[[954],256],120756:[[955],256],120757:[[956],256],120758:[[957],256],120759:[[958],256],120760:[[959],256],120761:[[960],256],120762:[[961],256],120763:[[962],256],120764:[[963],256],120765:[[964],256],120766:[[965],256],120767:[[966],256],120768:[[967],256],120769:[[968],256],120770:[[969],256],120771:[[8706],256],120772:[[1013],256],120773:[[977],256],120774:[[1008],256],120775:[[981],256],120776:[[1009],256],120777:[[982],256],120778:[[988],256],120779:[[989],256],120782:[[48],256],120783:[[49],256],120784:[[50],256],120785:[[51],256],120786:[[52],256],120787:[[53],256],120788:[[54],256],120789:[[55],256],120790:[[56],256],120791:[[57],256],120792:[[48],256],120793:[[49],256],120794:[[50],256],120795:[[51],256],120796:[[52],256],120797:[[53],256],120798:[[54],256],120799:[[55],256],120800:[[56],256],120801:[[57],256],120802:[[48],256],120803:[[49],256],120804:[[50],256],120805:[[51],256],120806:[[52],256],120807:[[53],256],120808:[[54],256],120809:[[55],256],120810:[[56],256],120811:[[57],256],120812:[[48],256],120813:[[49],256],120814:[[50],256],120815:[[51],256],120816:[[52],256],120817:[[53],256],120818:[[54],256],120819:[[55],256],120820:[[56],256],120821:[[57],256],120822:[[48],256],120823:[[49],256],120824:[[50],256],120825:[[51],256],120826:[[52],256],120827:[[53],256],120828:[[54],256],120829:[[55],256],120830:[[56],256],120831:[[57],256]}, +59392:{125136:[,220],125137:[,220],125138:[,220],125139:[,220],125140:[,220],125141:[,220],125142:[,220]}, +60928:{126464:[[1575],256],126465:[[1576],256],126466:[[1580],256],126467:[[1583],256],126469:[[1608],256],126470:[[1586],256],126471:[[1581],256],126472:[[1591],256],126473:[[1610],256],126474:[[1603],256],126475:[[1604],256],126476:[[1605],256],126477:[[1606],256],126478:[[1587],256],126479:[[1593],256],126480:[[1601],256],126481:[[1589],256],126482:[[1602],256],126483:[[1585],256],126484:[[1588],256],126485:[[1578],256],126486:[[1579],256],126487:[[1582],256],126488:[[1584],256],126489:[[1590],256],126490:[[1592],256],126491:[[1594],256],126492:[[1646],256],126493:[[1722],256],126494:[[1697],256],126495:[[1647],256],126497:[[1576],256],126498:[[1580],256],126500:[[1607],256],126503:[[1581],256],126505:[[1610],256],126506:[[1603],256],126507:[[1604],256],126508:[[1605],256],126509:[[1606],256],126510:[[1587],256],126511:[[1593],256],126512:[[1601],256],126513:[[1589],256],126514:[[1602],256],126516:[[1588],256],126517:[[1578],256],126518:[[1579],256],126519:[[1582],256],126521:[[1590],256],126523:[[1594],256],126530:[[1580],256],126535:[[1581],256],126537:[[1610],256],126539:[[1604],256],126541:[[1606],256],126542:[[1587],256],126543:[[1593],256],126545:[[1589],256],126546:[[1602],256],126548:[[1588],256],126551:[[1582],256],126553:[[1590],256],126555:[[1594],256],126557:[[1722],256],126559:[[1647],256],126561:[[1576],256],126562:[[1580],256],126564:[[1607],256],126567:[[1581],256],126568:[[1591],256],126569:[[1610],256],126570:[[1603],256],126572:[[1605],256],126573:[[1606],256],126574:[[1587],256],126575:[[1593],256],126576:[[1601],256],126577:[[1589],256],126578:[[1602],256],126580:[[1588],256],126581:[[1578],256],126582:[[1579],256],126583:[[1582],256],126585:[[1590],256],126586:[[1592],256],126587:[[1594],256],126588:[[1646],256],126590:[[1697],256],126592:[[1575],256],126593:[[1576],256],126594:[[1580],256],126595:[[1583],256],126596:[[1607],256],126597:[[1608],256],126598:[[1586],256],126599:[[1581],256],126600:[[1591],256],126601:[[1610],256],126603:[[1604],256],126604:[[1605],256],126605:[[1606],256],126606:[[1587],256],126607:[[1593],256],126608:[[1601],256],126609:[[1589],256],126610:[[1602],256],126611:[[1585],256],126612:[[1588],256],126613:[[1578],256],126614:[[1579],256],126615:[[1582],256],126616:[[1584],256],126617:[[1590],256],126618:[[1592],256],126619:[[1594],256],126625:[[1576],256],126626:[[1580],256],126627:[[1583],256],126629:[[1608],256],126630:[[1586],256],126631:[[1581],256],126632:[[1591],256],126633:[[1610],256],126635:[[1604],256],126636:[[1605],256],126637:[[1606],256],126638:[[1587],256],126639:[[1593],256],126640:[[1601],256],126641:[[1589],256],126642:[[1602],256],126643:[[1585],256],126644:[[1588],256],126645:[[1578],256],126646:[[1579],256],126647:[[1582],256],126648:[[1584],256],126649:[[1590],256],126650:[[1592],256],126651:[[1594],256]}, +61696:{127232:[[48,46],256],127233:[[48,44],256],127234:[[49,44],256],127235:[[50,44],256],127236:[[51,44],256],127237:[[52,44],256],127238:[[53,44],256],127239:[[54,44],256],127240:[[55,44],256],127241:[[56,44],256],127242:[[57,44],256],127248:[[40,65,41],256],127249:[[40,66,41],256],127250:[[40,67,41],256],127251:[[40,68,41],256],127252:[[40,69,41],256],127253:[[40,70,41],256],127254:[[40,71,41],256],127255:[[40,72,41],256],127256:[[40,73,41],256],127257:[[40,74,41],256],127258:[[40,75,41],256],127259:[[40,76,41],256],127260:[[40,77,41],256],127261:[[40,78,41],256],127262:[[40,79,41],256],127263:[[40,80,41],256],127264:[[40,81,41],256],127265:[[40,82,41],256],127266:[[40,83,41],256],127267:[[40,84,41],256],127268:[[40,85,41],256],127269:[[40,86,41],256],127270:[[40,87,41],256],127271:[[40,88,41],256],127272:[[40,89,41],256],127273:[[40,90,41],256],127274:[[12308,83,12309],256],127275:[[67],256],127276:[[82],256],127277:[[67,68],256],127278:[[87,90],256],127280:[[65],256],127281:[[66],256],127282:[[67],256],127283:[[68],256],127284:[[69],256],127285:[[70],256],127286:[[71],256],127287:[[72],256],127288:[[73],256],127289:[[74],256],127290:[[75],256],127291:[[76],256],127292:[[77],256],127293:[[78],256],127294:[[79],256],127295:[[80],256],127296:[[81],256],127297:[[82],256],127298:[[83],256],127299:[[84],256],127300:[[85],256],127301:[[86],256],127302:[[87],256],127303:[[88],256],127304:[[89],256],127305:[[90],256],127306:[[72,86],256],127307:[[77,86],256],127308:[[83,68],256],127309:[[83,83],256],127310:[[80,80,86],256],127311:[[87,67],256],127338:[[77,67],256],127339:[[77,68],256],127376:[[68,74],256]}, +61952:{127488:[[12411,12363],256],127489:[[12467,12467],256],127490:[[12469],256],127504:[[25163],256],127505:[[23383],256],127506:[[21452],256],127507:[[12487],256],127508:[[20108],256],127509:[[22810],256],127510:[[35299],256],127511:[[22825],256],127512:[[20132],256],127513:[[26144],256],127514:[[28961],256],127515:[[26009],256],127516:[[21069],256],127517:[[24460],256],127518:[[20877],256],127519:[[26032],256],127520:[[21021],256],127521:[[32066],256],127522:[[29983],256],127523:[[36009],256],127524:[[22768],256],127525:[[21561],256],127526:[[28436],256],127527:[[25237],256],127528:[[25429],256],127529:[[19968],256],127530:[[19977],256],127531:[[36938],256],127532:[[24038],256],127533:[[20013],256],127534:[[21491],256],127535:[[25351],256],127536:[[36208],256],127537:[[25171],256],127538:[[31105],256],127539:[[31354],256],127540:[[21512],256],127541:[[28288],256],127542:[[26377],256],127543:[[26376],256],127544:[[30003],256],127545:[[21106],256],127546:[[21942],256],127552:[[12308,26412,12309],256],127553:[[12308,19977,12309],256],127554:[[12308,20108,12309],256],127555:[[12308,23433,12309],256],127556:[[12308,28857,12309],256],127557:[[12308,25171,12309],256],127558:[[12308,30423,12309],256],127559:[[12308,21213,12309],256],127560:[[12308,25943,12309],256],127568:[[24471],256],127569:[[21487],256]}, +63488:{194560:[[20029]],194561:[[20024]],194562:[[20033]],194563:[[131362]],194564:[[20320]],194565:[[20398]],194566:[[20411]],194567:[[20482]],194568:[[20602]],194569:[[20633]],194570:[[20711]],194571:[[20687]],194572:[[13470]],194573:[[132666]],194574:[[20813]],194575:[[20820]],194576:[[20836]],194577:[[20855]],194578:[[132380]],194579:[[13497]],194580:[[20839]],194581:[[20877]],194582:[[132427]],194583:[[20887]],194584:[[20900]],194585:[[20172]],194586:[[20908]],194587:[[20917]],194588:[[168415]],194589:[[20981]],194590:[[20995]],194591:[[13535]],194592:[[21051]],194593:[[21062]],194594:[[21106]],194595:[[21111]],194596:[[13589]],194597:[[21191]],194598:[[21193]],194599:[[21220]],194600:[[21242]],194601:[[21253]],194602:[[21254]],194603:[[21271]],194604:[[21321]],194605:[[21329]],194606:[[21338]],194607:[[21363]],194608:[[21373]],194609:[[21375]],194610:[[21375]],194611:[[21375]],194612:[[133676]],194613:[[28784]],194614:[[21450]],194615:[[21471]],194616:[[133987]],194617:[[21483]],194618:[[21489]],194619:[[21510]],194620:[[21662]],194621:[[21560]],194622:[[21576]],194623:[[21608]],194624:[[21666]],194625:[[21750]],194626:[[21776]],194627:[[21843]],194628:[[21859]],194629:[[21892]],194630:[[21892]],194631:[[21913]],194632:[[21931]],194633:[[21939]],194634:[[21954]],194635:[[22294]],194636:[[22022]],194637:[[22295]],194638:[[22097]],194639:[[22132]],194640:[[20999]],194641:[[22766]],194642:[[22478]],194643:[[22516]],194644:[[22541]],194645:[[22411]],194646:[[22578]],194647:[[22577]],194648:[[22700]],194649:[[136420]],194650:[[22770]],194651:[[22775]],194652:[[22790]],194653:[[22810]],194654:[[22818]],194655:[[22882]],194656:[[136872]],194657:[[136938]],194658:[[23020]],194659:[[23067]],194660:[[23079]],194661:[[23000]],194662:[[23142]],194663:[[14062]],194664:[[14076]],194665:[[23304]],194666:[[23358]],194667:[[23358]],194668:[[137672]],194669:[[23491]],194670:[[23512]],194671:[[23527]],194672:[[23539]],194673:[[138008]],194674:[[23551]],194675:[[23558]],194676:[[24403]],194677:[[23586]],194678:[[14209]],194679:[[23648]],194680:[[23662]],194681:[[23744]],194682:[[23693]],194683:[[138724]],194684:[[23875]],194685:[[138726]],194686:[[23918]],194687:[[23915]],194688:[[23932]],194689:[[24033]],194690:[[24034]],194691:[[14383]],194692:[[24061]],194693:[[24104]],194694:[[24125]],194695:[[24169]],194696:[[14434]],194697:[[139651]],194698:[[14460]],194699:[[24240]],194700:[[24243]],194701:[[24246]],194702:[[24266]],194703:[[172946]],194704:[[24318]],194705:[[140081]],194706:[[140081]],194707:[[33281]],194708:[[24354]],194709:[[24354]],194710:[[14535]],194711:[[144056]],194712:[[156122]],194713:[[24418]],194714:[[24427]],194715:[[14563]],194716:[[24474]],194717:[[24525]],194718:[[24535]],194719:[[24569]],194720:[[24705]],194721:[[14650]],194722:[[14620]],194723:[[24724]],194724:[[141012]],194725:[[24775]],194726:[[24904]],194727:[[24908]],194728:[[24910]],194729:[[24908]],194730:[[24954]],194731:[[24974]],194732:[[25010]],194733:[[24996]],194734:[[25007]],194735:[[25054]],194736:[[25074]],194737:[[25078]],194738:[[25104]],194739:[[25115]],194740:[[25181]],194741:[[25265]],194742:[[25300]],194743:[[25424]],194744:[[142092]],194745:[[25405]],194746:[[25340]],194747:[[25448]],194748:[[25475]],194749:[[25572]],194750:[[142321]],194751:[[25634]],194752:[[25541]],194753:[[25513]],194754:[[14894]],194755:[[25705]],194756:[[25726]],194757:[[25757]],194758:[[25719]],194759:[[14956]],194760:[[25935]],194761:[[25964]],194762:[[143370]],194763:[[26083]],194764:[[26360]],194765:[[26185]],194766:[[15129]],194767:[[26257]],194768:[[15112]],194769:[[15076]],194770:[[20882]],194771:[[20885]],194772:[[26368]],194773:[[26268]],194774:[[32941]],194775:[[17369]],194776:[[26391]],194777:[[26395]],194778:[[26401]],194779:[[26462]],194780:[[26451]],194781:[[144323]],194782:[[15177]],194783:[[26618]],194784:[[26501]],194785:[[26706]],194786:[[26757]],194787:[[144493]],194788:[[26766]],194789:[[26655]],194790:[[26900]],194791:[[15261]],194792:[[26946]],194793:[[27043]],194794:[[27114]],194795:[[27304]],194796:[[145059]],194797:[[27355]],194798:[[15384]],194799:[[27425]],194800:[[145575]],194801:[[27476]],194802:[[15438]],194803:[[27506]],194804:[[27551]],194805:[[27578]],194806:[[27579]],194807:[[146061]],194808:[[138507]],194809:[[146170]],194810:[[27726]],194811:[[146620]],194812:[[27839]],194813:[[27853]],194814:[[27751]],194815:[[27926]]}, +63744:{63744:[[35912]],63745:[[26356]],63746:[[36554]],63747:[[36040]],63748:[[28369]],63749:[[20018]],63750:[[21477]],63751:[[40860]],63752:[[40860]],63753:[[22865]],63754:[[37329]],63755:[[21895]],63756:[[22856]],63757:[[25078]],63758:[[30313]],63759:[[32645]],63760:[[34367]],63761:[[34746]],63762:[[35064]],63763:[[37007]],63764:[[27138]],63765:[[27931]],63766:[[28889]],63767:[[29662]],63768:[[33853]],63769:[[37226]],63770:[[39409]],63771:[[20098]],63772:[[21365]],63773:[[27396]],63774:[[29211]],63775:[[34349]],63776:[[40478]],63777:[[23888]],63778:[[28651]],63779:[[34253]],63780:[[35172]],63781:[[25289]],63782:[[33240]],63783:[[34847]],63784:[[24266]],63785:[[26391]],63786:[[28010]],63787:[[29436]],63788:[[37070]],63789:[[20358]],63790:[[20919]],63791:[[21214]],63792:[[25796]],63793:[[27347]],63794:[[29200]],63795:[[30439]],63796:[[32769]],63797:[[34310]],63798:[[34396]],63799:[[36335]],63800:[[38706]],63801:[[39791]],63802:[[40442]],63803:[[30860]],63804:[[31103]],63805:[[32160]],63806:[[33737]],63807:[[37636]],63808:[[40575]],63809:[[35542]],63810:[[22751]],63811:[[24324]],63812:[[31840]],63813:[[32894]],63814:[[29282]],63815:[[30922]],63816:[[36034]],63817:[[38647]],63818:[[22744]],63819:[[23650]],63820:[[27155]],63821:[[28122]],63822:[[28431]],63823:[[32047]],63824:[[32311]],63825:[[38475]],63826:[[21202]],63827:[[32907]],63828:[[20956]],63829:[[20940]],63830:[[31260]],63831:[[32190]],63832:[[33777]],63833:[[38517]],63834:[[35712]],63835:[[25295]],63836:[[27138]],63837:[[35582]],63838:[[20025]],63839:[[23527]],63840:[[24594]],63841:[[29575]],63842:[[30064]],63843:[[21271]],63844:[[30971]],63845:[[20415]],63846:[[24489]],63847:[[19981]],63848:[[27852]],63849:[[25976]],63850:[[32034]],63851:[[21443]],63852:[[22622]],63853:[[30465]],63854:[[33865]],63855:[[35498]],63856:[[27578]],63857:[[36784]],63858:[[27784]],63859:[[25342]],63860:[[33509]],63861:[[25504]],63862:[[30053]],63863:[[20142]],63864:[[20841]],63865:[[20937]],63866:[[26753]],63867:[[31975]],63868:[[33391]],63869:[[35538]],63870:[[37327]],63871:[[21237]],63872:[[21570]],63873:[[22899]],63874:[[24300]],63875:[[26053]],63876:[[28670]],63877:[[31018]],63878:[[38317]],63879:[[39530]],63880:[[40599]],63881:[[40654]],63882:[[21147]],63883:[[26310]],63884:[[27511]],63885:[[36706]],63886:[[24180]],63887:[[24976]],63888:[[25088]],63889:[[25754]],63890:[[28451]],63891:[[29001]],63892:[[29833]],63893:[[31178]],63894:[[32244]],63895:[[32879]],63896:[[36646]],63897:[[34030]],63898:[[36899]],63899:[[37706]],63900:[[21015]],63901:[[21155]],63902:[[21693]],63903:[[28872]],63904:[[35010]],63905:[[35498]],63906:[[24265]],63907:[[24565]],63908:[[25467]],63909:[[27566]],63910:[[31806]],63911:[[29557]],63912:[[20196]],63913:[[22265]],63914:[[23527]],63915:[[23994]],63916:[[24604]],63917:[[29618]],63918:[[29801]],63919:[[32666]],63920:[[32838]],63921:[[37428]],63922:[[38646]],63923:[[38728]],63924:[[38936]],63925:[[20363]],63926:[[31150]],63927:[[37300]],63928:[[38584]],63929:[[24801]],63930:[[20102]],63931:[[20698]],63932:[[23534]],63933:[[23615]],63934:[[26009]],63935:[[27138]],63936:[[29134]],63937:[[30274]],63938:[[34044]],63939:[[36988]],63940:[[40845]],63941:[[26248]],63942:[[38446]],63943:[[21129]],63944:[[26491]],63945:[[26611]],63946:[[27969]],63947:[[28316]],63948:[[29705]],63949:[[30041]],63950:[[30827]],63951:[[32016]],63952:[[39006]],63953:[[20845]],63954:[[25134]],63955:[[38520]],63956:[[20523]],63957:[[23833]],63958:[[28138]],63959:[[36650]],63960:[[24459]],63961:[[24900]],63962:[[26647]],63963:[[29575]],63964:[[38534]],63965:[[21033]],63966:[[21519]],63967:[[23653]],63968:[[26131]],63969:[[26446]],63970:[[26792]],63971:[[27877]],63972:[[29702]],63973:[[30178]],63974:[[32633]],63975:[[35023]],63976:[[35041]],63977:[[37324]],63978:[[38626]],63979:[[21311]],63980:[[28346]],63981:[[21533]],63982:[[29136]],63983:[[29848]],63984:[[34298]],63985:[[38563]],63986:[[40023]],63987:[[40607]],63988:[[26519]],63989:[[28107]],63990:[[33256]],63991:[[31435]],63992:[[31520]],63993:[[31890]],63994:[[29376]],63995:[[28825]],63996:[[35672]],63997:[[20160]],63998:[[33590]],63999:[[21050]],194816:[[27966]],194817:[[28023]],194818:[[27969]],194819:[[28009]],194820:[[28024]],194821:[[28037]],194822:[[146718]],194823:[[27956]],194824:[[28207]],194825:[[28270]],194826:[[15667]],194827:[[28363]],194828:[[28359]],194829:[[147153]],194830:[[28153]],194831:[[28526]],194832:[[147294]],194833:[[147342]],194834:[[28614]],194835:[[28729]],194836:[[28702]],194837:[[28699]],194838:[[15766]],194839:[[28746]],194840:[[28797]],194841:[[28791]],194842:[[28845]],194843:[[132389]],194844:[[28997]],194845:[[148067]],194846:[[29084]],194847:[[148395]],194848:[[29224]],194849:[[29237]],194850:[[29264]],194851:[[149000]],194852:[[29312]],194853:[[29333]],194854:[[149301]],194855:[[149524]],194856:[[29562]],194857:[[29579]],194858:[[16044]],194859:[[29605]],194860:[[16056]],194861:[[16056]],194862:[[29767]],194863:[[29788]],194864:[[29809]],194865:[[29829]],194866:[[29898]],194867:[[16155]],194868:[[29988]],194869:[[150582]],194870:[[30014]],194871:[[150674]],194872:[[30064]],194873:[[139679]],194874:[[30224]],194875:[[151457]],194876:[[151480]],194877:[[151620]],194878:[[16380]],194879:[[16392]],194880:[[30452]],194881:[[151795]],194882:[[151794]],194883:[[151833]],194884:[[151859]],194885:[[30494]],194886:[[30495]],194887:[[30495]],194888:[[30538]],194889:[[16441]],194890:[[30603]],194891:[[16454]],194892:[[16534]],194893:[[152605]],194894:[[30798]],194895:[[30860]],194896:[[30924]],194897:[[16611]],194898:[[153126]],194899:[[31062]],194900:[[153242]],194901:[[153285]],194902:[[31119]],194903:[[31211]],194904:[[16687]],194905:[[31296]],194906:[[31306]],194907:[[31311]],194908:[[153980]],194909:[[154279]],194910:[[154279]],194911:[[31470]],194912:[[16898]],194913:[[154539]],194914:[[31686]],194915:[[31689]],194916:[[16935]],194917:[[154752]],194918:[[31954]],194919:[[17056]],194920:[[31976]],194921:[[31971]],194922:[[32000]],194923:[[155526]],194924:[[32099]],194925:[[17153]],194926:[[32199]],194927:[[32258]],194928:[[32325]],194929:[[17204]],194930:[[156200]],194931:[[156231]],194932:[[17241]],194933:[[156377]],194934:[[32634]],194935:[[156478]],194936:[[32661]],194937:[[32762]],194938:[[32773]],194939:[[156890]],194940:[[156963]],194941:[[32864]],194942:[[157096]],194943:[[32880]],194944:[[144223]],194945:[[17365]],194946:[[32946]],194947:[[33027]],194948:[[17419]],194949:[[33086]],194950:[[23221]],194951:[[157607]],194952:[[157621]],194953:[[144275]],194954:[[144284]],194955:[[33281]],194956:[[33284]],194957:[[36766]],194958:[[17515]],194959:[[33425]],194960:[[33419]],194961:[[33437]],194962:[[21171]],194963:[[33457]],194964:[[33459]],194965:[[33469]],194966:[[33510]],194967:[[158524]],194968:[[33509]],194969:[[33565]],194970:[[33635]],194971:[[33709]],194972:[[33571]],194973:[[33725]],194974:[[33767]],194975:[[33879]],194976:[[33619]],194977:[[33738]],194978:[[33740]],194979:[[33756]],194980:[[158774]],194981:[[159083]],194982:[[158933]],194983:[[17707]],194984:[[34033]],194985:[[34035]],194986:[[34070]],194987:[[160714]],194988:[[34148]],194989:[[159532]],194990:[[17757]],194991:[[17761]],194992:[[159665]],194993:[[159954]],194994:[[17771]],194995:[[34384]],194996:[[34396]],194997:[[34407]],194998:[[34409]],194999:[[34473]],195000:[[34440]],195001:[[34574]],195002:[[34530]],195003:[[34681]],195004:[[34600]],195005:[[34667]],195006:[[34694]],195007:[[17879]],195008:[[34785]],195009:[[34817]],195010:[[17913]],195011:[[34912]],195012:[[34915]],195013:[[161383]],195014:[[35031]],195015:[[35038]],195016:[[17973]],195017:[[35066]],195018:[[13499]],195019:[[161966]],195020:[[162150]],195021:[[18110]],195022:[[18119]],195023:[[35488]],195024:[[35565]],195025:[[35722]],195026:[[35925]],195027:[[162984]],195028:[[36011]],195029:[[36033]],195030:[[36123]],195031:[[36215]],195032:[[163631]],195033:[[133124]],195034:[[36299]],195035:[[36284]],195036:[[36336]],195037:[[133342]],195038:[[36564]],195039:[[36664]],195040:[[165330]],195041:[[165357]],195042:[[37012]],195043:[[37105]],195044:[[37137]],195045:[[165678]],195046:[[37147]],195047:[[37432]],195048:[[37591]],195049:[[37592]],195050:[[37500]],195051:[[37881]],195052:[[37909]],195053:[[166906]],195054:[[38283]],195055:[[18837]],195056:[[38327]],195057:[[167287]],195058:[[18918]],195059:[[38595]],195060:[[23986]],195061:[[38691]],195062:[[168261]],195063:[[168474]],195064:[[19054]],195065:[[19062]],195066:[[38880]],195067:[[168970]],195068:[[19122]],195069:[[169110]],195070:[[38923]],195071:[[38923]]}, +64000:{64000:[[20999]],64001:[[24230]],64002:[[25299]],64003:[[31958]],64004:[[23429]],64005:[[27934]],64006:[[26292]],64007:[[36667]],64008:[[34892]],64009:[[38477]],64010:[[35211]],64011:[[24275]],64012:[[20800]],64013:[[21952]],64016:[[22618]],64018:[[26228]],64021:[[20958]],64022:[[29482]],64023:[[30410]],64024:[[31036]],64025:[[31070]],64026:[[31077]],64027:[[31119]],64028:[[38742]],64029:[[31934]],64030:[[32701]],64032:[[34322]],64034:[[35576]],64037:[[36920]],64038:[[37117]],64042:[[39151]],64043:[[39164]],64044:[[39208]],64045:[[40372]],64046:[[37086]],64047:[[38583]],64048:[[20398]],64049:[[20711]],64050:[[20813]],64051:[[21193]],64052:[[21220]],64053:[[21329]],64054:[[21917]],64055:[[22022]],64056:[[22120]],64057:[[22592]],64058:[[22696]],64059:[[23652]],64060:[[23662]],64061:[[24724]],64062:[[24936]],64063:[[24974]],64064:[[25074]],64065:[[25935]],64066:[[26082]],64067:[[26257]],64068:[[26757]],64069:[[28023]],64070:[[28186]],64071:[[28450]],64072:[[29038]],64073:[[29227]],64074:[[29730]],64075:[[30865]],64076:[[31038]],64077:[[31049]],64078:[[31048]],64079:[[31056]],64080:[[31062]],64081:[[31069]],64082:[[31117]],64083:[[31118]],64084:[[31296]],64085:[[31361]],64086:[[31680]],64087:[[32244]],64088:[[32265]],64089:[[32321]],64090:[[32626]],64091:[[32773]],64092:[[33261]],64093:[[33401]],64094:[[33401]],64095:[[33879]],64096:[[35088]],64097:[[35222]],64098:[[35585]],64099:[[35641]],64100:[[36051]],64101:[[36104]],64102:[[36790]],64103:[[36920]],64104:[[38627]],64105:[[38911]],64106:[[38971]],64107:[[24693]],64108:[[148206]],64109:[[33304]],64112:[[20006]],64113:[[20917]],64114:[[20840]],64115:[[20352]],64116:[[20805]],64117:[[20864]],64118:[[21191]],64119:[[21242]],64120:[[21917]],64121:[[21845]],64122:[[21913]],64123:[[21986]],64124:[[22618]],64125:[[22707]],64126:[[22852]],64127:[[22868]],64128:[[23138]],64129:[[23336]],64130:[[24274]],64131:[[24281]],64132:[[24425]],64133:[[24493]],64134:[[24792]],64135:[[24910]],64136:[[24840]],64137:[[24974]],64138:[[24928]],64139:[[25074]],64140:[[25140]],64141:[[25540]],64142:[[25628]],64143:[[25682]],64144:[[25942]],64145:[[26228]],64146:[[26391]],64147:[[26395]],64148:[[26454]],64149:[[27513]],64150:[[27578]],64151:[[27969]],64152:[[28379]],64153:[[28363]],64154:[[28450]],64155:[[28702]],64156:[[29038]],64157:[[30631]],64158:[[29237]],64159:[[29359]],64160:[[29482]],64161:[[29809]],64162:[[29958]],64163:[[30011]],64164:[[30237]],64165:[[30239]],64166:[[30410]],64167:[[30427]],64168:[[30452]],64169:[[30538]],64170:[[30528]],64171:[[30924]],64172:[[31409]],64173:[[31680]],64174:[[31867]],64175:[[32091]],64176:[[32244]],64177:[[32574]],64178:[[32773]],64179:[[33618]],64180:[[33775]],64181:[[34681]],64182:[[35137]],64183:[[35206]],64184:[[35222]],64185:[[35519]],64186:[[35576]],64187:[[35531]],64188:[[35585]],64189:[[35582]],64190:[[35565]],64191:[[35641]],64192:[[35722]],64193:[[36104]],64194:[[36664]],64195:[[36978]],64196:[[37273]],64197:[[37494]],64198:[[38524]],64199:[[38627]],64200:[[38742]],64201:[[38875]],64202:[[38911]],64203:[[38923]],64204:[[38971]],64205:[[39698]],64206:[[40860]],64207:[[141386]],64208:[[141380]],64209:[[144341]],64210:[[15261]],64211:[[16408]],64212:[[16441]],64213:[[152137]],64214:[[154832]],64215:[[163539]],64216:[[40771]],64217:[[40846]],195072:[[38953]],195073:[[169398]],195074:[[39138]],195075:[[19251]],195076:[[39209]],195077:[[39335]],195078:[[39362]],195079:[[39422]],195080:[[19406]],195081:[[170800]],195082:[[39698]],195083:[[40000]],195084:[[40189]],195085:[[19662]],195086:[[19693]],195087:[[40295]],195088:[[172238]],195089:[[19704]],195090:[[172293]],195091:[[172558]],195092:[[172689]],195093:[[40635]],195094:[[19798]],195095:[[40697]],195096:[[40702]],195097:[[40709]],195098:[[40719]],195099:[[40726]],195100:[[40763]],195101:[[173568]]}, +64256:{64256:[[102,102],256],64257:[[102,105],256],64258:[[102,108],256],64259:[[102,102,105],256],64260:[[102,102,108],256],64261:[[383,116],256],64262:[[115,116],256],64275:[[1396,1398],256],64276:[[1396,1381],256],64277:[[1396,1387],256],64278:[[1406,1398],256],64279:[[1396,1389],256],64285:[[1497,1460],512],64286:[,26],64287:[[1522,1463],512],64288:[[1506],256],64289:[[1488],256],64290:[[1491],256],64291:[[1492],256],64292:[[1499],256],64293:[[1500],256],64294:[[1501],256],64295:[[1512],256],64296:[[1514],256],64297:[[43],256],64298:[[1513,1473],512],64299:[[1513,1474],512],64300:[[64329,1473],512],64301:[[64329,1474],512],64302:[[1488,1463],512],64303:[[1488,1464],512],64304:[[1488,1468],512],64305:[[1489,1468],512],64306:[[1490,1468],512],64307:[[1491,1468],512],64308:[[1492,1468],512],64309:[[1493,1468],512],64310:[[1494,1468],512],64312:[[1496,1468],512],64313:[[1497,1468],512],64314:[[1498,1468],512],64315:[[1499,1468],512],64316:[[1500,1468],512],64318:[[1502,1468],512],64320:[[1504,1468],512],64321:[[1505,1468],512],64323:[[1507,1468],512],64324:[[1508,1468],512],64326:[[1510,1468],512],64327:[[1511,1468],512],64328:[[1512,1468],512],64329:[[1513,1468],512],64330:[[1514,1468],512],64331:[[1493,1465],512],64332:[[1489,1471],512],64333:[[1499,1471],512],64334:[[1508,1471],512],64335:[[1488,1500],256],64336:[[1649],256],64337:[[1649],256],64338:[[1659],256],64339:[[1659],256],64340:[[1659],256],64341:[[1659],256],64342:[[1662],256],64343:[[1662],256],64344:[[1662],256],64345:[[1662],256],64346:[[1664],256],64347:[[1664],256],64348:[[1664],256],64349:[[1664],256],64350:[[1658],256],64351:[[1658],256],64352:[[1658],256],64353:[[1658],256],64354:[[1663],256],64355:[[1663],256],64356:[[1663],256],64357:[[1663],256],64358:[[1657],256],64359:[[1657],256],64360:[[1657],256],64361:[[1657],256],64362:[[1700],256],64363:[[1700],256],64364:[[1700],256],64365:[[1700],256],64366:[[1702],256],64367:[[1702],256],64368:[[1702],256],64369:[[1702],256],64370:[[1668],256],64371:[[1668],256],64372:[[1668],256],64373:[[1668],256],64374:[[1667],256],64375:[[1667],256],64376:[[1667],256],64377:[[1667],256],64378:[[1670],256],64379:[[1670],256],64380:[[1670],256],64381:[[1670],256],64382:[[1671],256],64383:[[1671],256],64384:[[1671],256],64385:[[1671],256],64386:[[1677],256],64387:[[1677],256],64388:[[1676],256],64389:[[1676],256],64390:[[1678],256],64391:[[1678],256],64392:[[1672],256],64393:[[1672],256],64394:[[1688],256],64395:[[1688],256],64396:[[1681],256],64397:[[1681],256],64398:[[1705],256],64399:[[1705],256],64400:[[1705],256],64401:[[1705],256],64402:[[1711],256],64403:[[1711],256],64404:[[1711],256],64405:[[1711],256],64406:[[1715],256],64407:[[1715],256],64408:[[1715],256],64409:[[1715],256],64410:[[1713],256],64411:[[1713],256],64412:[[1713],256],64413:[[1713],256],64414:[[1722],256],64415:[[1722],256],64416:[[1723],256],64417:[[1723],256],64418:[[1723],256],64419:[[1723],256],64420:[[1728],256],64421:[[1728],256],64422:[[1729],256],64423:[[1729],256],64424:[[1729],256],64425:[[1729],256],64426:[[1726],256],64427:[[1726],256],64428:[[1726],256],64429:[[1726],256],64430:[[1746],256],64431:[[1746],256],64432:[[1747],256],64433:[[1747],256],64467:[[1709],256],64468:[[1709],256],64469:[[1709],256],64470:[[1709],256],64471:[[1735],256],64472:[[1735],256],64473:[[1734],256],64474:[[1734],256],64475:[[1736],256],64476:[[1736],256],64477:[[1655],256],64478:[[1739],256],64479:[[1739],256],64480:[[1733],256],64481:[[1733],256],64482:[[1737],256],64483:[[1737],256],64484:[[1744],256],64485:[[1744],256],64486:[[1744],256],64487:[[1744],256],64488:[[1609],256],64489:[[1609],256],64490:[[1574,1575],256],64491:[[1574,1575],256],64492:[[1574,1749],256],64493:[[1574,1749],256],64494:[[1574,1608],256],64495:[[1574,1608],256],64496:[[1574,1735],256],64497:[[1574,1735],256],64498:[[1574,1734],256],64499:[[1574,1734],256],64500:[[1574,1736],256],64501:[[1574,1736],256],64502:[[1574,1744],256],64503:[[1574,1744],256],64504:[[1574,1744],256],64505:[[1574,1609],256],64506:[[1574,1609],256],64507:[[1574,1609],256],64508:[[1740],256],64509:[[1740],256],64510:[[1740],256],64511:[[1740],256]}, +64512:{64512:[[1574,1580],256],64513:[[1574,1581],256],64514:[[1574,1605],256],64515:[[1574,1609],256],64516:[[1574,1610],256],64517:[[1576,1580],256],64518:[[1576,1581],256],64519:[[1576,1582],256],64520:[[1576,1605],256],64521:[[1576,1609],256],64522:[[1576,1610],256],64523:[[1578,1580],256],64524:[[1578,1581],256],64525:[[1578,1582],256],64526:[[1578,1605],256],64527:[[1578,1609],256],64528:[[1578,1610],256],64529:[[1579,1580],256],64530:[[1579,1605],256],64531:[[1579,1609],256],64532:[[1579,1610],256],64533:[[1580,1581],256],64534:[[1580,1605],256],64535:[[1581,1580],256],64536:[[1581,1605],256],64537:[[1582,1580],256],64538:[[1582,1581],256],64539:[[1582,1605],256],64540:[[1587,1580],256],64541:[[1587,1581],256],64542:[[1587,1582],256],64543:[[1587,1605],256],64544:[[1589,1581],256],64545:[[1589,1605],256],64546:[[1590,1580],256],64547:[[1590,1581],256],64548:[[1590,1582],256],64549:[[1590,1605],256],64550:[[1591,1581],256],64551:[[1591,1605],256],64552:[[1592,1605],256],64553:[[1593,1580],256],64554:[[1593,1605],256],64555:[[1594,1580],256],64556:[[1594,1605],256],64557:[[1601,1580],256],64558:[[1601,1581],256],64559:[[1601,1582],256],64560:[[1601,1605],256],64561:[[1601,1609],256],64562:[[1601,1610],256],64563:[[1602,1581],256],64564:[[1602,1605],256],64565:[[1602,1609],256],64566:[[1602,1610],256],64567:[[1603,1575],256],64568:[[1603,1580],256],64569:[[1603,1581],256],64570:[[1603,1582],256],64571:[[1603,1604],256],64572:[[1603,1605],256],64573:[[1603,1609],256],64574:[[1603,1610],256],64575:[[1604,1580],256],64576:[[1604,1581],256],64577:[[1604,1582],256],64578:[[1604,1605],256],64579:[[1604,1609],256],64580:[[1604,1610],256],64581:[[1605,1580],256],64582:[[1605,1581],256],64583:[[1605,1582],256],64584:[[1605,1605],256],64585:[[1605,1609],256],64586:[[1605,1610],256],64587:[[1606,1580],256],64588:[[1606,1581],256],64589:[[1606,1582],256],64590:[[1606,1605],256],64591:[[1606,1609],256],64592:[[1606,1610],256],64593:[[1607,1580],256],64594:[[1607,1605],256],64595:[[1607,1609],256],64596:[[1607,1610],256],64597:[[1610,1580],256],64598:[[1610,1581],256],64599:[[1610,1582],256],64600:[[1610,1605],256],64601:[[1610,1609],256],64602:[[1610,1610],256],64603:[[1584,1648],256],64604:[[1585,1648],256],64605:[[1609,1648],256],64606:[[32,1612,1617],256],64607:[[32,1613,1617],256],64608:[[32,1614,1617],256],64609:[[32,1615,1617],256],64610:[[32,1616,1617],256],64611:[[32,1617,1648],256],64612:[[1574,1585],256],64613:[[1574,1586],256],64614:[[1574,1605],256],64615:[[1574,1606],256],64616:[[1574,1609],256],64617:[[1574,1610],256],64618:[[1576,1585],256],64619:[[1576,1586],256],64620:[[1576,1605],256],64621:[[1576,1606],256],64622:[[1576,1609],256],64623:[[1576,1610],256],64624:[[1578,1585],256],64625:[[1578,1586],256],64626:[[1578,1605],256],64627:[[1578,1606],256],64628:[[1578,1609],256],64629:[[1578,1610],256],64630:[[1579,1585],256],64631:[[1579,1586],256],64632:[[1579,1605],256],64633:[[1579,1606],256],64634:[[1579,1609],256],64635:[[1579,1610],256],64636:[[1601,1609],256],64637:[[1601,1610],256],64638:[[1602,1609],256],64639:[[1602,1610],256],64640:[[1603,1575],256],64641:[[1603,1604],256],64642:[[1603,1605],256],64643:[[1603,1609],256],64644:[[1603,1610],256],64645:[[1604,1605],256],64646:[[1604,1609],256],64647:[[1604,1610],256],64648:[[1605,1575],256],64649:[[1605,1605],256],64650:[[1606,1585],256],64651:[[1606,1586],256],64652:[[1606,1605],256],64653:[[1606,1606],256],64654:[[1606,1609],256],64655:[[1606,1610],256],64656:[[1609,1648],256],64657:[[1610,1585],256],64658:[[1610,1586],256],64659:[[1610,1605],256],64660:[[1610,1606],256],64661:[[1610,1609],256],64662:[[1610,1610],256],64663:[[1574,1580],256],64664:[[1574,1581],256],64665:[[1574,1582],256],64666:[[1574,1605],256],64667:[[1574,1607],256],64668:[[1576,1580],256],64669:[[1576,1581],256],64670:[[1576,1582],256],64671:[[1576,1605],256],64672:[[1576,1607],256],64673:[[1578,1580],256],64674:[[1578,1581],256],64675:[[1578,1582],256],64676:[[1578,1605],256],64677:[[1578,1607],256],64678:[[1579,1605],256],64679:[[1580,1581],256],64680:[[1580,1605],256],64681:[[1581,1580],256],64682:[[1581,1605],256],64683:[[1582,1580],256],64684:[[1582,1605],256],64685:[[1587,1580],256],64686:[[1587,1581],256],64687:[[1587,1582],256],64688:[[1587,1605],256],64689:[[1589,1581],256],64690:[[1589,1582],256],64691:[[1589,1605],256],64692:[[1590,1580],256],64693:[[1590,1581],256],64694:[[1590,1582],256],64695:[[1590,1605],256],64696:[[1591,1581],256],64697:[[1592,1605],256],64698:[[1593,1580],256],64699:[[1593,1605],256],64700:[[1594,1580],256],64701:[[1594,1605],256],64702:[[1601,1580],256],64703:[[1601,1581],256],64704:[[1601,1582],256],64705:[[1601,1605],256],64706:[[1602,1581],256],64707:[[1602,1605],256],64708:[[1603,1580],256],64709:[[1603,1581],256],64710:[[1603,1582],256],64711:[[1603,1604],256],64712:[[1603,1605],256],64713:[[1604,1580],256],64714:[[1604,1581],256],64715:[[1604,1582],256],64716:[[1604,1605],256],64717:[[1604,1607],256],64718:[[1605,1580],256],64719:[[1605,1581],256],64720:[[1605,1582],256],64721:[[1605,1605],256],64722:[[1606,1580],256],64723:[[1606,1581],256],64724:[[1606,1582],256],64725:[[1606,1605],256],64726:[[1606,1607],256],64727:[[1607,1580],256],64728:[[1607,1605],256],64729:[[1607,1648],256],64730:[[1610,1580],256],64731:[[1610,1581],256],64732:[[1610,1582],256],64733:[[1610,1605],256],64734:[[1610,1607],256],64735:[[1574,1605],256],64736:[[1574,1607],256],64737:[[1576,1605],256],64738:[[1576,1607],256],64739:[[1578,1605],256],64740:[[1578,1607],256],64741:[[1579,1605],256],64742:[[1579,1607],256],64743:[[1587,1605],256],64744:[[1587,1607],256],64745:[[1588,1605],256],64746:[[1588,1607],256],64747:[[1603,1604],256],64748:[[1603,1605],256],64749:[[1604,1605],256],64750:[[1606,1605],256],64751:[[1606,1607],256],64752:[[1610,1605],256],64753:[[1610,1607],256],64754:[[1600,1614,1617],256],64755:[[1600,1615,1617],256],64756:[[1600,1616,1617],256],64757:[[1591,1609],256],64758:[[1591,1610],256],64759:[[1593,1609],256],64760:[[1593,1610],256],64761:[[1594,1609],256],64762:[[1594,1610],256],64763:[[1587,1609],256],64764:[[1587,1610],256],64765:[[1588,1609],256],64766:[[1588,1610],256],64767:[[1581,1609],256]}, +64768:{64768:[[1581,1610],256],64769:[[1580,1609],256],64770:[[1580,1610],256],64771:[[1582,1609],256],64772:[[1582,1610],256],64773:[[1589,1609],256],64774:[[1589,1610],256],64775:[[1590,1609],256],64776:[[1590,1610],256],64777:[[1588,1580],256],64778:[[1588,1581],256],64779:[[1588,1582],256],64780:[[1588,1605],256],64781:[[1588,1585],256],64782:[[1587,1585],256],64783:[[1589,1585],256],64784:[[1590,1585],256],64785:[[1591,1609],256],64786:[[1591,1610],256],64787:[[1593,1609],256],64788:[[1593,1610],256],64789:[[1594,1609],256],64790:[[1594,1610],256],64791:[[1587,1609],256],64792:[[1587,1610],256],64793:[[1588,1609],256],64794:[[1588,1610],256],64795:[[1581,1609],256],64796:[[1581,1610],256],64797:[[1580,1609],256],64798:[[1580,1610],256],64799:[[1582,1609],256],64800:[[1582,1610],256],64801:[[1589,1609],256],64802:[[1589,1610],256],64803:[[1590,1609],256],64804:[[1590,1610],256],64805:[[1588,1580],256],64806:[[1588,1581],256],64807:[[1588,1582],256],64808:[[1588,1605],256],64809:[[1588,1585],256],64810:[[1587,1585],256],64811:[[1589,1585],256],64812:[[1590,1585],256],64813:[[1588,1580],256],64814:[[1588,1581],256],64815:[[1588,1582],256],64816:[[1588,1605],256],64817:[[1587,1607],256],64818:[[1588,1607],256],64819:[[1591,1605],256],64820:[[1587,1580],256],64821:[[1587,1581],256],64822:[[1587,1582],256],64823:[[1588,1580],256],64824:[[1588,1581],256],64825:[[1588,1582],256],64826:[[1591,1605],256],64827:[[1592,1605],256],64828:[[1575,1611],256],64829:[[1575,1611],256],64848:[[1578,1580,1605],256],64849:[[1578,1581,1580],256],64850:[[1578,1581,1580],256],64851:[[1578,1581,1605],256],64852:[[1578,1582,1605],256],64853:[[1578,1605,1580],256],64854:[[1578,1605,1581],256],64855:[[1578,1605,1582],256],64856:[[1580,1605,1581],256],64857:[[1580,1605,1581],256],64858:[[1581,1605,1610],256],64859:[[1581,1605,1609],256],64860:[[1587,1581,1580],256],64861:[[1587,1580,1581],256],64862:[[1587,1580,1609],256],64863:[[1587,1605,1581],256],64864:[[1587,1605,1581],256],64865:[[1587,1605,1580],256],64866:[[1587,1605,1605],256],64867:[[1587,1605,1605],256],64868:[[1589,1581,1581],256],64869:[[1589,1581,1581],256],64870:[[1589,1605,1605],256],64871:[[1588,1581,1605],256],64872:[[1588,1581,1605],256],64873:[[1588,1580,1610],256],64874:[[1588,1605,1582],256],64875:[[1588,1605,1582],256],64876:[[1588,1605,1605],256],64877:[[1588,1605,1605],256],64878:[[1590,1581,1609],256],64879:[[1590,1582,1605],256],64880:[[1590,1582,1605],256],64881:[[1591,1605,1581],256],64882:[[1591,1605,1581],256],64883:[[1591,1605,1605],256],64884:[[1591,1605,1610],256],64885:[[1593,1580,1605],256],64886:[[1593,1605,1605],256],64887:[[1593,1605,1605],256],64888:[[1593,1605,1609],256],64889:[[1594,1605,1605],256],64890:[[1594,1605,1610],256],64891:[[1594,1605,1609],256],64892:[[1601,1582,1605],256],64893:[[1601,1582,1605],256],64894:[[1602,1605,1581],256],64895:[[1602,1605,1605],256],64896:[[1604,1581,1605],256],64897:[[1604,1581,1610],256],64898:[[1604,1581,1609],256],64899:[[1604,1580,1580],256],64900:[[1604,1580,1580],256],64901:[[1604,1582,1605],256],64902:[[1604,1582,1605],256],64903:[[1604,1605,1581],256],64904:[[1604,1605,1581],256],64905:[[1605,1581,1580],256],64906:[[1605,1581,1605],256],64907:[[1605,1581,1610],256],64908:[[1605,1580,1581],256],64909:[[1605,1580,1605],256],64910:[[1605,1582,1580],256],64911:[[1605,1582,1605],256],64914:[[1605,1580,1582],256],64915:[[1607,1605,1580],256],64916:[[1607,1605,1605],256],64917:[[1606,1581,1605],256],64918:[[1606,1581,1609],256],64919:[[1606,1580,1605],256],64920:[[1606,1580,1605],256],64921:[[1606,1580,1609],256],64922:[[1606,1605,1610],256],64923:[[1606,1605,1609],256],64924:[[1610,1605,1605],256],64925:[[1610,1605,1605],256],64926:[[1576,1582,1610],256],64927:[[1578,1580,1610],256],64928:[[1578,1580,1609],256],64929:[[1578,1582,1610],256],64930:[[1578,1582,1609],256],64931:[[1578,1605,1610],256],64932:[[1578,1605,1609],256],64933:[[1580,1605,1610],256],64934:[[1580,1581,1609],256],64935:[[1580,1605,1609],256],64936:[[1587,1582,1609],256],64937:[[1589,1581,1610],256],64938:[[1588,1581,1610],256],64939:[[1590,1581,1610],256],64940:[[1604,1580,1610],256],64941:[[1604,1605,1610],256],64942:[[1610,1581,1610],256],64943:[[1610,1580,1610],256],64944:[[1610,1605,1610],256],64945:[[1605,1605,1610],256],64946:[[1602,1605,1610],256],64947:[[1606,1581,1610],256],64948:[[1602,1605,1581],256],64949:[[1604,1581,1605],256],64950:[[1593,1605,1610],256],64951:[[1603,1605,1610],256],64952:[[1606,1580,1581],256],64953:[[1605,1582,1610],256],64954:[[1604,1580,1605],256],64955:[[1603,1605,1605],256],64956:[[1604,1580,1605],256],64957:[[1606,1580,1581],256],64958:[[1580,1581,1610],256],64959:[[1581,1580,1610],256],64960:[[1605,1580,1610],256],64961:[[1601,1605,1610],256],64962:[[1576,1581,1610],256],64963:[[1603,1605,1605],256],64964:[[1593,1580,1605],256],64965:[[1589,1605,1605],256],64966:[[1587,1582,1610],256],64967:[[1606,1580,1610],256],65008:[[1589,1604,1746],256],65009:[[1602,1604,1746],256],65010:[[1575,1604,1604,1607],256],65011:[[1575,1603,1576,1585],256],65012:[[1605,1581,1605,1583],256],65013:[[1589,1604,1593,1605],256],65014:[[1585,1587,1608,1604],256],65015:[[1593,1604,1610,1607],256],65016:[[1608,1587,1604,1605],256],65017:[[1589,1604,1609],256],65018:[[1589,1604,1609,32,1575,1604,1604,1607,32,1593,1604,1610,1607,32,1608,1587,1604,1605],256],65019:[[1580,1604,32,1580,1604,1575,1604,1607],256],65020:[[1585,1740,1575,1604],256]}, +65024:{65040:[[44],256],65041:[[12289],256],65042:[[12290],256],65043:[[58],256],65044:[[59],256],65045:[[33],256],65046:[[63],256],65047:[[12310],256],65048:[[12311],256],65049:[[8230],256],65056:[,230],65057:[,230],65058:[,230],65059:[,230],65060:[,230],65061:[,230],65062:[,230],65063:[,220],65064:[,220],65065:[,220],65066:[,220],65067:[,220],65068:[,220],65069:[,220],65072:[[8229],256],65073:[[8212],256],65074:[[8211],256],65075:[[95],256],65076:[[95],256],65077:[[40],256],65078:[[41],256],65079:[[123],256],65080:[[125],256],65081:[[12308],256],65082:[[12309],256],65083:[[12304],256],65084:[[12305],256],65085:[[12298],256],65086:[[12299],256],65087:[[12296],256],65088:[[12297],256],65089:[[12300],256],65090:[[12301],256],65091:[[12302],256],65092:[[12303],256],65095:[[91],256],65096:[[93],256],65097:[[8254],256],65098:[[8254],256],65099:[[8254],256],65100:[[8254],256],65101:[[95],256],65102:[[95],256],65103:[[95],256],65104:[[44],256],65105:[[12289],256],65106:[[46],256],65108:[[59],256],65109:[[58],256],65110:[[63],256],65111:[[33],256],65112:[[8212],256],65113:[[40],256],65114:[[41],256],65115:[[123],256],65116:[[125],256],65117:[[12308],256],65118:[[12309],256],65119:[[35],256],65120:[[38],256],65121:[[42],256],65122:[[43],256],65123:[[45],256],65124:[[60],256],65125:[[62],256],65126:[[61],256],65128:[[92],256],65129:[[36],256],65130:[[37],256],65131:[[64],256],65136:[[32,1611],256],65137:[[1600,1611],256],65138:[[32,1612],256],65140:[[32,1613],256],65142:[[32,1614],256],65143:[[1600,1614],256],65144:[[32,1615],256],65145:[[1600,1615],256],65146:[[32,1616],256],65147:[[1600,1616],256],65148:[[32,1617],256],65149:[[1600,1617],256],65150:[[32,1618],256],65151:[[1600,1618],256],65152:[[1569],256],65153:[[1570],256],65154:[[1570],256],65155:[[1571],256],65156:[[1571],256],65157:[[1572],256],65158:[[1572],256],65159:[[1573],256],65160:[[1573],256],65161:[[1574],256],65162:[[1574],256],65163:[[1574],256],65164:[[1574],256],65165:[[1575],256],65166:[[1575],256],65167:[[1576],256],65168:[[1576],256],65169:[[1576],256],65170:[[1576],256],65171:[[1577],256],65172:[[1577],256],65173:[[1578],256],65174:[[1578],256],65175:[[1578],256],65176:[[1578],256],65177:[[1579],256],65178:[[1579],256],65179:[[1579],256],65180:[[1579],256],65181:[[1580],256],65182:[[1580],256],65183:[[1580],256],65184:[[1580],256],65185:[[1581],256],65186:[[1581],256],65187:[[1581],256],65188:[[1581],256],65189:[[1582],256],65190:[[1582],256],65191:[[1582],256],65192:[[1582],256],65193:[[1583],256],65194:[[1583],256],65195:[[1584],256],65196:[[1584],256],65197:[[1585],256],65198:[[1585],256],65199:[[1586],256],65200:[[1586],256],65201:[[1587],256],65202:[[1587],256],65203:[[1587],256],65204:[[1587],256],65205:[[1588],256],65206:[[1588],256],65207:[[1588],256],65208:[[1588],256],65209:[[1589],256],65210:[[1589],256],65211:[[1589],256],65212:[[1589],256],65213:[[1590],256],65214:[[1590],256],65215:[[1590],256],65216:[[1590],256],65217:[[1591],256],65218:[[1591],256],65219:[[1591],256],65220:[[1591],256],65221:[[1592],256],65222:[[1592],256],65223:[[1592],256],65224:[[1592],256],65225:[[1593],256],65226:[[1593],256],65227:[[1593],256],65228:[[1593],256],65229:[[1594],256],65230:[[1594],256],65231:[[1594],256],65232:[[1594],256],65233:[[1601],256],65234:[[1601],256],65235:[[1601],256],65236:[[1601],256],65237:[[1602],256],65238:[[1602],256],65239:[[1602],256],65240:[[1602],256],65241:[[1603],256],65242:[[1603],256],65243:[[1603],256],65244:[[1603],256],65245:[[1604],256],65246:[[1604],256],65247:[[1604],256],65248:[[1604],256],65249:[[1605],256],65250:[[1605],256],65251:[[1605],256],65252:[[1605],256],65253:[[1606],256],65254:[[1606],256],65255:[[1606],256],65256:[[1606],256],65257:[[1607],256],65258:[[1607],256],65259:[[1607],256],65260:[[1607],256],65261:[[1608],256],65262:[[1608],256],65263:[[1609],256],65264:[[1609],256],65265:[[1610],256],65266:[[1610],256],65267:[[1610],256],65268:[[1610],256],65269:[[1604,1570],256],65270:[[1604,1570],256],65271:[[1604,1571],256],65272:[[1604,1571],256],65273:[[1604,1573],256],65274:[[1604,1573],256],65275:[[1604,1575],256],65276:[[1604,1575],256]}, +65280:{65281:[[33],256],65282:[[34],256],65283:[[35],256],65284:[[36],256],65285:[[37],256],65286:[[38],256],65287:[[39],256],65288:[[40],256],65289:[[41],256],65290:[[42],256],65291:[[43],256],65292:[[44],256],65293:[[45],256],65294:[[46],256],65295:[[47],256],65296:[[48],256],65297:[[49],256],65298:[[50],256],65299:[[51],256],65300:[[52],256],65301:[[53],256],65302:[[54],256],65303:[[55],256],65304:[[56],256],65305:[[57],256],65306:[[58],256],65307:[[59],256],65308:[[60],256],65309:[[61],256],65310:[[62],256],65311:[[63],256],65312:[[64],256],65313:[[65],256],65314:[[66],256],65315:[[67],256],65316:[[68],256],65317:[[69],256],65318:[[70],256],65319:[[71],256],65320:[[72],256],65321:[[73],256],65322:[[74],256],65323:[[75],256],65324:[[76],256],65325:[[77],256],65326:[[78],256],65327:[[79],256],65328:[[80],256],65329:[[81],256],65330:[[82],256],65331:[[83],256],65332:[[84],256],65333:[[85],256],65334:[[86],256],65335:[[87],256],65336:[[88],256],65337:[[89],256],65338:[[90],256],65339:[[91],256],65340:[[92],256],65341:[[93],256],65342:[[94],256],65343:[[95],256],65344:[[96],256],65345:[[97],256],65346:[[98],256],65347:[[99],256],65348:[[100],256],65349:[[101],256],65350:[[102],256],65351:[[103],256],65352:[[104],256],65353:[[105],256],65354:[[106],256],65355:[[107],256],65356:[[108],256],65357:[[109],256],65358:[[110],256],65359:[[111],256],65360:[[112],256],65361:[[113],256],65362:[[114],256],65363:[[115],256],65364:[[116],256],65365:[[117],256],65366:[[118],256],65367:[[119],256],65368:[[120],256],65369:[[121],256],65370:[[122],256],65371:[[123],256],65372:[[124],256],65373:[[125],256],65374:[[126],256],65375:[[10629],256],65376:[[10630],256],65377:[[12290],256],65378:[[12300],256],65379:[[12301],256],65380:[[12289],256],65381:[[12539],256],65382:[[12530],256],65383:[[12449],256],65384:[[12451],256],65385:[[12453],256],65386:[[12455],256],65387:[[12457],256],65388:[[12515],256],65389:[[12517],256],65390:[[12519],256],65391:[[12483],256],65392:[[12540],256],65393:[[12450],256],65394:[[12452],256],65395:[[12454],256],65396:[[12456],256],65397:[[12458],256],65398:[[12459],256],65399:[[12461],256],65400:[[12463],256],65401:[[12465],256],65402:[[12467],256],65403:[[12469],256],65404:[[12471],256],65405:[[12473],256],65406:[[12475],256],65407:[[12477],256],65408:[[12479],256],65409:[[12481],256],65410:[[12484],256],65411:[[12486],256],65412:[[12488],256],65413:[[12490],256],65414:[[12491],256],65415:[[12492],256],65416:[[12493],256],65417:[[12494],256],65418:[[12495],256],65419:[[12498],256],65420:[[12501],256],65421:[[12504],256],65422:[[12507],256],65423:[[12510],256],65424:[[12511],256],65425:[[12512],256],65426:[[12513],256],65427:[[12514],256],65428:[[12516],256],65429:[[12518],256],65430:[[12520],256],65431:[[12521],256],65432:[[12522],256],65433:[[12523],256],65434:[[12524],256],65435:[[12525],256],65436:[[12527],256],65437:[[12531],256],65438:[[12441],256],65439:[[12442],256],65440:[[12644],256],65441:[[12593],256],65442:[[12594],256],65443:[[12595],256],65444:[[12596],256],65445:[[12597],256],65446:[[12598],256],65447:[[12599],256],65448:[[12600],256],65449:[[12601],256],65450:[[12602],256],65451:[[12603],256],65452:[[12604],256],65453:[[12605],256],65454:[[12606],256],65455:[[12607],256],65456:[[12608],256],65457:[[12609],256],65458:[[12610],256],65459:[[12611],256],65460:[[12612],256],65461:[[12613],256],65462:[[12614],256],65463:[[12615],256],65464:[[12616],256],65465:[[12617],256],65466:[[12618],256],65467:[[12619],256],65468:[[12620],256],65469:[[12621],256],65470:[[12622],256],65474:[[12623],256],65475:[[12624],256],65476:[[12625],256],65477:[[12626],256],65478:[[12627],256],65479:[[12628],256],65482:[[12629],256],65483:[[12630],256],65484:[[12631],256],65485:[[12632],256],65486:[[12633],256],65487:[[12634],256],65490:[[12635],256],65491:[[12636],256],65492:[[12637],256],65493:[[12638],256],65494:[[12639],256],65495:[[12640],256],65498:[[12641],256],65499:[[12642],256],65500:[[12643],256],65504:[[162],256],65505:[[163],256],65506:[[172],256],65507:[[175],256],65508:[[166],256],65509:[[165],256],65510:[[8361],256],65512:[[9474],256],65513:[[8592],256],65514:[[8593],256],65515:[[8594],256],65516:[[8595],256],65517:[[9632],256],65518:[[9675],256]} -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); }; -nacl.box.open.after = nacl.secretbox.open; + /***** Module to export */ + var unorm = { + nfc: nfc, + nfd: nfd, + nfkc: nfkc, + nfkd: nfkd + }; -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + /*globals module:true,define:true*/ -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + // CommonJS + if (typeof module === "object") { + module.exports = unorm; -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; + // AMD + } else if (typeof define === "function" && define.amd) { + define("unorm", function () { + return unorm; + }); -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; + // Global + } else { + root.unorm = unorm; + } -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; + /***** Export as shim for String::normalize method *****/ + /* + http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#november_8_2013_draft_rev_21 -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; + 21.1.3.12 String.prototype.normalize(form="NFC") + When the normalize method is called with one argument form, the following steps are taken: -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; + 1. Let O be CheckObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. If form is not provided or undefined let form be "NFC". + 5. Let f be ToString(form). + 6. ReturnIfAbrupt(f). + 7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw a RangeError Exception. + 8. Let ns be the String value is the result of normalizing S into the normalization form named by f as specified in Unicode Standard Annex #15, UnicodeNormalizatoin Forms. + 9. Return ns. -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + The length property of the normalize method is 0. -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + *NOTE* The normalize function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. + */ + unorm.shimApplied = false; -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; + if (!String.prototype.normalize) { + Object.defineProperty(String.prototype, "normalize", { + enumerable: false, + configurable: true, + writable: true, + value: function normalize (/*form*/) { + + var str = "" + this; + var form = arguments[0] === undefined ? "NFC" : arguments[0]; + + if (this === null || this === undefined) { + throw new TypeError("Cannot call method on " + Object.prototype.toString.call(this)); + } + + if (form === "NFC") { + return unorm.nfc(str); + } else if (form === "NFD") { + return unorm.nfd(str); + } else if (form === "NFKC") { + return unorm.nfkc(str); + } else if (form === "NFKD") { + return unorm.nfkd(str); + } else { + throw new RangeError("Invalid normalization form: " + form); + } + } + }); -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; + unorm.shimApplied = true; + } +}(this)); -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; +},{}],524:[function(require,module,exports){ +(function (global){(function (){ -nacl.hash.hashLength = crypto_hash_BYTES; +/** + * Module exports. + */ -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; +module.exports = deprecate; -nacl.setPRNG = function(fn) { - randombytes = fn; -}; +/** + * Mark that a method should not be used. + * Returns a modified function which warns once by default. + * + * If `localStorage.noDeprecation = true` is set, then it is a no-op. + * + * If `localStorage.throwDeprecation = true` is set, then deprecated functions + * will throw an Error when invoked. + * + * If `localStorage.traceDeprecation = true` is set, then deprecated functions + * will invoke `console.trace()` instead of `console.error()`. + * + * @param {Function} fn - the function to deprecate + * @param {String} msg - the string to print to the console when `fn` is invoked + * @returns {Function} a new "deprecated" version of `fn` + * @api public + */ -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); +function deprecate (fn, msg) { + if (config('noDeprecation')) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (config('throwDeprecation')) { + throw new Error(msg); + } else if (config('traceDeprecation')) { + console.trace(msg); + } else { + console.warn(msg); } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (typeof require !== 'undefined') { - // Node.js. - crypto = require('crypto'); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); + warned = true; } + return fn.apply(this, arguments); } -})(); -})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {})); + return deprecated; +} -},{"crypto":105}],322:[function(require,module,exports){ -var native = require('./native') +/** + * Checks `localStorage` for boolean values for the given `name`. + * + * @param {String} name + * @returns {Boolean} + * @api private + */ -function getTypeName (fn) { - return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1] +function config (name) { + // accessing global.localStorage can trigger a DOMException in sandboxed iframes + try { + if (!global.localStorage) return false; + } catch (_) { + return false; + } + var val = global.localStorage[name]; + if (null == val) return false; + return String(val).toLowerCase() === 'true'; } -function getValueTypeName (value) { - return native.Nil(value) ? '' : getTypeName(value.constructor) -} +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],525:[function(require,module,exports){ +arguments[4][115][0].apply(exports,arguments) +},{"dup":115}],526:[function(require,module,exports){ +// Currently in sync with Node.js lib/internal/util/types.js +// https://github.com/nodejs/node/commit/112cc7c27551254aa2b17098fb774867f05ed0d9 -function getValue (value) { - if (native.Function(value)) return '' - if (native.String(value)) return JSON.stringify(value) - if (value && native.Object(value)) return '' - return value -} +'use strict'; -function captureStackTrace (e, t) { - if (Error.captureStackTrace) { - Error.captureStackTrace(e, t) - } +var isArgumentsObject = require('is-arguments'); +var isGeneratorFunction = require('is-generator-function'); +var whichTypedArray = require('which-typed-array'); +var isTypedArray = require('is-typed-array'); + +function uncurryThis(f) { + return f.call.bind(f); } -function tfJSON (type) { - if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type) - if (native.Array(type)) return 'Array' - if (type && native.Object(type)) return 'Object' +var BigIntSupported = typeof BigInt !== 'undefined'; +var SymbolSupported = typeof Symbol !== 'undefined'; - return type !== undefined ? type : '' -} +var ObjectToString = uncurryThis(Object.prototype.toString); -function tfErrorString (type, value, valueTypeName) { - var valueJson = getValue(value) +var numberValue = uncurryThis(Number.prototype.valueOf); +var stringValue = uncurryThis(String.prototype.valueOf); +var booleanValue = uncurryThis(Boolean.prototype.valueOf); - return 'Expected ' + tfJSON(type) + ', got' + - (valueTypeName !== '' ? ' ' + valueTypeName : '') + - (valueJson !== '' ? ' ' + valueJson : '') +if (BigIntSupported) { + var bigIntValue = uncurryThis(BigInt.prototype.valueOf); } -function TfTypeError (type, value, valueTypeName) { - valueTypeName = valueTypeName || getValueTypeName(value) - this.message = tfErrorString(type, value, valueTypeName) - - captureStackTrace(this, TfTypeError) - this.__type = type - this.__value = value - this.__valueTypeName = valueTypeName +if (SymbolSupported) { + var symbolValue = uncurryThis(Symbol.prototype.valueOf); } -TfTypeError.prototype = Object.create(Error.prototype) -TfTypeError.prototype.constructor = TfTypeError +function checkBoxedPrimitive(value, prototypeValueOf) { + if (typeof value !== 'object') { + return false; + } + try { + prototypeValueOf(value); + return true; + } catch(e) { + return false; + } +} -function tfPropertyErrorString (type, label, name, value, valueTypeName) { - var description = '" of type ' - if (label === 'key') description = '" with key type ' +exports.isArgumentsObject = isArgumentsObject; +exports.isGeneratorFunction = isGeneratorFunction; +exports.isTypedArray = isTypedArray; - return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName) +// Taken from here and modified for better browser support +// https://github.com/sindresorhus/p-is-promise/blob/cda35a513bda03f977ad5cde3a079d237e82d7ef/index.js +function isPromise(input) { + return ( + ( + typeof Promise !== 'undefined' && + input instanceof Promise + ) || + ( + input !== null && + typeof input === 'object' && + typeof input.then === 'function' && + typeof input.catch === 'function' + ) + ); } +exports.isPromise = isPromise; -function TfPropertyTypeError (type, property, label, value, valueTypeName) { - if (type) { - valueTypeName = valueTypeName || getValueTypeName(value) - this.message = tfPropertyErrorString(type, label, property, value, valueTypeName) - } else { - this.message = 'Unexpected property "' + property + '"' +function isArrayBufferView(value) { + if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) { + return ArrayBuffer.isView(value); } - captureStackTrace(this, TfTypeError) - this.__label = label - this.__property = property - this.__type = type - this.__value = value - this.__valueTypeName = valueTypeName + return ( + isTypedArray(value) || + isDataView(value) + ); } +exports.isArrayBufferView = isArrayBufferView; -TfPropertyTypeError.prototype = Object.create(Error.prototype) -TfPropertyTypeError.prototype.constructor = TfTypeError -function tfCustomError (expected, actual) { - return new TfTypeError(expected, {}, actual) +function isUint8Array(value) { + return whichTypedArray(value) === 'Uint8Array'; } +exports.isUint8Array = isUint8Array; -function tfSubError (e, property, label) { - // sub child? - if (e instanceof TfPropertyTypeError) { - property = property + '.' + e.__property +function isUint8ClampedArray(value) { + return whichTypedArray(value) === 'Uint8ClampedArray'; +} +exports.isUint8ClampedArray = isUint8ClampedArray; - e = new TfPropertyTypeError( - e.__type, property, e.__label, e.__value, e.__valueTypeName - ) +function isUint16Array(value) { + return whichTypedArray(value) === 'Uint16Array'; +} +exports.isUint16Array = isUint16Array; - // child? - } else if (e instanceof TfTypeError) { - e = new TfPropertyTypeError( - e.__type, property, label, e.__value, e.__valueTypeName - ) - } +function isUint32Array(value) { + return whichTypedArray(value) === 'Uint32Array'; +} +exports.isUint32Array = isUint32Array; - captureStackTrace(e) - return e +function isInt8Array(value) { + return whichTypedArray(value) === 'Int8Array'; } +exports.isInt8Array = isInt8Array; -module.exports = { - TfTypeError: TfTypeError, - TfPropertyTypeError: TfPropertyTypeError, - tfCustomError: tfCustomError, - tfSubError: tfSubError, - tfJSON: tfJSON, - getValueTypeName: getValueTypeName +function isInt16Array(value) { + return whichTypedArray(value) === 'Int16Array'; } +exports.isInt16Array = isInt16Array; -},{"./native":325}],323:[function(require,module,exports){ -(function (Buffer){ -var NATIVE = require('./native') -var ERRORS = require('./errors') +function isInt32Array(value) { + return whichTypedArray(value) === 'Int32Array'; +} +exports.isInt32Array = isInt32Array; -function _Buffer (value) { - return Buffer.isBuffer(value) +function isFloat32Array(value) { + return whichTypedArray(value) === 'Float32Array'; } +exports.isFloat32Array = isFloat32Array; -function Hex (value) { - return typeof value === 'string' && /^([0-9a-f]{2})+$/i.test(value) +function isFloat64Array(value) { + return whichTypedArray(value) === 'Float64Array'; } +exports.isFloat64Array = isFloat64Array; -function _LengthN (type, length) { - var name = type.toJSON() +function isBigInt64Array(value) { + return whichTypedArray(value) === 'BigInt64Array'; +} +exports.isBigInt64Array = isBigInt64Array; - function Length (value) { - if (!type(value)) return false - if (value.length === length) return true +function isBigUint64Array(value) { + return whichTypedArray(value) === 'BigUint64Array'; +} +exports.isBigUint64Array = isBigUint64Array; - throw ERRORS.tfCustomError(name + '(Length: ' + length + ')', name + '(Length: ' + value.length + ')') +function isMapToString(value) { + return ObjectToString(value) === '[object Map]'; +} +isMapToString.working = ( + typeof Map !== 'undefined' && + isMapToString(new Map()) +); + +function isMap(value) { + if (typeof Map === 'undefined') { + return false; } - Length.toJSON = function () { return name } - return Length + return isMapToString.working + ? isMapToString(value) + : value instanceof Map; } +exports.isMap = isMap; -var _ArrayN = _LengthN.bind(null, NATIVE.Array) -var _BufferN = _LengthN.bind(null, _Buffer) -var _HexN = _LengthN.bind(null, Hex) -var _StringN = _LengthN.bind(null, NATIVE.String) - -function Range (a, b, f) { - f = f || NATIVE.Number - function _range (value, strict) { - return f(value, strict) && (value > a) && (value < b) - } - _range.toJSON = function () { - return `${f.toJSON()} between [${a}, ${b}]` +function isSetToString(value) { + return ObjectToString(value) === '[object Set]'; +} +isSetToString.working = ( + typeof Set !== 'undefined' && + isSetToString(new Set()) +); +function isSet(value) { + if (typeof Set === 'undefined') { + return false; } - return _range + + return isSetToString.working + ? isSetToString(value) + : value instanceof Set; } +exports.isSet = isSet; -var INT53_MAX = Math.pow(2, 53) - 1 +function isWeakMapToString(value) { + return ObjectToString(value) === '[object WeakMap]'; +} +isWeakMapToString.working = ( + typeof WeakMap !== 'undefined' && + isWeakMapToString(new WeakMap()) +); +function isWeakMap(value) { + if (typeof WeakMap === 'undefined') { + return false; + } -function Finite (value) { - return typeof value === 'number' && isFinite(value) + return isWeakMapToString.working + ? isWeakMapToString(value) + : value instanceof WeakMap; } -function Int8 (value) { return ((value << 24) >> 24) === value } -function Int16 (value) { return ((value << 16) >> 16) === value } -function Int32 (value) { return (value | 0) === value } -function Int53 (value) { - return typeof value === 'number' && - value >= -INT53_MAX && - value <= INT53_MAX && - Math.floor(value) === value +exports.isWeakMap = isWeakMap; + +function isWeakSetToString(value) { + return ObjectToString(value) === '[object WeakSet]'; } -function UInt8 (value) { return (value & 0xff) === value } -function UInt16 (value) { return (value & 0xffff) === value } -function UInt32 (value) { return (value >>> 0) === value } -function UInt53 (value) { - return typeof value === 'number' && - value >= 0 && - value <= INT53_MAX && - Math.floor(value) === value +isWeakSetToString.working = ( + typeof WeakSet !== 'undefined' && + isWeakSetToString(new WeakSet()) +); +function isWeakSet(value) { + return isWeakSetToString(value); } +exports.isWeakSet = isWeakSet; -var types = { - ArrayN: _ArrayN, - Buffer: _Buffer, - BufferN: _BufferN, - Finite: Finite, - Hex: Hex, - HexN: _HexN, - Int8: Int8, - Int16: Int16, - Int32: Int32, - Int53: Int53, - Range: Range, - StringN: _StringN, - UInt8: UInt8, - UInt16: UInt16, - UInt32: UInt32, - UInt53: UInt53 +function isArrayBufferToString(value) { + return ObjectToString(value) === '[object ArrayBuffer]'; } +isArrayBufferToString.working = ( + typeof ArrayBuffer !== 'undefined' && + isArrayBufferToString(new ArrayBuffer()) +); +function isArrayBuffer(value) { + if (typeof ArrayBuffer === 'undefined') { + return false; + } -for (var typeName in types) { - types[typeName].toJSON = function (t) { - return t - }.bind(null, typeName) + return isArrayBufferToString.working + ? isArrayBufferToString(value) + : value instanceof ArrayBuffer; } +exports.isArrayBuffer = isArrayBuffer; -module.exports = types - -}).call(this,{"isBuffer":require("../is-buffer/index.js")}) -},{"../is-buffer/index.js":231,"./errors":322,"./native":325}],324:[function(require,module,exports){ -var ERRORS = require('./errors') -var NATIVE = require('./native') +function isDataViewToString(value) { + return ObjectToString(value) === '[object DataView]'; +} +isDataViewToString.working = ( + typeof ArrayBuffer !== 'undefined' && + typeof DataView !== 'undefined' && + isDataViewToString(new DataView(new ArrayBuffer(1), 0, 1)) +); +function isDataView(value) { + if (typeof DataView === 'undefined') { + return false; + } -// short-hand -var tfJSON = ERRORS.tfJSON -var TfTypeError = ERRORS.TfTypeError -var TfPropertyTypeError = ERRORS.TfPropertyTypeError -var tfSubError = ERRORS.tfSubError -var getValueTypeName = ERRORS.getValueTypeName + return isDataViewToString.working + ? isDataViewToString(value) + : value instanceof DataView; +} +exports.isDataView = isDataView; -var TYPES = { - arrayOf: function arrayOf (type, options) { - type = compile(type) - options = options || {} +// Store a copy of SharedArrayBuffer in case it's deleted elsewhere +var SharedArrayBufferCopy = typeof SharedArrayBuffer !== 'undefined' ? SharedArrayBuffer : undefined; +function isSharedArrayBufferToString(value) { + return ObjectToString(value) === '[object SharedArrayBuffer]'; +} +function isSharedArrayBuffer(value) { + if (typeof SharedArrayBufferCopy === 'undefined') { + return false; + } - function _arrayOf (array, strict) { - if (!NATIVE.Array(array)) return false - if (NATIVE.Nil(array)) return false - if (options.minLength !== undefined && array.length < options.minLength) return false - if (options.maxLength !== undefined && array.length > options.maxLength) return false - if (options.length !== undefined && array.length !== options.length) return false + if (typeof isSharedArrayBufferToString.working === 'undefined') { + isSharedArrayBufferToString.working = isSharedArrayBufferToString(new SharedArrayBufferCopy()); + } - return array.every(function (value, i) { - try { - return typeforce(type, value, strict) - } catch (e) { - throw tfSubError(e, i) - } - }) - } - _arrayOf.toJSON = function () { - var str = '[' + tfJSON(type) + ']' - if (options.length !== undefined) { - str += '{' + options.length + '}' - } else if (options.minLength !== undefined || options.maxLength !== undefined) { - str += '{' + - (options.minLength === undefined ? 0 : options.minLength) + ',' + - (options.maxLength === undefined ? Infinity : options.maxLength) + '}' - } - return str - } + return isSharedArrayBufferToString.working + ? isSharedArrayBufferToString(value) + : value instanceof SharedArrayBufferCopy; +} +exports.isSharedArrayBuffer = isSharedArrayBuffer; - return _arrayOf - }, +function isAsyncFunction(value) { + return ObjectToString(value) === '[object AsyncFunction]'; +} +exports.isAsyncFunction = isAsyncFunction; - maybe: function maybe (type) { - type = compile(type) +function isMapIterator(value) { + return ObjectToString(value) === '[object Map Iterator]'; +} +exports.isMapIterator = isMapIterator; - function _maybe (value, strict) { - return NATIVE.Nil(value) || type(value, strict, maybe) - } - _maybe.toJSON = function () { return '?' + tfJSON(type) } +function isSetIterator(value) { + return ObjectToString(value) === '[object Set Iterator]'; +} +exports.isSetIterator = isSetIterator; - return _maybe - }, +function isGeneratorObject(value) { + return ObjectToString(value) === '[object Generator]'; +} +exports.isGeneratorObject = isGeneratorObject; - map: function map (propertyType, propertyKeyType) { - propertyType = compile(propertyType) - if (propertyKeyType) propertyKeyType = compile(propertyKeyType) +function isWebAssemblyCompiledModule(value) { + return ObjectToString(value) === '[object WebAssembly.Module]'; +} +exports.isWebAssemblyCompiledModule = isWebAssemblyCompiledModule; - function _map (value, strict) { - if (!NATIVE.Object(value)) return false - if (NATIVE.Nil(value)) return false +function isNumberObject(value) { + return checkBoxedPrimitive(value, numberValue); +} +exports.isNumberObject = isNumberObject; - for (var propertyName in value) { - try { - if (propertyKeyType) { - typeforce(propertyKeyType, propertyName, strict) - } - } catch (e) { - throw tfSubError(e, propertyName, 'key') - } +function isStringObject(value) { + return checkBoxedPrimitive(value, stringValue); +} +exports.isStringObject = isStringObject; - try { - var propertyValue = value[propertyName] - typeforce(propertyType, propertyValue, strict) - } catch (e) { - throw tfSubError(e, propertyName) - } - } +function isBooleanObject(value) { + return checkBoxedPrimitive(value, booleanValue); +} +exports.isBooleanObject = isBooleanObject; - return true - } +function isBigIntObject(value) { + return BigIntSupported && checkBoxedPrimitive(value, bigIntValue); +} +exports.isBigIntObject = isBigIntObject; - if (propertyKeyType) { - _map.toJSON = function () { - return '{' + tfJSON(propertyKeyType) + ': ' + tfJSON(propertyType) + '}' - } - } else { - _map.toJSON = function () { return '{' + tfJSON(propertyType) + '}' } - } +function isSymbolObject(value) { + return SymbolSupported && checkBoxedPrimitive(value, symbolValue); +} +exports.isSymbolObject = isSymbolObject; - return _map - }, +function isBoxedPrimitive(value) { + return ( + isNumberObject(value) || + isStringObject(value) || + isBooleanObject(value) || + isBigIntObject(value) || + isSymbolObject(value) + ); +} +exports.isBoxedPrimitive = isBoxedPrimitive; - object: function object (uncompiled) { - var type = {} +function isAnyArrayBuffer(value) { + return typeof Uint8Array !== 'undefined' && ( + isArrayBuffer(value) || + isSharedArrayBuffer(value) + ); +} +exports.isAnyArrayBuffer = isAnyArrayBuffer; - for (var typePropertyName in uncompiled) { - type[typePropertyName] = compile(uncompiled[typePropertyName]) +['isProxy', 'isExternal', 'isModuleNamespaceObject'].forEach(function(method) { + Object.defineProperty(exports, method, { + enumerable: false, + value: function() { + throw new Error(method + ' is not supported in userland'); } + }); +}); - function _object (value, strict) { - if (!NATIVE.Object(value)) return false - if (NATIVE.Nil(value)) return false - - var propertyName - - try { - for (propertyName in type) { - var propertyType = type[propertyName] - var propertyValue = value[propertyName] - - typeforce(propertyType, propertyValue, strict) - } - } catch (e) { - throw tfSubError(e, propertyName) - } - - if (strict) { - for (propertyName in value) { - if (type[propertyName]) continue - - throw new TfPropertyTypeError(undefined, propertyName) - } - } +},{"is-arguments":350,"is-generator-function":353,"is-typed-array":354,"which-typed-array":529}],527:[function(require,module,exports){ +(function (process){(function (){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. - return true +var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || + function getOwnPropertyDescriptors(obj) { + var keys = Object.keys(obj); + var descriptors = {}; + for (var i = 0; i < keys.length; i++) { + descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]); } - _object.toJSON = function () { return tfJSON(type) } - - return _object - }, + return descriptors; + }; - anyOf: function anyOf () { - var types = [].slice.call(arguments).map(compile) +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } - function _anyOf (value, strict) { - return types.some(function (type) { + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': try { - return typeforce(type, value, strict) - } catch (e) { - return false + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; } - }) + default: + return x; } - _anyOf.toJSON = function () { return types.map(tfJSON).join('|') } - - return _anyOf - }, + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; - allOf: function allOf () { - var types = [].slice.call(arguments).map(compile) - function _allOf (value, strict) { - return types.every(function (type) { - try { - return typeforce(type, value, strict) - } catch (e) { - return false - } - }) - } - _allOf.toJSON = function () { return types.map(tfJSON).join(' & ') } +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + if (typeof process !== 'undefined' && process.noDeprecation === true) { + return fn; + } - return _allOf - }, + // Allow for deprecating things in the process of starting up. + if (typeof process === 'undefined') { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } - quacksLike: function quacksLike (type) { - function _quacksLike (value) { - return type === getValueTypeName(value) + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; } - _quacksLike.toJSON = function () { return type } + return fn.apply(this, arguments); + } - return _quacksLike - }, + return deprecated; +}; - tuple: function tuple () { - var types = [].slice.call(arguments).map(compile) - function _tuple (values, strict) { - if (NATIVE.Nil(values)) return false - if (NATIVE.Nil(values.length)) return false - if (strict && (values.length !== types.length)) return false +var debugs = {}; +var debugEnvRegex = /^$/; - return types.every(function (type, i) { - try { - return typeforce(type, values[i], strict) - } catch (e) { - throw tfSubError(e, i) - } - }) +if (process.env.NODE_DEBUG) { + var debugEnv = process.env.NODE_DEBUG; + debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&') + .replace(/\*/g, '.*') + .replace(/,/g, '$|^') + .toUpperCase(); + debugEnvRegex = new RegExp('^' + debugEnv + '$', 'i'); +} +exports.debuglog = function(set) { + set = set.toUpperCase(); + if (!debugs[set]) { + if (debugEnvRegex.test(set)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; } - _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' } - - return _tuple - }, + } + return debugs[set]; +}; - value: function value (expected) { - function _value (actual) { - return actual === expected - } - _value.toJSON = function () { return expected } - return _value +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); } +exports.inspect = inspect; -// TODO: deprecate -TYPES.oneOf = TYPES.anyOf -function compile (type) { - if (NATIVE.String(type)) { - if (type[0] === '?') return TYPES.maybe(type.slice(1)) +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; - return NATIVE[type] || TYPES.quacksLike(type) - } else if (type && NATIVE.Object(type)) { - if (NATIVE.Array(type)) { - if (type.length !== 1) throw new TypeError('Expected compile() parameter of type Array of length 1') - return TYPES.arrayOf(type[0]) - } +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; - return TYPES.object(type) - } else if (NATIVE.Function(type)) { - return type + +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; } +} - return TYPES.value(type) + +function stylizeNoColor(str, styleType) { + return str; } -function typeforce (type, value, strict, surrogate) { - if (NATIVE.Function(type)) { - if (type(value, strict)) return true - throw new TfTypeError(surrogate || type, value) - } +function arrayToHash(array) { + var hash = {}; - // JIT - return typeforce(compile(type), value, strict) -} + array.forEach(function(val, idx) { + hash[val] = true; + }); -// assign types to typeforce function -for (var typeName in NATIVE) { - typeforce[typeName] = NATIVE[typeName] + return hash; } -for (typeName in TYPES) { - typeforce[typeName] = TYPES[typeName] -} -var EXTRA = require('./extra') -for (typeName in EXTRA) { - typeforce[typeName] = EXTRA[typeName] -} +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } -typeforce.compile = compile -typeforce.TfTypeError = TfTypeError -typeforce.TfPropertyTypeError = TfPropertyTypeError + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } -module.exports = typeforce + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); -},{"./errors":322,"./extra":323,"./native":325}],325:[function(require,module,exports){ -var types = { - Array: function (value) { return value !== null && value !== undefined && value.constructor === Array }, - Boolean: function (value) { return typeof value === 'boolean' }, - Function: function (value) { return typeof value === 'function' }, - Nil: function (value) { return value === undefined || value === null }, - Number: function (value) { return typeof value === 'number' }, - Object: function (value) { return typeof value === 'object' }, - String: function (value) { return typeof value === 'string' }, - '': function () { return true } -} + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } -// TODO: deprecate -types.Null = types.Nil + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } -for (var typeName in types) { - types[typeName].toJSON = function (t) { - return t - }.bind(null, typeName) -} + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } -module.exports = types + var base = '', array = false, braces = ['{', '}']; -},{}],326:[function(require,module,exports){ -(function (root) { - "use strict"; + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } -/***** unorm.js *****/ + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } -/* - * UnicodeNormalizer 1.0.0 - * Copyright (c) 2008 Matsuza - * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. - * $Date: 2008-06-05 16:44:17 +0200 (Thu, 05 Jun 2008) $ - * $Rev: 13309 $ - */ + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } - var DEFAULT_FEATURE = [null, 0, {}]; - var CACHE_THRESHOLD = 10; - var SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7, LCount = 19, VCount = 21, TCount = 28; - var NCount = VCount * TCount; // 588 - var SCount = LCount * NCount; // 11172 + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } - var UChar = function(cp, feature){ - this.codepoint = cp; - this.feature = feature; - }; + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } - // Strategies - var cache = {}; - var cacheCounter = []; - for (var i = 0; i <= 0xFF; ++i){ - cacheCounter[i] = 0; - } + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } - function fromCache(next, cp, needFeature){ - var ret = cache[cp]; - if(!ret){ - ret = next(cp, needFeature); - if(!!ret.feature && ++cacheCounter[(cp >> 8) & 0xFF] > CACHE_THRESHOLD){ - cache[cp] = ret; - } - } - return ret; - } + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } - function fromData(next, cp, needFeature){ - var hash = cp & 0xFF00; - var dunit = UChar.udata[hash] || {}; - var f = dunit[cp]; - return f ? new UChar(cp, f) : new UChar(cp, DEFAULT_FEATURE); - } - function fromCpOnly(next, cp, needFeature){ - return !!needFeature ? next(cp, needFeature) : new UChar(cp, null); - } - function fromRuleBasedJamo(next, cp, needFeature){ - var j; - if(cp < LBase || (LBase + LCount <= cp && cp < SBase) || (SBase + SCount < cp)){ - return next(cp, needFeature); - } - if(LBase <= cp && cp < LBase + LCount){ - var c = {}; - var base = (cp - LBase) * VCount; - for (j = 0; j < VCount; ++j){ - c[VBase + j] = SBase + TCount * (j + base); - } - return new UChar(cp, [,,c]); - } + ctx.seen.push(value); - var SIndex = cp - SBase; - var TIndex = SIndex % TCount; - var feature = []; - if(TIndex !== 0){ - feature[0] = [SBase + SIndex - TIndex, TBase + TIndex]; - } else { - feature[0] = [LBase + Math.floor(SIndex / NCount), VBase + Math.floor((SIndex % NCount) / TCount)]; - feature[2] = {}; - for (j = 1; j < TCount; ++j){ - feature[2][TBase + j] = cp + j; - } - } - return new UChar(cp, feature); - } - function fromCpFilter(next, cp, needFeature){ - return cp < 60 || 13311 < cp && cp < 42607 ? new UChar(cp, DEFAULT_FEATURE) : next(cp, needFeature); - } + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } - var strategies = [fromCpFilter, fromCache, fromCpOnly, fromRuleBasedJamo, fromData]; + ctx.seen.pop(); - UChar.fromCharCode = strategies.reduceRight(function (next, strategy) { - return function (cp, needFeature) { - return strategy(next, cp, needFeature); - }; - }, null); + return reduceToSingleString(output, base, braces); +} - UChar.isHighSurrogate = function(cp){ - return cp >= 0xD800 && cp <= 0xDBFF; - }; - UChar.isLowSurrogate = function(cp){ - return cp >= 0xDC00 && cp <= 0xDFFF; - }; - UChar.prototype.prepFeature = function(){ - if(!this.feature){ - this.feature = UChar.fromCharCode(this.codepoint, true).feature; - } - }; +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} - UChar.prototype.toString = function(){ - if(this.codepoint < 0x10000){ - return String.fromCharCode(this.codepoint); - } else { - var x = this.codepoint - 0x10000; - return String.fromCharCode(Math.floor(x / 0x400) + 0xD800, x % 0x400 + 0xDC00); - } - }; - UChar.prototype.getDecomp = function(){ - this.prepFeature(); - return this.feature[0] || null; - }; +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} - UChar.prototype.isCompatibility = function(){ - this.prepFeature(); - return !!this.feature[1] && (this.feature[1] & (1 << 8)); - }; - UChar.prototype.isExclude = function(){ - this.prepFeature(); - return !!this.feature[1] && (this.feature[1] & (1 << 9)); - }; - UChar.prototype.getCanonicalClass = function(){ - this.prepFeature(); - return !!this.feature[1] ? (this.feature[1] & 0xff) : 0; - }; - UChar.prototype.getComposite = function(following){ - this.prepFeature(); - if(!this.feature[2]){ - return null; - } - var cp = this.feature[2][following.codepoint]; - return cp ? UChar.fromCharCode(cp) : null; - }; - var UCharIterator = function(str){ - this.str = str; - this.cursor = 0; - }; - UCharIterator.prototype.next = function(){ - if(!!this.str && this.cursor < this.str.length){ - var cp = this.str.charCodeAt(this.cursor++); - var d; - if(UChar.isHighSurrogate(cp) && this.cursor < this.str.length && UChar.isLowSurrogate((d = this.str.charCodeAt(this.cursor)))){ - cp = (cp - 0xD800) * 0x400 + (d -0xDC00) + 0x10000; - ++this.cursor; - } - return UChar.fromCharCode(cp); - } else { - this.str = null; - return null; - } - }; +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} - var RecursDecompIterator = function(it, cano){ - this.it = it; - this.canonical = cano; - this.resBuf = []; - }; - RecursDecompIterator.prototype.next = function(){ - function recursiveDecomp(cano, uchar){ - var decomp = uchar.getDecomp(); - if(!!decomp && !(cano && uchar.isCompatibility())){ - var ret = []; - for(var i = 0; i < decomp.length; ++i){ - var a = recursiveDecomp(cano, UChar.fromCharCode(decomp[i])); - ret = ret.concat(a); - } - return ret; - } else { - return [uchar]; - } +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); } - if(this.resBuf.length === 0){ - var uchar = this.it.next(); - if(!uchar){ - return null; - } - this.resBuf = recursiveDecomp(this.canonical, uchar); + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').slice(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } } - return this.resBuf.shift(); - }; + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.slice(1, -1); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } - var DecompIterator = function(it){ - this.it = it; - this.resBuf = []; - }; + return name + ': ' + str; +} - DecompIterator.prototype.next = function(){ - var cc; - if(this.resBuf.length === 0){ - do{ - var uchar = this.it.next(); - if(!uchar){ - break; - } - cc = uchar.getCanonicalClass(); - var inspt = this.resBuf.length; - if(cc !== 0){ - for(; inspt > 0; --inspt){ - var uchar2 = this.resBuf[inspt - 1]; - var cc2 = uchar2.getCanonicalClass(); - if(cc2 <= cc){ - break; - } - } - } - this.resBuf.splice(inspt, 0, uchar); - } while(cc !== 0); - } - return this.resBuf.shift(); - }; - var CompIterator = function(it){ - this.it = it; - this.procBuf = []; - this.resBuf = []; - this.lastClass = null; - }; +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); - CompIterator.prototype.next = function(){ - while(this.resBuf.length === 0){ - var uchar = this.it.next(); - if(!uchar){ - this.resBuf = this.procBuf; - this.procBuf = []; - break; - } - if(this.procBuf.length === 0){ - this.lastClass = uchar.getCanonicalClass(); - this.procBuf.push(uchar); - } else { - var starter = this.procBuf[0]; - var composite = starter.getComposite(uchar); - var cc = uchar.getCanonicalClass(); - if(!!composite && (this.lastClass < cc || this.lastClass === 0)){ - this.procBuf[0] = composite; - } else { - if(cc === 0){ - this.resBuf = this.procBuf; - this.procBuf = []; - } - this.lastClass = cc; - this.procBuf.push(uchar); - } - } - } - return this.resBuf.shift(); - }; + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } - var createIterator = function(mode, str){ - switch(mode){ - case "NFD": - return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true)); - case "NFKD": - return new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false)); - case "NFC": - return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), true))); - case "NFKC": - return new CompIterator(new DecompIterator(new RecursDecompIterator(new UCharIterator(str), false))); - } - throw mode + " is invalid"; - }; - var normalize = function(mode, str){ - var it = createIterator(mode, str); - var ret = ""; - var uchar; - while(!!(uchar = it.next())){ - ret += uchar.toString(); - } - return ret; - }; + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} - /* API functions */ - function nfd(str){ - return normalize("NFD", str); - } - function nfkd(str){ - return normalize("NFKD", str); - } +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +exports.types = require('./support/types'); - function nfc(str){ - return normalize("NFC", str); - } +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; - function nfkc(str){ - return normalize("NFKC", str); - } +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; -/* Unicode data */ -UChar.udata={ -0:{60:[,,{824:8814}],61:[,,{824:8800}],62:[,,{824:8815}],65:[,,{768:192,769:193,770:194,771:195,772:256,774:258,775:550,776:196,777:7842,778:197,780:461,783:512,785:514,803:7840,805:7680,808:260}],66:[,,{775:7682,803:7684,817:7686}],67:[,,{769:262,770:264,775:266,780:268,807:199}],68:[,,{775:7690,780:270,803:7692,807:7696,813:7698,817:7694}],69:[,,{768:200,769:201,770:202,771:7868,772:274,774:276,775:278,776:203,777:7866,780:282,783:516,785:518,803:7864,807:552,808:280,813:7704,816:7706}],70:[,,{775:7710}],71:[,,{769:500,770:284,772:7712,774:286,775:288,780:486,807:290}],72:[,,{770:292,775:7714,776:7718,780:542,803:7716,807:7720,814:7722}],73:[,,{768:204,769:205,770:206,771:296,772:298,774:300,775:304,776:207,777:7880,780:463,783:520,785:522,803:7882,808:302,816:7724}],74:[,,{770:308}],75:[,,{769:7728,780:488,803:7730,807:310,817:7732}],76:[,,{769:313,780:317,803:7734,807:315,813:7740,817:7738}],77:[,,{769:7742,775:7744,803:7746}],78:[,,{768:504,769:323,771:209,775:7748,780:327,803:7750,807:325,813:7754,817:7752}],79:[,,{768:210,769:211,770:212,771:213,772:332,774:334,775:558,776:214,777:7886,779:336,780:465,783:524,785:526,795:416,803:7884,808:490}],80:[,,{769:7764,775:7766}],82:[,,{769:340,775:7768,780:344,783:528,785:530,803:7770,807:342,817:7774}],83:[,,{769:346,770:348,775:7776,780:352,803:7778,806:536,807:350}],84:[,,{775:7786,780:356,803:7788,806:538,807:354,813:7792,817:7790}],85:[,,{768:217,769:218,770:219,771:360,772:362,774:364,776:220,777:7910,778:366,779:368,780:467,783:532,785:534,795:431,803:7908,804:7794,808:370,813:7798,816:7796}],86:[,,{771:7804,803:7806}],87:[,,{768:7808,769:7810,770:372,775:7814,776:7812,803:7816}],88:[,,{775:7818,776:7820}],89:[,,{768:7922,769:221,770:374,771:7928,772:562,775:7822,776:376,777:7926,803:7924}],90:[,,{769:377,770:7824,775:379,780:381,803:7826,817:7828}],97:[,,{768:224,769:225,770:226,771:227,772:257,774:259,775:551,776:228,777:7843,778:229,780:462,783:513,785:515,803:7841,805:7681,808:261}],98:[,,{775:7683,803:7685,817:7687}],99:[,,{769:263,770:265,775:267,780:269,807:231}],100:[,,{775:7691,780:271,803:7693,807:7697,813:7699,817:7695}],101:[,,{768:232,769:233,770:234,771:7869,772:275,774:277,775:279,776:235,777:7867,780:283,783:517,785:519,803:7865,807:553,808:281,813:7705,816:7707}],102:[,,{775:7711}],103:[,,{769:501,770:285,772:7713,774:287,775:289,780:487,807:291}],104:[,,{770:293,775:7715,776:7719,780:543,803:7717,807:7721,814:7723,817:7830}],105:[,,{768:236,769:237,770:238,771:297,772:299,774:301,776:239,777:7881,780:464,783:521,785:523,803:7883,808:303,816:7725}],106:[,,{770:309,780:496}],107:[,,{769:7729,780:489,803:7731,807:311,817:7733}],108:[,,{769:314,780:318,803:7735,807:316,813:7741,817:7739}],109:[,,{769:7743,775:7745,803:7747}],110:[,,{768:505,769:324,771:241,775:7749,780:328,803:7751,807:326,813:7755,817:7753}],111:[,,{768:242,769:243,770:244,771:245,772:333,774:335,775:559,776:246,777:7887,779:337,780:466,783:525,785:527,795:417,803:7885,808:491}],112:[,,{769:7765,775:7767}],114:[,,{769:341,775:7769,780:345,783:529,785:531,803:7771,807:343,817:7775}],115:[,,{769:347,770:349,775:7777,780:353,803:7779,806:537,807:351}],116:[,,{775:7787,776:7831,780:357,803:7789,806:539,807:355,813:7793,817:7791}],117:[,,{768:249,769:250,770:251,771:361,772:363,774:365,776:252,777:7911,778:367,779:369,780:468,783:533,785:535,795:432,803:7909,804:7795,808:371,813:7799,816:7797}],118:[,,{771:7805,803:7807}],119:[,,{768:7809,769:7811,770:373,775:7815,776:7813,778:7832,803:7817}],120:[,,{775:7819,776:7821}],121:[,,{768:7923,769:253,770:375,771:7929,772:563,775:7823,776:255,777:7927,778:7833,803:7925}],122:[,,{769:378,770:7825,775:380,780:382,803:7827,817:7829}],160:[[32],256],168:[[32,776],256,{768:8173,769:901,834:8129}],170:[[97],256],175:[[32,772],256],178:[[50],256],179:[[51],256],180:[[32,769],256],181:[[956],256],184:[[32,807],256],185:[[49],256],186:[[111],256],188:[[49,8260,52],256],189:[[49,8260,50],256],190:[[51,8260,52],256],192:[[65,768]],193:[[65,769]],194:[[65,770],,{768:7846,769:7844,771:7850,777:7848}],195:[[65,771]],196:[[65,776],,{772:478}],197:[[65,778],,{769:506}],198:[,,{769:508,772:482}],199:[[67,807],,{769:7688}],200:[[69,768]],201:[[69,769]],202:[[69,770],,{768:7872,769:7870,771:7876,777:7874}],203:[[69,776]],204:[[73,768]],205:[[73,769]],206:[[73,770]],207:[[73,776],,{769:7726}],209:[[78,771]],210:[[79,768]],211:[[79,769]],212:[[79,770],,{768:7890,769:7888,771:7894,777:7892}],213:[[79,771],,{769:7756,772:556,776:7758}],214:[[79,776],,{772:554}],216:[,,{769:510}],217:[[85,768]],218:[[85,769]],219:[[85,770]],220:[[85,776],,{768:475,769:471,772:469,780:473}],221:[[89,769]],224:[[97,768]],225:[[97,769]],226:[[97,770],,{768:7847,769:7845,771:7851,777:7849}],227:[[97,771]],228:[[97,776],,{772:479}],229:[[97,778],,{769:507}],230:[,,{769:509,772:483}],231:[[99,807],,{769:7689}],232:[[101,768]],233:[[101,769]],234:[[101,770],,{768:7873,769:7871,771:7877,777:7875}],235:[[101,776]],236:[[105,768]],237:[[105,769]],238:[[105,770]],239:[[105,776],,{769:7727}],241:[[110,771]],242:[[111,768]],243:[[111,769]],244:[[111,770],,{768:7891,769:7889,771:7895,777:7893}],245:[[111,771],,{769:7757,772:557,776:7759}],246:[[111,776],,{772:555}],248:[,,{769:511}],249:[[117,768]],250:[[117,769]],251:[[117,770]],252:[[117,776],,{768:476,769:472,772:470,780:474}],253:[[121,769]],255:[[121,776]]}, -256:{256:[[65,772]],257:[[97,772]],258:[[65,774],,{768:7856,769:7854,771:7860,777:7858}],259:[[97,774],,{768:7857,769:7855,771:7861,777:7859}],260:[[65,808]],261:[[97,808]],262:[[67,769]],263:[[99,769]],264:[[67,770]],265:[[99,770]],266:[[67,775]],267:[[99,775]],268:[[67,780]],269:[[99,780]],270:[[68,780]],271:[[100,780]],274:[[69,772],,{768:7700,769:7702}],275:[[101,772],,{768:7701,769:7703}],276:[[69,774]],277:[[101,774]],278:[[69,775]],279:[[101,775]],280:[[69,808]],281:[[101,808]],282:[[69,780]],283:[[101,780]],284:[[71,770]],285:[[103,770]],286:[[71,774]],287:[[103,774]],288:[[71,775]],289:[[103,775]],290:[[71,807]],291:[[103,807]],292:[[72,770]],293:[[104,770]],296:[[73,771]],297:[[105,771]],298:[[73,772]],299:[[105,772]],300:[[73,774]],301:[[105,774]],302:[[73,808]],303:[[105,808]],304:[[73,775]],306:[[73,74],256],307:[[105,106],256],308:[[74,770]],309:[[106,770]],310:[[75,807]],311:[[107,807]],313:[[76,769]],314:[[108,769]],315:[[76,807]],316:[[108,807]],317:[[76,780]],318:[[108,780]],319:[[76,183],256],320:[[108,183],256],323:[[78,769]],324:[[110,769]],325:[[78,807]],326:[[110,807]],327:[[78,780]],328:[[110,780]],329:[[700,110],256],332:[[79,772],,{768:7760,769:7762}],333:[[111,772],,{768:7761,769:7763}],334:[[79,774]],335:[[111,774]],336:[[79,779]],337:[[111,779]],340:[[82,769]],341:[[114,769]],342:[[82,807]],343:[[114,807]],344:[[82,780]],345:[[114,780]],346:[[83,769],,{775:7780}],347:[[115,769],,{775:7781}],348:[[83,770]],349:[[115,770]],350:[[83,807]],351:[[115,807]],352:[[83,780],,{775:7782}],353:[[115,780],,{775:7783}],354:[[84,807]],355:[[116,807]],356:[[84,780]],357:[[116,780]],360:[[85,771],,{769:7800}],361:[[117,771],,{769:7801}],362:[[85,772],,{776:7802}],363:[[117,772],,{776:7803}],364:[[85,774]],365:[[117,774]],366:[[85,778]],367:[[117,778]],368:[[85,779]],369:[[117,779]],370:[[85,808]],371:[[117,808]],372:[[87,770]],373:[[119,770]],374:[[89,770]],375:[[121,770]],376:[[89,776]],377:[[90,769]],378:[[122,769]],379:[[90,775]],380:[[122,775]],381:[[90,780]],382:[[122,780]],383:[[115],256,{775:7835}],416:[[79,795],,{768:7900,769:7898,771:7904,777:7902,803:7906}],417:[[111,795],,{768:7901,769:7899,771:7905,777:7903,803:7907}],431:[[85,795],,{768:7914,769:7912,771:7918,777:7916,803:7920}],432:[[117,795],,{768:7915,769:7913,771:7919,777:7917,803:7921}],439:[,,{780:494}],452:[[68,381],256],453:[[68,382],256],454:[[100,382],256],455:[[76,74],256],456:[[76,106],256],457:[[108,106],256],458:[[78,74],256],459:[[78,106],256],460:[[110,106],256],461:[[65,780]],462:[[97,780]],463:[[73,780]],464:[[105,780]],465:[[79,780]],466:[[111,780]],467:[[85,780]],468:[[117,780]],469:[[220,772]],470:[[252,772]],471:[[220,769]],472:[[252,769]],473:[[220,780]],474:[[252,780]],475:[[220,768]],476:[[252,768]],478:[[196,772]],479:[[228,772]],480:[[550,772]],481:[[551,772]],482:[[198,772]],483:[[230,772]],486:[[71,780]],487:[[103,780]],488:[[75,780]],489:[[107,780]],490:[[79,808],,{772:492}],491:[[111,808],,{772:493}],492:[[490,772]],493:[[491,772]],494:[[439,780]],495:[[658,780]],496:[[106,780]],497:[[68,90],256],498:[[68,122],256],499:[[100,122],256],500:[[71,769]],501:[[103,769]],504:[[78,768]],505:[[110,768]],506:[[197,769]],507:[[229,769]],508:[[198,769]],509:[[230,769]],510:[[216,769]],511:[[248,769]],66045:[,220]}, -512:{512:[[65,783]],513:[[97,783]],514:[[65,785]],515:[[97,785]],516:[[69,783]],517:[[101,783]],518:[[69,785]],519:[[101,785]],520:[[73,783]],521:[[105,783]],522:[[73,785]],523:[[105,785]],524:[[79,783]],525:[[111,783]],526:[[79,785]],527:[[111,785]],528:[[82,783]],529:[[114,783]],530:[[82,785]],531:[[114,785]],532:[[85,783]],533:[[117,783]],534:[[85,785]],535:[[117,785]],536:[[83,806]],537:[[115,806]],538:[[84,806]],539:[[116,806]],542:[[72,780]],543:[[104,780]],550:[[65,775],,{772:480}],551:[[97,775],,{772:481}],552:[[69,807],,{774:7708}],553:[[101,807],,{774:7709}],554:[[214,772]],555:[[246,772]],556:[[213,772]],557:[[245,772]],558:[[79,775],,{772:560}],559:[[111,775],,{772:561}],560:[[558,772]],561:[[559,772]],562:[[89,772]],563:[[121,772]],658:[,,{780:495}],688:[[104],256],689:[[614],256],690:[[106],256],691:[[114],256],692:[[633],256],693:[[635],256],694:[[641],256],695:[[119],256],696:[[121],256],728:[[32,774],256],729:[[32,775],256],730:[[32,778],256],731:[[32,808],256],732:[[32,771],256],733:[[32,779],256],736:[[611],256],737:[[108],256],738:[[115],256],739:[[120],256],740:[[661],256],66272:[,220]}, -768:{768:[,230],769:[,230],770:[,230],771:[,230],772:[,230],773:[,230],774:[,230],775:[,230],776:[,230,{769:836}],777:[,230],778:[,230],779:[,230],780:[,230],781:[,230],782:[,230],783:[,230],784:[,230],785:[,230],786:[,230],787:[,230],788:[,230],789:[,232],790:[,220],791:[,220],792:[,220],793:[,220],794:[,232],795:[,216],796:[,220],797:[,220],798:[,220],799:[,220],800:[,220],801:[,202],802:[,202],803:[,220],804:[,220],805:[,220],806:[,220],807:[,202],808:[,202],809:[,220],810:[,220],811:[,220],812:[,220],813:[,220],814:[,220],815:[,220],816:[,220],817:[,220],818:[,220],819:[,220],820:[,1],821:[,1],822:[,1],823:[,1],824:[,1],825:[,220],826:[,220],827:[,220],828:[,220],829:[,230],830:[,230],831:[,230],832:[[768],230],833:[[769],230],834:[,230],835:[[787],230],836:[[776,769],230],837:[,240],838:[,230],839:[,220],840:[,220],841:[,220],842:[,230],843:[,230],844:[,230],845:[,220],846:[,220],848:[,230],849:[,230],850:[,230],851:[,220],852:[,220],853:[,220],854:[,220],855:[,230],856:[,232],857:[,220],858:[,220],859:[,230],860:[,233],861:[,234],862:[,234],863:[,233],864:[,234],865:[,234],866:[,233],867:[,230],868:[,230],869:[,230],870:[,230],871:[,230],872:[,230],873:[,230],874:[,230],875:[,230],876:[,230],877:[,230],878:[,230],879:[,230],884:[[697]],890:[[32,837],256],894:[[59]],900:[[32,769],256],901:[[168,769]],902:[[913,769]],903:[[183]],904:[[917,769]],905:[[919,769]],906:[[921,769]],908:[[927,769]],910:[[933,769]],911:[[937,769]],912:[[970,769]],913:[,,{768:8122,769:902,772:8121,774:8120,787:7944,788:7945,837:8124}],917:[,,{768:8136,769:904,787:7960,788:7961}],919:[,,{768:8138,769:905,787:7976,788:7977,837:8140}],921:[,,{768:8154,769:906,772:8153,774:8152,776:938,787:7992,788:7993}],927:[,,{768:8184,769:908,787:8008,788:8009}],929:[,,{788:8172}],933:[,,{768:8170,769:910,772:8169,774:8168,776:939,788:8025}],937:[,,{768:8186,769:911,787:8040,788:8041,837:8188}],938:[[921,776]],939:[[933,776]],940:[[945,769],,{837:8116}],941:[[949,769]],942:[[951,769],,{837:8132}],943:[[953,769]],944:[[971,769]],945:[,,{768:8048,769:940,772:8113,774:8112,787:7936,788:7937,834:8118,837:8115}],949:[,,{768:8050,769:941,787:7952,788:7953}],951:[,,{768:8052,769:942,787:7968,788:7969,834:8134,837:8131}],953:[,,{768:8054,769:943,772:8145,774:8144,776:970,787:7984,788:7985,834:8150}],959:[,,{768:8056,769:972,787:8000,788:8001}],961:[,,{787:8164,788:8165}],965:[,,{768:8058,769:973,772:8161,774:8160,776:971,787:8016,788:8017,834:8166}],969:[,,{768:8060,769:974,787:8032,788:8033,834:8182,837:8179}],970:[[953,776],,{768:8146,769:912,834:8151}],971:[[965,776],,{768:8162,769:944,834:8167}],972:[[959,769]],973:[[965,769]],974:[[969,769],,{837:8180}],976:[[946],256],977:[[952],256],978:[[933],256,{769:979,776:980}],979:[[978,769]],980:[[978,776]],981:[[966],256],982:[[960],256],1008:[[954],256],1009:[[961],256],1010:[[962],256],1012:[[920],256],1013:[[949],256],1017:[[931],256],66422:[,230],66423:[,230],66424:[,230],66425:[,230],66426:[,230]}, -1024:{1024:[[1045,768]],1025:[[1045,776]],1027:[[1043,769]],1030:[,,{776:1031}],1031:[[1030,776]],1036:[[1050,769]],1037:[[1048,768]],1038:[[1059,774]],1040:[,,{774:1232,776:1234}],1043:[,,{769:1027}],1045:[,,{768:1024,774:1238,776:1025}],1046:[,,{774:1217,776:1244}],1047:[,,{776:1246}],1048:[,,{768:1037,772:1250,774:1049,776:1252}],1049:[[1048,774]],1050:[,,{769:1036}],1054:[,,{776:1254}],1059:[,,{772:1262,774:1038,776:1264,779:1266}],1063:[,,{776:1268}],1067:[,,{776:1272}],1069:[,,{776:1260}],1072:[,,{774:1233,776:1235}],1075:[,,{769:1107}],1077:[,,{768:1104,774:1239,776:1105}],1078:[,,{774:1218,776:1245}],1079:[,,{776:1247}],1080:[,,{768:1117,772:1251,774:1081,776:1253}],1081:[[1080,774]],1082:[,,{769:1116}],1086:[,,{776:1255}],1091:[,,{772:1263,774:1118,776:1265,779:1267}],1095:[,,{776:1269}],1099:[,,{776:1273}],1101:[,,{776:1261}],1104:[[1077,768]],1105:[[1077,776]],1107:[[1075,769]],1110:[,,{776:1111}],1111:[[1110,776]],1116:[[1082,769]],1117:[[1080,768]],1118:[[1091,774]],1140:[,,{783:1142}],1141:[,,{783:1143}],1142:[[1140,783]],1143:[[1141,783]],1155:[,230],1156:[,230],1157:[,230],1158:[,230],1159:[,230],1217:[[1046,774]],1218:[[1078,774]],1232:[[1040,774]],1233:[[1072,774]],1234:[[1040,776]],1235:[[1072,776]],1238:[[1045,774]],1239:[[1077,774]],1240:[,,{776:1242}],1241:[,,{776:1243}],1242:[[1240,776]],1243:[[1241,776]],1244:[[1046,776]],1245:[[1078,776]],1246:[[1047,776]],1247:[[1079,776]],1250:[[1048,772]],1251:[[1080,772]],1252:[[1048,776]],1253:[[1080,776]],1254:[[1054,776]],1255:[[1086,776]],1256:[,,{776:1258}],1257:[,,{776:1259}],1258:[[1256,776]],1259:[[1257,776]],1260:[[1069,776]],1261:[[1101,776]],1262:[[1059,772]],1263:[[1091,772]],1264:[[1059,776]],1265:[[1091,776]],1266:[[1059,779]],1267:[[1091,779]],1268:[[1063,776]],1269:[[1095,776]],1272:[[1067,776]],1273:[[1099,776]]}, -1280:{1415:[[1381,1410],256],1425:[,220],1426:[,230],1427:[,230],1428:[,230],1429:[,230],1430:[,220],1431:[,230],1432:[,230],1433:[,230],1434:[,222],1435:[,220],1436:[,230],1437:[,230],1438:[,230],1439:[,230],1440:[,230],1441:[,230],1442:[,220],1443:[,220],1444:[,220],1445:[,220],1446:[,220],1447:[,220],1448:[,230],1449:[,230],1450:[,220],1451:[,230],1452:[,230],1453:[,222],1454:[,228],1455:[,230],1456:[,10],1457:[,11],1458:[,12],1459:[,13],1460:[,14],1461:[,15],1462:[,16],1463:[,17],1464:[,18],1465:[,19],1466:[,19],1467:[,20],1468:[,21],1469:[,22],1471:[,23],1473:[,24],1474:[,25],1476:[,230],1477:[,220],1479:[,18]}, -1536:{1552:[,230],1553:[,230],1554:[,230],1555:[,230],1556:[,230],1557:[,230],1558:[,230],1559:[,230],1560:[,30],1561:[,31],1562:[,32],1570:[[1575,1619]],1571:[[1575,1620]],1572:[[1608,1620]],1573:[[1575,1621]],1574:[[1610,1620]],1575:[,,{1619:1570,1620:1571,1621:1573}],1608:[,,{1620:1572}],1610:[,,{1620:1574}],1611:[,27],1612:[,28],1613:[,29],1614:[,30],1615:[,31],1616:[,32],1617:[,33],1618:[,34],1619:[,230],1620:[,230],1621:[,220],1622:[,220],1623:[,230],1624:[,230],1625:[,230],1626:[,230],1627:[,230],1628:[,220],1629:[,230],1630:[,230],1631:[,220],1648:[,35],1653:[[1575,1652],256],1654:[[1608,1652],256],1655:[[1735,1652],256],1656:[[1610,1652],256],1728:[[1749,1620]],1729:[,,{1620:1730}],1730:[[1729,1620]],1746:[,,{1620:1747}],1747:[[1746,1620]],1749:[,,{1620:1728}],1750:[,230],1751:[,230],1752:[,230],1753:[,230],1754:[,230],1755:[,230],1756:[,230],1759:[,230],1760:[,230],1761:[,230],1762:[,230],1763:[,220],1764:[,230],1767:[,230],1768:[,230],1770:[,220],1771:[,230],1772:[,230],1773:[,220]}, -1792:{1809:[,36],1840:[,230],1841:[,220],1842:[,230],1843:[,230],1844:[,220],1845:[,230],1846:[,230],1847:[,220],1848:[,220],1849:[,220],1850:[,230],1851:[,220],1852:[,220],1853:[,230],1854:[,220],1855:[,230],1856:[,230],1857:[,230],1858:[,220],1859:[,230],1860:[,220],1861:[,230],1862:[,220],1863:[,230],1864:[,220],1865:[,230],1866:[,230],2027:[,230],2028:[,230],2029:[,230],2030:[,230],2031:[,230],2032:[,230],2033:[,230],2034:[,220],2035:[,230]}, -2048:{2070:[,230],2071:[,230],2072:[,230],2073:[,230],2075:[,230],2076:[,230],2077:[,230],2078:[,230],2079:[,230],2080:[,230],2081:[,230],2082:[,230],2083:[,230],2085:[,230],2086:[,230],2087:[,230],2089:[,230],2090:[,230],2091:[,230],2092:[,230],2093:[,230],2137:[,220],2138:[,220],2139:[,220],2276:[,230],2277:[,230],2278:[,220],2279:[,230],2280:[,230],2281:[,220],2282:[,230],2283:[,230],2284:[,230],2285:[,220],2286:[,220],2287:[,220],2288:[,27],2289:[,28],2290:[,29],2291:[,230],2292:[,230],2293:[,230],2294:[,220],2295:[,230],2296:[,230],2297:[,220],2298:[,220],2299:[,230],2300:[,230],2301:[,230],2302:[,230],2303:[,230]}, -2304:{2344:[,,{2364:2345}],2345:[[2344,2364]],2352:[,,{2364:2353}],2353:[[2352,2364]],2355:[,,{2364:2356}],2356:[[2355,2364]],2364:[,7],2381:[,9],2385:[,230],2386:[,220],2387:[,230],2388:[,230],2392:[[2325,2364],512],2393:[[2326,2364],512],2394:[[2327,2364],512],2395:[[2332,2364],512],2396:[[2337,2364],512],2397:[[2338,2364],512],2398:[[2347,2364],512],2399:[[2351,2364],512],2492:[,7],2503:[,,{2494:2507,2519:2508}],2507:[[2503,2494]],2508:[[2503,2519]],2509:[,9],2524:[[2465,2492],512],2525:[[2466,2492],512],2527:[[2479,2492],512]}, -2560:{2611:[[2610,2620],512],2614:[[2616,2620],512],2620:[,7],2637:[,9],2649:[[2582,2620],512],2650:[[2583,2620],512],2651:[[2588,2620],512],2654:[[2603,2620],512],2748:[,7],2765:[,9],68109:[,220],68111:[,230],68152:[,230],68153:[,1],68154:[,220],68159:[,9],68325:[,230],68326:[,220]}, -2816:{2876:[,7],2887:[,,{2878:2891,2902:2888,2903:2892}],2888:[[2887,2902]],2891:[[2887,2878]],2892:[[2887,2903]],2893:[,9],2908:[[2849,2876],512],2909:[[2850,2876],512],2962:[,,{3031:2964}],2964:[[2962,3031]],3014:[,,{3006:3018,3031:3020}],3015:[,,{3006:3019}],3018:[[3014,3006]],3019:[[3015,3006]],3020:[[3014,3031]],3021:[,9]}, -3072:{3142:[,,{3158:3144}],3144:[[3142,3158]],3149:[,9],3157:[,84],3158:[,91],3260:[,7],3263:[,,{3285:3264}],3264:[[3263,3285]],3270:[,,{3266:3274,3285:3271,3286:3272}],3271:[[3270,3285]],3272:[[3270,3286]],3274:[[3270,3266],,{3285:3275}],3275:[[3274,3285]],3277:[,9]}, -3328:{3398:[,,{3390:3402,3415:3404}],3399:[,,{3390:3403}],3402:[[3398,3390]],3403:[[3399,3390]],3404:[[3398,3415]],3405:[,9],3530:[,9],3545:[,,{3530:3546,3535:3548,3551:3550}],3546:[[3545,3530]],3548:[[3545,3535],,{3530:3549}],3549:[[3548,3530]],3550:[[3545,3551]]}, -3584:{3635:[[3661,3634],256],3640:[,103],3641:[,103],3642:[,9],3656:[,107],3657:[,107],3658:[,107],3659:[,107],3763:[[3789,3762],256],3768:[,118],3769:[,118],3784:[,122],3785:[,122],3786:[,122],3787:[,122],3804:[[3755,3737],256],3805:[[3755,3745],256]}, -3840:{3852:[[3851],256],3864:[,220],3865:[,220],3893:[,220],3895:[,220],3897:[,216],3907:[[3906,4023],512],3917:[[3916,4023],512],3922:[[3921,4023],512],3927:[[3926,4023],512],3932:[[3931,4023],512],3945:[[3904,4021],512],3953:[,129],3954:[,130],3955:[[3953,3954],512],3956:[,132],3957:[[3953,3956],512],3958:[[4018,3968],512],3959:[[4018,3969],256],3960:[[4019,3968],512],3961:[[4019,3969],256],3962:[,130],3963:[,130],3964:[,130],3965:[,130],3968:[,130],3969:[[3953,3968],512],3970:[,230],3971:[,230],3972:[,9],3974:[,230],3975:[,230],3987:[[3986,4023],512],3997:[[3996,4023],512],4002:[[4001,4023],512],4007:[[4006,4023],512],4012:[[4011,4023],512],4025:[[3984,4021],512],4038:[,220]}, -4096:{4133:[,,{4142:4134}],4134:[[4133,4142]],4151:[,7],4153:[,9],4154:[,9],4237:[,220],4348:[[4316],256],69702:[,9],69759:[,9],69785:[,,{69818:69786}],69786:[[69785,69818]],69787:[,,{69818:69788}],69788:[[69787,69818]],69797:[,,{69818:69803}],69803:[[69797,69818]],69817:[,9],69818:[,7]}, -4352:{69888:[,230],69889:[,230],69890:[,230],69934:[[69937,69927]],69935:[[69938,69927]],69937:[,,{69927:69934}],69938:[,,{69927:69935}],69939:[,9],69940:[,9],70003:[,7],70080:[,9]}, -4608:{70197:[,9],70198:[,7],70377:[,7],70378:[,9]}, -4864:{4957:[,230],4958:[,230],4959:[,230],70460:[,7],70471:[,,{70462:70475,70487:70476}],70475:[[70471,70462]],70476:[[70471,70487]],70477:[,9],70502:[,230],70503:[,230],70504:[,230],70505:[,230],70506:[,230],70507:[,230],70508:[,230],70512:[,230],70513:[,230],70514:[,230],70515:[,230],70516:[,230]}, -5120:{70841:[,,{70832:70844,70842:70843,70845:70846}],70843:[[70841,70842]],70844:[[70841,70832]],70846:[[70841,70845]],70850:[,9],70851:[,7]}, -5376:{71096:[,,{71087:71098}],71097:[,,{71087:71099}],71098:[[71096,71087]],71099:[[71097,71087]],71103:[,9],71104:[,7]}, -5632:{71231:[,9],71350:[,9],71351:[,7]}, -5888:{5908:[,9],5940:[,9],6098:[,9],6109:[,230]}, -6144:{6313:[,228]}, -6400:{6457:[,222],6458:[,230],6459:[,220]}, -6656:{6679:[,230],6680:[,220],6752:[,9],6773:[,230],6774:[,230],6775:[,230],6776:[,230],6777:[,230],6778:[,230],6779:[,230],6780:[,230],6783:[,220],6832:[,230],6833:[,230],6834:[,230],6835:[,230],6836:[,230],6837:[,220],6838:[,220],6839:[,220],6840:[,220],6841:[,220],6842:[,220],6843:[,230],6844:[,230],6845:[,220]}, -6912:{6917:[,,{6965:6918}],6918:[[6917,6965]],6919:[,,{6965:6920}],6920:[[6919,6965]],6921:[,,{6965:6922}],6922:[[6921,6965]],6923:[,,{6965:6924}],6924:[[6923,6965]],6925:[,,{6965:6926}],6926:[[6925,6965]],6929:[,,{6965:6930}],6930:[[6929,6965]],6964:[,7],6970:[,,{6965:6971}],6971:[[6970,6965]],6972:[,,{6965:6973}],6973:[[6972,6965]],6974:[,,{6965:6976}],6975:[,,{6965:6977}],6976:[[6974,6965]],6977:[[6975,6965]],6978:[,,{6965:6979}],6979:[[6978,6965]],6980:[,9],7019:[,230],7020:[,220],7021:[,230],7022:[,230],7023:[,230],7024:[,230],7025:[,230],7026:[,230],7027:[,230],7082:[,9],7083:[,9],7142:[,7],7154:[,9],7155:[,9]}, -7168:{7223:[,7],7376:[,230],7377:[,230],7378:[,230],7380:[,1],7381:[,220],7382:[,220],7383:[,220],7384:[,220],7385:[,220],7386:[,230],7387:[,230],7388:[,220],7389:[,220],7390:[,220],7391:[,220],7392:[,230],7394:[,1],7395:[,1],7396:[,1],7397:[,1],7398:[,1],7399:[,1],7400:[,1],7405:[,220],7412:[,230],7416:[,230],7417:[,230]}, -7424:{7468:[[65],256],7469:[[198],256],7470:[[66],256],7472:[[68],256],7473:[[69],256],7474:[[398],256],7475:[[71],256],7476:[[72],256],7477:[[73],256],7478:[[74],256],7479:[[75],256],7480:[[76],256],7481:[[77],256],7482:[[78],256],7484:[[79],256],7485:[[546],256],7486:[[80],256],7487:[[82],256],7488:[[84],256],7489:[[85],256],7490:[[87],256],7491:[[97],256],7492:[[592],256],7493:[[593],256],7494:[[7426],256],7495:[[98],256],7496:[[100],256],7497:[[101],256],7498:[[601],256],7499:[[603],256],7500:[[604],256],7501:[[103],256],7503:[[107],256],7504:[[109],256],7505:[[331],256],7506:[[111],256],7507:[[596],256],7508:[[7446],256],7509:[[7447],256],7510:[[112],256],7511:[[116],256],7512:[[117],256],7513:[[7453],256],7514:[[623],256],7515:[[118],256],7516:[[7461],256],7517:[[946],256],7518:[[947],256],7519:[[948],256],7520:[[966],256],7521:[[967],256],7522:[[105],256],7523:[[114],256],7524:[[117],256],7525:[[118],256],7526:[[946],256],7527:[[947],256],7528:[[961],256],7529:[[966],256],7530:[[967],256],7544:[[1085],256],7579:[[594],256],7580:[[99],256],7581:[[597],256],7582:[[240],256],7583:[[604],256],7584:[[102],256],7585:[[607],256],7586:[[609],256],7587:[[613],256],7588:[[616],256],7589:[[617],256],7590:[[618],256],7591:[[7547],256],7592:[[669],256],7593:[[621],256],7594:[[7557],256],7595:[[671],256],7596:[[625],256],7597:[[624],256],7598:[[626],256],7599:[[627],256],7600:[[628],256],7601:[[629],256],7602:[[632],256],7603:[[642],256],7604:[[643],256],7605:[[427],256],7606:[[649],256],7607:[[650],256],7608:[[7452],256],7609:[[651],256],7610:[[652],256],7611:[[122],256],7612:[[656],256],7613:[[657],256],7614:[[658],256],7615:[[952],256],7616:[,230],7617:[,230],7618:[,220],7619:[,230],7620:[,230],7621:[,230],7622:[,230],7623:[,230],7624:[,230],7625:[,230],7626:[,220],7627:[,230],7628:[,230],7629:[,234],7630:[,214],7631:[,220],7632:[,202],7633:[,230],7634:[,230],7635:[,230],7636:[,230],7637:[,230],7638:[,230],7639:[,230],7640:[,230],7641:[,230],7642:[,230],7643:[,230],7644:[,230],7645:[,230],7646:[,230],7647:[,230],7648:[,230],7649:[,230],7650:[,230],7651:[,230],7652:[,230],7653:[,230],7654:[,230],7655:[,230],7656:[,230],7657:[,230],7658:[,230],7659:[,230],7660:[,230],7661:[,230],7662:[,230],7663:[,230],7664:[,230],7665:[,230],7666:[,230],7667:[,230],7668:[,230],7669:[,230],7676:[,233],7677:[,220],7678:[,230],7679:[,220]}, -7680:{7680:[[65,805]],7681:[[97,805]],7682:[[66,775]],7683:[[98,775]],7684:[[66,803]],7685:[[98,803]],7686:[[66,817]],7687:[[98,817]],7688:[[199,769]],7689:[[231,769]],7690:[[68,775]],7691:[[100,775]],7692:[[68,803]],7693:[[100,803]],7694:[[68,817]],7695:[[100,817]],7696:[[68,807]],7697:[[100,807]],7698:[[68,813]],7699:[[100,813]],7700:[[274,768]],7701:[[275,768]],7702:[[274,769]],7703:[[275,769]],7704:[[69,813]],7705:[[101,813]],7706:[[69,816]],7707:[[101,816]],7708:[[552,774]],7709:[[553,774]],7710:[[70,775]],7711:[[102,775]],7712:[[71,772]],7713:[[103,772]],7714:[[72,775]],7715:[[104,775]],7716:[[72,803]],7717:[[104,803]],7718:[[72,776]],7719:[[104,776]],7720:[[72,807]],7721:[[104,807]],7722:[[72,814]],7723:[[104,814]],7724:[[73,816]],7725:[[105,816]],7726:[[207,769]],7727:[[239,769]],7728:[[75,769]],7729:[[107,769]],7730:[[75,803]],7731:[[107,803]],7732:[[75,817]],7733:[[107,817]],7734:[[76,803],,{772:7736}],7735:[[108,803],,{772:7737}],7736:[[7734,772]],7737:[[7735,772]],7738:[[76,817]],7739:[[108,817]],7740:[[76,813]],7741:[[108,813]],7742:[[77,769]],7743:[[109,769]],7744:[[77,775]],7745:[[109,775]],7746:[[77,803]],7747:[[109,803]],7748:[[78,775]],7749:[[110,775]],7750:[[78,803]],7751:[[110,803]],7752:[[78,817]],7753:[[110,817]],7754:[[78,813]],7755:[[110,813]],7756:[[213,769]],7757:[[245,769]],7758:[[213,776]],7759:[[245,776]],7760:[[332,768]],7761:[[333,768]],7762:[[332,769]],7763:[[333,769]],7764:[[80,769]],7765:[[112,769]],7766:[[80,775]],7767:[[112,775]],7768:[[82,775]],7769:[[114,775]],7770:[[82,803],,{772:7772}],7771:[[114,803],,{772:7773}],7772:[[7770,772]],7773:[[7771,772]],7774:[[82,817]],7775:[[114,817]],7776:[[83,775]],7777:[[115,775]],7778:[[83,803],,{775:7784}],7779:[[115,803],,{775:7785}],7780:[[346,775]],7781:[[347,775]],7782:[[352,775]],7783:[[353,775]],7784:[[7778,775]],7785:[[7779,775]],7786:[[84,775]],7787:[[116,775]],7788:[[84,803]],7789:[[116,803]],7790:[[84,817]],7791:[[116,817]],7792:[[84,813]],7793:[[116,813]],7794:[[85,804]],7795:[[117,804]],7796:[[85,816]],7797:[[117,816]],7798:[[85,813]],7799:[[117,813]],7800:[[360,769]],7801:[[361,769]],7802:[[362,776]],7803:[[363,776]],7804:[[86,771]],7805:[[118,771]],7806:[[86,803]],7807:[[118,803]],7808:[[87,768]],7809:[[119,768]],7810:[[87,769]],7811:[[119,769]],7812:[[87,776]],7813:[[119,776]],7814:[[87,775]],7815:[[119,775]],7816:[[87,803]],7817:[[119,803]],7818:[[88,775]],7819:[[120,775]],7820:[[88,776]],7821:[[120,776]],7822:[[89,775]],7823:[[121,775]],7824:[[90,770]],7825:[[122,770]],7826:[[90,803]],7827:[[122,803]],7828:[[90,817]],7829:[[122,817]],7830:[[104,817]],7831:[[116,776]],7832:[[119,778]],7833:[[121,778]],7834:[[97,702],256],7835:[[383,775]],7840:[[65,803],,{770:7852,774:7862}],7841:[[97,803],,{770:7853,774:7863}],7842:[[65,777]],7843:[[97,777]],7844:[[194,769]],7845:[[226,769]],7846:[[194,768]],7847:[[226,768]],7848:[[194,777]],7849:[[226,777]],7850:[[194,771]],7851:[[226,771]],7852:[[7840,770]],7853:[[7841,770]],7854:[[258,769]],7855:[[259,769]],7856:[[258,768]],7857:[[259,768]],7858:[[258,777]],7859:[[259,777]],7860:[[258,771]],7861:[[259,771]],7862:[[7840,774]],7863:[[7841,774]],7864:[[69,803],,{770:7878}],7865:[[101,803],,{770:7879}],7866:[[69,777]],7867:[[101,777]],7868:[[69,771]],7869:[[101,771]],7870:[[202,769]],7871:[[234,769]],7872:[[202,768]],7873:[[234,768]],7874:[[202,777]],7875:[[234,777]],7876:[[202,771]],7877:[[234,771]],7878:[[7864,770]],7879:[[7865,770]],7880:[[73,777]],7881:[[105,777]],7882:[[73,803]],7883:[[105,803]],7884:[[79,803],,{770:7896}],7885:[[111,803],,{770:7897}],7886:[[79,777]],7887:[[111,777]],7888:[[212,769]],7889:[[244,769]],7890:[[212,768]],7891:[[244,768]],7892:[[212,777]],7893:[[244,777]],7894:[[212,771]],7895:[[244,771]],7896:[[7884,770]],7897:[[7885,770]],7898:[[416,769]],7899:[[417,769]],7900:[[416,768]],7901:[[417,768]],7902:[[416,777]],7903:[[417,777]],7904:[[416,771]],7905:[[417,771]],7906:[[416,803]],7907:[[417,803]],7908:[[85,803]],7909:[[117,803]],7910:[[85,777]],7911:[[117,777]],7912:[[431,769]],7913:[[432,769]],7914:[[431,768]],7915:[[432,768]],7916:[[431,777]],7917:[[432,777]],7918:[[431,771]],7919:[[432,771]],7920:[[431,803]],7921:[[432,803]],7922:[[89,768]],7923:[[121,768]],7924:[[89,803]],7925:[[121,803]],7926:[[89,777]],7927:[[121,777]],7928:[[89,771]],7929:[[121,771]]}, -7936:{7936:[[945,787],,{768:7938,769:7940,834:7942,837:8064}],7937:[[945,788],,{768:7939,769:7941,834:7943,837:8065}],7938:[[7936,768],,{837:8066}],7939:[[7937,768],,{837:8067}],7940:[[7936,769],,{837:8068}],7941:[[7937,769],,{837:8069}],7942:[[7936,834],,{837:8070}],7943:[[7937,834],,{837:8071}],7944:[[913,787],,{768:7946,769:7948,834:7950,837:8072}],7945:[[913,788],,{768:7947,769:7949,834:7951,837:8073}],7946:[[7944,768],,{837:8074}],7947:[[7945,768],,{837:8075}],7948:[[7944,769],,{837:8076}],7949:[[7945,769],,{837:8077}],7950:[[7944,834],,{837:8078}],7951:[[7945,834],,{837:8079}],7952:[[949,787],,{768:7954,769:7956}],7953:[[949,788],,{768:7955,769:7957}],7954:[[7952,768]],7955:[[7953,768]],7956:[[7952,769]],7957:[[7953,769]],7960:[[917,787],,{768:7962,769:7964}],7961:[[917,788],,{768:7963,769:7965}],7962:[[7960,768]],7963:[[7961,768]],7964:[[7960,769]],7965:[[7961,769]],7968:[[951,787],,{768:7970,769:7972,834:7974,837:8080}],7969:[[951,788],,{768:7971,769:7973,834:7975,837:8081}],7970:[[7968,768],,{837:8082}],7971:[[7969,768],,{837:8083}],7972:[[7968,769],,{837:8084}],7973:[[7969,769],,{837:8085}],7974:[[7968,834],,{837:8086}],7975:[[7969,834],,{837:8087}],7976:[[919,787],,{768:7978,769:7980,834:7982,837:8088}],7977:[[919,788],,{768:7979,769:7981,834:7983,837:8089}],7978:[[7976,768],,{837:8090}],7979:[[7977,768],,{837:8091}],7980:[[7976,769],,{837:8092}],7981:[[7977,769],,{837:8093}],7982:[[7976,834],,{837:8094}],7983:[[7977,834],,{837:8095}],7984:[[953,787],,{768:7986,769:7988,834:7990}],7985:[[953,788],,{768:7987,769:7989,834:7991}],7986:[[7984,768]],7987:[[7985,768]],7988:[[7984,769]],7989:[[7985,769]],7990:[[7984,834]],7991:[[7985,834]],7992:[[921,787],,{768:7994,769:7996,834:7998}],7993:[[921,788],,{768:7995,769:7997,834:7999}],7994:[[7992,768]],7995:[[7993,768]],7996:[[7992,769]],7997:[[7993,769]],7998:[[7992,834]],7999:[[7993,834]],8000:[[959,787],,{768:8002,769:8004}],8001:[[959,788],,{768:8003,769:8005}],8002:[[8000,768]],8003:[[8001,768]],8004:[[8000,769]],8005:[[8001,769]],8008:[[927,787],,{768:8010,769:8012}],8009:[[927,788],,{768:8011,769:8013}],8010:[[8008,768]],8011:[[8009,768]],8012:[[8008,769]],8013:[[8009,769]],8016:[[965,787],,{768:8018,769:8020,834:8022}],8017:[[965,788],,{768:8019,769:8021,834:8023}],8018:[[8016,768]],8019:[[8017,768]],8020:[[8016,769]],8021:[[8017,769]],8022:[[8016,834]],8023:[[8017,834]],8025:[[933,788],,{768:8027,769:8029,834:8031}],8027:[[8025,768]],8029:[[8025,769]],8031:[[8025,834]],8032:[[969,787],,{768:8034,769:8036,834:8038,837:8096}],8033:[[969,788],,{768:8035,769:8037,834:8039,837:8097}],8034:[[8032,768],,{837:8098}],8035:[[8033,768],,{837:8099}],8036:[[8032,769],,{837:8100}],8037:[[8033,769],,{837:8101}],8038:[[8032,834],,{837:8102}],8039:[[8033,834],,{837:8103}],8040:[[937,787],,{768:8042,769:8044,834:8046,837:8104}],8041:[[937,788],,{768:8043,769:8045,834:8047,837:8105}],8042:[[8040,768],,{837:8106}],8043:[[8041,768],,{837:8107}],8044:[[8040,769],,{837:8108}],8045:[[8041,769],,{837:8109}],8046:[[8040,834],,{837:8110}],8047:[[8041,834],,{837:8111}],8048:[[945,768],,{837:8114}],8049:[[940]],8050:[[949,768]],8051:[[941]],8052:[[951,768],,{837:8130}],8053:[[942]],8054:[[953,768]],8055:[[943]],8056:[[959,768]],8057:[[972]],8058:[[965,768]],8059:[[973]],8060:[[969,768],,{837:8178}],8061:[[974]],8064:[[7936,837]],8065:[[7937,837]],8066:[[7938,837]],8067:[[7939,837]],8068:[[7940,837]],8069:[[7941,837]],8070:[[7942,837]],8071:[[7943,837]],8072:[[7944,837]],8073:[[7945,837]],8074:[[7946,837]],8075:[[7947,837]],8076:[[7948,837]],8077:[[7949,837]],8078:[[7950,837]],8079:[[7951,837]],8080:[[7968,837]],8081:[[7969,837]],8082:[[7970,837]],8083:[[7971,837]],8084:[[7972,837]],8085:[[7973,837]],8086:[[7974,837]],8087:[[7975,837]],8088:[[7976,837]],8089:[[7977,837]],8090:[[7978,837]],8091:[[7979,837]],8092:[[7980,837]],8093:[[7981,837]],8094:[[7982,837]],8095:[[7983,837]],8096:[[8032,837]],8097:[[8033,837]],8098:[[8034,837]],8099:[[8035,837]],8100:[[8036,837]],8101:[[8037,837]],8102:[[8038,837]],8103:[[8039,837]],8104:[[8040,837]],8105:[[8041,837]],8106:[[8042,837]],8107:[[8043,837]],8108:[[8044,837]],8109:[[8045,837]],8110:[[8046,837]],8111:[[8047,837]],8112:[[945,774]],8113:[[945,772]],8114:[[8048,837]],8115:[[945,837]],8116:[[940,837]],8118:[[945,834],,{837:8119}],8119:[[8118,837]],8120:[[913,774]],8121:[[913,772]],8122:[[913,768]],8123:[[902]],8124:[[913,837]],8125:[[32,787],256],8126:[[953]],8127:[[32,787],256,{768:8141,769:8142,834:8143}],8128:[[32,834],256],8129:[[168,834]],8130:[[8052,837]],8131:[[951,837]],8132:[[942,837]],8134:[[951,834],,{837:8135}],8135:[[8134,837]],8136:[[917,768]],8137:[[904]],8138:[[919,768]],8139:[[905]],8140:[[919,837]],8141:[[8127,768]],8142:[[8127,769]],8143:[[8127,834]],8144:[[953,774]],8145:[[953,772]],8146:[[970,768]],8147:[[912]],8150:[[953,834]],8151:[[970,834]],8152:[[921,774]],8153:[[921,772]],8154:[[921,768]],8155:[[906]],8157:[[8190,768]],8158:[[8190,769]],8159:[[8190,834]],8160:[[965,774]],8161:[[965,772]],8162:[[971,768]],8163:[[944]],8164:[[961,787]],8165:[[961,788]],8166:[[965,834]],8167:[[971,834]],8168:[[933,774]],8169:[[933,772]],8170:[[933,768]],8171:[[910]],8172:[[929,788]],8173:[[168,768]],8174:[[901]],8175:[[96]],8178:[[8060,837]],8179:[[969,837]],8180:[[974,837]],8182:[[969,834],,{837:8183}],8183:[[8182,837]],8184:[[927,768]],8185:[[908]],8186:[[937,768]],8187:[[911]],8188:[[937,837]],8189:[[180]],8190:[[32,788],256,{768:8157,769:8158,834:8159}]}, -8192:{8192:[[8194]],8193:[[8195]],8194:[[32],256],8195:[[32],256],8196:[[32],256],8197:[[32],256],8198:[[32],256],8199:[[32],256],8200:[[32],256],8201:[[32],256],8202:[[32],256],8209:[[8208],256],8215:[[32,819],256],8228:[[46],256],8229:[[46,46],256],8230:[[46,46,46],256],8239:[[32],256],8243:[[8242,8242],256],8244:[[8242,8242,8242],256],8246:[[8245,8245],256],8247:[[8245,8245,8245],256],8252:[[33,33],256],8254:[[32,773],256],8263:[[63,63],256],8264:[[63,33],256],8265:[[33,63],256],8279:[[8242,8242,8242,8242],256],8287:[[32],256],8304:[[48],256],8305:[[105],256],8308:[[52],256],8309:[[53],256],8310:[[54],256],8311:[[55],256],8312:[[56],256],8313:[[57],256],8314:[[43],256],8315:[[8722],256],8316:[[61],256],8317:[[40],256],8318:[[41],256],8319:[[110],256],8320:[[48],256],8321:[[49],256],8322:[[50],256],8323:[[51],256],8324:[[52],256],8325:[[53],256],8326:[[54],256],8327:[[55],256],8328:[[56],256],8329:[[57],256],8330:[[43],256],8331:[[8722],256],8332:[[61],256],8333:[[40],256],8334:[[41],256],8336:[[97],256],8337:[[101],256],8338:[[111],256],8339:[[120],256],8340:[[601],256],8341:[[104],256],8342:[[107],256],8343:[[108],256],8344:[[109],256],8345:[[110],256],8346:[[112],256],8347:[[115],256],8348:[[116],256],8360:[[82,115],256],8400:[,230],8401:[,230],8402:[,1],8403:[,1],8404:[,230],8405:[,230],8406:[,230],8407:[,230],8408:[,1],8409:[,1],8410:[,1],8411:[,230],8412:[,230],8417:[,230],8421:[,1],8422:[,1],8423:[,230],8424:[,220],8425:[,230],8426:[,1],8427:[,1],8428:[,220],8429:[,220],8430:[,220],8431:[,220],8432:[,230]}, -8448:{8448:[[97,47,99],256],8449:[[97,47,115],256],8450:[[67],256],8451:[[176,67],256],8453:[[99,47,111],256],8454:[[99,47,117],256],8455:[[400],256],8457:[[176,70],256],8458:[[103],256],8459:[[72],256],8460:[[72],256],8461:[[72],256],8462:[[104],256],8463:[[295],256],8464:[[73],256],8465:[[73],256],8466:[[76],256],8467:[[108],256],8469:[[78],256],8470:[[78,111],256],8473:[[80],256],8474:[[81],256],8475:[[82],256],8476:[[82],256],8477:[[82],256],8480:[[83,77],256],8481:[[84,69,76],256],8482:[[84,77],256],8484:[[90],256],8486:[[937]],8488:[[90],256],8490:[[75]],8491:[[197]],8492:[[66],256],8493:[[67],256],8495:[[101],256],8496:[[69],256],8497:[[70],256],8499:[[77],256],8500:[[111],256],8501:[[1488],256],8502:[[1489],256],8503:[[1490],256],8504:[[1491],256],8505:[[105],256],8507:[[70,65,88],256],8508:[[960],256],8509:[[947],256],8510:[[915],256],8511:[[928],256],8512:[[8721],256],8517:[[68],256],8518:[[100],256],8519:[[101],256],8520:[[105],256],8521:[[106],256],8528:[[49,8260,55],256],8529:[[49,8260,57],256],8530:[[49,8260,49,48],256],8531:[[49,8260,51],256],8532:[[50,8260,51],256],8533:[[49,8260,53],256],8534:[[50,8260,53],256],8535:[[51,8260,53],256],8536:[[52,8260,53],256],8537:[[49,8260,54],256],8538:[[53,8260,54],256],8539:[[49,8260,56],256],8540:[[51,8260,56],256],8541:[[53,8260,56],256],8542:[[55,8260,56],256],8543:[[49,8260],256],8544:[[73],256],8545:[[73,73],256],8546:[[73,73,73],256],8547:[[73,86],256],8548:[[86],256],8549:[[86,73],256],8550:[[86,73,73],256],8551:[[86,73,73,73],256],8552:[[73,88],256],8553:[[88],256],8554:[[88,73],256],8555:[[88,73,73],256],8556:[[76],256],8557:[[67],256],8558:[[68],256],8559:[[77],256],8560:[[105],256],8561:[[105,105],256],8562:[[105,105,105],256],8563:[[105,118],256],8564:[[118],256],8565:[[118,105],256],8566:[[118,105,105],256],8567:[[118,105,105,105],256],8568:[[105,120],256],8569:[[120],256],8570:[[120,105],256],8571:[[120,105,105],256],8572:[[108],256],8573:[[99],256],8574:[[100],256],8575:[[109],256],8585:[[48,8260,51],256],8592:[,,{824:8602}],8594:[,,{824:8603}],8596:[,,{824:8622}],8602:[[8592,824]],8603:[[8594,824]],8622:[[8596,824]],8653:[[8656,824]],8654:[[8660,824]],8655:[[8658,824]],8656:[,,{824:8653}],8658:[,,{824:8655}],8660:[,,{824:8654}]}, -8704:{8707:[,,{824:8708}],8708:[[8707,824]],8712:[,,{824:8713}],8713:[[8712,824]],8715:[,,{824:8716}],8716:[[8715,824]],8739:[,,{824:8740}],8740:[[8739,824]],8741:[,,{824:8742}],8742:[[8741,824]],8748:[[8747,8747],256],8749:[[8747,8747,8747],256],8751:[[8750,8750],256],8752:[[8750,8750,8750],256],8764:[,,{824:8769}],8769:[[8764,824]],8771:[,,{824:8772}],8772:[[8771,824]],8773:[,,{824:8775}],8775:[[8773,824]],8776:[,,{824:8777}],8777:[[8776,824]],8781:[,,{824:8813}],8800:[[61,824]],8801:[,,{824:8802}],8802:[[8801,824]],8804:[,,{824:8816}],8805:[,,{824:8817}],8813:[[8781,824]],8814:[[60,824]],8815:[[62,824]],8816:[[8804,824]],8817:[[8805,824]],8818:[,,{824:8820}],8819:[,,{824:8821}],8820:[[8818,824]],8821:[[8819,824]],8822:[,,{824:8824}],8823:[,,{824:8825}],8824:[[8822,824]],8825:[[8823,824]],8826:[,,{824:8832}],8827:[,,{824:8833}],8828:[,,{824:8928}],8829:[,,{824:8929}],8832:[[8826,824]],8833:[[8827,824]],8834:[,,{824:8836}],8835:[,,{824:8837}],8836:[[8834,824]],8837:[[8835,824]],8838:[,,{824:8840}],8839:[,,{824:8841}],8840:[[8838,824]],8841:[[8839,824]],8849:[,,{824:8930}],8850:[,,{824:8931}],8866:[,,{824:8876}],8872:[,,{824:8877}],8873:[,,{824:8878}],8875:[,,{824:8879}],8876:[[8866,824]],8877:[[8872,824]],8878:[[8873,824]],8879:[[8875,824]],8882:[,,{824:8938}],8883:[,,{824:8939}],8884:[,,{824:8940}],8885:[,,{824:8941}],8928:[[8828,824]],8929:[[8829,824]],8930:[[8849,824]],8931:[[8850,824]],8938:[[8882,824]],8939:[[8883,824]],8940:[[8884,824]],8941:[[8885,824]]}, -8960:{9001:[[12296]],9002:[[12297]]}, -9216:{9312:[[49],256],9313:[[50],256],9314:[[51],256],9315:[[52],256],9316:[[53],256],9317:[[54],256],9318:[[55],256],9319:[[56],256],9320:[[57],256],9321:[[49,48],256],9322:[[49,49],256],9323:[[49,50],256],9324:[[49,51],256],9325:[[49,52],256],9326:[[49,53],256],9327:[[49,54],256],9328:[[49,55],256],9329:[[49,56],256],9330:[[49,57],256],9331:[[50,48],256],9332:[[40,49,41],256],9333:[[40,50,41],256],9334:[[40,51,41],256],9335:[[40,52,41],256],9336:[[40,53,41],256],9337:[[40,54,41],256],9338:[[40,55,41],256],9339:[[40,56,41],256],9340:[[40,57,41],256],9341:[[40,49,48,41],256],9342:[[40,49,49,41],256],9343:[[40,49,50,41],256],9344:[[40,49,51,41],256],9345:[[40,49,52,41],256],9346:[[40,49,53,41],256],9347:[[40,49,54,41],256],9348:[[40,49,55,41],256],9349:[[40,49,56,41],256],9350:[[40,49,57,41],256],9351:[[40,50,48,41],256],9352:[[49,46],256],9353:[[50,46],256],9354:[[51,46],256],9355:[[52,46],256],9356:[[53,46],256],9357:[[54,46],256],9358:[[55,46],256],9359:[[56,46],256],9360:[[57,46],256],9361:[[49,48,46],256],9362:[[49,49,46],256],9363:[[49,50,46],256],9364:[[49,51,46],256],9365:[[49,52,46],256],9366:[[49,53,46],256],9367:[[49,54,46],256],9368:[[49,55,46],256],9369:[[49,56,46],256],9370:[[49,57,46],256],9371:[[50,48,46],256],9372:[[40,97,41],256],9373:[[40,98,41],256],9374:[[40,99,41],256],9375:[[40,100,41],256],9376:[[40,101,41],256],9377:[[40,102,41],256],9378:[[40,103,41],256],9379:[[40,104,41],256],9380:[[40,105,41],256],9381:[[40,106,41],256],9382:[[40,107,41],256],9383:[[40,108,41],256],9384:[[40,109,41],256],9385:[[40,110,41],256],9386:[[40,111,41],256],9387:[[40,112,41],256],9388:[[40,113,41],256],9389:[[40,114,41],256],9390:[[40,115,41],256],9391:[[40,116,41],256],9392:[[40,117,41],256],9393:[[40,118,41],256],9394:[[40,119,41],256],9395:[[40,120,41],256],9396:[[40,121,41],256],9397:[[40,122,41],256],9398:[[65],256],9399:[[66],256],9400:[[67],256],9401:[[68],256],9402:[[69],256],9403:[[70],256],9404:[[71],256],9405:[[72],256],9406:[[73],256],9407:[[74],256],9408:[[75],256],9409:[[76],256],9410:[[77],256],9411:[[78],256],9412:[[79],256],9413:[[80],256],9414:[[81],256],9415:[[82],256],9416:[[83],256],9417:[[84],256],9418:[[85],256],9419:[[86],256],9420:[[87],256],9421:[[88],256],9422:[[89],256],9423:[[90],256],9424:[[97],256],9425:[[98],256],9426:[[99],256],9427:[[100],256],9428:[[101],256],9429:[[102],256],9430:[[103],256],9431:[[104],256],9432:[[105],256],9433:[[106],256],9434:[[107],256],9435:[[108],256],9436:[[109],256],9437:[[110],256],9438:[[111],256],9439:[[112],256],9440:[[113],256],9441:[[114],256],9442:[[115],256],9443:[[116],256],9444:[[117],256],9445:[[118],256],9446:[[119],256],9447:[[120],256],9448:[[121],256],9449:[[122],256],9450:[[48],256]}, -10752:{10764:[[8747,8747,8747,8747],256],10868:[[58,58,61],256],10869:[[61,61],256],10870:[[61,61,61],256],10972:[[10973,824],512]}, -11264:{11388:[[106],256],11389:[[86],256],11503:[,230],11504:[,230],11505:[,230]}, -11520:{11631:[[11617],256],11647:[,9],11744:[,230],11745:[,230],11746:[,230],11747:[,230],11748:[,230],11749:[,230],11750:[,230],11751:[,230],11752:[,230],11753:[,230],11754:[,230],11755:[,230],11756:[,230],11757:[,230],11758:[,230],11759:[,230],11760:[,230],11761:[,230],11762:[,230],11763:[,230],11764:[,230],11765:[,230],11766:[,230],11767:[,230],11768:[,230],11769:[,230],11770:[,230],11771:[,230],11772:[,230],11773:[,230],11774:[,230],11775:[,230]}, -11776:{11935:[[27597],256],12019:[[40863],256]}, -12032:{12032:[[19968],256],12033:[[20008],256],12034:[[20022],256],12035:[[20031],256],12036:[[20057],256],12037:[[20101],256],12038:[[20108],256],12039:[[20128],256],12040:[[20154],256],12041:[[20799],256],12042:[[20837],256],12043:[[20843],256],12044:[[20866],256],12045:[[20886],256],12046:[[20907],256],12047:[[20960],256],12048:[[20981],256],12049:[[20992],256],12050:[[21147],256],12051:[[21241],256],12052:[[21269],256],12053:[[21274],256],12054:[[21304],256],12055:[[21313],256],12056:[[21340],256],12057:[[21353],256],12058:[[21378],256],12059:[[21430],256],12060:[[21448],256],12061:[[21475],256],12062:[[22231],256],12063:[[22303],256],12064:[[22763],256],12065:[[22786],256],12066:[[22794],256],12067:[[22805],256],12068:[[22823],256],12069:[[22899],256],12070:[[23376],256],12071:[[23424],256],12072:[[23544],256],12073:[[23567],256],12074:[[23586],256],12075:[[23608],256],12076:[[23662],256],12077:[[23665],256],12078:[[24027],256],12079:[[24037],256],12080:[[24049],256],12081:[[24062],256],12082:[[24178],256],12083:[[24186],256],12084:[[24191],256],12085:[[24308],256],12086:[[24318],256],12087:[[24331],256],12088:[[24339],256],12089:[[24400],256],12090:[[24417],256],12091:[[24435],256],12092:[[24515],256],12093:[[25096],256],12094:[[25142],256],12095:[[25163],256],12096:[[25903],256],12097:[[25908],256],12098:[[25991],256],12099:[[26007],256],12100:[[26020],256],12101:[[26041],256],12102:[[26080],256],12103:[[26085],256],12104:[[26352],256],12105:[[26376],256],12106:[[26408],256],12107:[[27424],256],12108:[[27490],256],12109:[[27513],256],12110:[[27571],256],12111:[[27595],256],12112:[[27604],256],12113:[[27611],256],12114:[[27663],256],12115:[[27668],256],12116:[[27700],256],12117:[[28779],256],12118:[[29226],256],12119:[[29238],256],12120:[[29243],256],12121:[[29247],256],12122:[[29255],256],12123:[[29273],256],12124:[[29275],256],12125:[[29356],256],12126:[[29572],256],12127:[[29577],256],12128:[[29916],256],12129:[[29926],256],12130:[[29976],256],12131:[[29983],256],12132:[[29992],256],12133:[[30000],256],12134:[[30091],256],12135:[[30098],256],12136:[[30326],256],12137:[[30333],256],12138:[[30382],256],12139:[[30399],256],12140:[[30446],256],12141:[[30683],256],12142:[[30690],256],12143:[[30707],256],12144:[[31034],256],12145:[[31160],256],12146:[[31166],256],12147:[[31348],256],12148:[[31435],256],12149:[[31481],256],12150:[[31859],256],12151:[[31992],256],12152:[[32566],256],12153:[[32593],256],12154:[[32650],256],12155:[[32701],256],12156:[[32769],256],12157:[[32780],256],12158:[[32786],256],12159:[[32819],256],12160:[[32895],256],12161:[[32905],256],12162:[[33251],256],12163:[[33258],256],12164:[[33267],256],12165:[[33276],256],12166:[[33292],256],12167:[[33307],256],12168:[[33311],256],12169:[[33390],256],12170:[[33394],256],12171:[[33400],256],12172:[[34381],256],12173:[[34411],256],12174:[[34880],256],12175:[[34892],256],12176:[[34915],256],12177:[[35198],256],12178:[[35211],256],12179:[[35282],256],12180:[[35328],256],12181:[[35895],256],12182:[[35910],256],12183:[[35925],256],12184:[[35960],256],12185:[[35997],256],12186:[[36196],256],12187:[[36208],256],12188:[[36275],256],12189:[[36523],256],12190:[[36554],256],12191:[[36763],256],12192:[[36784],256],12193:[[36789],256],12194:[[37009],256],12195:[[37193],256],12196:[[37318],256],12197:[[37324],256],12198:[[37329],256],12199:[[38263],256],12200:[[38272],256],12201:[[38428],256],12202:[[38582],256],12203:[[38585],256],12204:[[38632],256],12205:[[38737],256],12206:[[38750],256],12207:[[38754],256],12208:[[38761],256],12209:[[38859],256],12210:[[38893],256],12211:[[38899],256],12212:[[38913],256],12213:[[39080],256],12214:[[39131],256],12215:[[39135],256],12216:[[39318],256],12217:[[39321],256],12218:[[39340],256],12219:[[39592],256],12220:[[39640],256],12221:[[39647],256],12222:[[39717],256],12223:[[39727],256],12224:[[39730],256],12225:[[39740],256],12226:[[39770],256],12227:[[40165],256],12228:[[40565],256],12229:[[40575],256],12230:[[40613],256],12231:[[40635],256],12232:[[40643],256],12233:[[40653],256],12234:[[40657],256],12235:[[40697],256],12236:[[40701],256],12237:[[40718],256],12238:[[40723],256],12239:[[40736],256],12240:[[40763],256],12241:[[40778],256],12242:[[40786],256],12243:[[40845],256],12244:[[40860],256],12245:[[40864],256]}, -12288:{12288:[[32],256],12330:[,218],12331:[,228],12332:[,232],12333:[,222],12334:[,224],12335:[,224],12342:[[12306],256],12344:[[21313],256],12345:[[21316],256],12346:[[21317],256],12358:[,,{12441:12436}],12363:[,,{12441:12364}],12364:[[12363,12441]],12365:[,,{12441:12366}],12366:[[12365,12441]],12367:[,,{12441:12368}],12368:[[12367,12441]],12369:[,,{12441:12370}],12370:[[12369,12441]],12371:[,,{12441:12372}],12372:[[12371,12441]],12373:[,,{12441:12374}],12374:[[12373,12441]],12375:[,,{12441:12376}],12376:[[12375,12441]],12377:[,,{12441:12378}],12378:[[12377,12441]],12379:[,,{12441:12380}],12380:[[12379,12441]],12381:[,,{12441:12382}],12382:[[12381,12441]],12383:[,,{12441:12384}],12384:[[12383,12441]],12385:[,,{12441:12386}],12386:[[12385,12441]],12388:[,,{12441:12389}],12389:[[12388,12441]],12390:[,,{12441:12391}],12391:[[12390,12441]],12392:[,,{12441:12393}],12393:[[12392,12441]],12399:[,,{12441:12400,12442:12401}],12400:[[12399,12441]],12401:[[12399,12442]],12402:[,,{12441:12403,12442:12404}],12403:[[12402,12441]],12404:[[12402,12442]],12405:[,,{12441:12406,12442:12407}],12406:[[12405,12441]],12407:[[12405,12442]],12408:[,,{12441:12409,12442:12410}],12409:[[12408,12441]],12410:[[12408,12442]],12411:[,,{12441:12412,12442:12413}],12412:[[12411,12441]],12413:[[12411,12442]],12436:[[12358,12441]],12441:[,8],12442:[,8],12443:[[32,12441],256],12444:[[32,12442],256],12445:[,,{12441:12446}],12446:[[12445,12441]],12447:[[12424,12426],256],12454:[,,{12441:12532}],12459:[,,{12441:12460}],12460:[[12459,12441]],12461:[,,{12441:12462}],12462:[[12461,12441]],12463:[,,{12441:12464}],12464:[[12463,12441]],12465:[,,{12441:12466}],12466:[[12465,12441]],12467:[,,{12441:12468}],12468:[[12467,12441]],12469:[,,{12441:12470}],12470:[[12469,12441]],12471:[,,{12441:12472}],12472:[[12471,12441]],12473:[,,{12441:12474}],12474:[[12473,12441]],12475:[,,{12441:12476}],12476:[[12475,12441]],12477:[,,{12441:12478}],12478:[[12477,12441]],12479:[,,{12441:12480}],12480:[[12479,12441]],12481:[,,{12441:12482}],12482:[[12481,12441]],12484:[,,{12441:12485}],12485:[[12484,12441]],12486:[,,{12441:12487}],12487:[[12486,12441]],12488:[,,{12441:12489}],12489:[[12488,12441]],12495:[,,{12441:12496,12442:12497}],12496:[[12495,12441]],12497:[[12495,12442]],12498:[,,{12441:12499,12442:12500}],12499:[[12498,12441]],12500:[[12498,12442]],12501:[,,{12441:12502,12442:12503}],12502:[[12501,12441]],12503:[[12501,12442]],12504:[,,{12441:12505,12442:12506}],12505:[[12504,12441]],12506:[[12504,12442]],12507:[,,{12441:12508,12442:12509}],12508:[[12507,12441]],12509:[[12507,12442]],12527:[,,{12441:12535}],12528:[,,{12441:12536}],12529:[,,{12441:12537}],12530:[,,{12441:12538}],12532:[[12454,12441]],12535:[[12527,12441]],12536:[[12528,12441]],12537:[[12529,12441]],12538:[[12530,12441]],12541:[,,{12441:12542}],12542:[[12541,12441]],12543:[[12467,12488],256]}, -12544:{12593:[[4352],256],12594:[[4353],256],12595:[[4522],256],12596:[[4354],256],12597:[[4524],256],12598:[[4525],256],12599:[[4355],256],12600:[[4356],256],12601:[[4357],256],12602:[[4528],256],12603:[[4529],256],12604:[[4530],256],12605:[[4531],256],12606:[[4532],256],12607:[[4533],256],12608:[[4378],256],12609:[[4358],256],12610:[[4359],256],12611:[[4360],256],12612:[[4385],256],12613:[[4361],256],12614:[[4362],256],12615:[[4363],256],12616:[[4364],256],12617:[[4365],256],12618:[[4366],256],12619:[[4367],256],12620:[[4368],256],12621:[[4369],256],12622:[[4370],256],12623:[[4449],256],12624:[[4450],256],12625:[[4451],256],12626:[[4452],256],12627:[[4453],256],12628:[[4454],256],12629:[[4455],256],12630:[[4456],256],12631:[[4457],256],12632:[[4458],256],12633:[[4459],256],12634:[[4460],256],12635:[[4461],256],12636:[[4462],256],12637:[[4463],256],12638:[[4464],256],12639:[[4465],256],12640:[[4466],256],12641:[[4467],256],12642:[[4468],256],12643:[[4469],256],12644:[[4448],256],12645:[[4372],256],12646:[[4373],256],12647:[[4551],256],12648:[[4552],256],12649:[[4556],256],12650:[[4558],256],12651:[[4563],256],12652:[[4567],256],12653:[[4569],256],12654:[[4380],256],12655:[[4573],256],12656:[[4575],256],12657:[[4381],256],12658:[[4382],256],12659:[[4384],256],12660:[[4386],256],12661:[[4387],256],12662:[[4391],256],12663:[[4393],256],12664:[[4395],256],12665:[[4396],256],12666:[[4397],256],12667:[[4398],256],12668:[[4399],256],12669:[[4402],256],12670:[[4406],256],12671:[[4416],256],12672:[[4423],256],12673:[[4428],256],12674:[[4593],256],12675:[[4594],256],12676:[[4439],256],12677:[[4440],256],12678:[[4441],256],12679:[[4484],256],12680:[[4485],256],12681:[[4488],256],12682:[[4497],256],12683:[[4498],256],12684:[[4500],256],12685:[[4510],256],12686:[[4513],256],12690:[[19968],256],12691:[[20108],256],12692:[[19977],256],12693:[[22235],256],12694:[[19978],256],12695:[[20013],256],12696:[[19979],256],12697:[[30002],256],12698:[[20057],256],12699:[[19993],256],12700:[[19969],256],12701:[[22825],256],12702:[[22320],256],12703:[[20154],256]}, -12800:{12800:[[40,4352,41],256],12801:[[40,4354,41],256],12802:[[40,4355,41],256],12803:[[40,4357,41],256],12804:[[40,4358,41],256],12805:[[40,4359,41],256],12806:[[40,4361,41],256],12807:[[40,4363,41],256],12808:[[40,4364,41],256],12809:[[40,4366,41],256],12810:[[40,4367,41],256],12811:[[40,4368,41],256],12812:[[40,4369,41],256],12813:[[40,4370,41],256],12814:[[40,4352,4449,41],256],12815:[[40,4354,4449,41],256],12816:[[40,4355,4449,41],256],12817:[[40,4357,4449,41],256],12818:[[40,4358,4449,41],256],12819:[[40,4359,4449,41],256],12820:[[40,4361,4449,41],256],12821:[[40,4363,4449,41],256],12822:[[40,4364,4449,41],256],12823:[[40,4366,4449,41],256],12824:[[40,4367,4449,41],256],12825:[[40,4368,4449,41],256],12826:[[40,4369,4449,41],256],12827:[[40,4370,4449,41],256],12828:[[40,4364,4462,41],256],12829:[[40,4363,4457,4364,4453,4523,41],256],12830:[[40,4363,4457,4370,4462,41],256],12832:[[40,19968,41],256],12833:[[40,20108,41],256],12834:[[40,19977,41],256],12835:[[40,22235,41],256],12836:[[40,20116,41],256],12837:[[40,20845,41],256],12838:[[40,19971,41],256],12839:[[40,20843,41],256],12840:[[40,20061,41],256],12841:[[40,21313,41],256],12842:[[40,26376,41],256],12843:[[40,28779,41],256],12844:[[40,27700,41],256],12845:[[40,26408,41],256],12846:[[40,37329,41],256],12847:[[40,22303,41],256],12848:[[40,26085,41],256],12849:[[40,26666,41],256],12850:[[40,26377,41],256],12851:[[40,31038,41],256],12852:[[40,21517,41],256],12853:[[40,29305,41],256],12854:[[40,36001,41],256],12855:[[40,31069,41],256],12856:[[40,21172,41],256],12857:[[40,20195,41],256],12858:[[40,21628,41],256],12859:[[40,23398,41],256],12860:[[40,30435,41],256],12861:[[40,20225,41],256],12862:[[40,36039,41],256],12863:[[40,21332,41],256],12864:[[40,31085,41],256],12865:[[40,20241,41],256],12866:[[40,33258,41],256],12867:[[40,33267,41],256],12868:[[21839],256],12869:[[24188],256],12870:[[25991],256],12871:[[31631],256],12880:[[80,84,69],256],12881:[[50,49],256],12882:[[50,50],256],12883:[[50,51],256],12884:[[50,52],256],12885:[[50,53],256],12886:[[50,54],256],12887:[[50,55],256],12888:[[50,56],256],12889:[[50,57],256],12890:[[51,48],256],12891:[[51,49],256],12892:[[51,50],256],12893:[[51,51],256],12894:[[51,52],256],12895:[[51,53],256],12896:[[4352],256],12897:[[4354],256],12898:[[4355],256],12899:[[4357],256],12900:[[4358],256],12901:[[4359],256],12902:[[4361],256],12903:[[4363],256],12904:[[4364],256],12905:[[4366],256],12906:[[4367],256],12907:[[4368],256],12908:[[4369],256],12909:[[4370],256],12910:[[4352,4449],256],12911:[[4354,4449],256],12912:[[4355,4449],256],12913:[[4357,4449],256],12914:[[4358,4449],256],12915:[[4359,4449],256],12916:[[4361,4449],256],12917:[[4363,4449],256],12918:[[4364,4449],256],12919:[[4366,4449],256],12920:[[4367,4449],256],12921:[[4368,4449],256],12922:[[4369,4449],256],12923:[[4370,4449],256],12924:[[4366,4449,4535,4352,4457],256],12925:[[4364,4462,4363,4468],256],12926:[[4363,4462],256],12928:[[19968],256],12929:[[20108],256],12930:[[19977],256],12931:[[22235],256],12932:[[20116],256],12933:[[20845],256],12934:[[19971],256],12935:[[20843],256],12936:[[20061],256],12937:[[21313],256],12938:[[26376],256],12939:[[28779],256],12940:[[27700],256],12941:[[26408],256],12942:[[37329],256],12943:[[22303],256],12944:[[26085],256],12945:[[26666],256],12946:[[26377],256],12947:[[31038],256],12948:[[21517],256],12949:[[29305],256],12950:[[36001],256],12951:[[31069],256],12952:[[21172],256],12953:[[31192],256],12954:[[30007],256],12955:[[22899],256],12956:[[36969],256],12957:[[20778],256],12958:[[21360],256],12959:[[27880],256],12960:[[38917],256],12961:[[20241],256],12962:[[20889],256],12963:[[27491],256],12964:[[19978],256],12965:[[20013],256],12966:[[19979],256],12967:[[24038],256],12968:[[21491],256],12969:[[21307],256],12970:[[23447],256],12971:[[23398],256],12972:[[30435],256],12973:[[20225],256],12974:[[36039],256],12975:[[21332],256],12976:[[22812],256],12977:[[51,54],256],12978:[[51,55],256],12979:[[51,56],256],12980:[[51,57],256],12981:[[52,48],256],12982:[[52,49],256],12983:[[52,50],256],12984:[[52,51],256],12985:[[52,52],256],12986:[[52,53],256],12987:[[52,54],256],12988:[[52,55],256],12989:[[52,56],256],12990:[[52,57],256],12991:[[53,48],256],12992:[[49,26376],256],12993:[[50,26376],256],12994:[[51,26376],256],12995:[[52,26376],256],12996:[[53,26376],256],12997:[[54,26376],256],12998:[[55,26376],256],12999:[[56,26376],256],13000:[[57,26376],256],13001:[[49,48,26376],256],13002:[[49,49,26376],256],13003:[[49,50,26376],256],13004:[[72,103],256],13005:[[101,114,103],256],13006:[[101,86],256],13007:[[76,84,68],256],13008:[[12450],256],13009:[[12452],256],13010:[[12454],256],13011:[[12456],256],13012:[[12458],256],13013:[[12459],256],13014:[[12461],256],13015:[[12463],256],13016:[[12465],256],13017:[[12467],256],13018:[[12469],256],13019:[[12471],256],13020:[[12473],256],13021:[[12475],256],13022:[[12477],256],13023:[[12479],256],13024:[[12481],256],13025:[[12484],256],13026:[[12486],256],13027:[[12488],256],13028:[[12490],256],13029:[[12491],256],13030:[[12492],256],13031:[[12493],256],13032:[[12494],256],13033:[[12495],256],13034:[[12498],256],13035:[[12501],256],13036:[[12504],256],13037:[[12507],256],13038:[[12510],256],13039:[[12511],256],13040:[[12512],256],13041:[[12513],256],13042:[[12514],256],13043:[[12516],256],13044:[[12518],256],13045:[[12520],256],13046:[[12521],256],13047:[[12522],256],13048:[[12523],256],13049:[[12524],256],13050:[[12525],256],13051:[[12527],256],13052:[[12528],256],13053:[[12529],256],13054:[[12530],256]}, -13056:{13056:[[12450,12497,12540,12488],256],13057:[[12450,12523,12501,12449],256],13058:[[12450,12531,12506,12450],256],13059:[[12450,12540,12523],256],13060:[[12452,12491,12531,12464],256],13061:[[12452,12531,12481],256],13062:[[12454,12457,12531],256],13063:[[12456,12473,12463,12540,12489],256],13064:[[12456,12540,12459,12540],256],13065:[[12458,12531,12473],256],13066:[[12458,12540,12512],256],13067:[[12459,12452,12522],256],13068:[[12459,12521,12483,12488],256],13069:[[12459,12525,12522,12540],256],13070:[[12460,12525,12531],256],13071:[[12460,12531,12510],256],13072:[[12462,12460],256],13073:[[12462,12491,12540],256],13074:[[12461,12517,12522,12540],256],13075:[[12462,12523,12480,12540],256],13076:[[12461,12525],256],13077:[[12461,12525,12464,12521,12512],256],13078:[[12461,12525,12513,12540,12488,12523],256],13079:[[12461,12525,12527,12483,12488],256],13080:[[12464,12521,12512],256],13081:[[12464,12521,12512,12488,12531],256],13082:[[12463,12523,12476,12452,12525],256],13083:[[12463,12525,12540,12493],256],13084:[[12465,12540,12473],256],13085:[[12467,12523,12490],256],13086:[[12467,12540,12509],256],13087:[[12469,12452,12463,12523],256],13088:[[12469,12531,12481,12540,12512],256],13089:[[12471,12522,12531,12464],256],13090:[[12475,12531,12481],256],13091:[[12475,12531,12488],256],13092:[[12480,12540,12473],256],13093:[[12487,12471],256],13094:[[12489,12523],256],13095:[[12488,12531],256],13096:[[12490,12494],256],13097:[[12494,12483,12488],256],13098:[[12495,12452,12484],256],13099:[[12497,12540,12475,12531,12488],256],13100:[[12497,12540,12484],256],13101:[[12496,12540,12524,12523],256],13102:[[12500,12450,12473,12488,12523],256],13103:[[12500,12463,12523],256],13104:[[12500,12467],256],13105:[[12499,12523],256],13106:[[12501,12449,12521,12483,12489],256],13107:[[12501,12451,12540,12488],256],13108:[[12502,12483,12471,12455,12523],256],13109:[[12501,12521,12531],256],13110:[[12504,12463,12479,12540,12523],256],13111:[[12506,12477],256],13112:[[12506,12491,12498],256],13113:[[12504,12523,12484],256],13114:[[12506,12531,12473],256],13115:[[12506,12540,12472],256],13116:[[12505,12540,12479],256],13117:[[12509,12452,12531,12488],256],13118:[[12508,12523,12488],256],13119:[[12507,12531],256],13120:[[12509,12531,12489],256],13121:[[12507,12540,12523],256],13122:[[12507,12540,12531],256],13123:[[12510,12452,12463,12525],256],13124:[[12510,12452,12523],256],13125:[[12510,12483,12495],256],13126:[[12510,12523,12463],256],13127:[[12510,12531,12471,12519,12531],256],13128:[[12511,12463,12525,12531],256],13129:[[12511,12522],256],13130:[[12511,12522,12496,12540,12523],256],13131:[[12513,12460],256],13132:[[12513,12460,12488,12531],256],13133:[[12513,12540,12488,12523],256],13134:[[12516,12540,12489],256],13135:[[12516,12540,12523],256],13136:[[12518,12450,12531],256],13137:[[12522,12483,12488,12523],256],13138:[[12522,12521],256],13139:[[12523,12500,12540],256],13140:[[12523,12540,12502,12523],256],13141:[[12524,12512],256],13142:[[12524,12531,12488,12466,12531],256],13143:[[12527,12483,12488],256],13144:[[48,28857],256],13145:[[49,28857],256],13146:[[50,28857],256],13147:[[51,28857],256],13148:[[52,28857],256],13149:[[53,28857],256],13150:[[54,28857],256],13151:[[55,28857],256],13152:[[56,28857],256],13153:[[57,28857],256],13154:[[49,48,28857],256],13155:[[49,49,28857],256],13156:[[49,50,28857],256],13157:[[49,51,28857],256],13158:[[49,52,28857],256],13159:[[49,53,28857],256],13160:[[49,54,28857],256],13161:[[49,55,28857],256],13162:[[49,56,28857],256],13163:[[49,57,28857],256],13164:[[50,48,28857],256],13165:[[50,49,28857],256],13166:[[50,50,28857],256],13167:[[50,51,28857],256],13168:[[50,52,28857],256],13169:[[104,80,97],256],13170:[[100,97],256],13171:[[65,85],256],13172:[[98,97,114],256],13173:[[111,86],256],13174:[[112,99],256],13175:[[100,109],256],13176:[[100,109,178],256],13177:[[100,109,179],256],13178:[[73,85],256],13179:[[24179,25104],256],13180:[[26157,21644],256],13181:[[22823,27491],256],13182:[[26126,27835],256],13183:[[26666,24335,20250,31038],256],13184:[[112,65],256],13185:[[110,65],256],13186:[[956,65],256],13187:[[109,65],256],13188:[[107,65],256],13189:[[75,66],256],13190:[[77,66],256],13191:[[71,66],256],13192:[[99,97,108],256],13193:[[107,99,97,108],256],13194:[[112,70],256],13195:[[110,70],256],13196:[[956,70],256],13197:[[956,103],256],13198:[[109,103],256],13199:[[107,103],256],13200:[[72,122],256],13201:[[107,72,122],256],13202:[[77,72,122],256],13203:[[71,72,122],256],13204:[[84,72,122],256],13205:[[956,8467],256],13206:[[109,8467],256],13207:[[100,8467],256],13208:[[107,8467],256],13209:[[102,109],256],13210:[[110,109],256],13211:[[956,109],256],13212:[[109,109],256],13213:[[99,109],256],13214:[[107,109],256],13215:[[109,109,178],256],13216:[[99,109,178],256],13217:[[109,178],256],13218:[[107,109,178],256],13219:[[109,109,179],256],13220:[[99,109,179],256],13221:[[109,179],256],13222:[[107,109,179],256],13223:[[109,8725,115],256],13224:[[109,8725,115,178],256],13225:[[80,97],256],13226:[[107,80,97],256],13227:[[77,80,97],256],13228:[[71,80,97],256],13229:[[114,97,100],256],13230:[[114,97,100,8725,115],256],13231:[[114,97,100,8725,115,178],256],13232:[[112,115],256],13233:[[110,115],256],13234:[[956,115],256],13235:[[109,115],256],13236:[[112,86],256],13237:[[110,86],256],13238:[[956,86],256],13239:[[109,86],256],13240:[[107,86],256],13241:[[77,86],256],13242:[[112,87],256],13243:[[110,87],256],13244:[[956,87],256],13245:[[109,87],256],13246:[[107,87],256],13247:[[77,87],256],13248:[[107,937],256],13249:[[77,937],256],13250:[[97,46,109,46],256],13251:[[66,113],256],13252:[[99,99],256],13253:[[99,100],256],13254:[[67,8725,107,103],256],13255:[[67,111,46],256],13256:[[100,66],256],13257:[[71,121],256],13258:[[104,97],256],13259:[[72,80],256],13260:[[105,110],256],13261:[[75,75],256],13262:[[75,77],256],13263:[[107,116],256],13264:[[108,109],256],13265:[[108,110],256],13266:[[108,111,103],256],13267:[[108,120],256],13268:[[109,98],256],13269:[[109,105,108],256],13270:[[109,111,108],256],13271:[[80,72],256],13272:[[112,46,109,46],256],13273:[[80,80,77],256],13274:[[80,82],256],13275:[[115,114],256],13276:[[83,118],256],13277:[[87,98],256],13278:[[86,8725,109],256],13279:[[65,8725,109],256],13280:[[49,26085],256],13281:[[50,26085],256],13282:[[51,26085],256],13283:[[52,26085],256],13284:[[53,26085],256],13285:[[54,26085],256],13286:[[55,26085],256],13287:[[56,26085],256],13288:[[57,26085],256],13289:[[49,48,26085],256],13290:[[49,49,26085],256],13291:[[49,50,26085],256],13292:[[49,51,26085],256],13293:[[49,52,26085],256],13294:[[49,53,26085],256],13295:[[49,54,26085],256],13296:[[49,55,26085],256],13297:[[49,56,26085],256],13298:[[49,57,26085],256],13299:[[50,48,26085],256],13300:[[50,49,26085],256],13301:[[50,50,26085],256],13302:[[50,51,26085],256],13303:[[50,52,26085],256],13304:[[50,53,26085],256],13305:[[50,54,26085],256],13306:[[50,55,26085],256],13307:[[50,56,26085],256],13308:[[50,57,26085],256],13309:[[51,48,26085],256],13310:[[51,49,26085],256],13311:[[103,97,108],256]}, -27136:{92912:[,1],92913:[,1],92914:[,1],92915:[,1],92916:[,1]}, -27392:{92976:[,230],92977:[,230],92978:[,230],92979:[,230],92980:[,230],92981:[,230],92982:[,230]}, -42496:{42607:[,230],42612:[,230],42613:[,230],42614:[,230],42615:[,230],42616:[,230],42617:[,230],42618:[,230],42619:[,230],42620:[,230],42621:[,230],42652:[[1098],256],42653:[[1100],256],42655:[,230],42736:[,230],42737:[,230]}, -42752:{42864:[[42863],256],43000:[[294],256],43001:[[339],256]}, -43008:{43014:[,9],43204:[,9],43232:[,230],43233:[,230],43234:[,230],43235:[,230],43236:[,230],43237:[,230],43238:[,230],43239:[,230],43240:[,230],43241:[,230],43242:[,230],43243:[,230],43244:[,230],43245:[,230],43246:[,230],43247:[,230],43248:[,230],43249:[,230]}, -43264:{43307:[,220],43308:[,220],43309:[,220],43347:[,9],43443:[,7],43456:[,9]}, -43520:{43696:[,230],43698:[,230],43699:[,230],43700:[,220],43703:[,230],43704:[,230],43710:[,230],43711:[,230],43713:[,230],43766:[,9]}, -43776:{43868:[[42791],256],43869:[[43831],256],43870:[[619],256],43871:[[43858],256],44013:[,9]}, -48128:{113822:[,1]}, -53504:{119134:[[119127,119141],512],119135:[[119128,119141],512],119136:[[119135,119150],512],119137:[[119135,119151],512],119138:[[119135,119152],512],119139:[[119135,119153],512],119140:[[119135,119154],512],119141:[,216],119142:[,216],119143:[,1],119144:[,1],119145:[,1],119149:[,226],119150:[,216],119151:[,216],119152:[,216],119153:[,216],119154:[,216],119163:[,220],119164:[,220],119165:[,220],119166:[,220],119167:[,220],119168:[,220],119169:[,220],119170:[,220],119173:[,230],119174:[,230],119175:[,230],119176:[,230],119177:[,230],119178:[,220],119179:[,220],119210:[,230],119211:[,230],119212:[,230],119213:[,230],119227:[[119225,119141],512],119228:[[119226,119141],512],119229:[[119227,119150],512],119230:[[119228,119150],512],119231:[[119227,119151],512],119232:[[119228,119151],512]}, -53760:{119362:[,230],119363:[,230],119364:[,230]}, -54272:{119808:[[65],256],119809:[[66],256],119810:[[67],256],119811:[[68],256],119812:[[69],256],119813:[[70],256],119814:[[71],256],119815:[[72],256],119816:[[73],256],119817:[[74],256],119818:[[75],256],119819:[[76],256],119820:[[77],256],119821:[[78],256],119822:[[79],256],119823:[[80],256],119824:[[81],256],119825:[[82],256],119826:[[83],256],119827:[[84],256],119828:[[85],256],119829:[[86],256],119830:[[87],256],119831:[[88],256],119832:[[89],256],119833:[[90],256],119834:[[97],256],119835:[[98],256],119836:[[99],256],119837:[[100],256],119838:[[101],256],119839:[[102],256],119840:[[103],256],119841:[[104],256],119842:[[105],256],119843:[[106],256],119844:[[107],256],119845:[[108],256],119846:[[109],256],119847:[[110],256],119848:[[111],256],119849:[[112],256],119850:[[113],256],119851:[[114],256],119852:[[115],256],119853:[[116],256],119854:[[117],256],119855:[[118],256],119856:[[119],256],119857:[[120],256],119858:[[121],256],119859:[[122],256],119860:[[65],256],119861:[[66],256],119862:[[67],256],119863:[[68],256],119864:[[69],256],119865:[[70],256],119866:[[71],256],119867:[[72],256],119868:[[73],256],119869:[[74],256],119870:[[75],256],119871:[[76],256],119872:[[77],256],119873:[[78],256],119874:[[79],256],119875:[[80],256],119876:[[81],256],119877:[[82],256],119878:[[83],256],119879:[[84],256],119880:[[85],256],119881:[[86],256],119882:[[87],256],119883:[[88],256],119884:[[89],256],119885:[[90],256],119886:[[97],256],119887:[[98],256],119888:[[99],256],119889:[[100],256],119890:[[101],256],119891:[[102],256],119892:[[103],256],119894:[[105],256],119895:[[106],256],119896:[[107],256],119897:[[108],256],119898:[[109],256],119899:[[110],256],119900:[[111],256],119901:[[112],256],119902:[[113],256],119903:[[114],256],119904:[[115],256],119905:[[116],256],119906:[[117],256],119907:[[118],256],119908:[[119],256],119909:[[120],256],119910:[[121],256],119911:[[122],256],119912:[[65],256],119913:[[66],256],119914:[[67],256],119915:[[68],256],119916:[[69],256],119917:[[70],256],119918:[[71],256],119919:[[72],256],119920:[[73],256],119921:[[74],256],119922:[[75],256],119923:[[76],256],119924:[[77],256],119925:[[78],256],119926:[[79],256],119927:[[80],256],119928:[[81],256],119929:[[82],256],119930:[[83],256],119931:[[84],256],119932:[[85],256],119933:[[86],256],119934:[[87],256],119935:[[88],256],119936:[[89],256],119937:[[90],256],119938:[[97],256],119939:[[98],256],119940:[[99],256],119941:[[100],256],119942:[[101],256],119943:[[102],256],119944:[[103],256],119945:[[104],256],119946:[[105],256],119947:[[106],256],119948:[[107],256],119949:[[108],256],119950:[[109],256],119951:[[110],256],119952:[[111],256],119953:[[112],256],119954:[[113],256],119955:[[114],256],119956:[[115],256],119957:[[116],256],119958:[[117],256],119959:[[118],256],119960:[[119],256],119961:[[120],256],119962:[[121],256],119963:[[122],256],119964:[[65],256],119966:[[67],256],119967:[[68],256],119970:[[71],256],119973:[[74],256],119974:[[75],256],119977:[[78],256],119978:[[79],256],119979:[[80],256],119980:[[81],256],119982:[[83],256],119983:[[84],256],119984:[[85],256],119985:[[86],256],119986:[[87],256],119987:[[88],256],119988:[[89],256],119989:[[90],256],119990:[[97],256],119991:[[98],256],119992:[[99],256],119993:[[100],256],119995:[[102],256],119997:[[104],256],119998:[[105],256],119999:[[106],256],120000:[[107],256],120001:[[108],256],120002:[[109],256],120003:[[110],256],120005:[[112],256],120006:[[113],256],120007:[[114],256],120008:[[115],256],120009:[[116],256],120010:[[117],256],120011:[[118],256],120012:[[119],256],120013:[[120],256],120014:[[121],256],120015:[[122],256],120016:[[65],256],120017:[[66],256],120018:[[67],256],120019:[[68],256],120020:[[69],256],120021:[[70],256],120022:[[71],256],120023:[[72],256],120024:[[73],256],120025:[[74],256],120026:[[75],256],120027:[[76],256],120028:[[77],256],120029:[[78],256],120030:[[79],256],120031:[[80],256],120032:[[81],256],120033:[[82],256],120034:[[83],256],120035:[[84],256],120036:[[85],256],120037:[[86],256],120038:[[87],256],120039:[[88],256],120040:[[89],256],120041:[[90],256],120042:[[97],256],120043:[[98],256],120044:[[99],256],120045:[[100],256],120046:[[101],256],120047:[[102],256],120048:[[103],256],120049:[[104],256],120050:[[105],256],120051:[[106],256],120052:[[107],256],120053:[[108],256],120054:[[109],256],120055:[[110],256],120056:[[111],256],120057:[[112],256],120058:[[113],256],120059:[[114],256],120060:[[115],256],120061:[[116],256],120062:[[117],256],120063:[[118],256]}, -54528:{120064:[[119],256],120065:[[120],256],120066:[[121],256],120067:[[122],256],120068:[[65],256],120069:[[66],256],120071:[[68],256],120072:[[69],256],120073:[[70],256],120074:[[71],256],120077:[[74],256],120078:[[75],256],120079:[[76],256],120080:[[77],256],120081:[[78],256],120082:[[79],256],120083:[[80],256],120084:[[81],256],120086:[[83],256],120087:[[84],256],120088:[[85],256],120089:[[86],256],120090:[[87],256],120091:[[88],256],120092:[[89],256],120094:[[97],256],120095:[[98],256],120096:[[99],256],120097:[[100],256],120098:[[101],256],120099:[[102],256],120100:[[103],256],120101:[[104],256],120102:[[105],256],120103:[[106],256],120104:[[107],256],120105:[[108],256],120106:[[109],256],120107:[[110],256],120108:[[111],256],120109:[[112],256],120110:[[113],256],120111:[[114],256],120112:[[115],256],120113:[[116],256],120114:[[117],256],120115:[[118],256],120116:[[119],256],120117:[[120],256],120118:[[121],256],120119:[[122],256],120120:[[65],256],120121:[[66],256],120123:[[68],256],120124:[[69],256],120125:[[70],256],120126:[[71],256],120128:[[73],256],120129:[[74],256],120130:[[75],256],120131:[[76],256],120132:[[77],256],120134:[[79],256],120138:[[83],256],120139:[[84],256],120140:[[85],256],120141:[[86],256],120142:[[87],256],120143:[[88],256],120144:[[89],256],120146:[[97],256],120147:[[98],256],120148:[[99],256],120149:[[100],256],120150:[[101],256],120151:[[102],256],120152:[[103],256],120153:[[104],256],120154:[[105],256],120155:[[106],256],120156:[[107],256],120157:[[108],256],120158:[[109],256],120159:[[110],256],120160:[[111],256],120161:[[112],256],120162:[[113],256],120163:[[114],256],120164:[[115],256],120165:[[116],256],120166:[[117],256],120167:[[118],256],120168:[[119],256],120169:[[120],256],120170:[[121],256],120171:[[122],256],120172:[[65],256],120173:[[66],256],120174:[[67],256],120175:[[68],256],120176:[[69],256],120177:[[70],256],120178:[[71],256],120179:[[72],256],120180:[[73],256],120181:[[74],256],120182:[[75],256],120183:[[76],256],120184:[[77],256],120185:[[78],256],120186:[[79],256],120187:[[80],256],120188:[[81],256],120189:[[82],256],120190:[[83],256],120191:[[84],256],120192:[[85],256],120193:[[86],256],120194:[[87],256],120195:[[88],256],120196:[[89],256],120197:[[90],256],120198:[[97],256],120199:[[98],256],120200:[[99],256],120201:[[100],256],120202:[[101],256],120203:[[102],256],120204:[[103],256],120205:[[104],256],120206:[[105],256],120207:[[106],256],120208:[[107],256],120209:[[108],256],120210:[[109],256],120211:[[110],256],120212:[[111],256],120213:[[112],256],120214:[[113],256],120215:[[114],256],120216:[[115],256],120217:[[116],256],120218:[[117],256],120219:[[118],256],120220:[[119],256],120221:[[120],256],120222:[[121],256],120223:[[122],256],120224:[[65],256],120225:[[66],256],120226:[[67],256],120227:[[68],256],120228:[[69],256],120229:[[70],256],120230:[[71],256],120231:[[72],256],120232:[[73],256],120233:[[74],256],120234:[[75],256],120235:[[76],256],120236:[[77],256],120237:[[78],256],120238:[[79],256],120239:[[80],256],120240:[[81],256],120241:[[82],256],120242:[[83],256],120243:[[84],256],120244:[[85],256],120245:[[86],256],120246:[[87],256],120247:[[88],256],120248:[[89],256],120249:[[90],256],120250:[[97],256],120251:[[98],256],120252:[[99],256],120253:[[100],256],120254:[[101],256],120255:[[102],256],120256:[[103],256],120257:[[104],256],120258:[[105],256],120259:[[106],256],120260:[[107],256],120261:[[108],256],120262:[[109],256],120263:[[110],256],120264:[[111],256],120265:[[112],256],120266:[[113],256],120267:[[114],256],120268:[[115],256],120269:[[116],256],120270:[[117],256],120271:[[118],256],120272:[[119],256],120273:[[120],256],120274:[[121],256],120275:[[122],256],120276:[[65],256],120277:[[66],256],120278:[[67],256],120279:[[68],256],120280:[[69],256],120281:[[70],256],120282:[[71],256],120283:[[72],256],120284:[[73],256],120285:[[74],256],120286:[[75],256],120287:[[76],256],120288:[[77],256],120289:[[78],256],120290:[[79],256],120291:[[80],256],120292:[[81],256],120293:[[82],256],120294:[[83],256],120295:[[84],256],120296:[[85],256],120297:[[86],256],120298:[[87],256],120299:[[88],256],120300:[[89],256],120301:[[90],256],120302:[[97],256],120303:[[98],256],120304:[[99],256],120305:[[100],256],120306:[[101],256],120307:[[102],256],120308:[[103],256],120309:[[104],256],120310:[[105],256],120311:[[106],256],120312:[[107],256],120313:[[108],256],120314:[[109],256],120315:[[110],256],120316:[[111],256],120317:[[112],256],120318:[[113],256],120319:[[114],256]}, -54784:{120320:[[115],256],120321:[[116],256],120322:[[117],256],120323:[[118],256],120324:[[119],256],120325:[[120],256],120326:[[121],256],120327:[[122],256],120328:[[65],256],120329:[[66],256],120330:[[67],256],120331:[[68],256],120332:[[69],256],120333:[[70],256],120334:[[71],256],120335:[[72],256],120336:[[73],256],120337:[[74],256],120338:[[75],256],120339:[[76],256],120340:[[77],256],120341:[[78],256],120342:[[79],256],120343:[[80],256],120344:[[81],256],120345:[[82],256],120346:[[83],256],120347:[[84],256],120348:[[85],256],120349:[[86],256],120350:[[87],256],120351:[[88],256],120352:[[89],256],120353:[[90],256],120354:[[97],256],120355:[[98],256],120356:[[99],256],120357:[[100],256],120358:[[101],256],120359:[[102],256],120360:[[103],256],120361:[[104],256],120362:[[105],256],120363:[[106],256],120364:[[107],256],120365:[[108],256],120366:[[109],256],120367:[[110],256],120368:[[111],256],120369:[[112],256],120370:[[113],256],120371:[[114],256],120372:[[115],256],120373:[[116],256],120374:[[117],256],120375:[[118],256],120376:[[119],256],120377:[[120],256],120378:[[121],256],120379:[[122],256],120380:[[65],256],120381:[[66],256],120382:[[67],256],120383:[[68],256],120384:[[69],256],120385:[[70],256],120386:[[71],256],120387:[[72],256],120388:[[73],256],120389:[[74],256],120390:[[75],256],120391:[[76],256],120392:[[77],256],120393:[[78],256],120394:[[79],256],120395:[[80],256],120396:[[81],256],120397:[[82],256],120398:[[83],256],120399:[[84],256],120400:[[85],256],120401:[[86],256],120402:[[87],256],120403:[[88],256],120404:[[89],256],120405:[[90],256],120406:[[97],256],120407:[[98],256],120408:[[99],256],120409:[[100],256],120410:[[101],256],120411:[[102],256],120412:[[103],256],120413:[[104],256],120414:[[105],256],120415:[[106],256],120416:[[107],256],120417:[[108],256],120418:[[109],256],120419:[[110],256],120420:[[111],256],120421:[[112],256],120422:[[113],256],120423:[[114],256],120424:[[115],256],120425:[[116],256],120426:[[117],256],120427:[[118],256],120428:[[119],256],120429:[[120],256],120430:[[121],256],120431:[[122],256],120432:[[65],256],120433:[[66],256],120434:[[67],256],120435:[[68],256],120436:[[69],256],120437:[[70],256],120438:[[71],256],120439:[[72],256],120440:[[73],256],120441:[[74],256],120442:[[75],256],120443:[[76],256],120444:[[77],256],120445:[[78],256],120446:[[79],256],120447:[[80],256],120448:[[81],256],120449:[[82],256],120450:[[83],256],120451:[[84],256],120452:[[85],256],120453:[[86],256],120454:[[87],256],120455:[[88],256],120456:[[89],256],120457:[[90],256],120458:[[97],256],120459:[[98],256],120460:[[99],256],120461:[[100],256],120462:[[101],256],120463:[[102],256],120464:[[103],256],120465:[[104],256],120466:[[105],256],120467:[[106],256],120468:[[107],256],120469:[[108],256],120470:[[109],256],120471:[[110],256],120472:[[111],256],120473:[[112],256],120474:[[113],256],120475:[[114],256],120476:[[115],256],120477:[[116],256],120478:[[117],256],120479:[[118],256],120480:[[119],256],120481:[[120],256],120482:[[121],256],120483:[[122],256],120484:[[305],256],120485:[[567],256],120488:[[913],256],120489:[[914],256],120490:[[915],256],120491:[[916],256],120492:[[917],256],120493:[[918],256],120494:[[919],256],120495:[[920],256],120496:[[921],256],120497:[[922],256],120498:[[923],256],120499:[[924],256],120500:[[925],256],120501:[[926],256],120502:[[927],256],120503:[[928],256],120504:[[929],256],120505:[[1012],256],120506:[[931],256],120507:[[932],256],120508:[[933],256],120509:[[934],256],120510:[[935],256],120511:[[936],256],120512:[[937],256],120513:[[8711],256],120514:[[945],256],120515:[[946],256],120516:[[947],256],120517:[[948],256],120518:[[949],256],120519:[[950],256],120520:[[951],256],120521:[[952],256],120522:[[953],256],120523:[[954],256],120524:[[955],256],120525:[[956],256],120526:[[957],256],120527:[[958],256],120528:[[959],256],120529:[[960],256],120530:[[961],256],120531:[[962],256],120532:[[963],256],120533:[[964],256],120534:[[965],256],120535:[[966],256],120536:[[967],256],120537:[[968],256],120538:[[969],256],120539:[[8706],256],120540:[[1013],256],120541:[[977],256],120542:[[1008],256],120543:[[981],256],120544:[[1009],256],120545:[[982],256],120546:[[913],256],120547:[[914],256],120548:[[915],256],120549:[[916],256],120550:[[917],256],120551:[[918],256],120552:[[919],256],120553:[[920],256],120554:[[921],256],120555:[[922],256],120556:[[923],256],120557:[[924],256],120558:[[925],256],120559:[[926],256],120560:[[927],256],120561:[[928],256],120562:[[929],256],120563:[[1012],256],120564:[[931],256],120565:[[932],256],120566:[[933],256],120567:[[934],256],120568:[[935],256],120569:[[936],256],120570:[[937],256],120571:[[8711],256],120572:[[945],256],120573:[[946],256],120574:[[947],256],120575:[[948],256]}, -55040:{120576:[[949],256],120577:[[950],256],120578:[[951],256],120579:[[952],256],120580:[[953],256],120581:[[954],256],120582:[[955],256],120583:[[956],256],120584:[[957],256],120585:[[958],256],120586:[[959],256],120587:[[960],256],120588:[[961],256],120589:[[962],256],120590:[[963],256],120591:[[964],256],120592:[[965],256],120593:[[966],256],120594:[[967],256],120595:[[968],256],120596:[[969],256],120597:[[8706],256],120598:[[1013],256],120599:[[977],256],120600:[[1008],256],120601:[[981],256],120602:[[1009],256],120603:[[982],256],120604:[[913],256],120605:[[914],256],120606:[[915],256],120607:[[916],256],120608:[[917],256],120609:[[918],256],120610:[[919],256],120611:[[920],256],120612:[[921],256],120613:[[922],256],120614:[[923],256],120615:[[924],256],120616:[[925],256],120617:[[926],256],120618:[[927],256],120619:[[928],256],120620:[[929],256],120621:[[1012],256],120622:[[931],256],120623:[[932],256],120624:[[933],256],120625:[[934],256],120626:[[935],256],120627:[[936],256],120628:[[937],256],120629:[[8711],256],120630:[[945],256],120631:[[946],256],120632:[[947],256],120633:[[948],256],120634:[[949],256],120635:[[950],256],120636:[[951],256],120637:[[952],256],120638:[[953],256],120639:[[954],256],120640:[[955],256],120641:[[956],256],120642:[[957],256],120643:[[958],256],120644:[[959],256],120645:[[960],256],120646:[[961],256],120647:[[962],256],120648:[[963],256],120649:[[964],256],120650:[[965],256],120651:[[966],256],120652:[[967],256],120653:[[968],256],120654:[[969],256],120655:[[8706],256],120656:[[1013],256],120657:[[977],256],120658:[[1008],256],120659:[[981],256],120660:[[1009],256],120661:[[982],256],120662:[[913],256],120663:[[914],256],120664:[[915],256],120665:[[916],256],120666:[[917],256],120667:[[918],256],120668:[[919],256],120669:[[920],256],120670:[[921],256],120671:[[922],256],120672:[[923],256],120673:[[924],256],120674:[[925],256],120675:[[926],256],120676:[[927],256],120677:[[928],256],120678:[[929],256],120679:[[1012],256],120680:[[931],256],120681:[[932],256],120682:[[933],256],120683:[[934],256],120684:[[935],256],120685:[[936],256],120686:[[937],256],120687:[[8711],256],120688:[[945],256],120689:[[946],256],120690:[[947],256],120691:[[948],256],120692:[[949],256],120693:[[950],256],120694:[[951],256],120695:[[952],256],120696:[[953],256],120697:[[954],256],120698:[[955],256],120699:[[956],256],120700:[[957],256],120701:[[958],256],120702:[[959],256],120703:[[960],256],120704:[[961],256],120705:[[962],256],120706:[[963],256],120707:[[964],256],120708:[[965],256],120709:[[966],256],120710:[[967],256],120711:[[968],256],120712:[[969],256],120713:[[8706],256],120714:[[1013],256],120715:[[977],256],120716:[[1008],256],120717:[[981],256],120718:[[1009],256],120719:[[982],256],120720:[[913],256],120721:[[914],256],120722:[[915],256],120723:[[916],256],120724:[[917],256],120725:[[918],256],120726:[[919],256],120727:[[920],256],120728:[[921],256],120729:[[922],256],120730:[[923],256],120731:[[924],256],120732:[[925],256],120733:[[926],256],120734:[[927],256],120735:[[928],256],120736:[[929],256],120737:[[1012],256],120738:[[931],256],120739:[[932],256],120740:[[933],256],120741:[[934],256],120742:[[935],256],120743:[[936],256],120744:[[937],256],120745:[[8711],256],120746:[[945],256],120747:[[946],256],120748:[[947],256],120749:[[948],256],120750:[[949],256],120751:[[950],256],120752:[[951],256],120753:[[952],256],120754:[[953],256],120755:[[954],256],120756:[[955],256],120757:[[956],256],120758:[[957],256],120759:[[958],256],120760:[[959],256],120761:[[960],256],120762:[[961],256],120763:[[962],256],120764:[[963],256],120765:[[964],256],120766:[[965],256],120767:[[966],256],120768:[[967],256],120769:[[968],256],120770:[[969],256],120771:[[8706],256],120772:[[1013],256],120773:[[977],256],120774:[[1008],256],120775:[[981],256],120776:[[1009],256],120777:[[982],256],120778:[[988],256],120779:[[989],256],120782:[[48],256],120783:[[49],256],120784:[[50],256],120785:[[51],256],120786:[[52],256],120787:[[53],256],120788:[[54],256],120789:[[55],256],120790:[[56],256],120791:[[57],256],120792:[[48],256],120793:[[49],256],120794:[[50],256],120795:[[51],256],120796:[[52],256],120797:[[53],256],120798:[[54],256],120799:[[55],256],120800:[[56],256],120801:[[57],256],120802:[[48],256],120803:[[49],256],120804:[[50],256],120805:[[51],256],120806:[[52],256],120807:[[53],256],120808:[[54],256],120809:[[55],256],120810:[[56],256],120811:[[57],256],120812:[[48],256],120813:[[49],256],120814:[[50],256],120815:[[51],256],120816:[[52],256],120817:[[53],256],120818:[[54],256],120819:[[55],256],120820:[[56],256],120821:[[57],256],120822:[[48],256],120823:[[49],256],120824:[[50],256],120825:[[51],256],120826:[[52],256],120827:[[53],256],120828:[[54],256],120829:[[55],256],120830:[[56],256],120831:[[57],256]}, -59392:{125136:[,220],125137:[,220],125138:[,220],125139:[,220],125140:[,220],125141:[,220],125142:[,220]}, -60928:{126464:[[1575],256],126465:[[1576],256],126466:[[1580],256],126467:[[1583],256],126469:[[1608],256],126470:[[1586],256],126471:[[1581],256],126472:[[1591],256],126473:[[1610],256],126474:[[1603],256],126475:[[1604],256],126476:[[1605],256],126477:[[1606],256],126478:[[1587],256],126479:[[1593],256],126480:[[1601],256],126481:[[1589],256],126482:[[1602],256],126483:[[1585],256],126484:[[1588],256],126485:[[1578],256],126486:[[1579],256],126487:[[1582],256],126488:[[1584],256],126489:[[1590],256],126490:[[1592],256],126491:[[1594],256],126492:[[1646],256],126493:[[1722],256],126494:[[1697],256],126495:[[1647],256],126497:[[1576],256],126498:[[1580],256],126500:[[1607],256],126503:[[1581],256],126505:[[1610],256],126506:[[1603],256],126507:[[1604],256],126508:[[1605],256],126509:[[1606],256],126510:[[1587],256],126511:[[1593],256],126512:[[1601],256],126513:[[1589],256],126514:[[1602],256],126516:[[1588],256],126517:[[1578],256],126518:[[1579],256],126519:[[1582],256],126521:[[1590],256],126523:[[1594],256],126530:[[1580],256],126535:[[1581],256],126537:[[1610],256],126539:[[1604],256],126541:[[1606],256],126542:[[1587],256],126543:[[1593],256],126545:[[1589],256],126546:[[1602],256],126548:[[1588],256],126551:[[1582],256],126553:[[1590],256],126555:[[1594],256],126557:[[1722],256],126559:[[1647],256],126561:[[1576],256],126562:[[1580],256],126564:[[1607],256],126567:[[1581],256],126568:[[1591],256],126569:[[1610],256],126570:[[1603],256],126572:[[1605],256],126573:[[1606],256],126574:[[1587],256],126575:[[1593],256],126576:[[1601],256],126577:[[1589],256],126578:[[1602],256],126580:[[1588],256],126581:[[1578],256],126582:[[1579],256],126583:[[1582],256],126585:[[1590],256],126586:[[1592],256],126587:[[1594],256],126588:[[1646],256],126590:[[1697],256],126592:[[1575],256],126593:[[1576],256],126594:[[1580],256],126595:[[1583],256],126596:[[1607],256],126597:[[1608],256],126598:[[1586],256],126599:[[1581],256],126600:[[1591],256],126601:[[1610],256],126603:[[1604],256],126604:[[1605],256],126605:[[1606],256],126606:[[1587],256],126607:[[1593],256],126608:[[1601],256],126609:[[1589],256],126610:[[1602],256],126611:[[1585],256],126612:[[1588],256],126613:[[1578],256],126614:[[1579],256],126615:[[1582],256],126616:[[1584],256],126617:[[1590],256],126618:[[1592],256],126619:[[1594],256],126625:[[1576],256],126626:[[1580],256],126627:[[1583],256],126629:[[1608],256],126630:[[1586],256],126631:[[1581],256],126632:[[1591],256],126633:[[1610],256],126635:[[1604],256],126636:[[1605],256],126637:[[1606],256],126638:[[1587],256],126639:[[1593],256],126640:[[1601],256],126641:[[1589],256],126642:[[1602],256],126643:[[1585],256],126644:[[1588],256],126645:[[1578],256],126646:[[1579],256],126647:[[1582],256],126648:[[1584],256],126649:[[1590],256],126650:[[1592],256],126651:[[1594],256]}, -61696:{127232:[[48,46],256],127233:[[48,44],256],127234:[[49,44],256],127235:[[50,44],256],127236:[[51,44],256],127237:[[52,44],256],127238:[[53,44],256],127239:[[54,44],256],127240:[[55,44],256],127241:[[56,44],256],127242:[[57,44],256],127248:[[40,65,41],256],127249:[[40,66,41],256],127250:[[40,67,41],256],127251:[[40,68,41],256],127252:[[40,69,41],256],127253:[[40,70,41],256],127254:[[40,71,41],256],127255:[[40,72,41],256],127256:[[40,73,41],256],127257:[[40,74,41],256],127258:[[40,75,41],256],127259:[[40,76,41],256],127260:[[40,77,41],256],127261:[[40,78,41],256],127262:[[40,79,41],256],127263:[[40,80,41],256],127264:[[40,81,41],256],127265:[[40,82,41],256],127266:[[40,83,41],256],127267:[[40,84,41],256],127268:[[40,85,41],256],127269:[[40,86,41],256],127270:[[40,87,41],256],127271:[[40,88,41],256],127272:[[40,89,41],256],127273:[[40,90,41],256],127274:[[12308,83,12309],256],127275:[[67],256],127276:[[82],256],127277:[[67,68],256],127278:[[87,90],256],127280:[[65],256],127281:[[66],256],127282:[[67],256],127283:[[68],256],127284:[[69],256],127285:[[70],256],127286:[[71],256],127287:[[72],256],127288:[[73],256],127289:[[74],256],127290:[[75],256],127291:[[76],256],127292:[[77],256],127293:[[78],256],127294:[[79],256],127295:[[80],256],127296:[[81],256],127297:[[82],256],127298:[[83],256],127299:[[84],256],127300:[[85],256],127301:[[86],256],127302:[[87],256],127303:[[88],256],127304:[[89],256],127305:[[90],256],127306:[[72,86],256],127307:[[77,86],256],127308:[[83,68],256],127309:[[83,83],256],127310:[[80,80,86],256],127311:[[87,67],256],127338:[[77,67],256],127339:[[77,68],256],127376:[[68,74],256]}, -61952:{127488:[[12411,12363],256],127489:[[12467,12467],256],127490:[[12469],256],127504:[[25163],256],127505:[[23383],256],127506:[[21452],256],127507:[[12487],256],127508:[[20108],256],127509:[[22810],256],127510:[[35299],256],127511:[[22825],256],127512:[[20132],256],127513:[[26144],256],127514:[[28961],256],127515:[[26009],256],127516:[[21069],256],127517:[[24460],256],127518:[[20877],256],127519:[[26032],256],127520:[[21021],256],127521:[[32066],256],127522:[[29983],256],127523:[[36009],256],127524:[[22768],256],127525:[[21561],256],127526:[[28436],256],127527:[[25237],256],127528:[[25429],256],127529:[[19968],256],127530:[[19977],256],127531:[[36938],256],127532:[[24038],256],127533:[[20013],256],127534:[[21491],256],127535:[[25351],256],127536:[[36208],256],127537:[[25171],256],127538:[[31105],256],127539:[[31354],256],127540:[[21512],256],127541:[[28288],256],127542:[[26377],256],127543:[[26376],256],127544:[[30003],256],127545:[[21106],256],127546:[[21942],256],127552:[[12308,26412,12309],256],127553:[[12308,19977,12309],256],127554:[[12308,20108,12309],256],127555:[[12308,23433,12309],256],127556:[[12308,28857,12309],256],127557:[[12308,25171,12309],256],127558:[[12308,30423,12309],256],127559:[[12308,21213,12309],256],127560:[[12308,25943,12309],256],127568:[[24471],256],127569:[[21487],256]}, -63488:{194560:[[20029]],194561:[[20024]],194562:[[20033]],194563:[[131362]],194564:[[20320]],194565:[[20398]],194566:[[20411]],194567:[[20482]],194568:[[20602]],194569:[[20633]],194570:[[20711]],194571:[[20687]],194572:[[13470]],194573:[[132666]],194574:[[20813]],194575:[[20820]],194576:[[20836]],194577:[[20855]],194578:[[132380]],194579:[[13497]],194580:[[20839]],194581:[[20877]],194582:[[132427]],194583:[[20887]],194584:[[20900]],194585:[[20172]],194586:[[20908]],194587:[[20917]],194588:[[168415]],194589:[[20981]],194590:[[20995]],194591:[[13535]],194592:[[21051]],194593:[[21062]],194594:[[21106]],194595:[[21111]],194596:[[13589]],194597:[[21191]],194598:[[21193]],194599:[[21220]],194600:[[21242]],194601:[[21253]],194602:[[21254]],194603:[[21271]],194604:[[21321]],194605:[[21329]],194606:[[21338]],194607:[[21363]],194608:[[21373]],194609:[[21375]],194610:[[21375]],194611:[[21375]],194612:[[133676]],194613:[[28784]],194614:[[21450]],194615:[[21471]],194616:[[133987]],194617:[[21483]],194618:[[21489]],194619:[[21510]],194620:[[21662]],194621:[[21560]],194622:[[21576]],194623:[[21608]],194624:[[21666]],194625:[[21750]],194626:[[21776]],194627:[[21843]],194628:[[21859]],194629:[[21892]],194630:[[21892]],194631:[[21913]],194632:[[21931]],194633:[[21939]],194634:[[21954]],194635:[[22294]],194636:[[22022]],194637:[[22295]],194638:[[22097]],194639:[[22132]],194640:[[20999]],194641:[[22766]],194642:[[22478]],194643:[[22516]],194644:[[22541]],194645:[[22411]],194646:[[22578]],194647:[[22577]],194648:[[22700]],194649:[[136420]],194650:[[22770]],194651:[[22775]],194652:[[22790]],194653:[[22810]],194654:[[22818]],194655:[[22882]],194656:[[136872]],194657:[[136938]],194658:[[23020]],194659:[[23067]],194660:[[23079]],194661:[[23000]],194662:[[23142]],194663:[[14062]],194664:[[14076]],194665:[[23304]],194666:[[23358]],194667:[[23358]],194668:[[137672]],194669:[[23491]],194670:[[23512]],194671:[[23527]],194672:[[23539]],194673:[[138008]],194674:[[23551]],194675:[[23558]],194676:[[24403]],194677:[[23586]],194678:[[14209]],194679:[[23648]],194680:[[23662]],194681:[[23744]],194682:[[23693]],194683:[[138724]],194684:[[23875]],194685:[[138726]],194686:[[23918]],194687:[[23915]],194688:[[23932]],194689:[[24033]],194690:[[24034]],194691:[[14383]],194692:[[24061]],194693:[[24104]],194694:[[24125]],194695:[[24169]],194696:[[14434]],194697:[[139651]],194698:[[14460]],194699:[[24240]],194700:[[24243]],194701:[[24246]],194702:[[24266]],194703:[[172946]],194704:[[24318]],194705:[[140081]],194706:[[140081]],194707:[[33281]],194708:[[24354]],194709:[[24354]],194710:[[14535]],194711:[[144056]],194712:[[156122]],194713:[[24418]],194714:[[24427]],194715:[[14563]],194716:[[24474]],194717:[[24525]],194718:[[24535]],194719:[[24569]],194720:[[24705]],194721:[[14650]],194722:[[14620]],194723:[[24724]],194724:[[141012]],194725:[[24775]],194726:[[24904]],194727:[[24908]],194728:[[24910]],194729:[[24908]],194730:[[24954]],194731:[[24974]],194732:[[25010]],194733:[[24996]],194734:[[25007]],194735:[[25054]],194736:[[25074]],194737:[[25078]],194738:[[25104]],194739:[[25115]],194740:[[25181]],194741:[[25265]],194742:[[25300]],194743:[[25424]],194744:[[142092]],194745:[[25405]],194746:[[25340]],194747:[[25448]],194748:[[25475]],194749:[[25572]],194750:[[142321]],194751:[[25634]],194752:[[25541]],194753:[[25513]],194754:[[14894]],194755:[[25705]],194756:[[25726]],194757:[[25757]],194758:[[25719]],194759:[[14956]],194760:[[25935]],194761:[[25964]],194762:[[143370]],194763:[[26083]],194764:[[26360]],194765:[[26185]],194766:[[15129]],194767:[[26257]],194768:[[15112]],194769:[[15076]],194770:[[20882]],194771:[[20885]],194772:[[26368]],194773:[[26268]],194774:[[32941]],194775:[[17369]],194776:[[26391]],194777:[[26395]],194778:[[26401]],194779:[[26462]],194780:[[26451]],194781:[[144323]],194782:[[15177]],194783:[[26618]],194784:[[26501]],194785:[[26706]],194786:[[26757]],194787:[[144493]],194788:[[26766]],194789:[[26655]],194790:[[26900]],194791:[[15261]],194792:[[26946]],194793:[[27043]],194794:[[27114]],194795:[[27304]],194796:[[145059]],194797:[[27355]],194798:[[15384]],194799:[[27425]],194800:[[145575]],194801:[[27476]],194802:[[15438]],194803:[[27506]],194804:[[27551]],194805:[[27578]],194806:[[27579]],194807:[[146061]],194808:[[138507]],194809:[[146170]],194810:[[27726]],194811:[[146620]],194812:[[27839]],194813:[[27853]],194814:[[27751]],194815:[[27926]]}, -63744:{63744:[[35912]],63745:[[26356]],63746:[[36554]],63747:[[36040]],63748:[[28369]],63749:[[20018]],63750:[[21477]],63751:[[40860]],63752:[[40860]],63753:[[22865]],63754:[[37329]],63755:[[21895]],63756:[[22856]],63757:[[25078]],63758:[[30313]],63759:[[32645]],63760:[[34367]],63761:[[34746]],63762:[[35064]],63763:[[37007]],63764:[[27138]],63765:[[27931]],63766:[[28889]],63767:[[29662]],63768:[[33853]],63769:[[37226]],63770:[[39409]],63771:[[20098]],63772:[[21365]],63773:[[27396]],63774:[[29211]],63775:[[34349]],63776:[[40478]],63777:[[23888]],63778:[[28651]],63779:[[34253]],63780:[[35172]],63781:[[25289]],63782:[[33240]],63783:[[34847]],63784:[[24266]],63785:[[26391]],63786:[[28010]],63787:[[29436]],63788:[[37070]],63789:[[20358]],63790:[[20919]],63791:[[21214]],63792:[[25796]],63793:[[27347]],63794:[[29200]],63795:[[30439]],63796:[[32769]],63797:[[34310]],63798:[[34396]],63799:[[36335]],63800:[[38706]],63801:[[39791]],63802:[[40442]],63803:[[30860]],63804:[[31103]],63805:[[32160]],63806:[[33737]],63807:[[37636]],63808:[[40575]],63809:[[35542]],63810:[[22751]],63811:[[24324]],63812:[[31840]],63813:[[32894]],63814:[[29282]],63815:[[30922]],63816:[[36034]],63817:[[38647]],63818:[[22744]],63819:[[23650]],63820:[[27155]],63821:[[28122]],63822:[[28431]],63823:[[32047]],63824:[[32311]],63825:[[38475]],63826:[[21202]],63827:[[32907]],63828:[[20956]],63829:[[20940]],63830:[[31260]],63831:[[32190]],63832:[[33777]],63833:[[38517]],63834:[[35712]],63835:[[25295]],63836:[[27138]],63837:[[35582]],63838:[[20025]],63839:[[23527]],63840:[[24594]],63841:[[29575]],63842:[[30064]],63843:[[21271]],63844:[[30971]],63845:[[20415]],63846:[[24489]],63847:[[19981]],63848:[[27852]],63849:[[25976]],63850:[[32034]],63851:[[21443]],63852:[[22622]],63853:[[30465]],63854:[[33865]],63855:[[35498]],63856:[[27578]],63857:[[36784]],63858:[[27784]],63859:[[25342]],63860:[[33509]],63861:[[25504]],63862:[[30053]],63863:[[20142]],63864:[[20841]],63865:[[20937]],63866:[[26753]],63867:[[31975]],63868:[[33391]],63869:[[35538]],63870:[[37327]],63871:[[21237]],63872:[[21570]],63873:[[22899]],63874:[[24300]],63875:[[26053]],63876:[[28670]],63877:[[31018]],63878:[[38317]],63879:[[39530]],63880:[[40599]],63881:[[40654]],63882:[[21147]],63883:[[26310]],63884:[[27511]],63885:[[36706]],63886:[[24180]],63887:[[24976]],63888:[[25088]],63889:[[25754]],63890:[[28451]],63891:[[29001]],63892:[[29833]],63893:[[31178]],63894:[[32244]],63895:[[32879]],63896:[[36646]],63897:[[34030]],63898:[[36899]],63899:[[37706]],63900:[[21015]],63901:[[21155]],63902:[[21693]],63903:[[28872]],63904:[[35010]],63905:[[35498]],63906:[[24265]],63907:[[24565]],63908:[[25467]],63909:[[27566]],63910:[[31806]],63911:[[29557]],63912:[[20196]],63913:[[22265]],63914:[[23527]],63915:[[23994]],63916:[[24604]],63917:[[29618]],63918:[[29801]],63919:[[32666]],63920:[[32838]],63921:[[37428]],63922:[[38646]],63923:[[38728]],63924:[[38936]],63925:[[20363]],63926:[[31150]],63927:[[37300]],63928:[[38584]],63929:[[24801]],63930:[[20102]],63931:[[20698]],63932:[[23534]],63933:[[23615]],63934:[[26009]],63935:[[27138]],63936:[[29134]],63937:[[30274]],63938:[[34044]],63939:[[36988]],63940:[[40845]],63941:[[26248]],63942:[[38446]],63943:[[21129]],63944:[[26491]],63945:[[26611]],63946:[[27969]],63947:[[28316]],63948:[[29705]],63949:[[30041]],63950:[[30827]],63951:[[32016]],63952:[[39006]],63953:[[20845]],63954:[[25134]],63955:[[38520]],63956:[[20523]],63957:[[23833]],63958:[[28138]],63959:[[36650]],63960:[[24459]],63961:[[24900]],63962:[[26647]],63963:[[29575]],63964:[[38534]],63965:[[21033]],63966:[[21519]],63967:[[23653]],63968:[[26131]],63969:[[26446]],63970:[[26792]],63971:[[27877]],63972:[[29702]],63973:[[30178]],63974:[[32633]],63975:[[35023]],63976:[[35041]],63977:[[37324]],63978:[[38626]],63979:[[21311]],63980:[[28346]],63981:[[21533]],63982:[[29136]],63983:[[29848]],63984:[[34298]],63985:[[38563]],63986:[[40023]],63987:[[40607]],63988:[[26519]],63989:[[28107]],63990:[[33256]],63991:[[31435]],63992:[[31520]],63993:[[31890]],63994:[[29376]],63995:[[28825]],63996:[[35672]],63997:[[20160]],63998:[[33590]],63999:[[21050]],194816:[[27966]],194817:[[28023]],194818:[[27969]],194819:[[28009]],194820:[[28024]],194821:[[28037]],194822:[[146718]],194823:[[27956]],194824:[[28207]],194825:[[28270]],194826:[[15667]],194827:[[28363]],194828:[[28359]],194829:[[147153]],194830:[[28153]],194831:[[28526]],194832:[[147294]],194833:[[147342]],194834:[[28614]],194835:[[28729]],194836:[[28702]],194837:[[28699]],194838:[[15766]],194839:[[28746]],194840:[[28797]],194841:[[28791]],194842:[[28845]],194843:[[132389]],194844:[[28997]],194845:[[148067]],194846:[[29084]],194847:[[148395]],194848:[[29224]],194849:[[29237]],194850:[[29264]],194851:[[149000]],194852:[[29312]],194853:[[29333]],194854:[[149301]],194855:[[149524]],194856:[[29562]],194857:[[29579]],194858:[[16044]],194859:[[29605]],194860:[[16056]],194861:[[16056]],194862:[[29767]],194863:[[29788]],194864:[[29809]],194865:[[29829]],194866:[[29898]],194867:[[16155]],194868:[[29988]],194869:[[150582]],194870:[[30014]],194871:[[150674]],194872:[[30064]],194873:[[139679]],194874:[[30224]],194875:[[151457]],194876:[[151480]],194877:[[151620]],194878:[[16380]],194879:[[16392]],194880:[[30452]],194881:[[151795]],194882:[[151794]],194883:[[151833]],194884:[[151859]],194885:[[30494]],194886:[[30495]],194887:[[30495]],194888:[[30538]],194889:[[16441]],194890:[[30603]],194891:[[16454]],194892:[[16534]],194893:[[152605]],194894:[[30798]],194895:[[30860]],194896:[[30924]],194897:[[16611]],194898:[[153126]],194899:[[31062]],194900:[[153242]],194901:[[153285]],194902:[[31119]],194903:[[31211]],194904:[[16687]],194905:[[31296]],194906:[[31306]],194907:[[31311]],194908:[[153980]],194909:[[154279]],194910:[[154279]],194911:[[31470]],194912:[[16898]],194913:[[154539]],194914:[[31686]],194915:[[31689]],194916:[[16935]],194917:[[154752]],194918:[[31954]],194919:[[17056]],194920:[[31976]],194921:[[31971]],194922:[[32000]],194923:[[155526]],194924:[[32099]],194925:[[17153]],194926:[[32199]],194927:[[32258]],194928:[[32325]],194929:[[17204]],194930:[[156200]],194931:[[156231]],194932:[[17241]],194933:[[156377]],194934:[[32634]],194935:[[156478]],194936:[[32661]],194937:[[32762]],194938:[[32773]],194939:[[156890]],194940:[[156963]],194941:[[32864]],194942:[[157096]],194943:[[32880]],194944:[[144223]],194945:[[17365]],194946:[[32946]],194947:[[33027]],194948:[[17419]],194949:[[33086]],194950:[[23221]],194951:[[157607]],194952:[[157621]],194953:[[144275]],194954:[[144284]],194955:[[33281]],194956:[[33284]],194957:[[36766]],194958:[[17515]],194959:[[33425]],194960:[[33419]],194961:[[33437]],194962:[[21171]],194963:[[33457]],194964:[[33459]],194965:[[33469]],194966:[[33510]],194967:[[158524]],194968:[[33509]],194969:[[33565]],194970:[[33635]],194971:[[33709]],194972:[[33571]],194973:[[33725]],194974:[[33767]],194975:[[33879]],194976:[[33619]],194977:[[33738]],194978:[[33740]],194979:[[33756]],194980:[[158774]],194981:[[159083]],194982:[[158933]],194983:[[17707]],194984:[[34033]],194985:[[34035]],194986:[[34070]],194987:[[160714]],194988:[[34148]],194989:[[159532]],194990:[[17757]],194991:[[17761]],194992:[[159665]],194993:[[159954]],194994:[[17771]],194995:[[34384]],194996:[[34396]],194997:[[34407]],194998:[[34409]],194999:[[34473]],195000:[[34440]],195001:[[34574]],195002:[[34530]],195003:[[34681]],195004:[[34600]],195005:[[34667]],195006:[[34694]],195007:[[17879]],195008:[[34785]],195009:[[34817]],195010:[[17913]],195011:[[34912]],195012:[[34915]],195013:[[161383]],195014:[[35031]],195015:[[35038]],195016:[[17973]],195017:[[35066]],195018:[[13499]],195019:[[161966]],195020:[[162150]],195021:[[18110]],195022:[[18119]],195023:[[35488]],195024:[[35565]],195025:[[35722]],195026:[[35925]],195027:[[162984]],195028:[[36011]],195029:[[36033]],195030:[[36123]],195031:[[36215]],195032:[[163631]],195033:[[133124]],195034:[[36299]],195035:[[36284]],195036:[[36336]],195037:[[133342]],195038:[[36564]],195039:[[36664]],195040:[[165330]],195041:[[165357]],195042:[[37012]],195043:[[37105]],195044:[[37137]],195045:[[165678]],195046:[[37147]],195047:[[37432]],195048:[[37591]],195049:[[37592]],195050:[[37500]],195051:[[37881]],195052:[[37909]],195053:[[166906]],195054:[[38283]],195055:[[18837]],195056:[[38327]],195057:[[167287]],195058:[[18918]],195059:[[38595]],195060:[[23986]],195061:[[38691]],195062:[[168261]],195063:[[168474]],195064:[[19054]],195065:[[19062]],195066:[[38880]],195067:[[168970]],195068:[[19122]],195069:[[169110]],195070:[[38923]],195071:[[38923]]}, -64000:{64000:[[20999]],64001:[[24230]],64002:[[25299]],64003:[[31958]],64004:[[23429]],64005:[[27934]],64006:[[26292]],64007:[[36667]],64008:[[34892]],64009:[[38477]],64010:[[35211]],64011:[[24275]],64012:[[20800]],64013:[[21952]],64016:[[22618]],64018:[[26228]],64021:[[20958]],64022:[[29482]],64023:[[30410]],64024:[[31036]],64025:[[31070]],64026:[[31077]],64027:[[31119]],64028:[[38742]],64029:[[31934]],64030:[[32701]],64032:[[34322]],64034:[[35576]],64037:[[36920]],64038:[[37117]],64042:[[39151]],64043:[[39164]],64044:[[39208]],64045:[[40372]],64046:[[37086]],64047:[[38583]],64048:[[20398]],64049:[[20711]],64050:[[20813]],64051:[[21193]],64052:[[21220]],64053:[[21329]],64054:[[21917]],64055:[[22022]],64056:[[22120]],64057:[[22592]],64058:[[22696]],64059:[[23652]],64060:[[23662]],64061:[[24724]],64062:[[24936]],64063:[[24974]],64064:[[25074]],64065:[[25935]],64066:[[26082]],64067:[[26257]],64068:[[26757]],64069:[[28023]],64070:[[28186]],64071:[[28450]],64072:[[29038]],64073:[[29227]],64074:[[29730]],64075:[[30865]],64076:[[31038]],64077:[[31049]],64078:[[31048]],64079:[[31056]],64080:[[31062]],64081:[[31069]],64082:[[31117]],64083:[[31118]],64084:[[31296]],64085:[[31361]],64086:[[31680]],64087:[[32244]],64088:[[32265]],64089:[[32321]],64090:[[32626]],64091:[[32773]],64092:[[33261]],64093:[[33401]],64094:[[33401]],64095:[[33879]],64096:[[35088]],64097:[[35222]],64098:[[35585]],64099:[[35641]],64100:[[36051]],64101:[[36104]],64102:[[36790]],64103:[[36920]],64104:[[38627]],64105:[[38911]],64106:[[38971]],64107:[[24693]],64108:[[148206]],64109:[[33304]],64112:[[20006]],64113:[[20917]],64114:[[20840]],64115:[[20352]],64116:[[20805]],64117:[[20864]],64118:[[21191]],64119:[[21242]],64120:[[21917]],64121:[[21845]],64122:[[21913]],64123:[[21986]],64124:[[22618]],64125:[[22707]],64126:[[22852]],64127:[[22868]],64128:[[23138]],64129:[[23336]],64130:[[24274]],64131:[[24281]],64132:[[24425]],64133:[[24493]],64134:[[24792]],64135:[[24910]],64136:[[24840]],64137:[[24974]],64138:[[24928]],64139:[[25074]],64140:[[25140]],64141:[[25540]],64142:[[25628]],64143:[[25682]],64144:[[25942]],64145:[[26228]],64146:[[26391]],64147:[[26395]],64148:[[26454]],64149:[[27513]],64150:[[27578]],64151:[[27969]],64152:[[28379]],64153:[[28363]],64154:[[28450]],64155:[[28702]],64156:[[29038]],64157:[[30631]],64158:[[29237]],64159:[[29359]],64160:[[29482]],64161:[[29809]],64162:[[29958]],64163:[[30011]],64164:[[30237]],64165:[[30239]],64166:[[30410]],64167:[[30427]],64168:[[30452]],64169:[[30538]],64170:[[30528]],64171:[[30924]],64172:[[31409]],64173:[[31680]],64174:[[31867]],64175:[[32091]],64176:[[32244]],64177:[[32574]],64178:[[32773]],64179:[[33618]],64180:[[33775]],64181:[[34681]],64182:[[35137]],64183:[[35206]],64184:[[35222]],64185:[[35519]],64186:[[35576]],64187:[[35531]],64188:[[35585]],64189:[[35582]],64190:[[35565]],64191:[[35641]],64192:[[35722]],64193:[[36104]],64194:[[36664]],64195:[[36978]],64196:[[37273]],64197:[[37494]],64198:[[38524]],64199:[[38627]],64200:[[38742]],64201:[[38875]],64202:[[38911]],64203:[[38923]],64204:[[38971]],64205:[[39698]],64206:[[40860]],64207:[[141386]],64208:[[141380]],64209:[[144341]],64210:[[15261]],64211:[[16408]],64212:[[16441]],64213:[[152137]],64214:[[154832]],64215:[[163539]],64216:[[40771]],64217:[[40846]],195072:[[38953]],195073:[[169398]],195074:[[39138]],195075:[[19251]],195076:[[39209]],195077:[[39335]],195078:[[39362]],195079:[[39422]],195080:[[19406]],195081:[[170800]],195082:[[39698]],195083:[[40000]],195084:[[40189]],195085:[[19662]],195086:[[19693]],195087:[[40295]],195088:[[172238]],195089:[[19704]],195090:[[172293]],195091:[[172558]],195092:[[172689]],195093:[[40635]],195094:[[19798]],195095:[[40697]],195096:[[40702]],195097:[[40709]],195098:[[40719]],195099:[[40726]],195100:[[40763]],195101:[[173568]]}, -64256:{64256:[[102,102],256],64257:[[102,105],256],64258:[[102,108],256],64259:[[102,102,105],256],64260:[[102,102,108],256],64261:[[383,116],256],64262:[[115,116],256],64275:[[1396,1398],256],64276:[[1396,1381],256],64277:[[1396,1387],256],64278:[[1406,1398],256],64279:[[1396,1389],256],64285:[[1497,1460],512],64286:[,26],64287:[[1522,1463],512],64288:[[1506],256],64289:[[1488],256],64290:[[1491],256],64291:[[1492],256],64292:[[1499],256],64293:[[1500],256],64294:[[1501],256],64295:[[1512],256],64296:[[1514],256],64297:[[43],256],64298:[[1513,1473],512],64299:[[1513,1474],512],64300:[[64329,1473],512],64301:[[64329,1474],512],64302:[[1488,1463],512],64303:[[1488,1464],512],64304:[[1488,1468],512],64305:[[1489,1468],512],64306:[[1490,1468],512],64307:[[1491,1468],512],64308:[[1492,1468],512],64309:[[1493,1468],512],64310:[[1494,1468],512],64312:[[1496,1468],512],64313:[[1497,1468],512],64314:[[1498,1468],512],64315:[[1499,1468],512],64316:[[1500,1468],512],64318:[[1502,1468],512],64320:[[1504,1468],512],64321:[[1505,1468],512],64323:[[1507,1468],512],64324:[[1508,1468],512],64326:[[1510,1468],512],64327:[[1511,1468],512],64328:[[1512,1468],512],64329:[[1513,1468],512],64330:[[1514,1468],512],64331:[[1493,1465],512],64332:[[1489,1471],512],64333:[[1499,1471],512],64334:[[1508,1471],512],64335:[[1488,1500],256],64336:[[1649],256],64337:[[1649],256],64338:[[1659],256],64339:[[1659],256],64340:[[1659],256],64341:[[1659],256],64342:[[1662],256],64343:[[1662],256],64344:[[1662],256],64345:[[1662],256],64346:[[1664],256],64347:[[1664],256],64348:[[1664],256],64349:[[1664],256],64350:[[1658],256],64351:[[1658],256],64352:[[1658],256],64353:[[1658],256],64354:[[1663],256],64355:[[1663],256],64356:[[1663],256],64357:[[1663],256],64358:[[1657],256],64359:[[1657],256],64360:[[1657],256],64361:[[1657],256],64362:[[1700],256],64363:[[1700],256],64364:[[1700],256],64365:[[1700],256],64366:[[1702],256],64367:[[1702],256],64368:[[1702],256],64369:[[1702],256],64370:[[1668],256],64371:[[1668],256],64372:[[1668],256],64373:[[1668],256],64374:[[1667],256],64375:[[1667],256],64376:[[1667],256],64377:[[1667],256],64378:[[1670],256],64379:[[1670],256],64380:[[1670],256],64381:[[1670],256],64382:[[1671],256],64383:[[1671],256],64384:[[1671],256],64385:[[1671],256],64386:[[1677],256],64387:[[1677],256],64388:[[1676],256],64389:[[1676],256],64390:[[1678],256],64391:[[1678],256],64392:[[1672],256],64393:[[1672],256],64394:[[1688],256],64395:[[1688],256],64396:[[1681],256],64397:[[1681],256],64398:[[1705],256],64399:[[1705],256],64400:[[1705],256],64401:[[1705],256],64402:[[1711],256],64403:[[1711],256],64404:[[1711],256],64405:[[1711],256],64406:[[1715],256],64407:[[1715],256],64408:[[1715],256],64409:[[1715],256],64410:[[1713],256],64411:[[1713],256],64412:[[1713],256],64413:[[1713],256],64414:[[1722],256],64415:[[1722],256],64416:[[1723],256],64417:[[1723],256],64418:[[1723],256],64419:[[1723],256],64420:[[1728],256],64421:[[1728],256],64422:[[1729],256],64423:[[1729],256],64424:[[1729],256],64425:[[1729],256],64426:[[1726],256],64427:[[1726],256],64428:[[1726],256],64429:[[1726],256],64430:[[1746],256],64431:[[1746],256],64432:[[1747],256],64433:[[1747],256],64467:[[1709],256],64468:[[1709],256],64469:[[1709],256],64470:[[1709],256],64471:[[1735],256],64472:[[1735],256],64473:[[1734],256],64474:[[1734],256],64475:[[1736],256],64476:[[1736],256],64477:[[1655],256],64478:[[1739],256],64479:[[1739],256],64480:[[1733],256],64481:[[1733],256],64482:[[1737],256],64483:[[1737],256],64484:[[1744],256],64485:[[1744],256],64486:[[1744],256],64487:[[1744],256],64488:[[1609],256],64489:[[1609],256],64490:[[1574,1575],256],64491:[[1574,1575],256],64492:[[1574,1749],256],64493:[[1574,1749],256],64494:[[1574,1608],256],64495:[[1574,1608],256],64496:[[1574,1735],256],64497:[[1574,1735],256],64498:[[1574,1734],256],64499:[[1574,1734],256],64500:[[1574,1736],256],64501:[[1574,1736],256],64502:[[1574,1744],256],64503:[[1574,1744],256],64504:[[1574,1744],256],64505:[[1574,1609],256],64506:[[1574,1609],256],64507:[[1574,1609],256],64508:[[1740],256],64509:[[1740],256],64510:[[1740],256],64511:[[1740],256]}, -64512:{64512:[[1574,1580],256],64513:[[1574,1581],256],64514:[[1574,1605],256],64515:[[1574,1609],256],64516:[[1574,1610],256],64517:[[1576,1580],256],64518:[[1576,1581],256],64519:[[1576,1582],256],64520:[[1576,1605],256],64521:[[1576,1609],256],64522:[[1576,1610],256],64523:[[1578,1580],256],64524:[[1578,1581],256],64525:[[1578,1582],256],64526:[[1578,1605],256],64527:[[1578,1609],256],64528:[[1578,1610],256],64529:[[1579,1580],256],64530:[[1579,1605],256],64531:[[1579,1609],256],64532:[[1579,1610],256],64533:[[1580,1581],256],64534:[[1580,1605],256],64535:[[1581,1580],256],64536:[[1581,1605],256],64537:[[1582,1580],256],64538:[[1582,1581],256],64539:[[1582,1605],256],64540:[[1587,1580],256],64541:[[1587,1581],256],64542:[[1587,1582],256],64543:[[1587,1605],256],64544:[[1589,1581],256],64545:[[1589,1605],256],64546:[[1590,1580],256],64547:[[1590,1581],256],64548:[[1590,1582],256],64549:[[1590,1605],256],64550:[[1591,1581],256],64551:[[1591,1605],256],64552:[[1592,1605],256],64553:[[1593,1580],256],64554:[[1593,1605],256],64555:[[1594,1580],256],64556:[[1594,1605],256],64557:[[1601,1580],256],64558:[[1601,1581],256],64559:[[1601,1582],256],64560:[[1601,1605],256],64561:[[1601,1609],256],64562:[[1601,1610],256],64563:[[1602,1581],256],64564:[[1602,1605],256],64565:[[1602,1609],256],64566:[[1602,1610],256],64567:[[1603,1575],256],64568:[[1603,1580],256],64569:[[1603,1581],256],64570:[[1603,1582],256],64571:[[1603,1604],256],64572:[[1603,1605],256],64573:[[1603,1609],256],64574:[[1603,1610],256],64575:[[1604,1580],256],64576:[[1604,1581],256],64577:[[1604,1582],256],64578:[[1604,1605],256],64579:[[1604,1609],256],64580:[[1604,1610],256],64581:[[1605,1580],256],64582:[[1605,1581],256],64583:[[1605,1582],256],64584:[[1605,1605],256],64585:[[1605,1609],256],64586:[[1605,1610],256],64587:[[1606,1580],256],64588:[[1606,1581],256],64589:[[1606,1582],256],64590:[[1606,1605],256],64591:[[1606,1609],256],64592:[[1606,1610],256],64593:[[1607,1580],256],64594:[[1607,1605],256],64595:[[1607,1609],256],64596:[[1607,1610],256],64597:[[1610,1580],256],64598:[[1610,1581],256],64599:[[1610,1582],256],64600:[[1610,1605],256],64601:[[1610,1609],256],64602:[[1610,1610],256],64603:[[1584,1648],256],64604:[[1585,1648],256],64605:[[1609,1648],256],64606:[[32,1612,1617],256],64607:[[32,1613,1617],256],64608:[[32,1614,1617],256],64609:[[32,1615,1617],256],64610:[[32,1616,1617],256],64611:[[32,1617,1648],256],64612:[[1574,1585],256],64613:[[1574,1586],256],64614:[[1574,1605],256],64615:[[1574,1606],256],64616:[[1574,1609],256],64617:[[1574,1610],256],64618:[[1576,1585],256],64619:[[1576,1586],256],64620:[[1576,1605],256],64621:[[1576,1606],256],64622:[[1576,1609],256],64623:[[1576,1610],256],64624:[[1578,1585],256],64625:[[1578,1586],256],64626:[[1578,1605],256],64627:[[1578,1606],256],64628:[[1578,1609],256],64629:[[1578,1610],256],64630:[[1579,1585],256],64631:[[1579,1586],256],64632:[[1579,1605],256],64633:[[1579,1606],256],64634:[[1579,1609],256],64635:[[1579,1610],256],64636:[[1601,1609],256],64637:[[1601,1610],256],64638:[[1602,1609],256],64639:[[1602,1610],256],64640:[[1603,1575],256],64641:[[1603,1604],256],64642:[[1603,1605],256],64643:[[1603,1609],256],64644:[[1603,1610],256],64645:[[1604,1605],256],64646:[[1604,1609],256],64647:[[1604,1610],256],64648:[[1605,1575],256],64649:[[1605,1605],256],64650:[[1606,1585],256],64651:[[1606,1586],256],64652:[[1606,1605],256],64653:[[1606,1606],256],64654:[[1606,1609],256],64655:[[1606,1610],256],64656:[[1609,1648],256],64657:[[1610,1585],256],64658:[[1610,1586],256],64659:[[1610,1605],256],64660:[[1610,1606],256],64661:[[1610,1609],256],64662:[[1610,1610],256],64663:[[1574,1580],256],64664:[[1574,1581],256],64665:[[1574,1582],256],64666:[[1574,1605],256],64667:[[1574,1607],256],64668:[[1576,1580],256],64669:[[1576,1581],256],64670:[[1576,1582],256],64671:[[1576,1605],256],64672:[[1576,1607],256],64673:[[1578,1580],256],64674:[[1578,1581],256],64675:[[1578,1582],256],64676:[[1578,1605],256],64677:[[1578,1607],256],64678:[[1579,1605],256],64679:[[1580,1581],256],64680:[[1580,1605],256],64681:[[1581,1580],256],64682:[[1581,1605],256],64683:[[1582,1580],256],64684:[[1582,1605],256],64685:[[1587,1580],256],64686:[[1587,1581],256],64687:[[1587,1582],256],64688:[[1587,1605],256],64689:[[1589,1581],256],64690:[[1589,1582],256],64691:[[1589,1605],256],64692:[[1590,1580],256],64693:[[1590,1581],256],64694:[[1590,1582],256],64695:[[1590,1605],256],64696:[[1591,1581],256],64697:[[1592,1605],256],64698:[[1593,1580],256],64699:[[1593,1605],256],64700:[[1594,1580],256],64701:[[1594,1605],256],64702:[[1601,1580],256],64703:[[1601,1581],256],64704:[[1601,1582],256],64705:[[1601,1605],256],64706:[[1602,1581],256],64707:[[1602,1605],256],64708:[[1603,1580],256],64709:[[1603,1581],256],64710:[[1603,1582],256],64711:[[1603,1604],256],64712:[[1603,1605],256],64713:[[1604,1580],256],64714:[[1604,1581],256],64715:[[1604,1582],256],64716:[[1604,1605],256],64717:[[1604,1607],256],64718:[[1605,1580],256],64719:[[1605,1581],256],64720:[[1605,1582],256],64721:[[1605,1605],256],64722:[[1606,1580],256],64723:[[1606,1581],256],64724:[[1606,1582],256],64725:[[1606,1605],256],64726:[[1606,1607],256],64727:[[1607,1580],256],64728:[[1607,1605],256],64729:[[1607,1648],256],64730:[[1610,1580],256],64731:[[1610,1581],256],64732:[[1610,1582],256],64733:[[1610,1605],256],64734:[[1610,1607],256],64735:[[1574,1605],256],64736:[[1574,1607],256],64737:[[1576,1605],256],64738:[[1576,1607],256],64739:[[1578,1605],256],64740:[[1578,1607],256],64741:[[1579,1605],256],64742:[[1579,1607],256],64743:[[1587,1605],256],64744:[[1587,1607],256],64745:[[1588,1605],256],64746:[[1588,1607],256],64747:[[1603,1604],256],64748:[[1603,1605],256],64749:[[1604,1605],256],64750:[[1606,1605],256],64751:[[1606,1607],256],64752:[[1610,1605],256],64753:[[1610,1607],256],64754:[[1600,1614,1617],256],64755:[[1600,1615,1617],256],64756:[[1600,1616,1617],256],64757:[[1591,1609],256],64758:[[1591,1610],256],64759:[[1593,1609],256],64760:[[1593,1610],256],64761:[[1594,1609],256],64762:[[1594,1610],256],64763:[[1587,1609],256],64764:[[1587,1610],256],64765:[[1588,1609],256],64766:[[1588,1610],256],64767:[[1581,1609],256]}, -64768:{64768:[[1581,1610],256],64769:[[1580,1609],256],64770:[[1580,1610],256],64771:[[1582,1609],256],64772:[[1582,1610],256],64773:[[1589,1609],256],64774:[[1589,1610],256],64775:[[1590,1609],256],64776:[[1590,1610],256],64777:[[1588,1580],256],64778:[[1588,1581],256],64779:[[1588,1582],256],64780:[[1588,1605],256],64781:[[1588,1585],256],64782:[[1587,1585],256],64783:[[1589,1585],256],64784:[[1590,1585],256],64785:[[1591,1609],256],64786:[[1591,1610],256],64787:[[1593,1609],256],64788:[[1593,1610],256],64789:[[1594,1609],256],64790:[[1594,1610],256],64791:[[1587,1609],256],64792:[[1587,1610],256],64793:[[1588,1609],256],64794:[[1588,1610],256],64795:[[1581,1609],256],64796:[[1581,1610],256],64797:[[1580,1609],256],64798:[[1580,1610],256],64799:[[1582,1609],256],64800:[[1582,1610],256],64801:[[1589,1609],256],64802:[[1589,1610],256],64803:[[1590,1609],256],64804:[[1590,1610],256],64805:[[1588,1580],256],64806:[[1588,1581],256],64807:[[1588,1582],256],64808:[[1588,1605],256],64809:[[1588,1585],256],64810:[[1587,1585],256],64811:[[1589,1585],256],64812:[[1590,1585],256],64813:[[1588,1580],256],64814:[[1588,1581],256],64815:[[1588,1582],256],64816:[[1588,1605],256],64817:[[1587,1607],256],64818:[[1588,1607],256],64819:[[1591,1605],256],64820:[[1587,1580],256],64821:[[1587,1581],256],64822:[[1587,1582],256],64823:[[1588,1580],256],64824:[[1588,1581],256],64825:[[1588,1582],256],64826:[[1591,1605],256],64827:[[1592,1605],256],64828:[[1575,1611],256],64829:[[1575,1611],256],64848:[[1578,1580,1605],256],64849:[[1578,1581,1580],256],64850:[[1578,1581,1580],256],64851:[[1578,1581,1605],256],64852:[[1578,1582,1605],256],64853:[[1578,1605,1580],256],64854:[[1578,1605,1581],256],64855:[[1578,1605,1582],256],64856:[[1580,1605,1581],256],64857:[[1580,1605,1581],256],64858:[[1581,1605,1610],256],64859:[[1581,1605,1609],256],64860:[[1587,1581,1580],256],64861:[[1587,1580,1581],256],64862:[[1587,1580,1609],256],64863:[[1587,1605,1581],256],64864:[[1587,1605,1581],256],64865:[[1587,1605,1580],256],64866:[[1587,1605,1605],256],64867:[[1587,1605,1605],256],64868:[[1589,1581,1581],256],64869:[[1589,1581,1581],256],64870:[[1589,1605,1605],256],64871:[[1588,1581,1605],256],64872:[[1588,1581,1605],256],64873:[[1588,1580,1610],256],64874:[[1588,1605,1582],256],64875:[[1588,1605,1582],256],64876:[[1588,1605,1605],256],64877:[[1588,1605,1605],256],64878:[[1590,1581,1609],256],64879:[[1590,1582,1605],256],64880:[[1590,1582,1605],256],64881:[[1591,1605,1581],256],64882:[[1591,1605,1581],256],64883:[[1591,1605,1605],256],64884:[[1591,1605,1610],256],64885:[[1593,1580,1605],256],64886:[[1593,1605,1605],256],64887:[[1593,1605,1605],256],64888:[[1593,1605,1609],256],64889:[[1594,1605,1605],256],64890:[[1594,1605,1610],256],64891:[[1594,1605,1609],256],64892:[[1601,1582,1605],256],64893:[[1601,1582,1605],256],64894:[[1602,1605,1581],256],64895:[[1602,1605,1605],256],64896:[[1604,1581,1605],256],64897:[[1604,1581,1610],256],64898:[[1604,1581,1609],256],64899:[[1604,1580,1580],256],64900:[[1604,1580,1580],256],64901:[[1604,1582,1605],256],64902:[[1604,1582,1605],256],64903:[[1604,1605,1581],256],64904:[[1604,1605,1581],256],64905:[[1605,1581,1580],256],64906:[[1605,1581,1605],256],64907:[[1605,1581,1610],256],64908:[[1605,1580,1581],256],64909:[[1605,1580,1605],256],64910:[[1605,1582,1580],256],64911:[[1605,1582,1605],256],64914:[[1605,1580,1582],256],64915:[[1607,1605,1580],256],64916:[[1607,1605,1605],256],64917:[[1606,1581,1605],256],64918:[[1606,1581,1609],256],64919:[[1606,1580,1605],256],64920:[[1606,1580,1605],256],64921:[[1606,1580,1609],256],64922:[[1606,1605,1610],256],64923:[[1606,1605,1609],256],64924:[[1610,1605,1605],256],64925:[[1610,1605,1605],256],64926:[[1576,1582,1610],256],64927:[[1578,1580,1610],256],64928:[[1578,1580,1609],256],64929:[[1578,1582,1610],256],64930:[[1578,1582,1609],256],64931:[[1578,1605,1610],256],64932:[[1578,1605,1609],256],64933:[[1580,1605,1610],256],64934:[[1580,1581,1609],256],64935:[[1580,1605,1609],256],64936:[[1587,1582,1609],256],64937:[[1589,1581,1610],256],64938:[[1588,1581,1610],256],64939:[[1590,1581,1610],256],64940:[[1604,1580,1610],256],64941:[[1604,1605,1610],256],64942:[[1610,1581,1610],256],64943:[[1610,1580,1610],256],64944:[[1610,1605,1610],256],64945:[[1605,1605,1610],256],64946:[[1602,1605,1610],256],64947:[[1606,1581,1610],256],64948:[[1602,1605,1581],256],64949:[[1604,1581,1605],256],64950:[[1593,1605,1610],256],64951:[[1603,1605,1610],256],64952:[[1606,1580,1581],256],64953:[[1605,1582,1610],256],64954:[[1604,1580,1605],256],64955:[[1603,1605,1605],256],64956:[[1604,1580,1605],256],64957:[[1606,1580,1581],256],64958:[[1580,1581,1610],256],64959:[[1581,1580,1610],256],64960:[[1605,1580,1610],256],64961:[[1601,1605,1610],256],64962:[[1576,1581,1610],256],64963:[[1603,1605,1605],256],64964:[[1593,1580,1605],256],64965:[[1589,1605,1605],256],64966:[[1587,1582,1610],256],64967:[[1606,1580,1610],256],65008:[[1589,1604,1746],256],65009:[[1602,1604,1746],256],65010:[[1575,1604,1604,1607],256],65011:[[1575,1603,1576,1585],256],65012:[[1605,1581,1605,1583],256],65013:[[1589,1604,1593,1605],256],65014:[[1585,1587,1608,1604],256],65015:[[1593,1604,1610,1607],256],65016:[[1608,1587,1604,1605],256],65017:[[1589,1604,1609],256],65018:[[1589,1604,1609,32,1575,1604,1604,1607,32,1593,1604,1610,1607,32,1608,1587,1604,1605],256],65019:[[1580,1604,32,1580,1604,1575,1604,1607],256],65020:[[1585,1740,1575,1604],256]}, -65024:{65040:[[44],256],65041:[[12289],256],65042:[[12290],256],65043:[[58],256],65044:[[59],256],65045:[[33],256],65046:[[63],256],65047:[[12310],256],65048:[[12311],256],65049:[[8230],256],65056:[,230],65057:[,230],65058:[,230],65059:[,230],65060:[,230],65061:[,230],65062:[,230],65063:[,220],65064:[,220],65065:[,220],65066:[,220],65067:[,220],65068:[,220],65069:[,220],65072:[[8229],256],65073:[[8212],256],65074:[[8211],256],65075:[[95],256],65076:[[95],256],65077:[[40],256],65078:[[41],256],65079:[[123],256],65080:[[125],256],65081:[[12308],256],65082:[[12309],256],65083:[[12304],256],65084:[[12305],256],65085:[[12298],256],65086:[[12299],256],65087:[[12296],256],65088:[[12297],256],65089:[[12300],256],65090:[[12301],256],65091:[[12302],256],65092:[[12303],256],65095:[[91],256],65096:[[93],256],65097:[[8254],256],65098:[[8254],256],65099:[[8254],256],65100:[[8254],256],65101:[[95],256],65102:[[95],256],65103:[[95],256],65104:[[44],256],65105:[[12289],256],65106:[[46],256],65108:[[59],256],65109:[[58],256],65110:[[63],256],65111:[[33],256],65112:[[8212],256],65113:[[40],256],65114:[[41],256],65115:[[123],256],65116:[[125],256],65117:[[12308],256],65118:[[12309],256],65119:[[35],256],65120:[[38],256],65121:[[42],256],65122:[[43],256],65123:[[45],256],65124:[[60],256],65125:[[62],256],65126:[[61],256],65128:[[92],256],65129:[[36],256],65130:[[37],256],65131:[[64],256],65136:[[32,1611],256],65137:[[1600,1611],256],65138:[[32,1612],256],65140:[[32,1613],256],65142:[[32,1614],256],65143:[[1600,1614],256],65144:[[32,1615],256],65145:[[1600,1615],256],65146:[[32,1616],256],65147:[[1600,1616],256],65148:[[32,1617],256],65149:[[1600,1617],256],65150:[[32,1618],256],65151:[[1600,1618],256],65152:[[1569],256],65153:[[1570],256],65154:[[1570],256],65155:[[1571],256],65156:[[1571],256],65157:[[1572],256],65158:[[1572],256],65159:[[1573],256],65160:[[1573],256],65161:[[1574],256],65162:[[1574],256],65163:[[1574],256],65164:[[1574],256],65165:[[1575],256],65166:[[1575],256],65167:[[1576],256],65168:[[1576],256],65169:[[1576],256],65170:[[1576],256],65171:[[1577],256],65172:[[1577],256],65173:[[1578],256],65174:[[1578],256],65175:[[1578],256],65176:[[1578],256],65177:[[1579],256],65178:[[1579],256],65179:[[1579],256],65180:[[1579],256],65181:[[1580],256],65182:[[1580],256],65183:[[1580],256],65184:[[1580],256],65185:[[1581],256],65186:[[1581],256],65187:[[1581],256],65188:[[1581],256],65189:[[1582],256],65190:[[1582],256],65191:[[1582],256],65192:[[1582],256],65193:[[1583],256],65194:[[1583],256],65195:[[1584],256],65196:[[1584],256],65197:[[1585],256],65198:[[1585],256],65199:[[1586],256],65200:[[1586],256],65201:[[1587],256],65202:[[1587],256],65203:[[1587],256],65204:[[1587],256],65205:[[1588],256],65206:[[1588],256],65207:[[1588],256],65208:[[1588],256],65209:[[1589],256],65210:[[1589],256],65211:[[1589],256],65212:[[1589],256],65213:[[1590],256],65214:[[1590],256],65215:[[1590],256],65216:[[1590],256],65217:[[1591],256],65218:[[1591],256],65219:[[1591],256],65220:[[1591],256],65221:[[1592],256],65222:[[1592],256],65223:[[1592],256],65224:[[1592],256],65225:[[1593],256],65226:[[1593],256],65227:[[1593],256],65228:[[1593],256],65229:[[1594],256],65230:[[1594],256],65231:[[1594],256],65232:[[1594],256],65233:[[1601],256],65234:[[1601],256],65235:[[1601],256],65236:[[1601],256],65237:[[1602],256],65238:[[1602],256],65239:[[1602],256],65240:[[1602],256],65241:[[1603],256],65242:[[1603],256],65243:[[1603],256],65244:[[1603],256],65245:[[1604],256],65246:[[1604],256],65247:[[1604],256],65248:[[1604],256],65249:[[1605],256],65250:[[1605],256],65251:[[1605],256],65252:[[1605],256],65253:[[1606],256],65254:[[1606],256],65255:[[1606],256],65256:[[1606],256],65257:[[1607],256],65258:[[1607],256],65259:[[1607],256],65260:[[1607],256],65261:[[1608],256],65262:[[1608],256],65263:[[1609],256],65264:[[1609],256],65265:[[1610],256],65266:[[1610],256],65267:[[1610],256],65268:[[1610],256],65269:[[1604,1570],256],65270:[[1604,1570],256],65271:[[1604,1571],256],65272:[[1604,1571],256],65273:[[1604,1573],256],65274:[[1604,1573],256],65275:[[1604,1575],256],65276:[[1604,1575],256]}, -65280:{65281:[[33],256],65282:[[34],256],65283:[[35],256],65284:[[36],256],65285:[[37],256],65286:[[38],256],65287:[[39],256],65288:[[40],256],65289:[[41],256],65290:[[42],256],65291:[[43],256],65292:[[44],256],65293:[[45],256],65294:[[46],256],65295:[[47],256],65296:[[48],256],65297:[[49],256],65298:[[50],256],65299:[[51],256],65300:[[52],256],65301:[[53],256],65302:[[54],256],65303:[[55],256],65304:[[56],256],65305:[[57],256],65306:[[58],256],65307:[[59],256],65308:[[60],256],65309:[[61],256],65310:[[62],256],65311:[[63],256],65312:[[64],256],65313:[[65],256],65314:[[66],256],65315:[[67],256],65316:[[68],256],65317:[[69],256],65318:[[70],256],65319:[[71],256],65320:[[72],256],65321:[[73],256],65322:[[74],256],65323:[[75],256],65324:[[76],256],65325:[[77],256],65326:[[78],256],65327:[[79],256],65328:[[80],256],65329:[[81],256],65330:[[82],256],65331:[[83],256],65332:[[84],256],65333:[[85],256],65334:[[86],256],65335:[[87],256],65336:[[88],256],65337:[[89],256],65338:[[90],256],65339:[[91],256],65340:[[92],256],65341:[[93],256],65342:[[94],256],65343:[[95],256],65344:[[96],256],65345:[[97],256],65346:[[98],256],65347:[[99],256],65348:[[100],256],65349:[[101],256],65350:[[102],256],65351:[[103],256],65352:[[104],256],65353:[[105],256],65354:[[106],256],65355:[[107],256],65356:[[108],256],65357:[[109],256],65358:[[110],256],65359:[[111],256],65360:[[112],256],65361:[[113],256],65362:[[114],256],65363:[[115],256],65364:[[116],256],65365:[[117],256],65366:[[118],256],65367:[[119],256],65368:[[120],256],65369:[[121],256],65370:[[122],256],65371:[[123],256],65372:[[124],256],65373:[[125],256],65374:[[126],256],65375:[[10629],256],65376:[[10630],256],65377:[[12290],256],65378:[[12300],256],65379:[[12301],256],65380:[[12289],256],65381:[[12539],256],65382:[[12530],256],65383:[[12449],256],65384:[[12451],256],65385:[[12453],256],65386:[[12455],256],65387:[[12457],256],65388:[[12515],256],65389:[[12517],256],65390:[[12519],256],65391:[[12483],256],65392:[[12540],256],65393:[[12450],256],65394:[[12452],256],65395:[[12454],256],65396:[[12456],256],65397:[[12458],256],65398:[[12459],256],65399:[[12461],256],65400:[[12463],256],65401:[[12465],256],65402:[[12467],256],65403:[[12469],256],65404:[[12471],256],65405:[[12473],256],65406:[[12475],256],65407:[[12477],256],65408:[[12479],256],65409:[[12481],256],65410:[[12484],256],65411:[[12486],256],65412:[[12488],256],65413:[[12490],256],65414:[[12491],256],65415:[[12492],256],65416:[[12493],256],65417:[[12494],256],65418:[[12495],256],65419:[[12498],256],65420:[[12501],256],65421:[[12504],256],65422:[[12507],256],65423:[[12510],256],65424:[[12511],256],65425:[[12512],256],65426:[[12513],256],65427:[[12514],256],65428:[[12516],256],65429:[[12518],256],65430:[[12520],256],65431:[[12521],256],65432:[[12522],256],65433:[[12523],256],65434:[[12524],256],65435:[[12525],256],65436:[[12527],256],65437:[[12531],256],65438:[[12441],256],65439:[[12442],256],65440:[[12644],256],65441:[[12593],256],65442:[[12594],256],65443:[[12595],256],65444:[[12596],256],65445:[[12597],256],65446:[[12598],256],65447:[[12599],256],65448:[[12600],256],65449:[[12601],256],65450:[[12602],256],65451:[[12603],256],65452:[[12604],256],65453:[[12605],256],65454:[[12606],256],65455:[[12607],256],65456:[[12608],256],65457:[[12609],256],65458:[[12610],256],65459:[[12611],256],65460:[[12612],256],65461:[[12613],256],65462:[[12614],256],65463:[[12615],256],65464:[[12616],256],65465:[[12617],256],65466:[[12618],256],65467:[[12619],256],65468:[[12620],256],65469:[[12621],256],65470:[[12622],256],65474:[[12623],256],65475:[[12624],256],65476:[[12625],256],65477:[[12626],256],65478:[[12627],256],65479:[[12628],256],65482:[[12629],256],65483:[[12630],256],65484:[[12631],256],65485:[[12632],256],65486:[[12633],256],65487:[[12634],256],65490:[[12635],256],65491:[[12636],256],65492:[[12637],256],65493:[[12638],256],65494:[[12639],256],65495:[[12640],256],65498:[[12641],256],65499:[[12642],256],65500:[[12643],256],65504:[[162],256],65505:[[163],256],65506:[[172],256],65507:[[175],256],65508:[[166],256],65509:[[165],256],65510:[[8361],256],65512:[[9474],256],65513:[[8592],256],65514:[[8593],256],65515:[[8594],256],65516:[[8595],256],65517:[[9632],256],65518:[[9675],256]} +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; -}; +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; - /***** Module to export */ - var unorm = { - nfc: nfc, - nfd: nfd, - nfkc: nfkc, - nfkd: nfkd - }; +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; - /*globals module:true,define:true*/ +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; - // CommonJS - if (typeof module === "object") { - module.exports = unorm; +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; - // AMD - } else if (typeof define === "function" && define.amd) { - define("unorm", function () { - return unorm; - }); +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; - // Global - } else { - root.unorm = unorm; - } +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; +exports.types.isRegExp = isRegExp; - /***** Export as shim for String::normalize method *****/ - /* - http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#november_8_2013_draft_rev_21 +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; - 21.1.3.12 String.prototype.normalize(form="NFC") - When the normalize method is called with one argument form, the following steps are taken: +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; +exports.types.isDate = isDate; - 1. Let O be CheckObjectCoercible(this value). - 2. Let S be ToString(O). - 3. ReturnIfAbrupt(S). - 4. If form is not provided or undefined let form be "NFC". - 5. Let f be ToString(form). - 6. ReturnIfAbrupt(f). - 7. If f is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw a RangeError Exception. - 8. Let ns be the String value is the result of normalizing S into the normalization form named by f as specified in Unicode Standard Annex #15, UnicodeNormalizatoin Forms. - 9. Return ns. +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; +exports.types.isNativeError = isError; - The length property of the normalize method is 0. +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; - *NOTE* The normalize function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. - */ - unorm.shimApplied = false; +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; - if (!String.prototype.normalize) { - Object.defineProperty(String.prototype, "normalize", { - enumerable: false, - configurable: true, - writable: true, - value: function normalize (/*form*/) { - - var str = "" + this; - var form = arguments[0] === undefined ? "NFC" : arguments[0]; +exports.isBuffer = require('./support/isBuffer'); - if (this === null || this === undefined) { - throw new TypeError("Cannot call method on " + Object.prototype.toString.call(this)); - } +function objectToString(o) { + return Object.prototype.toString.call(o); +} - if (form === "NFC") { - return unorm.nfc(str); - } else if (form === "NFD") { - return unorm.nfd(str); - } else if (form === "NFKC") { - return unorm.nfkc(str); - } else if (form === "NFKD") { - return unorm.nfkd(str); - } else { - throw new RangeError("Invalid normalization form: " + form); - } - } - }); - unorm.shimApplied = true; - } -}(this)); +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} -},{}],327:[function(require,module,exports){ -(function (global){ -/** - * Module exports. - */ +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} + + +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; -module.exports = deprecate; /** - * Mark that a method should not be used. - * Returns a modified function which warns once by default. - * - * If `localStorage.noDeprecation = true` is set, then it is a no-op. - * - * If `localStorage.throwDeprecation = true` is set, then deprecated functions - * will throw an Error when invoked. + * Inherit the prototype methods from one constructor into another. * - * If `localStorage.traceDeprecation = true` is set, then deprecated functions - * will invoke `console.trace()` instead of `console.error()`. + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). * - * @param {Function} fn - the function to deprecate - * @param {String} msg - the string to print to the console when `fn` is invoked - * @returns {Function} a new "deprecated" version of `fn` - * @api public + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. */ +exports.inherits = require('inherits'); -function deprecate (fn, msg) { - if (config('noDeprecation')) { +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined; + +exports.promisify = function promisify(original) { + if (typeof original !== 'function') + throw new TypeError('The "original" argument must be of type Function'); + + if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) { + var fn = original[kCustomPromisifiedSymbol]; + if (typeof fn !== 'function') { + throw new TypeError('The "util.promisify.custom" argument must be of type Function'); + } + Object.defineProperty(fn, kCustomPromisifiedSymbol, { + value: fn, enumerable: false, writable: false, configurable: true + }); return fn; } - var warned = false; - function deprecated() { - if (!warned) { - if (config('throwDeprecation')) { - throw new Error(msg); - } else if (config('traceDeprecation')) { - console.trace(msg); + function fn() { + var promiseResolve, promiseReject; + var promise = new Promise(function (resolve, reject) { + promiseResolve = resolve; + promiseReject = reject; + }); + + var args = []; + for (var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + args.push(function (err, value) { + if (err) { + promiseReject(err); } else { - console.warn(msg); + promiseResolve(value); } - warned = true; + }); + + try { + original.apply(this, args); + } catch (err) { + promiseReject(err); } - return fn.apply(this, arguments); + + return promise; } - return deprecated; + Object.setPrototypeOf(fn, Object.getPrototypeOf(original)); + + if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, { + value: fn, enumerable: false, writable: false, configurable: true + }); + return Object.defineProperties( + fn, + getOwnPropertyDescriptors(original) + ); } -/** - * Checks `localStorage` for boolean values for the given `name`. - * - * @param {String} name - * @returns {Boolean} - * @api private - */ +exports.promisify.custom = kCustomPromisifiedSymbol -function config (name) { - // accessing global.localStorage can trigger a DOMException in sandboxed iframes - try { - if (!global.localStorage) return false; - } catch (_) { - return false; +function callbackifyOnRejected(reason, cb) { + // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M). + // Because `null` is a special error value in callbacks which means "no error + // occurred", we error-wrap so the callback consumer can distinguish between + // "the promise rejected with null" or "the promise fulfilled with undefined". + if (!reason) { + var newReason = new Error('Promise was rejected with a falsy value'); + newReason.reason = reason; + reason = newReason; } - var val = global.localStorage[name]; - if (null == val) return false; - return String(val).toLowerCase() === 'true'; + return cb(reason); } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],328:[function(require,module,exports){ -arguments[4][22][0].apply(exports,arguments) -},{"dup":22}],329:[function(require,module,exports){ -arguments[4][23][0].apply(exports,arguments) -},{"dup":23}],330:[function(require,module,exports){ -arguments[4][24][0].apply(exports,arguments) -},{"./support/isBuffer":329,"_process":253,"dup":24,"inherits":328}],331:[function(require,module,exports){ +function callbackify(original) { + if (typeof original !== 'function') { + throw new TypeError('The "original" argument must be of type Function'); + } + + // We DO NOT return the promise as it gives the user a false sense that + // the promise is actually somehow related to the callback's execution + // and that the callback throwing will reject the promise. + function callbackified() { + var args = []; + for (var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + + var maybeCb = args.pop(); + if (typeof maybeCb !== 'function') { + throw new TypeError('The last argument must be of type Function'); + } + var self = this; + var cb = function() { + return maybeCb.apply(self, arguments); + }; + // In true node style we process the callback on `nextTick` with all the + // implications (stack, `uncaughtException`, `async_hooks`) + original.apply(this, args) + .then(function(ret) { process.nextTick(cb.bind(null, null, ret)) }, + function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) }); + } + + Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)); + Object.defineProperties(callbackified, + getOwnPropertyDescriptors(original)); + return callbackified; +} +exports.callbackify = callbackify; + +}).call(this)}).call(this,require('_process')) +},{"./support/isBuffer":525,"./support/types":526,"_process":451,"inherits":349}],528:[function(require,module,exports){ 'use strict' var Buffer = require('safe-buffer').Buffer @@ -71629,8 +93418,128 @@ function encodingLength (number) { module.exports = { encode: encode, decode: decode, encodingLength: encodingLength } -},{"safe-buffer":280}],332:[function(require,module,exports){ -(function (Buffer){ +},{"safe-buffer":463}],529:[function(require,module,exports){ +(function (global){(function (){ +'use strict'; + +var forEach = require('for-each'); +var availableTypedArrays = require('available-typed-arrays'); +var callBind = require('call-bind'); +var callBound = require('call-bind/callBound'); +var gOPD = require('gopd'); + +/** @type {(O: object) => string} */ +var $toString = callBound('Object.prototype.toString'); +var hasToStringTag = require('has-tostringtag/shams')(); + +var g = typeof globalThis === 'undefined' ? global : globalThis; +var typedArrays = availableTypedArrays(); + +var $slice = callBound('String.prototype.slice'); +var getPrototypeOf = Object.getPrototypeOf; // require('getprototypeof'); + +/** @type {(array: readonly T[], value: unknown) => number} */ +var $indexOf = callBound('Array.prototype.indexOf', true) || function indexOf(array, value) { + for (var i = 0; i < array.length; i += 1) { + if (array[i] === value) { + return i; + } + } + return -1; +}; + +/** @typedef {(receiver: import('.').TypedArray) => string | typeof Uint8Array.prototype.slice.call | typeof Uint8Array.prototype.set.call} Getter */ +/** @type {{ [k in `\$${import('.').TypedArrayName}`]?: Getter } & { __proto__: null }} */ +var cache = { __proto__: null }; +if (hasToStringTag && gOPD && getPrototypeOf) { + forEach(typedArrays, function (typedArray) { + var arr = new g[typedArray](); + if (Symbol.toStringTag in arr) { + var proto = getPrototypeOf(arr); + // @ts-expect-error TS won't narrow inside a closure + var descriptor = gOPD(proto, Symbol.toStringTag); + if (!descriptor) { + var superProto = getPrototypeOf(proto); + // @ts-expect-error TS won't narrow inside a closure + descriptor = gOPD(superProto, Symbol.toStringTag); + } + // @ts-expect-error TODO: fix + cache['$' + typedArray] = callBind(descriptor.get); + } + }); +} else { + forEach(typedArrays, function (typedArray) { + var arr = new g[typedArray](); + var fn = arr.slice || arr.set; + if (fn) { + // @ts-expect-error TODO: fix + cache['$' + typedArray] = callBind(fn); + } + }); +} + +/** @type {(value: object) => false | import('.').TypedArrayName} */ +var tryTypedArrays = function tryAllTypedArrays(value) { + /** @type {ReturnType} */ var found = false; + forEach( + // eslint-disable-next-line no-extra-parens + /** @type {Record<`\$${TypedArrayName}`, Getter>} */ /** @type {any} */ (cache), + /** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void} */ + function (getter, typedArray) { + if (!found) { + try { + // @ts-expect-error TODO: fix + if ('$' + getter(value) === typedArray) { + found = $slice(typedArray, 1); + } + } catch (e) { /**/ } + } + } + ); + return found; +}; + +/** @type {(value: object) => false | import('.').TypedArrayName} */ +var trySlices = function tryAllSlices(value) { + /** @type {ReturnType} */ var found = false; + forEach( + // eslint-disable-next-line no-extra-parens + /** @type {Record<`\$${TypedArrayName}`, Getter>} */ /** @type {any} */ (cache), + /** @type {(getter: typeof cache, name: `\$${import('.').TypedArrayName}`) => void} */ function (getter, name) { + if (!found) { + try { + // @ts-expect-error TODO: fix + getter(value); + found = $slice(name, 1); + } catch (e) { /**/ } + } + } + ); + return found; +}; + +/** @type {import('.')} */ +module.exports = function whichTypedArray(value) { + if (!value || typeof value !== 'object') { return false; } + if (!hasToStringTag) { + /** @type {string} */ + var tag = $slice($toString(value), 8, -1); + if ($indexOf(typedArrays, tag) > -1) { + return tag; + } + if (tag !== 'Object') { + return false; + } + // node < 0.6 hits here on real Typed Arrays + return trySlices(value); + } + if (!gOPD) { return null; } // unknown engine + return tryTypedArrays(value); +}; + +}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"available-typed-arrays":117,"call-bind":251,"call-bind/callBound":250,"for-each":307,"gopd":312,"has-tostringtag/shams":317}],530:[function(require,module,exports){ +(function (Buffer){(function (){ var bs58check = require('bs58check') function decodeRaw (buffer, version) { @@ -71695,8 +93604,8 @@ module.exports = { encodeRaw: encodeRaw } -}).call(this,require("buffer").Buffer) -},{"bs58check":152,"buffer":155}],333:[function(require,module,exports){ +}).call(this)}).call(this,require("buffer").Buffer) +},{"bs58check":246,"buffer":249}],531:[function(require,module,exports){ /** * @fileoverview * @enhanceable @@ -72174,5 +94083,5 @@ proto.Op.prototype.clearActionsList = function() { goog.object.extend(exports, proto); -},{"google-protobuf":198}]},{},[1])(1) +},{"google-protobuf":311}]},{},[1])(1) }); diff --git a/libs/templates.js b/libs/templates.js index 6b2cae9..81e4e06 100644 --- a/libs/templates.js +++ b/libs/templates.js @@ -1354,6 +1354,16 @@ angular.module('app').run(['$templateCache', function($templateCache) { ); + $templateCache.put('node_modules/tslib/tslib.es6.html', + "" + ); + + + $templateCache.put('node_modules/tslib/tslib.html', + "" + ); + + $templateCache.put('node_modules/uglify-js/tools/domprops.html', "\n" + "\n" + @@ -1817,7 +1827,6 @@ angular.module('app').run(['$templateCache', function($templateCache) { $templateCache.put('node_modules/vm-browserify/example/run/index.html', "\n" + " \n" + - " \n" + " \n" + " \n" + " \n" + diff --git a/package.json b/package.json index d369ab9..02641f1 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,14 @@ "bip66": "^1.1.0", "bitcoin-ops": "^1.4.1", "bitcoinjs-lib": "^5.2.0", - "browserify": "^14.5.0", + "@bitcoinerlab/descriptors": "^2.2.0", + "@bitcoinerlab/secp256k1": "^1.1.1", + "browserify": "^17.0.0", "bs58check": "^2.1.0", "create-hash": "^1.1.0", "create-hmac": "^1.1.3", "ecurve": "^1.0.0", + "ecpair": "^2.1.0", "fast-crc32c": "^1.0.4", "google-protobuf": "^3.7.1", "grpc-web": "^1.0.4", @@ -31,6 +34,7 @@ "grunt-angular-templates": "^1.1.0", "grunt-cli": "^1.3.2", "husky": "^2.1.0", + "ledger-bitcoin": "^0.2.3", "macaroon": "guggero/js-macaroon", "merkle-lib": "^2.0.10", "pbkdf2": "^3.0.13", diff --git a/pages/wallet-import/wallet-import.js b/pages/wallet-import/wallet-import.js index b9a3f0b..a7d6153 100644 --- a/pages/wallet-import/wallet-import.js +++ b/pages/wallet-import/wallet-import.js @@ -9,6 +9,7 @@ angular function WalletImportPageController(lodash, bitcoin, allNetworks, Buffer) { const vm = this; + const {Output} = bitcoin.descriptors.DescriptorsFactory(bitcoin.descriptorsSecp); const PBKDF2_SALT = 'Digital Bitbox', PBKDF2_HMACLEN = 64, @@ -72,6 +73,9 @@ function WalletImportPageController(lodash, bitcoin, allNetworks, Buffer) { {label: 'Wallet Dump format (importwallet)', id: 'dump'}, {label: 'bitcoin-cli importprivkey', id: 'importprivkey'}, {label: 'bitcoin-cli importpubkey', id: 'importpubkey'}, + {label: 'bitcoin-cli importdescriptors (wpkh)', id: 'importdescriptorswpkh'}, + // {label: 'bitcoin-cli importdescriptors (tr)', id: 'importdescriptorstr'}, + {label: 'Electrum', id: 'electrum'}, ]; const MODES = [ {label: 'Import from BIP39 Mnemonic', id: 'mnemonic'}, @@ -229,6 +233,77 @@ function WalletImportPageController(lodash, bitcoin, allNetworks, Buffer) { return str; }; + vm.getResultAsImportdescriptorswpkh = function (rootNode, basePath, network) { + const baseKey = rootNode.derivePath(basePath); + let str = `# Paste the following lines into a command line window. +# You might want to adjust the block number to rescan from at the bottom of the +# file if the wallet was originally created before 2017-12-18 18:35:25. +`; + for (let change = vm.changeStart; change <= vm.changeEnd; change++) { + const changePath = `${change}${vm.path.indexOf('_chg_\'') >= 0 ? '\'' : ''}`; + const changeKey = baseKey.derivePath(changePath); + for (let index = vm.indexStart; index <= vm.indexEnd; index++) { + const indexPath = `${index}${vm.path.indexOf('_idx_\'') >= 0 ? '\'' : ''}`; + const key = changeKey.derivePath(indexPath); + const desc = `wpkh(${key.toWIF()})`; + const output = new Output({ + descriptor: desc, + network: network, + }); + const checksum = bitcoin.descriptors.checksum(desc); + const addr = output.getAddress(); + str += `bitcoin-cli importdescriptors '[{"desc":"wpkh(${key.toWIF()})#${checksum}","timestamp":"now"}]' # ${addr}\n`; + } + } + str += 'bitcoin-cli rescanblockchain 500000\n'; + return str; + }; + + // TODO(guggero): Enable once @bitcoinerlab/descriptors supports P2TR descriptors. + vm.getResultAsImportdescriptorstr = function (rootNode, basePath, network) { + const baseKey = rootNode.derivePath(basePath); + let str = `# Paste the following lines into a command line window. +# You might want to adjust the block number to rescan from at the bottom of the +# file if the wallet was originally created before 2017-12-18 18:35:25. +`; + for (let change = vm.changeStart; change <= vm.changeEnd; change++) { + const changePath = `${change}${vm.path.indexOf('_chg_\'') >= 0 ? '\'' : ''}`; + const changeKey = baseKey.derivePath(changePath); + for (let index = vm.indexStart; index <= vm.indexEnd; index++) { + const indexPath = `${index}${vm.path.indexOf('_idx_\'') >= 0 ? '\'' : ''}`; + const key = changeKey.derivePath(indexPath); + const desc = `tr(${key.toWIF()})`; + const output = new Output({ + descriptor: desc, + network: network, + }); + const checksum = bitcoin.descriptors.checksum(desc); + const addr = output.getAddress(); + str += `bitcoin-cli importdescriptors '[{"desc":"tr(${key.toWIF()})#${checksum}","timestamp":"now"}]' # ${addr}\n`; + } + } + str += 'bitcoin-cli rescanblockchain 500000\n'; + return str; + }; + + vm.getResultAsElectrum = function (rootNode, basePath) { + const baseKey = rootNode.derivePath(basePath); + let str = ``; + for (let change = vm.changeStart; change <= vm.changeEnd; change++) { + const changePath = `${change}${vm.path.indexOf('_chg_\'') >= 0 ? '\'' : ''}`; + const changeKey = baseKey.derivePath(changePath); + for (let index = vm.indexStart; index <= vm.indexEnd; index++) { + const indexPath = `${index}${vm.path.indexOf('_idx_\'') >= 0 ? '\'' : ''}`; + const key = changeKey.derivePath(indexPath); + + str += `p2wpkh:${key.toWIF()}\n`; + str += `p2pkh:${key.toWIF()}\n`; + str += `p2wpkh-p2sh:${key.toWIF()}\n`; + } + } + return str; + }; + vm.getAddress = function (keyPair, network) { if (vm.scheme.id === 'xprv' || vm.scheme.id === 'tprv') { return getP2PKHAddress(keyPair, network); diff --git a/yarn.lock b/yarn.lock index 9314e1c..33cf424 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,6 +23,90 @@ chalk "^2.0.0" js-tokens "^4.0.0" +"@bitcoinerlab/descriptors@^1.0.2": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@bitcoinerlab/descriptors/-/descriptors-1.1.1.tgz#0d1a828cea66c51ebc9863d3e5c43c4ffcde2fe5" + integrity sha512-AMFkbBBg9T1iWtEmWB23oADk7zaOQix6wUPLXalhTyFDjhkFXDd6pCRfto/HAdaPg/ccM4GMTVgYLee9WdYFyQ== + dependencies: + "@bitcoinerlab/miniscript" "^1.2.1" + "@bitcoinerlab/secp256k1" "^1.0.5" + bip32 "^4.0.0" + bitcoinjs-lib "^6.1.3" + ecpair "^2.1.0" + +"@bitcoinerlab/descriptors@^2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@bitcoinerlab/descriptors/-/descriptors-2.2.0.tgz#a80a470bc0987e0ee4c784c708094de65418e402" + integrity sha512-z9GOZYT5jO8oE4aq8XF0czGW1W9JrJXdslUaCfUMEMo5KnygKZhOFXZCHEvtdrEXBACURh1+b/MVhy3pH9Pi7g== + dependencies: + "@bitcoinerlab/miniscript" "^1.4.0" + "@bitcoinerlab/secp256k1" "^1.1.1" + bip32 "^4.0.0" + bitcoinjs-lib "^6.1.3" + ecpair "^2.1.0" + lodash.memoize "^4.1.2" + varuint-bitcoin "^1.1.2" + +"@bitcoinerlab/miniscript@^1.2.1", "@bitcoinerlab/miniscript@^1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@bitcoinerlab/miniscript/-/miniscript-1.4.0.tgz#9beda21d4dadb1cb806de6f846470927cfd96f6c" + integrity sha512-BsG3dmwQmgKHnRZecDgUsPjwcpnf1wgaZbolcMTByS10k1zYzIx97W51LzG7GvokRJ+wnzTX/GhC8Y3L2X0CQA== + dependencies: + bip68 "^1.0.4" + +"@bitcoinerlab/secp256k1@^1.0.5", "@bitcoinerlab/secp256k1@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@bitcoinerlab/secp256k1/-/secp256k1-1.1.1.tgz#938305c30505b67b15f3de53627bc9d8b4cc7680" + integrity sha512-uhjW51WfVLpnHN7+G0saDcM/k9IqcyTbZ+bDgLF3AX8V/a3KXSE9vn7UPBrcdU72tp0J4YPR7BHp2m7MLAZ/1Q== + dependencies: + "@noble/hashes" "^1.1.5" + "@noble/secp256k1" "^1.7.1" + +"@ledgerhq/devices@^8.4.1": + version "8.4.1" + resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-8.4.1.tgz#ab47c188ef9156f6b81c37c4ef2f2aeec97c19bf" + integrity sha512-Mbjzqlcj4Q2StxEmaYEb5wv6sK5Sk26L4xs0BC9io/AyvpXNTDAp67tryB/klNcvd+WwZPcPdYYvlNzfQ0WTUA== + dependencies: + "@ledgerhq/errors" "^6.18.0" + "@ledgerhq/logs" "^6.12.0" + rxjs "^7.8.1" + semver "^7.3.5" + +"@ledgerhq/errors@^6.18.0": + version "6.18.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.18.0.tgz#d55d6a57430d7a86532a9033ce0b45103264c620" + integrity sha512-L3jQWAGyooxRDk/MRlW2v4Ji9+kloBtdmz9wBkHaj2j0n+05rweJSV3GHw9oye1BYMbVFqFffmT4H3hlXlCasw== + +"@ledgerhq/hw-transport@^6.20.0": + version "6.31.1" + resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.31.1.tgz#fb462c5455fc6c1e8300c216cc52df6f3fb88565" + integrity sha512-0hVcrqUOM7AYV/JEq8yoeBiXLjpWrentgYt8MC3n+iNFfpORU/SUprcbu0s884IHzj+a8mx0JCZp9y7uPSLlzg== + dependencies: + "@ledgerhq/devices" "^8.4.1" + "@ledgerhq/errors" "^6.18.0" + "@ledgerhq/logs" "^6.12.0" + events "^3.3.0" + +"@ledgerhq/logs@^6.12.0": + version "6.12.0" + resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-6.12.0.tgz#ad903528bf3687a44da435d7b2479d724d374f5d" + integrity sha512-ExDoj1QV5eC6TEbMdLUMMk9cfvNKhhv5gXol4SmULRVCx/3iyCPhJ74nsb3S0Vb+/f+XujBEj3vQn5+cwS0fNA== + +"@noble/hashes@^1.1.5", "@noble/hashes@^1.2.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426" + integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg== + +"@noble/secp256k1@^1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" + integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw== + +"@scure/base@^1.1.1": + version "1.1.7" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.7.tgz#fe973311a5c6267846aa131bc72e96c5d40d2b30" + integrity sha512-PPNYBslrLNNUQ/Yad37MHYsNQtK67EhWb6WtSvNLLPo7SdVZgkUjD6Dg+5On7zNwmskf8OX7I7Nx5oN+MIWE0g== + "@types/color-name@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" @@ -51,7 +135,7 @@ abbrev@1: resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== -acorn-node@^1.2.0, acorn-node@^1.3.0, acorn-node@^1.5.2: +acorn-node@^1.2.0, acorn-node@^1.3.0, acorn-node@^1.5.2, acorn-node@^1.8.2: version "1.8.2" resolved "https://registry.yarnpkg.com/acorn-node/-/acorn-node-1.8.2.tgz#114c95d64539e53dede23de8b9d96df7c7ae2af8" integrity sha512-8mt+fslDufLYntIoPAaIMUe/lrbrehIiwmR3t2k9LljIzoigEPF27eLk2hy8zSGzmR/ogr7zbRKINMo1u0yh5A== @@ -65,11 +149,6 @@ acorn-walk@^7.0.0: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA== -acorn@^5.2.1: - version "5.7.4" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" - integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== - acorn@^7.0.0: version "7.4.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" @@ -178,6 +257,13 @@ atob@^2.1.2: resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +available-typed-arrays@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz#a5cc375d6a03c2efc87a553f3e0b1522def14846" + integrity sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ== + dependencies: + possible-typed-array-names "^1.0.0" + babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -706,6 +792,11 @@ base-x@^3.0.2: dependencies: safe-buffer "^5.0.1" +base-x@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" + integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== + base64-js@^1.0.2: version "1.3.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" @@ -724,7 +815,7 @@ base@^0.11.1: mixin-deep "^1.2.0" pascalcase "^0.1.1" -bech32@2.0.0: +bech32@2.0.0, bech32@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== @@ -762,6 +853,16 @@ bip174@^2.0.1: resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.0.1.tgz#39cf8ca99e50ce538fb762589832f4481d07c254" integrity sha512-i3X26uKJOkDTAalYAp0Er+qGMDhrbbh2o93/xiPyAN2s25KrClSpe3VXo/7mNJoqA5qfko8rLS2l3RWZgYmjKQ== +bip174@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.1.1.tgz#ef3e968cf76de234a546962bcf572cc150982f9f" + integrity sha512-mdFV5+/v0XyNYXjBS6CQPLo9ekCx4gtKZFnJm5PMto7Fs9hTTDpkkzOB7/FtluRI6JbUUAu+snTYfJRgHLZbZQ== + +bip32-path@^0.4.2: + version "0.4.2" + resolved "https://registry.yarnpkg.com/bip32-path/-/bip32-path-0.4.2.tgz#5db0416ad6822712f077836e2557b8697c0c7c99" + integrity sha512-ZBMCELjJfcNMkz5bDuJ1WrYvjlhEF5k6mQ8vUr4N7MbVRsXei7ZOg8VhhwMfNiW68NWmLkgkc6WvTickrLGprQ== + bip32@^2.0.4, bip32@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/bip32/-/bip32-2.0.6.tgz#6a81d9f98c4cd57d05150c60d8f9e75121635134" @@ -775,6 +876,16 @@ bip32@^2.0.4, bip32@^2.0.6: typeforce "^1.11.5" wif "^2.0.6" +bip32@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/bip32/-/bip32-4.0.0.tgz#7fac3c05072188d2d355a4d6596b37188f06aa2f" + integrity sha512-aOGy88DDlVUhspIXJN+dVEtclhIsfAUppD43V0j40cPTld3pv/0X/MlrZSZ6jowIaQQzFwP8M6rFU2z2mVYjDQ== + dependencies: + "@noble/hashes" "^1.2.0" + "@scure/base" "^1.1.1" + typeforce "^1.11.5" + wif "^2.0.6" + bip38@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/bip38/-/bip38-2.0.3.tgz#12e48749d6c28dd14e8bcb37a9f2dae67a797da0" @@ -806,6 +917,11 @@ bip66@^1.1.0: dependencies: safe-buffer "^5.0.1" +bip68@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/bip68/-/bip68-1.0.4.tgz#78a95c7a43fad183957995cc2e08d79b0c372c4d" + integrity sha512-O1htyufFTYy3EO0JkHg2CLykdXEtV2ssqw47Gq9A0WByp662xpJnMEB9m43LZjsSDjIAOozWRExlFQk2hlV1XQ== + bitcoin-ops@^1.3.0, bitcoin-ops@^1.4.0, bitcoin-ops@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz#e45de620398e22fd4ca6023de43974ff42240278" @@ -832,6 +948,18 @@ bitcoinjs-lib@^5.2.0: varuint-bitcoin "^1.0.4" wif "^2.0.1" +bitcoinjs-lib@^6.1.3: + version "6.1.6" + resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-6.1.6.tgz#f57c17c82511f860f11946d784c18da39f8618a8" + integrity sha512-Fk8+Vc+e2rMoDU5gXkW9tD+313rhkm5h6N9HfZxXvYU9LedttVvmXKTgd9k5rsQJjkSfsv6XRM8uhJv94SrvcA== + dependencies: + "@noble/hashes" "^1.2.0" + bech32 "^2.0.0" + bip174 "^2.1.1" + bs58check "^3.0.1" + typeforce "^1.11.3" + varuint-bitcoin "^1.1.2" + blakejs@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.1.0.tgz#69df92ef953aa88ca51a32df6ab1c54a155fc7a5" @@ -893,12 +1021,12 @@ browser-pack@^6.0.1: through2 "^2.0.0" umd "^3.0.0" -browser-resolve@^1.11.0, browser-resolve@^1.7.0: - version "1.11.3" - resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.3.tgz#9b7cbb3d0f510e4cb86bdbd796124d28b5890af6" - integrity sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ== +browser-resolve@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-2.0.0.tgz#99b7304cb392f8d73dba741bb2d7da28c6d7842b" + integrity sha512-7sWsQlYL2rGLy2IWm8WL8DCTJvYLc/qlOnsakDac87SOoCd16WLsaAMdCiAqsTNHIe+SXfaqyxyo6THoWqs8WQ== dependencies: - resolve "1.1.7" + resolve "^1.17.0" browserify-aes@^1.0.0, browserify-aes@^1.0.1, browserify-aes@^1.0.4: version "1.2.0" @@ -961,57 +1089,58 @@ browserify-zlib@~0.2.0: dependencies: pako "~1.0.5" -browserify@^14.5.0: - version "14.5.0" - resolved "https://registry.yarnpkg.com/browserify/-/browserify-14.5.0.tgz#0bbbce521acd6e4d1d54d8e9365008efb85a9cc5" - integrity sha512-gKfOsNQv/toWz+60nSPfYzuwSEdzvV2WdxrVPUbPD/qui44rAkB3t3muNtmmGYHqrG56FGwX9SUEQmzNLAeS7g== +browserify@^17.0.0: + version "17.0.0" + resolved "https://registry.yarnpkg.com/browserify/-/browserify-17.0.0.tgz#4c48fed6c02bfa2b51fd3b670fddb805723cdc22" + integrity sha512-SaHqzhku9v/j6XsQMRxPyBrSP3gnwmE27gLJYZgMT2GeK3J0+0toN+MnuNYDfHwVGQfLiMZ7KSNSIXHemy905w== dependencies: JSONStream "^1.0.3" assert "^1.4.0" browser-pack "^6.0.1" - browser-resolve "^1.11.0" + browser-resolve "^2.0.0" browserify-zlib "~0.2.0" - buffer "^5.0.2" + buffer "~5.2.1" cached-path-relative "^1.0.0" - concat-stream "~1.5.1" + concat-stream "^1.6.0" console-browserify "^1.1.0" constants-browserify "~1.0.0" crypto-browserify "^3.0.0" defined "^1.0.0" - deps-sort "^2.0.0" - domain-browser "~1.1.0" + deps-sort "^2.0.1" + domain-browser "^1.2.0" duplexer2 "~0.1.2" - events "~1.1.0" + events "^3.0.0" glob "^7.1.0" has "^1.0.0" htmlescape "^1.1.0" https-browserify "^1.0.0" inherits "~2.0.1" - insert-module-globals "^7.0.0" + insert-module-globals "^7.2.1" labeled-stream-splicer "^2.0.0" - module-deps "^4.0.8" + mkdirp-classic "^0.5.2" + module-deps "^6.2.3" os-browserify "~0.3.0" parents "^1.0.1" - path-browserify "~0.0.0" + path-browserify "^1.0.0" process "~0.11.0" punycode "^1.3.2" querystring-es3 "~0.2.0" read-only-stream "^2.0.0" readable-stream "^2.0.2" resolve "^1.1.4" - shasum "^1.0.0" + shasum-object "^1.0.0" shell-quote "^1.6.1" - stream-browserify "^2.0.0" - stream-http "^2.0.0" - string_decoder "~1.0.0" + stream-browserify "^3.0.0" + stream-http "^3.0.0" + string_decoder "^1.1.1" subarg "^1.0.0" syntax-error "^1.1.1" through2 "^2.0.0" timers-browserify "^1.0.1" - tty-browserify "~0.0.0" + tty-browserify "0.0.1" url "~0.11.0" - util "~0.10.1" - vm-browserify "~0.0.1" + util "~0.12.0" + vm-browserify "^1.0.0" xtend "^4.0.0" browserslist@^3.2.6: @@ -1029,6 +1158,13 @@ bs58@^4.0.0: dependencies: base-x "^3.0.2" +bs58@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279" + integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ== + dependencies: + base-x "^4.0.0" + bs58check@<3.0.0, bs58check@^2.0.0, bs58check@^2.1.0, bs58check@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc" @@ -1038,6 +1174,14 @@ bs58check@<3.0.0, bs58check@^2.0.0, bs58check@^2.1.0, bs58check@^2.1.1: create-hash "^1.1.0" safe-buffer "^5.1.2" +bs58check@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-3.0.1.tgz#2094d13720a28593de1cba1d8c4e48602fdd841c" + integrity sha512-hjuuJvoWEybo7Hn/0xOrczQKKEKD63WguEjlhLExYs2wUBcebDC1jDNK17eEAD2lYfw82d5ASC1d7K3SWszjaQ== + dependencies: + "@noble/hashes" "^1.2.0" + bs58 "^5.0.0" + buffer-from@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" @@ -1048,10 +1192,10 @@ buffer-xor@^1.0.2, buffer-xor@^1.0.3: resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk= -buffer@^5.0.2: - version "5.6.0" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786" - integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw== +buffer@~5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.1.tgz#dd57fa0f109ac59c602479044dca7b8b3d0b71d6" + integrity sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg== dependencies: base64-js "^1.0.2" ieee754 "^1.1.4" @@ -1081,6 +1225,22 @@ cached-path-relative@^1.0.0: resolved "https://registry.yarnpkg.com/cached-path-relative/-/cached-path-relative-1.0.2.tgz#a13df4196d26776220cc3356eb147a52dba2c6db" integrity sha512-5r2GqsoEb4qMTTN9J+WzXfjov+hjxT+j3u5K+kIVNIwAd99DLCJE9pBIMP1qVeybV6JiijL385Oz0DcYxfbOIg== +cached-path-relative@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/cached-path-relative/-/cached-path-relative-1.1.0.tgz#865576dfef39c0d6a7defde794d078f5308e3ef3" + integrity sha512-WF0LihfemtesFcJgO7xfOoOcnWzY/QHR4qeDqV44jPU3HTI54+LnfXK3SA27AVVGCdZFgjjFFaqUA9Jx7dMJZA== + +call-bind@^1.0.2, call-bind@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.7.tgz#06016599c40c56498c18769d2730be242b6fa3b9" + integrity sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + set-function-length "^1.2.1" + caller-callsite@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/caller-callsite/-/caller-callsite-2.0.0.tgz#847e0fce0a223750a9a027c54b33731ad3154134" @@ -1233,7 +1393,7 @@ concat-map@0.0.1: resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= -concat-stream@^1.6.1: +concat-stream@^1.6.0, concat-stream@^1.6.1, concat-stream@~1.6.0: version "1.6.2" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34" integrity sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw== @@ -1243,15 +1403,6 @@ concat-stream@^1.6.1: readable-stream "^2.2.2" typedarray "^0.0.6" -concat-stream@~1.5.0, concat-stream@~1.5.1: - version "1.5.2" - resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266" - integrity sha1-cIl4Yk2FavQaWnQd790mHadSwmY= - dependencies: - inherits "~2.0.1" - readable-stream "~2.0.0" - typedarray "~0.0.5" - console-browserify@^1.1.0: version "1.2.0" resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.2.0.tgz#67063cef57ceb6cf4993a2ab3a55840ae8c49336" @@ -1380,6 +1531,15 @@ decode-uri-component@^0.2.0: resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= +define-data-property@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/define-data-property/-/define-data-property-1.1.4.tgz#894dc141bb7d3060ae4366f6a0107e68fbe48c5e" + integrity sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A== + dependencies: + es-define-property "^1.0.0" + es-errors "^1.3.0" + gopd "^1.0.1" + define-property@^0.2.5: version "0.2.5" resolved "https://registry.yarnpkg.com/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116" @@ -1407,7 +1567,7 @@ defined@^1.0.0: resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM= -deps-sort@^2.0.0: +deps-sort@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/deps-sort/-/deps-sort-2.0.1.tgz#9dfdc876d2bcec3386b6829ac52162cda9fa208d" integrity sha512-1orqXQr5po+3KI6kQb9A4jnXT1PBwggGl2d7Sq2xsnOeI9GPcE/tGcF9UiSZtZBM7MukY4cAh7MemS6tZYipfw== @@ -1437,13 +1597,14 @@ detect-indent@^4.0.0: dependencies: repeating "^2.0.0" -detective@^4.0.0: - version "4.7.1" - resolved "https://registry.yarnpkg.com/detective/-/detective-4.7.1.tgz#0eca7314338442febb6d65da54c10bb1c82b246e" - integrity sha512-H6PmeeUcZloWtdt4DAkFyzFL94arpHr3NOwwmVILFiy+9Qd4JTxxXrzfyGk/lmct2qVGBwTSwSXagqu2BxmWig== +detective@^5.2.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/detective/-/detective-5.2.1.tgz#6af01eeda11015acb0e73f933242b70f24f91034" + integrity sha512-v9XE1zRnz1wRtgurGu0Bs8uHKFSTdteYZNbIPFVhUZ39L/S79ppMpdmVOZAnoz1jfEFodc48n6MX483Xo3t1yw== dependencies: - acorn "^5.2.1" + acorn-node "^1.8.2" defined "^1.0.0" + minimist "^1.2.6" diffie-hellman@^5.0.0: version "5.0.3" @@ -1454,10 +1615,10 @@ diffie-hellman@^5.0.0: miller-rabin "^4.0.0" randombytes "^2.0.0" -domain-browser@~1.1.0: - version "1.1.7" - resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" - integrity sha1-hnqksJP6oF8d4IwG9NeyH9+GmLw= +domain-browser@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda" + integrity sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA== duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2: version "0.1.4" @@ -1466,6 +1627,15 @@ duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2: dependencies: readable-stream "^2.0.2" +ecpair@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/ecpair/-/ecpair-2.1.0.tgz#673f826b1d80d5eb091b8e2010c6b588e8d2cb45" + integrity sha512-cL/mh3MtJutFOvFc27GPZE2pWL3a3k4YvzUWEOvilnfZVlH3Jwgx/7d6tlD7/75tNk8TG2m+7Kgtz0SI1tWcqw== + dependencies: + randombytes "^2.1.0" + typeforce "^1.18.0" + wif "^2.0.6" + ecurve@^1.0.0, ecurve@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/ecurve/-/ecurve-1.0.6.tgz#dfdabbb7149f8d8b78816be5a7d5b83fcf6de797" @@ -1519,6 +1689,18 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +es-define-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/es-define-property/-/es-define-property-1.0.0.tgz#c7faefbdff8b2696cf5f46921edfb77cc4ba3845" + integrity sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ== + dependencies: + get-intrinsic "^1.2.4" + +es-errors@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/es-errors/-/es-errors-1.3.0.tgz#05f75a25dab98e4fb1dcd5e1472c0546d5057c8f" + integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw== + escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -1539,10 +1721,10 @@ eventemitter2@~0.4.13: resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-0.4.14.tgz#8f61b75cde012b2e9eb284d4545583b5643b61ab" integrity sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas= -events@~1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" - integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ= +events@^3.0.0, events@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" + integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: version "1.0.3" @@ -1699,6 +1881,13 @@ flagged-respawn@^1.0.0: resolved "https://registry.yarnpkg.com/flagged-respawn/-/flagged-respawn-1.0.1.tgz#e7de6f1279ddd9ca9aac8a5971d618606b3aab41" integrity sha512-lNaHNVymajmk0OJMBn8fVUAU1BtDeKIqKoVhk4xAALB57aALg6b4W0MfJ/cUE0g9YBXy5XhSlPIpYIJ7HaY/3Q== +for-each@^0.3.3: + version "0.3.3" + resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e" + integrity sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw== + dependencies: + is-callable "^1.1.3" + for-in@^1.0.1, for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -1728,11 +1917,27 @@ function-bind@^1.1.1: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function-bind@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" + integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== + get-assigned-identifiers@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/get-assigned-identifiers/-/get-assigned-identifiers-1.2.0.tgz#6dbf411de648cbaf8d9169ebb0d2d576191e2ff1" integrity sha512-mBBwmeGTrxEMO4pMaaf/uUEFHnYtwr8FTe8Y/mer4rcV/bye0qGm6pw1bGZFGStxC5O76c5ZAVBGnqHmOaJpdQ== +get-intrinsic@^1.1.3, get-intrinsic@^1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz#e385f5a4b5227d449c3eabbad05494ef0abbeadd" + integrity sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ== + dependencies: + es-errors "^1.3.0" + function-bind "^1.1.2" + has-proto "^1.0.1" + has-symbols "^1.0.3" + hasown "^2.0.0" + get-stdin@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-7.0.0.tgz#8d5de98f15171a125c5e516643c7a6d0ea8a96f6" @@ -1808,6 +2013,13 @@ google-protobuf@^3.7.1: resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.13.0.tgz#909c5983d75dd6101ed57c79e0528d000cdc3251" integrity sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw== +gopd@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c" + integrity sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA== + dependencies: + get-intrinsic "^1.1.3" + grpc-web@^1.0.4: version "1.2.1" resolved "https://registry.yarnpkg.com/grpc-web/-/grpc-web-1.2.1.tgz#860051d705bf5baa7b81fcbd14030060bf16b7b9" @@ -1905,6 +2117,30 @@ has-flag@^4.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== +has-property-descriptors@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz#963ed7d071dc7bf5f084c5bfbe0d1b6222586854" + integrity sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg== + dependencies: + es-define-property "^1.0.0" + +has-proto@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has-proto/-/has-proto-1.0.3.tgz#b31ddfe9b0e6e9914536a6ab286426d0214f77fd" + integrity sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q== + +has-symbols@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" + integrity sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A== + +has-tostringtag@^1.0.0, has-tostringtag@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-tostringtag/-/has-tostringtag-1.0.2.tgz#2cdc42d40bef2e5b4eeab7c01a73c54ce7ab5abc" + integrity sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw== + dependencies: + has-symbols "^1.0.3" + has-value@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" @@ -1960,6 +2196,13 @@ hash.js@^1.0.0, hash.js@^1.0.3: inherits "^2.0.3" minimalistic-assert "^1.0.1" +hasown@^2.0.0, hasown@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.2.tgz#003eaf91be7adc372e84ec59dc37252cedb80003" + integrity sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ== + dependencies: + function-bind "^1.1.2" + he@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" @@ -2058,11 +2301,6 @@ import-fresh@^2.0.0: caller-path "^2.0.0" resolve-from "^3.0.0" -indexof@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" - integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= - inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -2071,7 +2309,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3: +inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -2081,11 +2319,6 @@ inherits@2.0.1: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE= -inherits@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" - integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= - ini@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -2098,10 +2331,10 @@ inline-source-map@~0.6.0: dependencies: source-map "~0.5.3" -insert-module-globals@^7.0.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/insert-module-globals/-/insert-module-globals-7.2.0.tgz#ec87e5b42728479e327bd5c5c71611ddfb4752ba" - integrity sha512-VE6NlW+WGn2/AeOMd496AHFYmE7eLKkUY6Ty31k4og5vmA3Fjuwe9v6ifH6Xx/Hz27QvdoMoviw1/pqWRB09Sw== +insert-module-globals@^7.2.1: + version "7.2.1" + resolved "https://registry.yarnpkg.com/insert-module-globals/-/insert-module-globals-7.2.1.tgz#d5e33185181a4e1f33b15f7bf100ee91890d5cb3" + integrity sha512-ufS5Qq9RZN+Bu899eA9QCAYThY+gGW7oRkmb0vC93Vlyu/CFGcH0OYPEjVkDXA5FEbTt1+VWzdoOD3Ny9N+8tg== dependencies: JSONStream "^1.0.3" acorn-node "^1.5.2" @@ -2148,6 +2381,14 @@ is-accessor-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" +is-arguments@^1.0.4: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b" + integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA== + dependencies: + call-bind "^1.0.2" + has-tostringtag "^1.0.0" + is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" @@ -2158,6 +2399,11 @@ is-buffer@^1.1.0, is-buffer@^1.1.5: resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== +is-callable@^1.1.3: + version "1.2.7" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055" + integrity sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA== + is-ci@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" @@ -2165,6 +2411,13 @@ is-ci@^2.0.0: dependencies: ci-info "^2.0.0" +is-core-module@^2.13.0: + version "2.15.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.15.0.tgz#71c72ec5442ace7e76b306e9d48db361f22699ea" + integrity sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA== + dependencies: + hasown "^2.0.2" + is-data-descriptor@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56" @@ -2224,6 +2477,13 @@ is-finite@^1.0.0: resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.1.0.tgz#904135c77fb42c0641d6aa1bcdbc4daa8da082f3" integrity sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w== +is-generator-function@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.0.10.tgz#f1558baf1ac17e0deea7c0415c438351ff2b3c72" + integrity sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A== + dependencies: + has-tostringtag "^1.0.0" + is-glob@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" @@ -2257,6 +2517,13 @@ is-stream@^1.1.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= +is-typed-array@^1.1.3: + version "1.1.13" + resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.13.tgz#d6c5ca56df62334959322d7d7dd1cca50debe229" + integrity sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw== + dependencies: + which-typed-array "^1.1.14" + is-unc-path@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-unc-path/-/is-unc-path-1.0.0.tgz#d731e8898ed090a12c352ad2eaed5095ad322c9d" @@ -2334,23 +2601,11 @@ json-parse-even-better-errors@^2.3.0: resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w== -json-stable-stringify@~0.0.0: - version "0.0.1" - resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45" - integrity sha1-YRwj6BTbN1Un34URk9tZ3Sryf0U= - dependencies: - jsonify "~0.0.0" - json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" integrity sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE= -jsonify@~0.0.0: - version "0.0.0" - resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" - integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM= - jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" @@ -2388,6 +2643,17 @@ labeled-stream-splicer@^2.0.0: inherits "^2.0.1" stream-splicer "^2.0.0" +ledger-bitcoin@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/ledger-bitcoin/-/ledger-bitcoin-0.2.3.tgz#9954f4464f1f439e393d228ae477ad86573d023b" + integrity sha512-sWdvMTR5CkebNlM0Mam9ROdpsD7Y4087kj4cbIaCCq8IXShCQ44vE3j0wTmt+sHp13eETgY63OWN1rkuIfMfuQ== + dependencies: + "@bitcoinerlab/descriptors" "^1.0.2" + "@bitcoinerlab/secp256k1" "^1.0.5" + "@ledgerhq/hw-transport" "^6.20.0" + bip32-path "^0.4.2" + bitcoinjs-lib "^6.1.3" + liftoff@~2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/liftoff/-/liftoff-2.5.0.tgz#2009291bb31cea861bbf10a7c15a28caf75c31ec" @@ -2422,6 +2688,11 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" +lodash.memoize@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" + integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag== + lodash.memoize@~3.0.3: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-3.0.4.tgz#2dcbd2c287cbc0a55cc42328bd0c736150d53e3f" @@ -2534,6 +2805,11 @@ minimist@^1.1.0, minimist@^1.2.5: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== +minimist@^1.2.6: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== + mixin-deep@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.2.tgz#1120b43dc359a785dce65b55b82e257ccf479566" @@ -2542,6 +2818,11 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" +mkdirp-classic@^0.5.2: + version "0.5.3" + resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113" + integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A== + mkdirp@^0.5.1: version "0.5.5" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" @@ -2554,22 +2835,22 @@ mkdirp@~1.0.4: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== -module-deps@^4.0.8: - version "4.1.1" - resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-4.1.1.tgz#23215833f1da13fd606ccb8087b44852dcb821fd" - integrity sha1-IyFYM/HaE/1gbMuAh7RIUty4If0= +module-deps@^6.2.3: + version "6.2.3" + resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-6.2.3.tgz#15490bc02af4b56cf62299c7c17cba32d71a96ee" + integrity sha512-fg7OZaQBcL4/L+AK5f4iVqf9OMbCclXfy/znXRxTVhJSeW5AIlS9AwheYwDaXM3lVW7OBeaeUEY3gbaC6cLlSA== dependencies: JSONStream "^1.0.3" - browser-resolve "^1.7.0" - cached-path-relative "^1.0.0" - concat-stream "~1.5.0" + browser-resolve "^2.0.0" + cached-path-relative "^1.0.2" + concat-stream "~1.6.0" defined "^1.0.0" - detective "^4.0.0" + detective "^5.2.0" duplexer2 "^0.1.2" inherits "^2.0.1" parents "^1.0.0" readable-stream "^2.0.2" - resolve "^1.1.3" + resolve "^1.4.0" stream-combiner2 "^1.1.1" subarg "^1.0.0" through2 "^2.0.0" @@ -2825,10 +3106,10 @@ pascalcase@^0.1.1: resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= -path-browserify@~0.0.0: - version "0.0.1" - resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" - integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ== +path-browserify@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" + integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g== path-exists@^3.0.0: version "3.0.0" @@ -2855,6 +3136,11 @@ path-parse@^1.0.6: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +path-parse@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== + path-platform@~0.11.15: version "0.11.15" resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2" @@ -2902,16 +3188,16 @@ posix-character-classes@^0.1.0: resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= +possible-typed-array-names@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz#89bb63c6fada2c3e90adc4a647beeeb39cc7bf8f" + integrity sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q== + private@^0.1.6, private@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" integrity sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg== -process-nextick-args@~1.0.6: - version "1.0.7" - resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" - integrity sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M= - process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" @@ -3006,7 +3292,7 @@ read-pkg@^5.1.1: parse-json "^5.0.0" type-fest "^0.6.0" -readable-stream@^2.0.2, readable-stream@^2.2.2, readable-stream@^2.3.6, readable-stream@~2.3.6: +readable-stream@^2.0.2, readable-stream@^2.2.2, readable-stream@~2.3.6: version "2.3.7" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57" integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw== @@ -3019,6 +3305,15 @@ readable-stream@^2.0.2, readable-stream@^2.2.2, readable-stream@^2.3.6, readable string_decoder "~1.1.1" util-deprecate "~1.0.1" +readable-stream@^3.5.0: + version "3.6.2" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967" + integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + readable-stream@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" @@ -3028,18 +3323,6 @@ readable-stream@^3.6.0: string_decoder "^1.1.1" util-deprecate "^1.0.1" -readable-stream@~2.0.0: - version "2.0.6" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" - integrity sha1-j5A0HmilPMySh4jaz80Rs265t44= - dependencies: - core-util-is "~1.0.0" - inherits "~2.0.1" - isarray "~1.0.0" - process-nextick-args "~1.0.6" - string_decoder "~0.10.x" - util-deprecate "~1.0.1" - rechoir@^0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" @@ -3135,18 +3418,22 @@ resolve-url@^0.2.1: resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo= -resolve@1.1.7: - version "1.1.7" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" - integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= - -resolve@^1.1.3, resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0: +resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0: version "1.17.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444" integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== dependencies: path-parse "^1.0.6" +resolve@^1.17.0, resolve@^1.4.0: + version "1.22.8" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" + integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw== + dependencies: + is-core-module "^2.13.0" + path-parse "^1.0.7" + supports-preserve-symlinks-flag "^1.0.0" + ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" @@ -3172,6 +3459,13 @@ run-node@^1.0.0: resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e" integrity sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A== +rxjs@^7.8.1: + version "7.8.1" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" + integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== + dependencies: + tslib "^2.1.0" + safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@^5.2.1, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -3219,6 +3513,23 @@ semver-compare@^1.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== +semver@^7.3.5: + version "7.6.3" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" + integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A== + +set-function-length@^1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449" + integrity sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg== + dependencies: + define-data-property "^1.1.4" + es-errors "^1.3.0" + function-bind "^1.1.2" + get-intrinsic "^1.2.4" + gopd "^1.0.1" + has-property-descriptors "^1.0.2" + set-value@^2.0.0, set-value@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/set-value/-/set-value-2.0.1.tgz#a18d40530e6f07de4228c7defe4227af8cad005b" @@ -3229,7 +3540,7 @@ set-value@^2.0.0, set-value@^2.0.1: is-plain-object "^2.0.3" split-string "^3.0.1" -sha.js@^2.4.0, sha.js@^2.4.8, sha.js@~2.4.4: +sha.js@^2.4.0, sha.js@^2.4.8: version "2.4.11" resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.11.tgz#37a5cf0b81ecbc6943de109ba2960d1b26584ae7" integrity sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ== @@ -3244,14 +3555,6 @@ shasum-object@^1.0.0: dependencies: fast-safe-stringify "^2.0.7" -shasum@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/shasum/-/shasum-1.0.2.tgz#e7012310d8f417f4deb5712150e5678b87ae565f" - integrity sha1-5wEjENj0F/TetXEhUOVni4euVl8= - dependencies: - json-stable-stringify "~0.0.0" - sha.js "~2.4.4" - shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -3416,13 +3719,13 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -stream-browserify@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.2.tgz#87521d38a44aa7ee91ce1cd2a47df0cb49dd660b" - integrity sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg== +stream-browserify@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f" + integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA== dependencies: - inherits "~2.0.1" - readable-stream "^2.0.2" + inherits "~2.0.4" + readable-stream "^3.5.0" stream-combiner2@^1.1.1: version "1.1.1" @@ -3432,16 +3735,15 @@ stream-combiner2@^1.1.1: duplexer2 "~0.1.0" readable-stream "^2.0.2" -stream-http@^2.0.0: - version "2.8.3" - resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.8.3.tgz#b2d242469288a5a27ec4fe8933acf623de6514fc" - integrity sha512-+TSkfINHDo4J+ZobQLWiMouQYB+UVYFttRA94FpEzzJ7ZdqcL4uUUQ7WkdkI4DSozGmgBUE/a47L+38PenXhUw== +stream-http@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-3.2.0.tgz#1872dfcf24cb15752677e40e5c3f9cc1926028b5" + integrity sha512-Oq1bLqisTyK3TSCXpPbT4sdeYNdmyZJv1LxpEm2vu1ZhK89kSE5YXwZc3cWk0MagGaKriBh9mCFbVGtO+vY29A== dependencies: builtin-status-codes "^3.0.0" - inherits "^2.0.1" - readable-stream "^2.3.6" - to-arraybuffer "^1.0.0" - xtend "^4.0.0" + inherits "^2.0.4" + readable-stream "^3.6.0" + xtend "^4.0.2" stream-splicer@^2.0.0: version "2.0.1" @@ -3458,18 +3760,6 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -string_decoder@~0.10.x: - version "0.10.31" - resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" - integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= - -string_decoder@~1.0.0: - version "1.0.3" - resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab" - integrity sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ== - dependencies: - safe-buffer "~5.1.0" - string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -3515,6 +3805,11 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +supports-preserve-symlinks-flag@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" + integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== + syntax-error@^1.1.1: version "1.4.0" resolved "https://registry.yarnpkg.com/syntax-error/-/syntax-error-1.4.0.tgz#2d9d4ff5c064acb711594a3e3b95054ad51d907c" @@ -3553,11 +3848,6 @@ tiny-secp256k1@^1.1.1, tiny-secp256k1@^1.1.3: elliptic "^6.4.0" nan "^2.13.2" -to-arraybuffer@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" - integrity sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M= - to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" @@ -3593,7 +3883,12 @@ trim-right@^1.0.1: resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= -tty-browserify@~0.0.0: +tslib@^2.1.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" + integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== + +tty-browserify@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw== @@ -3613,12 +3908,12 @@ type-fest@^0.6.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== -typedarray@^0.0.6, typedarray@~0.0.5: +typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typeforce@^1.11.3, typeforce@^1.11.5: +typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0: version "1.18.0" resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== @@ -3715,12 +4010,16 @@ util@0.10.3: dependencies: inherits "2.0.1" -util@~0.10.1: - version "0.10.4" - resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901" - integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A== +util@~0.12.0: + version "0.12.5" + resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" + integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== dependencies: - inherits "2.0.3" + inherits "^2.0.3" + is-arguments "^1.0.4" + is-generator-function "^1.0.7" + is-typed-array "^1.1.3" + which-typed-array "^1.1.2" v8flags@~3.1.1: version "3.1.3" @@ -3737,19 +4036,28 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -varuint-bitcoin@^1.0.4: +varuint-bitcoin@^1.0.4, varuint-bitcoin@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92" integrity sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw== dependencies: safe-buffer "^5.1.1" -vm-browserify@~0.0.1: - version "0.0.4" - resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73" - integrity sha1-XX6kW7755Kb/ZflUOOCofDV9WnM= - dependencies: - indexof "0.0.1" +vm-browserify@^1.0.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0" + integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ== + +which-typed-array@^1.1.14, which-typed-array@^1.1.2: + version "1.1.15" + resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" + integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== + dependencies: + available-typed-arrays "^1.0.7" + call-bind "^1.0.7" + for-each "^0.3.3" + gopd "^1.0.1" + has-tostringtag "^1.0.2" which@^1.2.14, which@^1.2.9, which@~1.3.0: version "1.3.1"