mirror of
https://github.com/zhigang1992/session-key-aspect.git
synced 2026-05-01 18:54:42 +08:00
add block height verify at join poin
This commit is contained in:
@@ -90,14 +90,13 @@ export class Aspect implements IAspectTransaction, IAspectOperation, ITransactio
|
|||||||
"illegal session key scope, method isn't allowed. actual is " + method + ". detail: " + sys.utils.uint8ArrayToHex(ctx.tx.content.unwrap().input));
|
"illegal session key scope, method isn't allowed. actual is " + method + ". detail: " + sys.utils.uint8ArrayToHex(ctx.tx.content.unwrap().input));
|
||||||
|
|
||||||
// 4. verify expire block height
|
// 4. verify expire block height
|
||||||
// const response = sys.hostApi.runtimeContext.get("tx^context");
|
const response = sys.hostApi.runtimeContext.get("block^header^0");
|
||||||
// sys.require(response.result!.success, "get tx context fail");
|
|
||||||
|
|
||||||
// let tx = Protobuf.decode<EthTransaction>(response.data!.value, EthTransaction.decode)
|
var ethBlockHeader = Protobuf.decode<EthBlockHeader>(response.data!.value, EthBlockHeader.decode);
|
||||||
|
|
||||||
// const currentBlockHeight = ctx.tx.content.unwrap().blockNumber;
|
// const currentBlockHeight = ctx.tx.content.unwrap().blockNumber;
|
||||||
const expireBlockHeight = sKeyObj.getExpireBlockHeight();
|
const expireBlockHeight = sKeyObj.getExpireBlockHeight();
|
||||||
const currentBlockHeight = expireBlockHeight - 1 ;
|
const currentBlockHeight = ethBlockHeader.number + 1;
|
||||||
sys.require(currentBlockHeight <= expireBlockHeight,
|
sys.require(currentBlockHeight <= expireBlockHeight,
|
||||||
"session key has expired; " + expireBlockHeight.toString() + " < " + currentBlockHeight.toString());
|
"session key has expired; " + expireBlockHeight.toString() + " < " + currentBlockHeight.toString());
|
||||||
|
|
||||||
|
|||||||
@@ -185,15 +185,16 @@ async function f() {
|
|||||||
"// ******************************************\n\n");
|
"// ******************************************\n\n");
|
||||||
|
|
||||||
let currentBlockHeight = await web3.eth.getBlockNumber();
|
let currentBlockHeight = await web3.eth.getBlockNumber();
|
||||||
let expireBlockHeight = currentBlockHeight + 20; // ~10s
|
console.log("currentBlockHeight :", currentBlockHeight);
|
||||||
|
let expireBlockHeight = currentBlockHeight + 10; // ~10s
|
||||||
// let op = "0x0001" + sKey + sKeyContract + "0001" + contractCallMethod + expireBlockHeight;
|
// let op = "0x0001" + sKey + sKeyContract + "0001" + contractCallMethod + expireBlockHeight;
|
||||||
let op =
|
let op =
|
||||||
"0x0001"
|
"0x0001"
|
||||||
+ sKey
|
+ sKey
|
||||||
+ sKeyContract
|
+ sKeyContract
|
||||||
+ "0001" + contractCallMethod
|
+ "0001" + contractCallMethod
|
||||||
+ web3.eth.abi.encodeParameter('uint256', expireBlockHeight).slice(48, 64);
|
+ rmPrefix(web3.eth.abi.encodeParameter('uint256', expireBlockHeight)).slice(48, 64);
|
||||||
|
|
||||||
let sessionKeyRegData = aspect.operation(op).encodeABI();
|
let sessionKeyRegData = aspect.operation(op).encodeABI();
|
||||||
console.log("op: ", op);
|
console.log("op: ", op);
|
||||||
console.log("calldata: ", sessionKeyRegData);
|
console.log("calldata: ", sessionKeyRegData);
|
||||||
|
|||||||
Reference in New Issue
Block a user