# 订单过滤器

订单过滤器基于脚本运行,输入参数是一个固定格式的签名,具体格式如下。脚本行为是白名单模式,返回 0 代表通过,其他形式返回代表失败。

# json 输入格式如下

  1. Unknow 任意类型的签名请求
{
    "SignType": "unknown",
    "Data": "Atr07xEANQWh7ROmHCuYSA=="
}
  1. Message 消息类型
{
  "SignType": "message",
  "Data": {
    "CID": {
      "/": "bafy2bzacear2n4ycnqjwtomnoeghubwjzw7hzao74yrvzm6i3lfuk6gtsq57q"
    },
    "Version": 2444968627297155987,
    "To": "t08332628015320862903",
    "From": "t3kbwxng5pwwg557tw2us4fnggphbsbsvhreu2bdlnthumhbx2eliw7bzyahdx2n6eztwdigj5axtsjdsicy5a",
    "Nonce": 3740335547662638783,
    "Value": "-975788697497809581006163199035224656",
    "GasLimit": 4282355688707494097,
    "GasFeeCap": "912296103548088579871476377389990303",
    "GasPremium": "1320896501926152015536953388071793382",
    "Method": 2204816356752865940,
    "Params": "zrnFGEN3Fj1y4xyqKYMJOw=="
  }
}
  1. BlockHeader 签 blockHeader 出块使用
{
  "SignType": "block",
  "Data": {
    "Miner": "t3vv3kbwqxp34wl3tmqb7v53i2wbu5r2bj2ew3zfdw5n7wyn5rkfamzsicfzskj5fxh7gn3fdkf4stzlt6klsa",
    "Ticket": {
      "VRFProof": "ZTllYjQyZDQzMGExYjU0MDQxYWJhODZlYmZhODAxYzk="
    },
    "ElectionProof": {
      "WinCount": 3199911358100100289,
      "VRFProof": "Zjg2NWFhMTI2MzdhZDAzOWQ5N2Y4MDA2ZWE1ZmFmY2M="
    },
    "BeaconEntries": [
      {
        "Round": 7432925912533959900,
        "Data": "IRbjoLa9HfBQXveU8u8BzA=="
      }
    ],
    "WinPoStProof": [
      {
        "PoStProof": 9065943393210184747,
        "ProofBytes": "QHAN+HBEFmTILChWA0dlkQ=="
      }
    ],
    "Parents": [
      {
        "/": "bafy2bzaced6ghmr7hr6ghkkds5n5vadqgwgykjxbwvnetngbf3rldktibhknc"
      }
    ],
    "ParentWeight": "623276483858531870747041268427681083",
    "Height": 1316567932866987913,
    "ParentStateRoot": {
      "/": "bafy2bzacecnvcrfwl3wehlp2o7t5v5rdztw55q5adjjz7ck6qju7iyf7uage4"
    },
    "ParentMessageReceipts": {
      "/": "bafy2bzaced7yjgbm4av7tyxox74gb4zbgngblufjldyonrxb5vperjtt647iw"
    },
    "Messages": {
      "/": "bafy2bzacec3u65n7xqv42fdcwgmx6esrxdxvdkfddrkwnv7yqme6eldomp7ng"
    },
    "BLSAggregate": {
      "Type": 2,
      "Data": "h6AHgAU4UNQrNOQ+t9FPAQ=="
    },
    "Timestamp": 3742226815733021007,
    "BlockSig": {
      "Type": 1,
      "Data": "d+Z/kgfDflfBGCMHEcTrZg=="
    },
    "ForkSignaling": 6517981467652975258,
    "ParentBaseFee": "556231998514121926756971426438976110"
  }
}
  1. DrawRandomParam 签随机数 出块使用
{
  "SignType": "drawrandomparam",
  "Data": {
    "Rbase": "vDc1+fzj1BKYDCTestRdGQ==",
    "Pers": 7646088051308888681,
    "Round": 7764645693368415036,
    "Entropy": "7KPPmEUJ9ac+2nWPZfiJyQ=="
  }
}
  1. AskResponse 签 Ask 响应信息 市场使用
{
  "SignType": "askresponse",
  "Data": {
    "Ask": {
      "Ask": {
        "Price": "876769343940609135856544637649618760",
        "VerifiedPrice": "-423379214357071078461170406986732960",
        "MinPieceSize": 4096,
        "MaxPieceSize": 34359738368,
        "Miner": "t36bzqatys5kyw4jkviqsbb4www4yppufavkbzjctw63ck7a4btqfdp4ca4ynvd6kghy5ocfkmazq27hgogvaa",
        "Timestamp": 94205847225915303,
        "Expiry": 722654141236847609,
        "SeqNo": 6062932104092928274
      },
      "Signature": {
        "Type": 1,
        "Data": "Hq8rj+qBL8ODCQHh4c30eA=="
      }
    }
  }
}
  1. StorageAsk 签存储 市场使用
{
  "SignType": "storageask",
  "Data": {
    "Price": "719994981195590266343102388204369970",
    "VerifiedPrice": "748694542022590025127711955652923242",
    "MinPieceSize": 9007199254740992,
    "MaxPieceSize": 35184372088832,
    "Miner": "t01230808583741956570",
    "Timestamp": 3010190245328398123,
    "Expiry": 6073288181466151141,
    "SeqNo": 6945466807109953627
  }
}
  1. ClientDeal 签客户端订单 市场使用
{
  "SignType": "clientdeal",
  "Data": {
    "Proposal": {
      "PieceCID": {
        "/": "bafy2bzacedkthe3gtj3xcwmblkqyskvps5m4yo6o44gg74pnz422el7gc2li6"
      },
      "PieceSize": 128,
      "VerifiedDeal": false,
      "Client": "t1j236245g6mviscio4weby7j7dnssarqialyqynq",
      "Provider": "t06305738302858884039",
      "Label": "0a97531553fe21025e5d82c18aa9ee68",
      "StartEpoch": 513424421293552762,
      "EndEpoch": 3747388252008935428,
      "StoragePricePerEpoch": "417693738761263006641117675603187051",
      "ProviderCollateral": "803912607344509151922250619993055103",
      "ClientCollateral": "213611766944708452191700924930145887"
    },
    "ClientSignature": {
      "Type": 1,
      "Data": "mknqGHaNB0EIAW5eunn9WQ=="
    }
  }
}
  1. DealProposal 签订单信息 市场使用
{
  "SignType": "dealproposal",
  "Data": {
    "PieceCID": {
      "/": "bafy2bzacedd5rgozi7npb2jsijebzciy3nljqsgmx5hi3ukhtbpid5ifmyyhe"
    },
    "PieceSize": 8192,
    "VerifiedDeal": false,
    "Client": "t1bqrqhrkkujkurrjtknnaxvk6bvjjrutvo65afti",
    "Provider": "t1seivchsnbggqbjxb5znyxsfj6dz4q7srv7cz3zq",
    "Label": "9180fd5021b7ce7df5f2b267be6cd72a",
    "StartEpoch": 560058135229642805,
    "EndEpoch": 5758166429440783409,
    "StoragePricePerEpoch": "424686176949526803042686184357263858",
    "ProviderCollateral": "-119795694841418693127842572130627227",
    "ClientCollateral": "-836958944296813066609357371376465576"
  }
}
  1. NetworkResponse 签网络响应 市场使用
{
  "SignType": "networkresposne",
  "Data": {
    "State": 4617742545728625595,
    "Message": "1b94004ba927b4e62fa8fb390bfd00a4",
    "Proposal": {
      "/": "bafy2bzacedz7txpajv2jjooy2fb46uoasanmzvx54gep6qr7nmfp2htyjfkeo"
    },
    "PublishMessage": {
      "/": "bafy2bzacebw2zidtr4fgwshcjofb5udtcennxi5h4cgfjuhm2fqqeelaxig42"
    }
  }
}
  1. SignedVoucher 签 Paychannel 信息 市场使用
{
  "SignType": "signedvoucher",
  "Data": {
    "ChannelAddr": "t3dhakxdepgekvrpy2tghgpwu4whzw6cvmibyqsyudfnyzyxcxewmrg633wysjzgu7batceqnxjobdchlzagma",
    "TimeLockMin": 8062818293762699587,
    "TimeLockMax": 1215837457230280974,
    "SecretPreimage": "b+nU8pBDeWWvr04HCf+87Q==",
    "Extra": {
      "Actor": "t3owhfd3q5crjjxg7ba2sd4ki5v4don76di5zqvmpk5jn76zq7jidm3m3wvxf7pv622a26i7yx6pdkhzghif6a",
      "Method": 2814310330734337689,
      "Data": "EwJS40N2TNl25Cx/duJsUw=="
    },
    "Lane": 1594676427337122628,
    "Nonce": 5638699559370206144,
    "Amount": "852321156424351894084048080709189129",
    "MinSettleHeight": 3573882704948875979,
    "Merges": [
      {
        "Lane": 1865589806043563536,
        "Nonce": 3497224577891096239
      }
    ],
    "Signature": {
      "Type": 1,
      "Data": "y1yZyEho+vZaCnr+cIlTuQ=="
    }
  }
}
  1. ProviderDealstate 签存储订单信息 市场使用
{
  "SignType": "providerdealstate",
  "Data": {
    "State": 2249531363633528266,
    "Message": "fe26487118515a657634c90f015d7e55",
    "Proposal": {
      "PieceCID": {
        "/": "bafy2bzaceacsukba7yjo3xedgelylpe24hmogiened6yrwurcm6y7xxtxe2t2"
      },
      "PieceSize": 8589934592,
      "VerifiedDeal": false,
      "Client": "t1fmg7n5hyzcupyqscllnsq7ly6egdmhwuy7qzkki",
      "Provider": "t13hrxbyl7qxke4nr7h43lak5naujtna55lzrj7lq",
      "Label": "",
      "StartEpoch": 6347307826864809625,
      "EndEpoch": 1724993406456267541,
      "StoragePricePerEpoch": "-754967228854409089321131956816507836",
      "ProviderCollateral": "279347961707834779099087641125705202",
      "ClientCollateral": "-576424698295802851049249504821521666"
    },
    "ProposalCid": {
      "/": "bafy2bzaceadky2ukixnq7gmef4j6vqwjvzed6pz7xvj2pp3ph2zwc66s2odsg"
    },
    "AddFundsCid": {
      "/": "bafy2bzacec5gnjl6kinqs6lwvnez6a6tzmkg7o6ckkws3pv5kilofgb54pvyi"
    },
    "PublishCid": {
      "/": "bafy2bzaceavvmglvzyru5ant4t6kubhyoxtqygrsl6jfwylvsa3hgwsgyqmom"
    },
    "DealID": 5913897054946672202,
    "FastRetrieval": false
  }
}

