mirror of
https://github.com/zhigang1992/session-key-aspect.git
synced 2026-01-12 22:52:16 +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));
|
||||
|
||||
// 4. verify expire block height
|
||||
// const response = sys.hostApi.runtimeContext.get("tx^context");
|
||||
// sys.require(response.result!.success, "get tx context fail");
|
||||
const response = sys.hostApi.runtimeContext.get("block^header^0");
|
||||
|
||||
// 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 expireBlockHeight = sKeyObj.getExpireBlockHeight();
|
||||
const currentBlockHeight = expireBlockHeight - 1 ;
|
||||
const currentBlockHeight = ethBlockHeader.number + 1;
|
||||
sys.require(currentBlockHeight <= expireBlockHeight,
|
||||
"session key has expired; " + expireBlockHeight.toString() + " < " + currentBlockHeight.toString());
|
||||
|
||||
|
||||
@@ -185,15 +185,16 @@ async function f() {
|
||||
"// ******************************************\n\n");
|
||||
|
||||
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
|
||||
+ 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();
|
||||
console.log("op: ", op);
|
||||
console.log("calldata: ", sessionKeyRegData);
|
||||
|
||||
Reference in New Issue
Block a user