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AEjF,KAAK,QAAQ,aAAa,gBAAe,UACrC,KAAK,QAAQ,mBAAmB,CAC5B,QAAS,EACT,gBAAiB,EACjB,IAAK,KAAK,IACV,SAAU,EACV,QAAS,IACV,MAAK,IACJ,KAAK,QAAQ,kBAAkB,GAAS,MAAK,IACzC,EAAS,KAAM,EAAc,IAC9B,OAAO,IACN,EAAS,EAAI,GACf,IACH,OAAO,IACN,EAAS,EAAI,GACf,IACH,OAAO,IACN,EAAS,EAAI,GAErB,EAGA,WAAW,UAAU,WAAa,SAAU,EAAM,EAAQ,GAetD,OARc,EAAO,iBAAiB,CAClC,KAAM,EACN,MAAO,EAEP,kBAAmB,KAAK,gBAAgB,KAAI,SAAU,GAClD,OAAQ,EAAY,IACxB,KAGR,EAGA,WAAW,UAAU,mBAAqB,WAYtC,OALiC,SAAS,cAAc,CACpD,SAAU,KAAK,KACf,KAAM,KAAK,KACX,cAAe,KAGvB,EAYA,OAAO,QAAU","file":"/npm/kin-node-callback@2.0.1/kinWrapper.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/kin-node-callback@2.0.1/kinWrapper.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const KinClient = require('@kinecosystem/kin-sdk-node').KinClient;\r\nconst Environment = require('@kinecosystem/kin-sdk-node').Environment;\r\nconst Channels = require('@kinecosystem/kin-sdk-node').Channels;\r\n\r\n\r\nfunction KinWrapper(seed, salt, production, appId) {\r\n    /**\r\n    * @param {String} seed - private key of your account\r\n    * @param {Boolean} production - true for production environment\r\n    * @param {String} appId - unique app id provided by the Kin foundation\r\n    */\r\n\r\n    //Safety in case user forgets 'new' keyword\r\n    if (!(this instanceof KinWrapper)) {\r\n        return new KinWrapper(seed);\r\n    }\r\n\r\n    //this can only work with a seed and salt\r\n    if (typeof seed === 'undefined') {\r\n        throw new Error('seed not defined when instantiating object');\r\n    }\r\n\r\n    if (typeof salt === 'undefined') {\r\n        throw new Error('salt not defined when instantiating object');\r\n    }\r\n\r\n    if (typeof appId === 'undefined') {\r\n        appId = ''; //will default to anon on the blockchain\r\n    }\r\n\r\n    if (!production) {\r\n        this.environment = Environment.Testnet;\r\n    } else {\r\n        this.environment = Environment.Production;\r\n    }\r\n\r\n    this.seed = seed;\r\n    this.salt = salt;\r\n    this.client = new KinClient(this.environment);\r\n    this.channelKeyPairs = this.getChannelKeyPairs();\r\n    this.account = this.getAccount(seed, this.client, appId);\r\n    this.channels = Channels;\r\n    this.fee = 100; //todo: fetch this dynamically\r\n}\r\n\r\n\r\n\r\nKinWrapper.prototype.CreateChannels = function (callBack) {\r\n    /**\r\n    *Create and fund our channel wallets and only needs to run once. After that we can use the\r\n    *generateSeeds function to re-generate the channel keypairs as long as the seed and salt are the same.\r\n    *@param {Function} callback (err, channels)\r\n    */\r\n    \r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.channels.createChannels({\r\n        environment: this.environment,\r\n        baseSeed: this.seed,\r\n        salt: this.salt,\r\n        channelsCount: 100,\r\n        startingBalance: 1 //nominal amount. For whitelisted accounts, this does not get used up\r\n    }).then(() => {\r\n        callBack(null, true);\r\n    }).catch(err => {\r\n        callBack(err);\r\n    });\r\n};\r\n\r\n\r\n\r\n\r\n\r\nKinWrapper.prototype.friendbot = function (address, amount, callBack) {\r\n    /**\r\n    *Return the transaction details of a transactionId\r\n    * @param {String} address - address of account\r\n    * @param {Number} amount - amount to fund\r\n    * @param {Function} callBack - callback (err, transactionId)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.client.friendbot({\r\n        address: address,\r\n        amount: amount\r\n    }).then(transactionId => {\r\n        callBack(null, transactionId);\r\n    }).catch((err) => {\r\n        callBack(err);\r\n    });\r\n};\r\n\r\n\r\n\r\nKinWrapper.prototype.getTransactionData = function (transactionId, callBack) {\r\n    /**\r\n    *Return the transaction details of a transactionId\r\n    * @param {String} transactionId - transactionId of account\r\n    * @param {Function} callBack - callback (err, number)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.client.getTransactionData(transactionId)\r\n        .then(transactionData => {\r\n            callBack(null, transactionData);\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n};\r\n\r\n\r\n\r\nKinWrapper.prototype.getAccountData = function (address, callBack) {\r\n    /**\r\n    *Return the account balance\r\n    * @param {String} address - address of account\r\n    * @param {Function} callBack - callback (err, number)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.client.getAccountData(address)\r\n        .then(accountData => {\r\n            callBack(null, accountData);\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n};\r\n\r\n\r\n\r\nKinWrapper.prototype.getAccountBalance = function (address, callBack) {\r\n    /**\r\n    *Return the account balance\r\n    * @param {String} address - address of account\r\n    * @param {Function} callBack - callback (err, number)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.client.getAccountBalance(address)\r\n        .then(balance => {\r\n            callBack(null, balance);\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n};\r\n\r\n\r\n\r\nKinWrapper.prototype.getMinimumFee = function (callBack) {\r\n    /**\r\n    *Return the minimum fee\r\n    * @param {Function} callBack - callback (err, number)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n    this.client.getMinimumFee()\r\n        .then(minFee => {\r\n            callBack(null, minFee);\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n};\r\n\r\n\r\n\r\nKinWrapper.prototype.isAccountExisting = function (address, callBack) {\r\n    /**\r\n    *Return if an account exists on the blockchain \r\n    * @param {String} address - address of account\r\n    * @param {Function} callBack - callback (err, bool)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.client.isAccountExisting(address)\r\n        .then(exist => {\r\n            callBack(null, exist);\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n};\r\n\r\n\r\nKinWrapper.prototype.sendKin = function (destination, amount, memoText, callBack) {\r\n    /**\r\n    * Send Kin to an account\r\n    * @param {String} destination - address of account\r\n    * @param {Number} amount - amount to send\r\n    * @param {String} memoText - optional memo\r\n    * @param {Function} callBack - callback (err, bool)\r\n    */\r\n\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    this.account.channelsPool.acquireChannel(async channel => {\r\n        this.account.buildSendKin({\r\n            address: destination,\r\n            amount: amount,\r\n            fee: this.fee,\r\n            memoText: memoText,\r\n            channel: channel\r\n        }).then(builder => {\r\n            //use the builder to submit the transaction to the blockchain\r\n            this.account.submitTransaction(builder).then(transactionId => {\r\n                callBack(null, transactionId);\r\n            }).catch((err) => {\r\n                callBack(err);\r\n            });\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n    }).catch((err) => {\r\n        callBack(err);\r\n    });\r\n};\r\n\r\n\r\nKinWrapper.prototype.createAccount = function (address, startingBalance, memoText, callBack) {\r\n    /**\r\n    * Create an account on the blockchain\r\n    * @param {String} address - address of account\r\n    * @param {Number} startingBalance - starting balance of account\r\n    * @param {String} memoText - optional memo\r\n    * @param {Function} callBack - callback (err, bool)\r\n    */\r\n    if (!isFunction(callBack)) callBack = function () { };\r\n\r\n    if (typeof memoText === 'undefined') memoText = '';\r\n    if (memoText.length > 21) callback('memo too long - shorten to 21 characters:' + memoText);\r\n\r\n    this.account.channelsPool.acquireChannel(async channel => {\r\n        this.account.buildCreateAccount({\r\n            address: address,\r\n            startingBalance: startingBalance,\r\n            fee: this.fee,\r\n            memoText: memoText, //a text memo can also be added; memos cannot exceed 21 characters\r\n            channel: channel\r\n        }).then(builder => {\r\n            this.account.submitTransaction(builder).then(transactionId => {\r\n                callBack(null, transactionId);\r\n            }).catch((err) => {\r\n                callBack(err);\r\n            });\r\n        }).catch((err) => {\r\n            callBack(err);\r\n        });\r\n    }).catch((err) => {\r\n        callBack(err);\r\n    });\r\n};\r\n\r\n\r\nKinWrapper.prototype.getAccount = function (seed, client, appId) {\r\n    /**\r\n    * Create an account on the blockchain\r\n    * @param {String} seed - seed/ private key\r\n    * @param {Object} client - kin client\r\n    * @param {String} appId - appId\r\n    */\r\n    let account = client.createKinAccount({\r\n        seed: seed,\r\n        appId: appId,\r\n        //Mapping the keypair array to a seed array because we only need the seeds\r\n        channelSecretKeys: this.channelKeyPairs.map(function (keypair) {\r\n            return (keypair.seed);\r\n        })\r\n    });\r\n    return (account);\r\n};\r\n\r\n\r\nKinWrapper.prototype.getChannelKeyPairs = function () {\r\n    /**\r\n     * Return channel key/pairs\r\n    *Regenerage created channels for use\r\n    *generateSeeds function to re-generate the channel keypairs as long as the seed and salt are the same.\r\n    */\r\n\r\n    const generatedChannelKeypairs = Channels.generateSeeds({\r\n        baseSeed: this.seed,\r\n        salt: this.salt,\r\n        channelsCount: 100\r\n    });\r\n    return (generatedChannelKeypairs);\r\n};\r\n\r\n//helper functions below\r\n\r\nfunction isFunction(possibleFunction) {\r\n    return typeof (possibleFunction) === typeof (Function);\r\n}\r\n\r\n\r\n\r\n\r\n\r\nmodule.exports = KinWrapper;\r\n"]}