# jq 过滤器 示例

使用 jq 脚本来运行订单过滤 需要先安装 jq 命令 jq install (opens new window).

  1. 仅允许确定类型的签名
[SignFilter]
  expr = "jq -e '.SignType!=\"unknown\"'"
  1. 仅允许签出块过程的消息
[SignFilter]
  expr = "jq -e '.SignType==\"block\" or .SignType==\"drawrandomparam\"'"
  1. 仅允许签 t01001 在封装过程中发送的消息
[SignFilter]
  expr = "jq -e '.SignType==\"message\" and .Data.To[1:]==\"01001\" and (.Data.Method == 32 or (.Data.Method >= 5  and .Data.Method <= 11 ) or (.Data.Method >= 18  and .Data.Method <= 20 ) or (.Data.Method >= 24  and .Data.Method <= 29 ))'"
  1. 仅签名从 t01001 提取资金消息
[SignFilter]
  expr = "jq -e '.SignType==\"message\" and .Data.To[1:]==\"01001\" and (.Data.Method == 16)'"

# javascript 脚本过滤器

使用 javascript 脚本来运行订单过滤,相对于 jq 脚本,用 js 脚本可以直接编辑,并且立即生效。 需要先安装 node 工具 nodejs install (opens new window).

配置方式

[SignFilter]
  expr = "node <path to js script>"
  1. 仅允许确定类型的签名
