{"size": 7472, "ext": "js", "max_stars_repo_path": "public/js/cljs-runtime/module$node_modules$blockstack$lib$wallet.js", "max_stars_repo_name": "kitefishlabs/hello-blockstack-meet-cljs", "max_stars_repo_stars_event_min_datetime": "2020-06-02T00:47:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-02T00:47:00.000Z", "max_issues_repo_path": "public/js/cljs-runtime/module$node_modules$blockstack$lib$wallet.js", "max_issues_repo_name": "kitefishlabs/hello-blockstack-meet-cljs", "max_issues_repo_issues_event_min_datetime": "2021-03-09T20:37:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-09T20:37:12.000Z", "max_forks_repo_path": "public/js/cljs-runtime/module$node_modules$blockstack$lib$wallet.js", "max_forks_repo_name": "kitefishlabs/hello-blockstack-meet-cljs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 467.0, "max_line_length": 595, "alphanum_fraction": 0.8233404711}
shadow$provide.module$node_modules$blockstack$lib$wallet=function(global,process,require,module,exports,shadow$shims){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg),value$jscomp$0=info.value}catch(error){reject(error);return}if(info.done)resolve(value$jscomp$0);else return Promise.resolve(value$jscomp$0).then(function(value){step("next",
value)},function(err){step("throw",err)})}return step("next")})}}function getNodePrivateKey(node){return(0,_utils.ecPairToHexString)(_bitcoinjsLib.ECPair.fromPrivateKey(node.privateKey))}Object.defineProperty(exports,"__esModule",{value:!0});exports.BlockstackWallet=void 0;global=require("module$node_modules$babel_runtime$regenerator$index");var _regenerator2=_interopRequireDefault(global),_createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=
props[i];descriptor.enumerable=descriptor.enumerable||!1;descriptor.configurable=!0;"value"in descriptor&&(descriptor.writable=!0);Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){protoProps&&defineProperties(Constructor.prototype,protoProps);staticProps&&defineProperties(Constructor,staticProps);return Constructor}}(),_crypto=require("module$node_modules$crypto_browserify$index"),_crypto2=_interopRequireDefault(_crypto),_bitcoinjsLib=require("module$node_modules$bitcoinjs_lib$src$index"),
_bitcoinjsLib2=_interopRequireDefault(_bitcoinjsLib);global=require("module$node_modules$bip39$index");var _bip2=_interopRequireDefault(global);global=require("module$node_modules$bip32$index");var _bip4=_interopRequireDefault(global),_utils=require("module$node_modules$blockstack$lib$utils"),_encryption=require("module$node_modules$blockstack$lib$encryption");exports.BlockstackWallet=function(){function BlockstackWallet(rootNode){if(!(this instanceof BlockstackWallet))throw new TypeError("Cannot call a class as a function");
this.rootNode=rootNode}_createClass(BlockstackWallet,[{key:"toBase58",value:function(){return this.rootNode.toBase58()}},{key:"getIdentityPrivateKeychain",value:function(){return this.rootNode.deriveHardened(888).deriveHardened(0)}},{key:"getBitcoinPrivateKeychain",value:function(){return this.rootNode.deriveHardened(44).deriveHardened(0).deriveHardened(0)}},{key:"getBitcoinNode",value:function(addressIndex){var chainType=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"EXTERNAL_ADDRESS";return BlockstackWallet.getNodeFromBitcoinKeychain(this.getBitcoinPrivateKeychain().toBase58(),
addressIndex,chainType)}},{key:"getIdentityAddressNode",value:function(identityIndex){return this.getIdentityPrivateKeychain().deriveHardened(identityIndex)}},{key:"getIdentitySalt",value:function(){var publicKeyHex=this.getIdentityPrivateKeychain().publicKey.toString("hex");return _crypto2.default.createHash("sha256").update(publicKeyHex).digest("hex")}},{key:"getBitcoinAddress",value:function(addressIndex){return BlockstackWallet.getAddressFromBIP32Node(this.getBitcoinNode(addressIndex))}},{key:"getBitcoinPrivateKey",
value:function(addressIndex){return getNodePrivateKey(this.getBitcoinNode(addressIndex))}},{key:"getBitcoinPublicKeychain",value:function(){return this.getBitcoinPrivateKeychain().neutered()}},{key:"getIdentityPublicKeychain",value:function(){return this.getIdentityPrivateKeychain().neutered()}},{key:"getIdentityKeyPair",value:function(addressIndex){var alwaysUncompressed=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!1,identityNode=this.getIdentityAddressNode(addressIndex),address=BlockstackWallet.getAddressFromBIP32Node(identityNode),
identityKey=getNodePrivateKey(identityNode);alwaysUncompressed&&66===identityKey.length&&(identityKey=identityKey.slice(0,64));alwaysUncompressed=identityNode.publicKey.toString("hex");identityNode=BlockstackWallet.getAppsNode(identityNode).toBase58();var salt=this.getIdentitySalt();return{key:identityKey,keyID:alwaysUncompressed,address:address,appsNodeKey:identityNode,salt:salt}}}],[{key:"fromSeedBuffer",value:function(seed){return new BlockstackWallet(_bip4.default.fromSeed(seed))}},{key:"fromBase58",
value:function(keychain){return new BlockstackWallet(_bip4.default.fromBase58(keychain))}},{key:"fromEncryptedMnemonic",value:function(data,password){return(0,_encryption.decryptMnemonic)(data,password).then(function(mnemonic){mnemonic=_bip2.default.mnemonicToSeed(mnemonic);return new BlockstackWallet(_bip4.default.fromSeed(mnemonic))}).catch(function(err){if(err.message&&err.message.startsWith("bad header;"))throw Error("Incorrect password");throw err;})}},{key:"generateMnemonic",value:function(){return _bip2.default.generateMnemonic(128,
_crypto.randomBytes)}},{key:"encryptMnemonic",value:function(){var _ref=_asyncToGenerator(_regenerator2.default.mark(function _callee(mnemonic,password){var encryptedBuffer;return _regenerator2.default.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.next=2,(0,_encryption.encryptMnemonic)(mnemonic,password);case 2:return encryptedBuffer=_context.sent,_context.abrupt("return",encryptedBuffer.toString("hex"));case 4:case "end":return _context.stop()}},_callee,
this)}));return function(_x3,_x4){return _ref.apply(this,arguments)}}()},{key:"getAppsNode",value:function(identityNode){return identityNode.deriveHardened(0)}},{key:"getNodeFromBitcoinKeychain",value:function(keychainBase58,addressIndex){var chainType=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"EXTERNAL_ADDRESS";if("EXTERNAL_ADDRESS"===chainType)chainType=0;else if("CHANGE_ADDRESS"===chainType)chainType=1;else throw Error("Invalid chain type");return _bip4.default.fromBase58(keychainBase58).derive(chainType).derive(addressIndex)}},
{key:"getAddressFromBitcoinKeychain",value:function(keychainBase58,addressIndex){return BlockstackWallet.getAddressFromBIP32Node(BlockstackWallet.getNodeFromBitcoinKeychain(keychainBase58,addressIndex,2<arguments.length&&void 0!==arguments[2]?arguments[2]:"EXTERNAL_ADDRESS"))}},{key:"getLegacyAppPrivateKey",value:function(appsNodeKey,salt,appDomain){salt=_crypto2.default.createHash("sha256").update(""+appDomain+salt).digest("hex");appDomain=0;if(0===salt.length)salt=appDomain;else{for(var i=0;i<salt.length;i++){var character=
salt.charCodeAt(i);appDomain=(appDomain<<5)-appDomain+character;appDomain&=appDomain}salt=appDomain&2147483647}appsNodeKey=_bip4.default.fromBase58(appsNodeKey).deriveHardened(salt);return getNodePrivateKey(appsNodeKey).slice(0,64)}},{key:"getAddressFromBIP32Node",value:function(node){return _bitcoinjsLib2.default.payments.p2pkh({pubkey:node.publicKey}).address}},{key:"getAppPrivateKey",value:function(appsNodeKey,salt,appDomain){salt=_crypto2.default.createHash("sha256").update(""+appDomain+salt).digest("hex");
appDomain=[];if(64!==salt.length)throw Error("Unexpected app-domain hash length of "+salt.length);for(var i=0;11>i;i++)appDomain.push(salt.slice(6*i,6*i+6));var appNode=_bip4.default.fromBase58(appsNodeKey);appDomain.forEach(function(hex){if(6<hex.length)throw Error("Invalid hex string length");appNode=appNode.deriveHardened(parseInt(hex,16))});return getNodePrivateKey(appNode).slice(0,64)}}]);return BlockstackWallet}()}
//# sourceMappingURL=module$node_modules$blockstack$lib$wallet.js.map
