@zerochain/0chain
Advanced tools
Comparing version 1.3.29 to 1.3.30
183
index.js
@@ -166,3 +166,3 @@ /* | ||
getSdkMetadata: () => { | ||
@@ -193,3 +193,3 @@ return "version: " + version + " cluster: " + clusterName; | ||
getChainStats: () => { | ||
@@ -311,22 +311,22 @@ return getInformationFromRandomSharder(Endpoints.GET_CHAIN_STATS, {}, (rawData) => { | ||
registerClient: async function registerClient(){ | ||
const mnemonic = bip39.generateMnemonic(256); | ||
const wallet = await createWallet(mnemonic); | ||
//creating read pool | ||
await this.createReadPool(wallet) | ||
return wallet; | ||
}, | ||
registerClient: async function registerClient() { | ||
const mnemonic = bip39.generateMnemonic(256); | ||
const wallet = await createWallet(mnemonic); | ||
//creating read pool | ||
await this.createReadPool(wallet) | ||
return wallet; | ||
}, | ||
createReadPool: async function createReadPool(ae){ | ||
const payload = { | ||
name: "new_read_pool", | ||
input: null | ||
} | ||
return this.executeSmartContract( | ||
ae, | ||
undefined, | ||
JSON.stringify(payload) | ||
); | ||
}, | ||
createReadPool: async function createReadPool(ae) { | ||
const payload = { | ||
name: "new_read_pool", | ||
input: null | ||
} | ||
return this.executeSmartContract( | ||
ae, | ||
undefined, | ||
JSON.stringify(payload) | ||
); | ||
}, | ||
validateMnemonic: (mnemonic) => { | ||
@@ -369,35 +369,35 @@ return bip39.validateMnemonic(mnemonic) | ||
) { | ||
Date.prototype.addDays = function(days) { | ||
var date = new Date(this.valueOf()); | ||
date.setDate(date.getDate() + days); | ||
return date; | ||
} | ||
expiration_date = Math.floor(expiration_date.addDays(30).getTime()/1000) | ||
const payload = { | ||
name: "new_allocation_request", | ||
input: { | ||
data_shards: data_shards, | ||
parity_shards: parity_shards, | ||
owner_id: ae.id, | ||
owner_public_key: ae.public_key, | ||
size: size, | ||
expiration_date: expiration_date, | ||
read_price_range: readPrice, | ||
write_price_range: writePrice, | ||
max_challenge_completion_time: 3600000000000, | ||
preferred_blobbers: preferred_blobbers, | ||
}, | ||
}; | ||
return this.executeSmartContract( | ||
ae, | ||
undefined, | ||
JSON.stringify(payload), | ||
lockTokens | ||
); | ||
}, | ||
Date.prototype.addDays = function (days) { | ||
var date = new Date(this.valueOf()); | ||
date.setDate(date.getDate() + days); | ||
return date; | ||
} | ||
expiration_date = Math.floor(expiration_date.addDays(30).getTime() / 1000) | ||
const payload = { | ||
name: "new_allocation_request", | ||
input: { | ||
data_shards: data_shards, | ||
parity_shards: parity_shards, | ||
owner_id: ae.id, | ||
owner_public_key: ae.public_key, | ||
size: size, | ||
expiration_date: expiration_date, | ||
read_price_range: readPrice, | ||
write_price_range: writePrice, | ||
max_challenge_completion_time: 3600000000000, | ||
preferred_blobbers: preferred_blobbers, | ||
}, | ||
}; | ||
return this.executeSmartContract( | ||
ae, | ||
undefined, | ||
JSON.stringify(payload), | ||
lockTokens | ||
); | ||
}, | ||
updateAllocation: function updateAllocation(ae, allocation_id, expiration_date = 2592000, size = 2147483648, tokens) { | ||
@@ -426,4 +426,4 @@ const payload = { | ||
return utils.getConsensusedInformationFromSharders( | ||
sharders, | ||
Endpoints.SC_REST_READPOOL_STATS, | ||
sharders, | ||
Endpoints.SC_REST_READPOOL_STATS, | ||
{ client_id: id } | ||
@@ -454,4 +454,4 @@ ) | ||
// zcncore.ConvertToValue(tokens), zcncore.ConvertToValue(fee) | ||
lockTokensInReadPool: async function(ae, allocation, duration, tokens){ | ||
lockTokensInReadPool: async function (ae, allocation, duration, tokens) { | ||
const payload = { | ||
@@ -467,3 +467,3 @@ name: "read_pool_lock", | ||
lockTokensInWritePool: async function(ae, allocation, duration, tokens){ | ||
lockTokensInWritePool: async function (ae, allocation, duration, tokens) { | ||
const payload = { | ||
@@ -513,3 +513,3 @@ name: "write_pool_lock", | ||
getAllocationSharedFilesFromPath: async function (allocation_id, lookup_hash, client_id, auth_token = "") { | ||
getAllocationSharedFilesFromPath: async function (allocation_id, lookup_hash, client_id, auth_token = "") { | ||
var blobber_url; | ||
@@ -519,10 +519,10 @@ const completeAllocationInfo = await this.allocationInfo(allocation_id); | ||
blobber_url = blobber + Endpoints.ALLOCATION_FILE_LIST + allocation_id | ||
const list = await utils.getReqBlobbers(blobber_url, {path_hash: lookup_hash, auth_token:auth_token }, client_id); | ||
const list = await utils.getReqBlobbers(blobber_url, { path_hash: lookup_hash, auth_token: auth_token }, client_id); | ||
return list | ||
}, | ||
getAllocationFilesFromPath: async function (allocation_id, path, client_id) { | ||
getAllocationFilesFromPath: async function (allocation_id, path, client_id) { | ||
var blobber_url; | ||
const completeAllocationInfo = await this.allocationInfo(allocation_id); | ||
@@ -532,8 +532,8 @@ blobber = completeAllocationInfo.blobbers[0].url; | ||
const list = await utils.getReqBlobbers(blobber_url, {path: path}, client_id); | ||
const list = await utils.getReqBlobbers(blobber_url, { path: path }, client_id); | ||
return list | ||
}, | ||
getAllocationFilesFromHash: async function (allocation_id, lookup_hash, client_id) { | ||
getAllocationFilesFromHash: async function (allocation_id, lookup_hash, client_id) { | ||
var blobber_url; | ||
@@ -544,4 +544,4 @@ const completeAllocationInfo = await this.allocationInfo(allocation_id); | ||
const list = await utils.getReqBlobbers(blobber_url, {path_hash: lookup_hash}, client_id); | ||
const list = await utils.getReqBlobbers(blobber_url, { path_hash: lookup_hash }, client_id); | ||
return list | ||
@@ -562,3 +562,3 @@ }, | ||
resolve(res) | ||
} else { | ||
} else { | ||
reject('Not able to fetch file details from blobbers') | ||
@@ -588,3 +588,3 @@ } | ||
const blobber_url = blobber + Endpoints.FILE_META_ENDPOINT + allocation_id; | ||
const response = await utils.postReqToBlobber(blobber_url, {}, { path_hash: path_hash, auth_token: atob(auth_ticket)}, client_id); | ||
const response = await utils.postReqToBlobber(blobber_url, {}, { path_hash: path_hash, auth_token: atob(auth_ticket) }, client_id); | ||
if (response.status === 200) { | ||
@@ -602,3 +602,3 @@ const res = { | ||
commitMetaTransaction: async function (ae, crudType, allocation_id, path='', auth_ticket = '',lookuphash='', metadata = '') { | ||
commitMetaTransaction: async function (ae, crudType, allocation_id, path = '', auth_ticket = '', lookuphash = '', metadata = '') { | ||
if (metadata.length === 0) { | ||
@@ -627,3 +627,3 @@ if (path.length > 0) { | ||
const submitResponse = await submitTransaction(ae, '', 0, JSON.stringify(payload)); | ||
const transactionData = JSON.parse(submitResponse.transaction_data) | ||
const transactionData = JSON.parse(submitResponse.transaction_data) | ||
await this.updateMetaCommitToBlobbers(submitResponse.hash, allocation_id, transactionData.MetaData.LookupHash, ae.id, auth_ticket); | ||
@@ -633,3 +633,3 @@ return submitResponse | ||
updateMetaCommitToBlobbers: async function(transaction_hash, allocation, lookup_hash, client_id, auth_ticket=""){ | ||
updateMetaCommitToBlobbers: async function (transaction_hash, allocation, lookup_hash, client_id, auth_ticket = "") { | ||
const completeAllocationInfo = await this.allocationInfo(allocation); | ||
@@ -647,3 +647,3 @@ blobber_list = completeAllocationInfo.blobbers.map(blobber => { | ||
formData.append('txn_id', transaction_hash); | ||
if(auth_ticket){ | ||
if (auth_ticket) { | ||
formData.append("auth_token", atob(auth_ticket)); | ||
@@ -661,3 +661,3 @@ } | ||
uploadObject: async function (file, allocation_id, path, encrypt=false, client_json, option = null) { | ||
uploadObject: async function (file, allocation_id, path, encrypt = false, client_json, option = null) { | ||
const url = proxyServerUrl + Endpoints.PROXY_SERVER_UPLOAD_ENDPOINT | ||
@@ -757,9 +757,9 @@ const formData = new FormData(); | ||
formData.append('dest_path', dest); | ||
formData.append('client_json', JSON.stringify(client_json)); | ||
formData.append('client_json', JSON.stringify(client_json)); | ||
const response = await utils.putReq(url, formData); | ||
return response | ||
}, | ||
recoverWalletFromCloud: async function (AppIDToken,AppPhoneNumber) { | ||
const response = await utils.recoverWalletFromCloud(AppIDToken,AppPhoneNumber); | ||
recoverWalletFromCloud: async function (AppIDToken, AppPhoneNumber) { | ||
const response = await utils.recoverWalletFromCloud(AppIDToken, AppPhoneNumber); | ||
return response | ||
@@ -779,4 +779,11 @@ }, | ||
postShareInfo: async function (phoneNumber, tokenId, authTicket, activeWallet, message, fromInfo, receiver_id) { | ||
postShareInfo: async function (phoneNumber, tokenId, authTicket, activeWallet, message, fromInfo, receiver_id, ae) { | ||
const url = '/shareinfo'; | ||
// GET SIGN USING CLIENT_ID AND WALLET PRIVATE_KEY (ADDED BY GOURAV (9 SEP)) | ||
const bytehash = utils.hexStringToByte(receiver_id); | ||
const sec = new bls.SecretKey(); | ||
sec.deserializeHexStr(ae.secretKey); | ||
const sig = sec.sign(bytehash); | ||
const data = new FormData(); | ||
@@ -788,3 +795,5 @@ data.append('id_token', tokenId); | ||
data.append('from_info', fromInfo); | ||
data.append('client_id', receiver_id); | ||
data.append('client_id', receiver_id); | ||
data.append('reciever_client_id', receiver_id); // ADD BY GOURAV (9 SEP) | ||
data.append('client_signature', sig); // ADD BY GOURAV (9 SEP) | ||
const response = await utils.postMethodTo0box(url, data, activeWallet.client_id, activeWallet.client_key); | ||
@@ -804,2 +813,10 @@ return response | ||
getSign: function (client_id, private_key) { | ||
const bytehash = utils.hexStringToByte(client_id); | ||
const sec = new bls.SecretKey(); | ||
sec.deserializeHexStr(private_key); | ||
const sig = sec.sign(bytehash); | ||
return sig | ||
}, | ||
getShareInfo: async function (phoneNumber, tokenId, activeWallet) { | ||
@@ -941,5 +958,5 @@ const response = await utils.getShareInfo(phoneNumber, tokenId, activeWallet.client_id, activeWallet.client_key); | ||
data.hash = hash; | ||
data.transaction_fee = 0; | ||
data.signature = sig.serializeToHexStr(); | ||
data.version='1.0' | ||
data.transaction_fee = 0; | ||
data.signature = sig.serializeToHexStr(); | ||
data.version = '1.0' | ||
return new Promise(function (resolve, reject) { | ||
@@ -946,0 +963,0 @@ utils.doParallelPostReqToAllMiners(miners, Endpoints.PUT_TRANSACTION, data) |
{ | ||
"name": "@zerochain/0chain", | ||
"version": "1.3.29", | ||
"version": "1.3.30", | ||
"description": "js client library to interact with 0chain Blockchain", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
169502
1589
1