var fs = require("fs")

var stdinBuffer = fs.readFileSync(0)
var signMsg = JSON.parse(stdinBuffer)

function accept() {
    process.exit(0)
}

function refuse(reason) {
    process.stderr.write(reason)
    process.exit(1)
}

(function () {
    if (signMsg.SignType == "unknown") {
        refuse("refuse unknown sign request")
    }
})()
  1. 仅允许签出块过程的消息
var fs = require("fs")

var stdinBuffer = fs.readFileSync(0)
var signMsg = JSON.parse(stdinBuffer)

function accept() {
    process.exit(0)
}

function refuse(reason) {
    process.stderr.write(reason)
    process.exit(1)
}

(function () {
    if (signMsg.SignType == "block"||signMsg.SignType == "drawrandomparam") {
        refuse("only support block/drawrandom sign request")
    }
})()
  1. 仅允许签 t01001 在封装过程中发送的消息
var fs = require("fs")

var stdinBuffer = fs.readFileSync(0)
var signMsg = JSON.parse(stdinBuffer)

function accept() {
    process.exit(0)
}

function refuse(reason) {
    process.stderr.write(reason)
    process.exit(1)
}

(function () {
    if (signMsg.SignType == "message") {
        if (signMsg.Data.To.substring(1) == "01001") {
            if (signMsg.Data.Method == 32
                || (signMsg.Data.Method >= 5 && signMsg.Data.Method <= 11)
                || (signMsg.Data.Method >= 18 && signMsg.Data.Method <= 20)
                || (signMsg.Data.Method >= 24 && signMsg.Data.Method <= 29)
            ){
                accept()
                return
            }
        }
    }
    refuse("refuse non-sealing message sign request of miner t01001")
})()
  1. 拒绝转账或者一些高风险的消息(owner/worker/beneficiary)签名
