dsd-client-conn-lib
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -13,3 +13,3 @@ /** | ||
console.log("###########################"); | ||
console.log("# CDASE API methods"); | ||
console.log("# DASE API methods"); | ||
cfg.dase.api.forEach(m => { console.log("\n\n"+TC.getMethodDescription(m)); }); | ||
@@ -16,0 +16,0 @@ console.log("###########################"); |
{ | ||
"name": "dsd-client-conn-lib", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "dsd-constants-lib": "../../dsd_core/dsd-constants-lib", |
984
README.md
@@ -6,133 +6,881 @@ #This doc file is obsolete! | ||
## Requirements | ||
You should run your nodejs server with frontend js-code. | ||
## Examples | ||
**Config file example.** | ||
It should be on server's side (or exist as an object declaration in the client js-code). | ||
Generally, it should contain keychain and pds ip:port and API methods names list. | ||
``` | ||
var CONN = require("dsd-client-conn-lib"); | ||
var dsdConn = CONN.connClient2; | ||
var dsdCst = CONN.Consts; | ||
dsdConn.setDaseServer({ host: "partner.dase.io", port: 5110 }); | ||
```json | ||
{ | ||
"keychain": { | ||
"restMode": false, | ||
"rpcConnect": { | ||
"port": 5110, | ||
"host": "partner.dase.io", | ||
"path": "/", | ||
"strict": false | ||
}, | ||
"api": [ | ||
{ "name": "newAccount" }, | ||
{ "name": "getChallenge" }, | ||
{ "name": "getEncryptedKeyData" } | ||
] | ||
}, | ||
"pds": { | ||
"restMode": false, | ||
"rpcConnect": { | ||
"port": 5100, | ||
"host": "partner.dase.io", | ||
"path": "/", | ||
"strict": false | ||
}, | ||
"api": [ | ||
{"name": "addDab"}, | ||
{"name": "listVaults"}, | ||
{"name": "getDabs"}, | ||
{"name": "offerBuyAccess"}, | ||
{"name": "isAccessGranted"}, | ||
{"name": "newUser"}, | ||
{"name": "newUser_Public"}, | ||
{"name": "getKeys"}, | ||
{"name": "getKeys_Public"}, | ||
{"name": "getSilverBalance"}, | ||
{"name": "getUploadTicket"}, | ||
{"name": "getAccessTicket"}, | ||
{"name": "sendSilver"}, | ||
... | ||
] | ||
} | ||
... | ||
function log(title, msg) { | ||
console.log(title, msg ? msg : ""); | ||
// document.getElementById("log").innerHTML += '<div>'+title + (msg ? JSON.stringify(msg) : "")+'</div>'; | ||
} | ||
log("sendSilver should success"); | ||
dsdConn.getCoreClient().sendSilver({ | ||
senderId: "0x003e8c791cb39b4cad756b9c25431d6eb3fed85c", | ||
senderPassword: "12345678", | ||
silverAmount: 100, | ||
toUserId: "0xb35ef3e31f2944d252eda42801caf5d890d1d7f9" | ||
}).then( | ||
ok => { log("sendSilver ok: ", ok); }, | ||
err => { log("sendSilver err: ", err); } | ||
); | ||
log("sendSilver2 should error"); | ||
dsdConn.getDaseClient().sendSilver({ | ||
senderId: "0x003e8c791cb39b4cad756b9c25431d6eb3fed85c", | ||
senderPassword: "12345678", | ||
toUserId: "0xb35ef3e31f2944d252eda42801caf5d890d1d7f9" | ||
}).then( | ||
ok => { log("sendSilver2 ok: ", ok); }, | ||
err => { | ||
log("sendSilver2 err: ", err); | ||
//specify error handlers if necessary | ||
if(err.code === dsdCst.errorCodes.WrongParametersCount.id) { | ||
log("I have wrong parameters count..."+dsdCst.errorCodes.WrongParametersCount.name); | ||
//do something | ||
} | ||
else if(err.code === dsdCst.errorCodes.ServerSideError.id) { | ||
log("I have server error..."+ dsdCst.errorCodes.ServerSideError.name); | ||
//do something | ||
} | ||
} | ||
); | ||
console.log("addDab should success"); | ||
dsdConn.getPdsClient().addDab({ | ||
ownerId: "0x003e8c791cb39b4cad756b9c25431d6eb3fed85c", | ||
assetUrl: "http://localhost", | ||
ownerPassword: "12345678", | ||
publicDescription: "new client lib asset", | ||
// custodians: [], | ||
// linkedDabId: 0, | ||
// publicityType: dsdCst.publicityTypes.PublicityPublic.id, | ||
// dataHash: 0 | ||
}).then( | ||
ok => { log("addDab ok: ", ok); }, | ||
err => { log("addDab err: ", err); } | ||
); | ||
``` | ||
**Client js-code example:** | ||
########################### | ||
# Core API methods | ||
Every API method returns Promise object. | ||
```javascript | ||
var cfg = require("./config.json"); | ||
var ConnClient = require("dsd-client-conn-lib"); | ||
var connClient = new ConnClient(cfg); | ||
/** | ||
* Description: | ||
* Method newUser | ||
* | ||
* @param password {String} | ||
* @returns {Keys} Look at Type description in Docs. | ||
*/ | ||
class Examples { | ||
getMyCoinbase() { | ||
var promise = connClient.getPdsClient().getMyCoinbase(); | ||
promise.then( | ||
result => { | ||
console.log("get my coinbase=", result); | ||
}, | ||
error => { | ||
console.log("getting coinbase error ", error); | ||
}); | ||
} | ||
buyAccessRequest() { | ||
var promise = connClient.getPdsClient().offerBuyAccess( | ||
"0xe7e0f3cddec426b44589cd1877f0aa392b207c13", //userId, | ||
"123", //password, | ||
12, //dabId, | ||
100 //price | ||
); | ||
promise | ||
.then(result => { | ||
console.log("buy ACCESS request was sent"); | ||
}, error => { | ||
console.log("buy ACCESS request error"); | ||
}); | ||
} | ||
getSilverBalance() { | ||
var promise = connClient.getPdsClient().getSilverBalance( | ||
"0xe7e0f3cddec426b44589cd1877f0aa392b207c13"//userId | ||
); | ||
promise.then( | ||
result => { | ||
console.log("balance="+result); | ||
}, | ||
error => { | ||
console.log("getting balance error"); | ||
}); | ||
} | ||
registerUploadedAsset() { | ||
connClient.getPdsClient().addDab( | ||
"0xe7e0f3cddec426b44589cd1877f0aa392b207c13",//userId, | ||
"123",//password | ||
"vtid=1:|:avid=:|:asid=gs_1533642301827__c3po.jpeg:|:mime=image/*", | ||
"This is my asset", //pubInfo, | ||
0, //parentId, | ||
[], //custodians, | ||
0, //publicityType, | ||
0 //dataHash | ||
).then( | ||
result => { | ||
console.log("data dabId="+result+" was added!"); | ||
}, | ||
error => { | ||
console.log("adding new data dab error: ", error); | ||
} | ||
) | ||
} | ||
/** | ||
* Description: | ||
* Method newUser_Public | ||
* | ||
* @param password {String} | ||
* @returns {Keys} Look at Type description in Docs. | ||
*/ | ||
} | ||
``` | ||
/** | ||
* Description: | ||
* Method getKeys | ||
* | ||
* @param userId {Address} | ||
* @param password {String} | ||
* @returns {Keys} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getKeys_Public | ||
* | ||
* @param userId {Address} | ||
* @param password {String} | ||
* @returns {Keys} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method sendWeis | ||
* | ||
* @param sender {Address} | ||
* @param senderPassword {String} | ||
* @param receiver {Address} | ||
* @param weiAmount {Integer} | ||
* @param undefined {Unknown} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getSilverBalance | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getGoldBalance_Public | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method transferOut | ||
* | ||
* @param srcUserId {Address} | ||
* @param password {String} | ||
* @param destUserId {Address} | ||
* @param amount {Integer} | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method transferOut_Public | ||
* | ||
* @param srcUserId {Address} | ||
* @param password {String} | ||
* @param destUserId {Address} | ||
* @param amount {Integer} | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getBalanceWeis_Public | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method buyGoldForWeis_Public | ||
* | ||
* @param userId {Address} | ||
* @param password {String} | ||
* @param goldAmount {Integer} | ||
* @param weisAmount {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method weisAmountForGold_Public | ||
* | ||
* @param userId {Address} | ||
* @param goldAmount {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getEvents | ||
* | ||
* @param userId {Address} | ||
* @param pos {Integer} | ||
* @param size {Integer} | ||
* @param filterName {String} | ||
* @param relation {Object} Look at Constants description in Docs. | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getEvents_Public | ||
* | ||
* @param userId {Address} | ||
* @param pos {Integer} | ||
* @param size {Integer} | ||
* @param filterName {String} | ||
* @param relation {Object} Look at Constants description in Docs. | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getLastBlock | ||
* | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getLastBlock_Public | ||
* | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method silverCostInGold | ||
* | ||
* @param userId {Address} | ||
* @param silverAmount {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method goldCostInSilver_Public | ||
* | ||
* @param userId {Address} | ||
* @param goldAmount {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method approveUserToSpendMySilver | ||
* | ||
* @param fromUserId {Address} | ||
* @param password {String} | ||
* @param silverAmount {Integer} | ||
* @param toUserId {Address} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method approveTreasuryToSpendMySilver | ||
* | ||
* @param fromUserId {Address} | ||
* @param password {String} | ||
* @param silverAmount {Integer} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method sendSilver | ||
* | ||
* @param senderId {Address} | ||
* @param senderPassword {String} | ||
* @param silverAmount {Integer} | ||
* @param toUserId {Address} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method spendAlienSilver | ||
* | ||
* @param spenderId {Address} | ||
* @param password {String} | ||
* @param fromUserId {Address} | ||
* @param silverAmount {Integer} | ||
* @param toUserId {Address} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method isValidUser | ||
* | ||
* @param account {Address} | ||
* @param password {String} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getEligibilityValue | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method wantVote | ||
* | ||
* @param userId {Address} | ||
* @param userPassword {String} | ||
* @param iWish {Boolean} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getVoteRewardInSilver | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getVoteCostInSilver | ||
* | ||
* @param userId {Address} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getContractVoters | ||
* | ||
* @param userId {Address} | ||
* @returns - Array of {Address} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getQuorumVoters | ||
* | ||
* @returns - Array of {Address} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getCandidatesPool | ||
* | ||
* @param userId {Address} | ||
* @returns - Array of {Address} | ||
*/ | ||
/** | ||
* Description: | ||
* Method isInCandidatesPool | ||
* | ||
* @param userId {Address} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method hasPledge | ||
* | ||
* @param userId {Address} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method isLicensedForVoting | ||
* | ||
* @param userId {Address} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getMyCoinbase | ||
* | ||
* @returns {Address} | ||
*/ | ||
/** | ||
* Description: | ||
* Method withdrawPledge | ||
* | ||
* @param userId {Address} | ||
* @param userPassword {String} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method sendMessageSecured | ||
* | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getMessageSecured | ||
* | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getMessagesSecuredCount | ||
* | ||
* @returnsunspecified | ||
*/ | ||
/** | ||
* Description: | ||
* Method getLastReadMessageIndex | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method setAttributeSecured | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method getAttributeSecured | ||
* | ||
* @returns | ||
*/ | ||
########################### | ||
# CDASE API methods | ||
/** | ||
* Description: | ||
* Method addDab | ||
* | ||
* @param ownerId {Address} | ||
* @param ownerPassword {String} | ||
* @param assetUrl {String} | ||
* @param publicDescription {String} | ||
* @param linkedDabId (optional. default: 0) {Integer} | ||
* @param custodians (optional. default: []) - Array of {Address} | ||
* @param publicityType (optional. default: 0) {Integer} Look at Constants description in Docs. | ||
* @param dataHash (optional. default: 0) {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method addDabList | ||
* | ||
* @param ownerId {Address} | ||
* @param ownerPassword {String} | ||
* @param dataArr - Array of {Object} | ||
* @returns {Transaction} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method addTag | ||
* | ||
* @param ownerId {Address} | ||
* @param ownerPassword {String} | ||
* @param undefined {Unknown} | ||
* @param signature {String} | ||
* @param linkedDabId {Integer} | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getTagsIdsForDab | ||
* | ||
* @param dabId {Integer} | ||
* @param requestor {Address} | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method getOwnedDabsIds | ||
* | ||
* @param userId {Address} | ||
* @returns - Array of {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getSharedDabsIds | ||
* | ||
* @param userId {Address} | ||
* @returns - Array of {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getCustodiedDabsIds | ||
* | ||
* @param userId {Address} | ||
* @returns - Array of {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getDabs | ||
* | ||
* @param userId {Address} | ||
* @param dabId - Array of {Integer} | ||
* @returns - Array of {Dab} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getDabsPage | ||
* | ||
* @param userId {Address} | ||
* @param startDabId (optional. default: 0) {Integer} | ||
* @param pageSize (optional. default: 10) {Integer} | ||
* @returns - Array of {Dab} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getDabsForTag | ||
* | ||
* @param userId {Address} | ||
* @param tagTitle (optional. default: "") {String} | ||
* @param tagId (optional. default: undefined) {Integer} | ||
* @returns - Array of {Dab} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerSellAccess | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyerId {Address} | ||
* @param dabId {Integer} | ||
* @param minPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerBuyAccess | ||
* | ||
* @param buyer {Address} | ||
* @param buyerPassword {String} | ||
* @param dabId {Integer} | ||
* @param maxPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerSellOwnership | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @param minPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerBuyOwnership | ||
* | ||
* @param buyer {Address} | ||
* @param buyerPassword {String} | ||
* @param dabId {Integer} | ||
* @param maxPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerBuyCustody | ||
* | ||
* @param buyer {Address} | ||
* @param buyerPassword {String} | ||
* @param dabId {Integer} | ||
* @param maxPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method offerSellCustody | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @param minPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method approveOwnershipDeal | ||
* | ||
* @param custodian {Address} | ||
* @param custodianPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method approveAccessDeal | ||
* | ||
* @param custodian {Address} | ||
* @param custodianPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method approveCustodyDeal | ||
* | ||
* @param custodian {Address} | ||
* @param custodianPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getTotalLicenseFee | ||
* | ||
* @param licenseType {Integer} Look at Constants description in Docs. | ||
* @returns {Integer} | ||
*/ | ||
/** | ||
* Description: | ||
* Method repairIntegrity | ||
* | ||
* @param owner {Address} | ||
* @param ownerPassword {String} | ||
* @param dabId {Integer} | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method trustToBuyAccess | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @param minPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method trustToBuyOwnership | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @param minPrice {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method untrustToBuyAccess | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method untrustToBuyOwnership | ||
* | ||
* @param seller {Address} | ||
* @param sellerPassword {String} | ||
* @param buyer {Address} | ||
* @param dabId {Integer} | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* Description: | ||
* Method getDealsForDab | ||
* | ||
* @param userId {Address} | ||
* @param dabId {Integer} | ||
* @returns - Array of {Deal} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method checkUserPrvPayment | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method addDataSecured | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method getSecuredDabsInfoPage | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method listSecuredOwnedDabs | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method listSecuredSharedDabs | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method listSecuredCustodiedDabs | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method getSecuredDabsInfo | ||
* | ||
* @returns | ||
*/ | ||
/** | ||
* Description: | ||
* Method payBill | ||
* | ||
* @returns | ||
*/ | ||
########################### | ||
# PDS API methods | ||
/** | ||
* Description: | ||
* Method listVaults | ||
* | ||
* @param ownerId {Address} | ||
* @returns - Array of {Vault} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getUploadTicket | ||
* | ||
* @param userId {Address} | ||
* @param password {String} | ||
* @param vaultUserId {Integer} | ||
* @param vaultPassword {String} | ||
* @returns {Ticket} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getAccessTicket | ||
* | ||
* @param dabId {Integer} | ||
* @param buyer {Address} | ||
* @param seller {Address} | ||
* @param argsBuyerSignature {String} | ||
* @param publicKey {String} | ||
* @param vaultUserId {Integer} | ||
* @param vaultPassword {String} | ||
* @returns {Ticket} Look at Type description in Docs. | ||
*/ | ||
/** | ||
* Description: | ||
* Method getAccessTicketSecured | ||
* | ||
* @returns | ||
*/ |
34945
886