Skip to content

Instantly share code, notes, and snippets.

View acastellana's full-sized avatar

Albert Castellana acastellana

View GitHub Profile
@acastellana
acastellana / isAvaliableForMS.js
Created January 27, 2017 16:04
isAvaliableForMS(address)
/**
* isAvaliableForMS(address) Checks if address can be obtained and transformed to a MultiSig account.
*
* @param {string} address - Address to check
*
* @return {promise} - A promise of the NetworkRequests service that returns true if the account is not another account's cosignatory nor already has cosignaroties.
*/
isAvaliableForMS(address){
var deferred = this._q.defer();
var promise = deferred.promise;
@acastellana
acastellana / getLastMessagesWithString.js
Created January 27, 2017 15:57
getLastMessagesWithString(address,str,start)
/*
* REQUIRES:
* - https://gist.github.com/acastellana/320c2e0fa722d9526e98f021d2e5a3b2
*/
/**
* getLastMessagesWithString(address,str,start) Obtains the last Message that contains string after position start
*
* @param {string} address - NEM Address to explore
* @param {string} str - String to find on addresses txs
@acastellana
acastellana / getTransactionMessagesWithString.js
Created January 27, 2017 15:54
getTransactionMessagesWithString(address, str, start)
/**
* getTransactionMessagesWithString(address, str, start) Obtains every transaction message that contains a certain string (starting from position start)
*
* @param {string} address - NEM Address to explore
* @param {string} str - String to find on addresses txs
* @param {integer} start - Starting position in the transaction message to search
*
* @return {promise} - A promise of the NetworkRequests service that returns an Array with the filtered messages
*/
getTransactionMessagesWithString(address, str, start){
@acastellana
acastellana / ownsMosaic.js
Created January 27, 2017 15:47
ownsMosaic(address,namespace, mosaic)
/*
* REQUIRES:
* - https://gist.github.com/acastellana/995326e3a41b5f690db50a17153af312
* - https://gist.github.com/acastellana/607a47838e842417d80622568543eb74
*/
/**
* ownsMosaic(address,namespace, mosaic) Checks if address owns any mosaics from namespace:mosaic
*
* @param {string} address - NEM Address to check for the mosaic
@acastellana
acastellana / sendMosaic.js
Created January 27, 2017 15:35
sendMosaic(recipient, namespaceId, mosaics, amount, common, options)
/*
* REQUIRES:
* - https://gist.github.com/acastellana/995326e3a41b5f690db50a17153af312
* - https://gist.github.com/acastellana/607a47838e842417d80622568543eb74
*/
/**
* sendMosaic(recipient, namespaceId, mosaics, amount, common, options) Sends a minimal transaction containing a mosaic and optionally a message and some xem
*
* @param {object} recipient - Transaction receiver's account
@acastellana
acastellana / processTxData.js
Last active January 27, 2017 16:16
processTxData(transferData)
/**
* processTxData(transferData) Processes transferData
*
* @param {object} tx - The transaction data
*
* @return {promise} - An announce transaction promise of the NetworkRequests service
*/
processTxData(transferData) {
// return if no value or address length < to min address length
if (!transferData || !transferData.recipient || transferData.recipient.length < 40) {
@acastellana
acastellana / sendMessage.js
Last active February 5, 2017 19:46
sendMessage(receiver, message, common)
/*
* REQUIRES:
* - https://gist.github.com/acastellana/995326e3a41b5f690db50a17153af312
* - https://gist.github.com/acastellana/607a47838e842417d80622568543eb74
*/
/**
* sendMessage(recipientAccount, message, common) Sends a minimal transaction containing a message to poin
*
* @param {object} receiver - Transaction receiver's account
/**
* send(entity) Sends a transaction to the network based on an entity
*
* @param {object} entity - The prepared transaction object
* @param {object} common - A password/privateKey object
*
* @return {promise} - An announce transaction promise of the NetworkRequests service
*/
send(entity, common){
// Construct transaction byte array, sign and broadcast it to the network
/**
* createBrainWallet(seed) creates a new brain wallet using the seed as name and passphrase and returns it's main account
*/
createBrainWallet(seed) {
var deferred = this._q.defer();
var promise = deferred.promise;
// Seed can't be empty
if (!seed) {
this._Alert.missingtransferData(); // TODO: Add proper alert
/**
* _checkAccess() Ensure that the user is authentic by checking his password and setting the private key to this.common
*/
checkAccess(){
// Decrypt/generate private key and check it. Returned private key is contained into this.common
if (!CryptoHelpers.passwordToPrivatekeyClear(this.common, this._Wallet.currentAccount, this._Wallet.algo, true)) {
this._Alert.invalidPassword();
// Enable send button
this.buttonDisabled = false;
return false;