var fs = require("fs")

var stdinBuffer = fs.readFileSync(0)
var signMsg = JSON.parse(stdinBuffer)

function accept() {
    process.exit(0)
}

function refuse(reason) {
    process.stderr.write(reason)
    process.exit(1)
}

(function () {
    if (signMsg.SignType == "message") {
        if (signMsg.Data.Method == 0 ) {  //send fund
            refuse("refuse send message sign request")
        }
        if (signMsg.Data.To.substring(1) == "01001") {
            if (signMsg.Data.Method == 4    //change worker/controller
               ||signMsg.Data.Method == 16  //withdraw
                ||signMsg.Data.Method == 23 //change owner
                ||signMsg.Data.Method == 21 //confirm update worker key
                ||signMsg.Data.Method == 30 //change beneficiary
            ){
                refuse("refuse high risk message sign request")
                return
            }
        }
    }else{
        refuse("refuse non-message sign request")
    }
})()
  1. 允许市场相关的签名签名
var fs = require("fs")

var stdinBuffer = fs.readFileSync(0)
var signMsg = JSON.parse(stdinBuffer)

function accept() {
    process.exit(0)
}

function refuse(reason) {
    process.stderr.write(reason)
    process.exit(1)
}

(function () {
    if (signMsg.SignType == "dealproposal"
        ||signMsg.SignType == "signedvoucher"
        ||signMsg.SignType == "storageask"
        ||signMsg.SignType == "askresponse"
        ||signMsg.SignType == "networkresposne"
        ||signMsg.SignType == "clientdeal"
        ||signMsg.SignType == "providerdealstate"
    ) {
        accept()
        return
    }

    if (signMsg.SignType == "message") {
        if (signMsg.Data.To.substring(1) == "01001") {
            if (signMsg.Data.Method == 18    //ChangeMultiaddrs
               ||signMsg.Data.Method == 4  //ChangePeerID
            ){
                accept()
                return
            }
        }

        if (signMsg.Data.To.substring(1) == "04") {  //market actor
            if (signMsg.Data.Method ==2 || signMsg.Data.Method == 4){
                accept()
                return
            }
        }

    }else{
        refuse("refuse non-message sign request")
    }
})()