Comparing version 1.0.39 to 2.0.0-alpha
@@ -44,3 +44,3 @@ "use strict"; | ||
* @property {string} previousBlockHash - 最新区块的父区块哈希值(base64编码字符串) | ||
* @property {string} currentWorldStateHash - 世界状态哈希值(base64编码字符串) | ||
* @property {string} currentStateHash - 世界状态哈希值(base64编码字符串) | ||
* @property {number} totalTransactions - 交易总量 | ||
@@ -118,6 +118,6 @@ * @memberof RestAPI | ||
}, { | ||
key: "chainCurrentWorldStateHash", | ||
value: function chainCurrentWorldStateHash() { | ||
key: "chainCurrentStateHash", | ||
value: function chainCurrentStateHash() { | ||
return this.chainInfo().then(function (chainInfo) { | ||
return chainInfo.currentWorldStateHash; | ||
return chainInfo.currentStateHash; | ||
}); | ||
@@ -214,4 +214,3 @@ } | ||
* @param {Buffer | String} tx 待发送的已签名交易数据,支持使用Buffer类型数据或其hex编码的String数据 | ||
* @returns {Promise<{txid: string, result: string, ol: Array.<Object>, err: string}>} | ||
* 接收交易后RepChain节点的返回信息 | ||
* @returns {Promise<{txid: string}> | Promise<{err: string}>} 接收交易后RepChain节点的返回信息 | ||
*/ | ||
@@ -218,0 +217,0 @@ |
@@ -23,7 +23,8 @@ "use strict"; | ||
// use generated static js code | ||
var txEnumTypes = ["CHAINCODE_DEPLOY", "CHAINCODE_INVOKE"]; | ||
var txEnumTypes = ["CHAINCODE_DEPLOY", "CHAINCODE_INVOKE", "CHAINCODE_SET_STATE"]; | ||
var chaincodeLanguageEnumTypes = ["CODE_SCALA", "CODE_JAVASCRIPT"]; // Private properties | ||
var txMsgCollection = new WeakMap(); | ||
var txMsgType = _peer.rep.protos.Transaction; // Private methods | ||
var txMsgType = _peer.rep.protos.Transaction; | ||
var signatureMsgType = _peer.rep.protos.Signature; // Private methods | ||
@@ -39,16 +40,2 @@ var getTimestamp = function getTimestamp(millis) { | ||
var getNonce = function getNonce(nonce) { | ||
if (nonce) return Buffer.from(nonce); | ||
return Buffer.from("nonce"); | ||
}; | ||
var getValidators = function getValidators(toValidators) { | ||
if (toValidators) return Buffer.from(toValidators); | ||
return Buffer.from("toValidators"); | ||
}; | ||
var getAccountAddr = function getAccountAddr(pubKeyPEM) { | ||
return (0, _crypto.CalculateAddr)(pubKeyPEM); | ||
}; | ||
var Transaction = | ||
@@ -59,16 +46,19 @@ /*#__PURE__*/ | ||
* 构建RepChain交易对象 | ||
* | ||
* @param {Object} consArgs - 交易对象实例构造参数 | ||
* @param {Buffer|Uint8Array} [consArgs.txBytes] - 二进制交易数据,当使用该参数时,将忽略其他参数 | ||
* @param {string} consArgs.type - 交易类型,需与RepChain的交易类型定义一致,可为CHAINCODE_DEPLOY, | ||
* CHAINCODE_INVOKE | ||
* @param {string} consArgs.pubKeyPEM - 交易发起者的pem格式公钥信息,或符合X.509标准的pem格式公钥证书信息 | ||
* CHAINCODE_INVOKE, CHAINCODE_SET_STATE | ||
* @param {string} consArgs.chaincodeName - 目标合约的名称 | ||
* @param {number} consArgs.chaincodeVersion - 目标合约的版本号 | ||
* @param {Object} consArgs.chaincodeDeployParams - 部署合约时(即type为CHAINCODE_DEPLOY)所需参数 | ||
* @param {number} consArgs.chaincodeDeployParams.timeout | ||
* @param {string} consArgs.chaincodeDeployParams.codePackage - 待部署合约的代码内容 | ||
* @param {string} consArgs.chaincodeDeployParams.legalProse - 待部署合约的法律文本 | ||
* @param {string} consArgs.chaincodeDeployParams.codeLanguageType - 待部署合约代码语言类型, | ||
* 目前只支持CODE_SCALA和CODE_JAVASCRIPT | ||
* @param {Object} consArgs.chaincodeInvokeParams - 调用合约时(即type为CHAINCODE_INVOKE)所需参数 | ||
* @param {string} consArgs.chaincodeInvokeParams.chaincodeName - 待调用合约的名称,即合约ID | ||
* @param {string} consArgs.chaincodeInvokeParams.chaincodeFunction - 待被调用的合约方法名 | ||
* @param {Array.<string>} consArgs.chaincodeInvokeParams.chaincodeFunctionArgs - 给待调用的合约方法的参数 | ||
* @param {Object} consArgs.chaincodeSetStateParams - 设置合约状态时(即type为CHAINCODE_SET_STATE)所需参数 | ||
* @param {boolean} consArgs.chaincodeSetStateParams.state - 目标合约的新状态,当值为false时表示使该合约无效 | ||
* @returns {Transaction} Transaction对象实例 | ||
@@ -79,12 +69,19 @@ */ | ||
type = _ref.type, | ||
pubKeyPEM = _ref.pubKeyPEM, | ||
chaincodeName = _ref.chaincodeName, | ||
chaincodeVersion = _ref.chaincodeVersion, | ||
_ref$chaincodeDeployP = _ref.chaincodeDeployParams; | ||
_ref$chaincodeDeployP = _ref$chaincodeDeployP === void 0 ? {} : _ref$chaincodeDeployP; | ||
var codePackage = _ref$chaincodeDeployP.codePackage, | ||
_ref$chaincodeDeployP = _ref$chaincodeDeployP === void 0 ? { | ||
timeout: 1000 | ||
} : _ref$chaincodeDeployP; | ||
var timeout = _ref$chaincodeDeployP.timeout, | ||
codePackage = _ref$chaincodeDeployP.codePackage, | ||
legalProse = _ref$chaincodeDeployP.legalProse, | ||
codeLanguageType = _ref$chaincodeDeployP.codeLanguageType, | ||
_ref$chaincodeInvokeP = _ref.chaincodeInvokeParams; | ||
_ref$chaincodeInvokeP = _ref$chaincodeInvokeP === void 0 ? {} : _ref$chaincodeInvokeP; | ||
var chaincodeName = _ref$chaincodeInvokeP.chaincodeName, | ||
chaincodeFunction = _ref$chaincodeInvokeP.chaincodeFunction, | ||
chaincodeFunctionArgs = _ref$chaincodeInvokeP.chaincodeFunctionArgs; | ||
var chaincodeFunction = _ref$chaincodeInvokeP.chaincodeFunction, | ||
chaincodeFunctionArgs = _ref$chaincodeInvokeP.chaincodeFunctionArgs, | ||
_ref$chaincodeSetStat = _ref.chaincodeSetStateParams; | ||
_ref$chaincodeSetStat = _ref$chaincodeSetStat === void 0 ? {} : _ref$chaincodeSetStat; | ||
var state = _ref$chaincodeSetStat.state; | ||
(0, _classCallCheck2.default)(this, Transaction); | ||
@@ -109,9 +106,25 @@ | ||
if (!_lodash.default.isString(pubKeyPEM)) { | ||
throw new TypeError("The pubKeyPEM field should be a string"); | ||
if (!_lodash.default.isString(chaincodeName)) { | ||
throw new TypeError("The chaincodeName field should be a string"); | ||
} | ||
if (!_lodash.default.isInteger(chaincodeVersion)) { | ||
throw new TypeError("The chaincodeversion field should be an integer"); | ||
} | ||
var txJsonObj = { | ||
id: "", | ||
cid: { | ||
chaincodeName: chaincodeName, | ||
version: chaincodeVersion | ||
} | ||
}; | ||
switch (type) { | ||
case "CHAINCODE_DEPLOY": | ||
{ | ||
if (!_lodash.default.isInteger(timeout)) { | ||
throw new TypeError("The timeout field should be an integer"); | ||
} | ||
if (!_lodash.default.isString(codePackage)) { | ||
@@ -121,2 +134,6 @@ throw new TypeError("The codePackage field should be a string"); | ||
if (!_lodash.default.isString(legalProse)) { | ||
throw new TypeError("The legalProse field should be a string"); | ||
} | ||
if (_lodash.default.indexOf(chaincodeLanguageEnumTypes, codeLanguageType) === -1) { | ||
@@ -126,2 +143,22 @@ throw new Error("The codeLanguageType field should be one of ".concat(chaincodeLanguageEnumTypes)); | ||
txJsonObj.type = 1; | ||
txJsonObj.spec = { | ||
timeout: timeout, | ||
codePackage: codePackage, | ||
legalProse: legalProse | ||
}; | ||
switch (codeLanguageType) { | ||
case "CODE_JAVASCRIPT": | ||
txJsonObj.spec.ctype = 1; | ||
break; | ||
case "CODE_SCALA": | ||
txJsonObj.spec.ctype = 2; | ||
break; | ||
default: | ||
break; | ||
} | ||
break; | ||
@@ -132,6 +169,2 @@ } | ||
{ | ||
if (!_lodash.default.isString(chaincodeName)) { | ||
throw new TypeError("The chaincodeName field should be a string"); | ||
} | ||
if (!_lodash.default.isString(chaincodeFunction)) { | ||
@@ -151,5 +184,21 @@ throw new TypeError("The chaincodeFunction field should be a string"); | ||
txJsonObj.type = 2; | ||
txJsonObj.ipt = { | ||
function: chaincodeFunction, | ||
args: chaincodeFunctionArgs | ||
}; | ||
break; | ||
} | ||
case "CHAINCODE_SET_STATE": | ||
{ | ||
if (!_lodash.default.isBoolean(state)) { | ||
throw new TypeError("The state field should be a Boolean"); | ||
} | ||
txJsonObj.type = 3; | ||
txJsonObj.state = state; | ||
break; | ||
} | ||
default: | ||
@@ -159,32 +208,4 @@ throw new Error("Wrong Transaction type"); | ||
var txJsonObj = { | ||
type: type === "CHAINCODE_DEPLOY" ? 1 : 2, | ||
chaincodeID: Buffer.from("path: \"path\"\nname: \"".concat(chaincodeName, "\"\n")), | ||
payload: { | ||
chaincodeID: { | ||
path: "path", | ||
name: chaincodeName | ||
}, | ||
ctorMsg: { | ||
function: chaincodeFunction, | ||
args: chaincodeFunctionArgs | ||
}, | ||
timeout: 1000, | ||
secureContext: "secure", | ||
codePackage: codePackage ? Buffer.from(codePackage) : codePackage, | ||
ctype: codeLanguageType === "CODE_SCALA" ? 2 : 1 | ||
}, | ||
txid: "", | ||
metadata: null, | ||
timestamp: getTimestamp(), | ||
confidentialityLevel: 1, | ||
confidentialityProtocolVersion: "cpv", | ||
nonce: getNonce(), | ||
toValidators: getValidators(), | ||
cert: getAccountAddr(pubKeyPEM), | ||
signature: null | ||
}; | ||
var err = txMsgType.verify(txJsonObj); | ||
if (err) throw err; | ||
this.pubKeyPEM = pubKeyPEM; // 计算txid | ||
if (err) throw err; // 计算txid | ||
@@ -196,4 +217,6 @@ var _msg = txMsgType.create(txJsonObj); // 在Browser环境下protobufjs中的encode().finish()返回原始的Uint8Array, | ||
var txBuffer = Buffer.from(txMsgType.encode(_msg).finish()); | ||
_msg.txid = (0, _crypto.GetHashVal)({ | ||
data: txBuffer, | ||
var timeStampBuffer = Buffer.from(new Date().toISOString()); | ||
var dataBuffer = Buffer.concat([txBuffer, timeStampBuffer], txBuffer.length + timeStampBuffer.length); | ||
_msg.id = (0, _crypto.GetHashVal)({ | ||
data: dataBuffer, | ||
alg: "sha256" | ||
@@ -212,7 +235,9 @@ }).toString("hex"); | ||
* 对新创建的交易实例进行签名 | ||
* | ||
* @param {Object} signArgs - 签名所需参数 | ||
* @param {string} signArgs.prvKey - 签名者的pem格式私钥 | ||
* @param {string} signArgs.pubKey - 签名者的pem格式公钥 | ||
* @param {string} signArgs.alg - 使用的签名算法名称 | ||
* @param {string} [signArgs.pass] - 私钥解密密码,如果prvKey为已加密的pem格式私钥,则需要提供此解密密码 | ||
* @param {string} signArgs.creditCode - 签名者的信用代码 | ||
* @param {string} signArgs.certName - 代表签名者的证书名 | ||
* @returns {Buffer} - 已签名交易数据 | ||
@@ -225,10 +250,16 @@ */ | ||
var prvKey = _ref2.prvKey, | ||
pubKey = _ref2.pubKey, | ||
alg = _ref2.alg, | ||
pass = _ref2.pass; | ||
pass = _ref2.pass, | ||
creditCode = _ref2.creditCode, | ||
certName = _ref2.certName; | ||
if (!_lodash.default.isString(prvKey)) throw new Error("The prvKey field should be a string"); | ||
if (!_lodash.default.isString(pubKey)) throw new Error("The pubKey field should be a string"); | ||
if (!_lodash.default.isString(alg)) throw new Error("The alg field should be a string"); | ||
if (pass && !_lodash.default.isString(pass)) throw new Error("The pass field should be a string"); | ||
if (!_lodash.default.isString(creditCode)) throw new Error("The creditCode field should be a string"); | ||
if (!_lodash.default.isString(certName)) throw new Error("The certName field should be a string"); | ||
var msg = txMsgCollection.get(this); | ||
if (msg.signature && msg.signature.length !== 0) { | ||
if (msg.signature && msg.signature.signature) { | ||
throw new Error("The transaction has been signed already"); | ||
@@ -244,3 +275,3 @@ } // 签名 | ||
// 否则签名将出错 | ||
prvKeyObj.pubKeyHex = (0, _crypto.ImportKey)(this.pubKeyPEM).pubKeyHex; | ||
prvKeyObj.pubKeyHex = (0, _crypto.ImportKey)(pubKey).pubKeyHex; | ||
} | ||
@@ -254,3 +285,13 @@ | ||
}); | ||
msg.signature = signature; | ||
var signatureJsonObj = { | ||
certId: { | ||
creditCode: creditCode, | ||
certName: certName | ||
}, | ||
tmLocal: getTimestamp(), | ||
signature: signature | ||
}; | ||
var err = signatureMsgType.verify(signatureJsonObj); | ||
if (err) throw err; | ||
msg.signature = signatureMsgType.create(signatureJsonObj); | ||
txBuffer = Buffer.from(txMsgType.encode(msg).finish()); | ||
@@ -261,3 +302,2 @@ return txBuffer; | ||
* 对已签名的交易对象进行签名验证 | ||
* | ||
* @param {String} pubKey pem格式的公钥 | ||
@@ -273,8 +313,8 @@ * @param {String} alg 使用的签名算法 | ||
if (!msg.signature || msg.signature.length === 0) { | ||
var signature = _lodash.default.cloneDeep(msg.signature); | ||
if (!signature || !signature.signature) { | ||
throw new Error("The transaction has not been signed yet"); | ||
} | ||
msg.metadata = null; | ||
var signature = msg.signature; | ||
msg.signature = null; | ||
@@ -284,3 +324,3 @@ var msgBuffer = Buffer.from(txMsgType.encode(msg).finish()); | ||
pubKey: pubKey, | ||
sigValue: signature, | ||
sigValue: signature.signature, | ||
data: msgBuffer, | ||
@@ -287,0 +327,0 @@ alg: alg |
{ | ||
"name": "rclink", | ||
"main": "./lib/index.js", | ||
"version": "1.0.39", | ||
"version": "2.0.0-alpha", | ||
"repository": "https://gitee.com/BTAJL/RCNode.git", | ||
@@ -6,0 +6,0 @@ "author": "c4w <“chen4w@sina.com”>", |
@@ -20,3 +20,3 @@ import testEnv from "./testEnvConfig"; | ||
if (msg.blk) { | ||
expect(msg.blk).toBeInstanceOf(blockMsgType); | ||
expect(blockMsgType.verify(msg.blk)).toBeNull(); | ||
et.close("works done"); | ||
@@ -23,0 +23,0 @@ done(); |
@@ -24,3 +24,3 @@ import validator from "validator"; | ||
expect(validator.isBase64(ci.previousBlockHash)).toBeTruthy(); | ||
expect(validator.isBase64(ci.currentWorldStateHash)).toBeTruthy(); | ||
expect(validator.isBase64(ci.currentStateHash)).toBeTruthy(); | ||
done(); | ||
@@ -38,4 +38,4 @@ }); | ||
})); | ||
it("使用chainCurrentStateHash方法,应能得到区块链的最新世界状态哈希值", () => ra.chainCurrentWorldStateHash().then((curWorldStateHash) => { | ||
expect(validator.isBase64(curWorldStateHash)).toBeTruthy(); | ||
it("使用chainCurrentStateHash方法,应能得到区块链的最新世界状态哈希值", () => ra.chainCurrentStateHash().then((curStateHash) => { | ||
expect(validator.isBase64(curStateHash)).toBeTruthy(); | ||
})); | ||
@@ -70,3 +70,3 @@ it("使用chainTotalTransactions方法,应能得到区块链的最新交易总量", () => ra.chainTotalTransactions().then((totalTransactions) => { | ||
it("使用block方法, 根据区块哈希值可以获取json格式的区块数据", async () => { | ||
const blkHash = await ra.chainCurrentBlockHash(); | ||
const blkHash = await ra.block(1).then(blk => blk.hashOfBlock); | ||
const blkHashBuffer = Buffer.from(blkHash, "base64"); | ||
@@ -114,3 +114,3 @@ // string hash and default blockFormat | ||
const blockObj = Block.decode(blockStream); | ||
expect(Buffer.from(blockObj.previousBlockHash).toString("base64")).toBe(blockJson.previousBlockHash); | ||
expect(Buffer.from(blockObj.hashOfBlock).toString("base64")).toBe(blockJson.hashOfBlock); | ||
}); | ||
@@ -120,20 +120,20 @@ }); | ||
describe("transaction相关方法测试", () => { | ||
const prvKeyPEM = `"-----BEGIN PRIVATE KEY----- | ||
MIGNAgEAMBAGByqGSM49AgEGBSuBBAAKBHYwdAIBAQQgOUm2PF8apyaK1bXjKH5j | ||
jCld/I6ExpefemRGsS0C4+WgBwYFK4EEAAqhRANCAAT6VLE/eF9+sK1ROn8n6x7h | ||
KsBxehW42qf1IB8quBn5OrQD3x2H4yZVDwPgcEUCjH8PcFgswdtbo8JL/7f66yEC | ||
-----END PRIVATE KEY-----"`; | ||
const prvKeyPEM = `-----BEGIN PRIVATE KEY----- | ||
MIGNAgEAMBAGByqGSM49AgEGBSuBBAAKBHYwdAIBAQQgPtHT816wJBatnif8laVo | ||
yW0R5NqtMiMkmECOYEAIzSWgBwYFK4EEAAqhRANCAASlh+oDBPdwHEkpQT4/g4RX | ||
9ubP7jMM2QodiFtsnv+ObQ3dxfQN/S515ePssn3HjPCwfzR3S1KY4O9vFtH1Jql9 | ||
-----END PRIVATE KEY-----`; | ||
const pubKeyPEM = `-----BEGIN PUBLIC KEY----- | ||
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE+lSxP3hffrCtUTp/J+se4SrAcXoVuNqn | ||
9SAfKrgZ+Tq0A98dh+MmVQ8D4HBFAox/D3BYLMHbW6PCS/+3+ushAg== | ||
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEpYfqAwT3cBxJKUE+P4OEV/bmz+4zDNkK | ||
HYhbbJ7/jm0N3cX0Df0udeXj7LJ9x4zwsH80d0tSmODvbxbR9SapfQ== | ||
-----END PUBLIC KEY-----`; | ||
const txToInvokeConsArgs = { | ||
type: "CHAINCODE_INVOKE", | ||
pubKeyPEM, | ||
chaincodeName: "ContractAssetsTPL", | ||
chaincodeVersion: 1, | ||
chaincodeInvokeParams: { | ||
chaincodeName: "8a43f35fddcef0268db5bce1f83e7dcda439c734bbd1b998241124694835e5b3", | ||
chaincodeFunction: "transfer", | ||
chaincodeFunctionArgs: [`{ | ||
"from" : "1MH9xedPTkWThJUgT8ZYehiGCM7bEZTVGN", | ||
"to" : "12kAzqqhuq7xYgm9YTph1b9zmCpZPyUWxf", | ||
"from" : "121000005l35120456", | ||
"to" : "12110107bi45jh675g", | ||
"amount" : 5 | ||
@@ -147,3 +147,6 @@ }`], | ||
prvKey: prvKeyPEM, | ||
pubKey: pubKeyPEM, | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -155,3 +158,6 @@ | ||
prvKey: GetKeyPEM(kp.prvKeyObj), | ||
pubKey: GetKeyPEM(kp.prvKeyObj), | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -162,3 +168,6 @@ | ||
prvKey: prvKeyPEM, | ||
pubKey: pubKeyPEM, | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -168,3 +177,3 @@ | ||
const result = await ra.sendTransaction(txSignedBuffer1.toString("hex")); | ||
expect(result.txid).toBe(tx1.getTxMsg().txid); | ||
expect(result.txid).toBe(tx1.getTxMsg().id); | ||
expect(result.err).toBeUndefined(); | ||
@@ -174,5 +183,5 @@ }); | ||
let result = await ra.sendTransaction(txSignedBuffer1.toString("base64")); | ||
expect(result.err).toMatch("parser error"); | ||
expect(result.err).toMatch("transaction parser error"); | ||
result = await ra.sendTransaction(txSignedBuffer1.toString("utf8")); | ||
expect(result.err).toMatch("parser error"); | ||
expect(result.err).toMatch("transaction parser error"); | ||
}); | ||
@@ -185,3 +194,3 @@ it("使用sendTransaction方法,以hex字符串形式提交错误私钥签名的交易,应返回验签错误信息", async () => { | ||
const result = await ra.sendTransaction(txSignedBuffer3); | ||
expect(result.txid).toBe(tx3.getTxMsg().txid); | ||
expect(result.txid).toBe(tx3.getTxMsg().id); | ||
expect(result.err).toBeUndefined(); | ||
@@ -188,0 +197,0 @@ }); |
@@ -15,5 +15,8 @@ import testEnv from "./testEnvConfig"; | ||
type: "CHAINCODE_DEPLOY", | ||
pubKeyPEM: GetKeyPEM(kp1.pubKeyObj), | ||
chaincodeName: "ContractAssetsTPL", | ||
chaincodeVersion: 2, | ||
chaincodeDeployParams: { | ||
timeout: 5000, | ||
codeLanguageType: "CODE_SCALA", | ||
legalProse: "fake-content", | ||
codePackage: "fake-content", | ||
@@ -24,9 +27,9 @@ }, | ||
type: "CHAINCODE_INVOKE", | ||
pubKeyPEM: GetKeyPEM(kp1.pubKeyObj), | ||
chaincodeName: "ContractAssetsTPL", | ||
chaincodeVersion: 2, | ||
chaincodeInvokeParams: { | ||
chaincodeName: "ContractAssetsTPL", | ||
chaincodeFunction: "transfer", | ||
chaincodeFunctionArgs: [`{ | ||
"from" : "1MH9xedPTkWThJUgT8ZYehiGCM7bEZTVGN", | ||
"to" : "12kAzqqhuq7xYgm9YTph1b9zmCpZPyUWxf", | ||
"from" : "121000005l35120456", | ||
"to" : "12110107bi45jh675g", | ||
"amount" : 5 | ||
@@ -37,13 +40,35 @@ }`], | ||
const txToSetStateConsArgs = { | ||
type: "CHAINCODE_SET_STATE", | ||
chaincodeName: "ContractAssetsTPL", | ||
chaincodeVersion: 2, | ||
chaincodeSetStateParams: { | ||
state: false, | ||
}, | ||
}; | ||
const txToDeploy = new Transaction(txToDeployConsArgs); | ||
const txToInvoke = new Transaction(txToInvokeConsArgs); | ||
const txToSetState = new Transaction(txToSetStateConsArgs); | ||
const txSignedBytes = txToDeploy.sign({ | ||
prvKey: GetKeyPEM(kp1.prvKeyObj), | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
txToInvoke.sign({ | ||
prvKey: GetKeyPEM(kp1.prvKeyObj), | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
txToSetState.sign({ | ||
prvKey: GetKeyPEM(kp1.prvKeyObj), | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: "ecdsa-with-SHA1", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
const signAlg = "ecdsa-with-SHA1"; | ||
@@ -54,2 +79,3 @@ | ||
expect(txToInvoke.verifySignature(GetKeyPEM(kp1.pubKeyObj), signAlg)).toBeTruthy(); | ||
expect(txToSetState.verifySignature(GetKeyPEM(kp1.pubKeyObj), signAlg)).toBeTruthy(); | ||
}); | ||
@@ -59,2 +85,3 @@ it("使用未加密私钥生成的签名交易信息,使用非对应公钥验证不应通过", () => { | ||
expect(txToInvoke.verifySignature(GetKeyPEM(kp2.pubKeyObj), signAlg)).toBeFalsy(); | ||
expect(txToSetState.verifySignature(GetKeyPEM(kp2.pubKeyObj), signAlg)).toBeFalsy(); | ||
}); | ||
@@ -65,2 +92,3 @@ it("使用未加密私钥生成的签名交易信息,使用错误签名算法验证不应通过", () => { | ||
expect(txToInvoke.verifySignature(GetKeyPEM(kp2.pubKeyObj), wrongSignAlg)).toBeFalsy(); | ||
expect(txToSetState.verifySignature(GetKeyPEM(kp2.pubKeyObj), wrongSignAlg)).toBeFalsy(); | ||
}); | ||
@@ -75,3 +103,6 @@ it("使用二进制交易数据构造交易对象实例,应能成功", () => { | ||
prvKey: GetKeyPEM(kp1.prvKeyObj), | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: signAlg, | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -92,6 +123,9 @@ }).toThrowError("The transaction has been signed already"); | ||
prvKey: prvKeyEncrypted, | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: signAlg, | ||
pass, | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
expect(txToDeployNew.verifySignature(GetKeyPEM(kp1.pubKeyObj), signAlg)).toBeTruthy(); | ||
expect(txToDeploy.verifySignature(GetKeyPEM(kp1.pubKeyObj), signAlg)).toBeTruthy(); | ||
}); | ||
@@ -105,4 +139,7 @@ it("使用加密私钥生成签名交易信息,输入密码错误时,应该抛出异常", () => { | ||
prvKey: prvKeyEncrypted, | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: signAlg, | ||
pass: "456", | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -113,3 +150,6 @@ }).toThrowError("提供的私钥信息无效或解密密码无效"); | ||
prvKey: prvKeyEncrypted, | ||
pubKey: GetKeyPEM(kp1.pubKeyObj), | ||
alg: signAlg, | ||
creditCode: "121000005l35120456", | ||
certName: "node1", | ||
}); | ||
@@ -116,0 +156,0 @@ }).toThrowError("提供的私钥信息无效或解密密码无效"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
63544
6890252
106
2