Skip to content

Commit 527b1f8

Browse files
committed
expose encrypt api
1 parent 7a19f07 commit 527b1f8

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "chainsql",
3-
"version": "0.6.61",
3+
"version": "0.6.62",
44
"description": "An database driver for chainsql ",
55
"main": "src/index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"dependencies": {
1010
"bignumber.js": "^2.4.0",
11-
"chainsql-keypairs": "^0.10.4",
12-
"chainsql-lib": "^0.17.43",
11+
"chainsql-keypairs": "^0.10.6",
12+
"chainsql-lib": "^0.17.44",
1313
"co": "^4.6.0",
1414
"elliptic": "^5.1.0",
1515
"hash.js": "^1.0.3",
16-
"lodash": "^4.14.1",
16+
"lodash": "^4.17.15",
1717
"protobufjs": "^6.8.0",
1818
"sjcl": "~1.0.3",
1919
"web3-core-helpers": "1.0.0-beta.36",

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,14 @@ ChainsqlAPI.prototype.sign = function (json, secret, option) {
786786
return ripple.sign(JSON.stringify(json), secret, option);
787787
};
788788

789-
// ChainsqlAPI.prototype.encrypt = function (plainText, listPublic) {
790-
791-
// }
792-
793-
// ChainsqlAPI.prototype.decrypt = function (cipher, secret) {
789+
ChainsqlAPI.prototype.eciesEncrypt = function (plainText, publicKey) {
790+
return crypto.eciesEncrypt(plainText,publicKey);
791+
}
794792

795-
// }
793+
ChainsqlAPI.prototype.eciesDecrypt = function (cipher, secret) {
794+
var keypair = keypairs.deriveKeypair(secret);
795+
return crypto.eciesDecrypt(cipher,keypair.privateKey);
796+
}
796797

797798
ChainsqlAPI.prototype.getAccountTables = function(address, bGetDetailInfo=false){
798799
var connection = this.api ? this.api.connection : this.connect.api.connection;

test/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict'
2-
const co = require('co')
32
const ChainsqlAPI = require('../src/index');
43
// ChainsqlAPI.prototype.callback2Promise = require('./callback2Promise');
54
const c = new ChainsqlAPI();

test/testCrypto.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
const ChainsqlAPI = require('../src/index');
3+
// ChainsqlAPI.prototype.callback2Promise = require('./callback2Promise');
4+
const c = new ChainsqlAPI();
5+
6+
7+
main();
8+
9+
async function main(){
10+
try {
11+
var wallet = c.generateAddress();
12+
var cipher = c.eciesEncrypt("hello",wallet.publicKey);
13+
console.log("cipher:",cipher);
14+
var origin = c.eciesDecrypt(cipher,wallet.secret);
15+
console.log("plaintext:",origin.toString());
16+
17+
//await c.disconnect();
18+
console.log('运行结束');
19+
}catch(e){
20+
console.error(e);
21+
}
22+
}

0 commit comments

Comments
 (0)