Session lock(会话密钥 lock)约束Session lock (session-key lock) Constraints
来源:luongthanhtung03/ckb-session-kit @ f51f07c / contracts/session-lock/src/main.rs · testnet 0xab41…08ce (data2) · 社区项目,仅测试网Source: luongthanhtung03/ckb-session-kit @ f51f07c / contracts/session-lock/src/main.rs · testnet 0xab41…08ce (data2) · community project, testnet only
给 AI agent:For AI agents: session_lock.md · llms.txt
ownerOwner 模式:任意花费 / 撤销Owner mode: spend anything / revoke
Inputs 输入Inputs
session-lock cell(s)session-lock cell(s)Cell{
lock: { codeHash: SESSION_LOCK (data2),
args: owner ‖ session ‖ max_per_tx ‖ min_interval }
}
owner 的 cell(任意 lock,自行验签)owner's cell (its own lock verifies)Cell{
lock: lock hash = owner_lock_hash
}Cell{
lock: lock hash = owner_lock_hash
}
Outputs 输出Outputs
任意anything不做任何检查no rule applied
lock.args 字节布局(80 / 112 / 128 / 160B)lock.args byte layout (80 / 112 / 128 / 160B)
owner_lock_hash32B
session_lock_hash32B
max_per_tx8B
min_interval8B
recipient / token…0/32/48/80B
- owner_lock_hash32Bowner 的 lock hashowner's lock hash任一输入 lock hash 等于它 → owner 模式,直接通过any input with this lock hash → owner mode, pass11
- session_lock_hash32Bsession key cell 的 lock hashsession key cell lock hashowner 不在场时必须有此 lock 的输入required among inputs when owner is absent11
- max_per_tx8B每笔最大流出 u64 LE(shannon,含手续费)max outflow per tx u64 LE (shannons, fee included)Σgroup 输入 − 找零 ≤ max_per_txΣ group inputs − change ≤ max_per_tx12
- min_interval8B最小间隔 u64 LE(区块)min interval u64 LE (blocks)>0 时每个 group 输入 since 必须为相对区块数 ≥ 该值if > 0 each group input's since must be relative block number ≥ it14
- recipient / token…0/32/48/80B80B:无;112B:recipient(32);128B:token_type_hash(32)+max_per_tx_token u128(16);160B:token + recipient80B: none; 112B: recipient(32); 128B: token_type_hash(32)+max_per_tx_token u128(16); 160B: token + recipient其它长度 → 10other lengths → 1010
owner_lock_hash0x1111111111111111111111111111111111111111111111111111111111111111
session_lock_hash0x2222222222222222222222222222222222222222222222222222222222222222
max_per_tx0x00e40b5402000000 (=100 CKB)
min_interval0x0300000000000000 (=3)
限制Constraints
- argsargs 长度 ∈ {80,112,128,160};script 读取缓冲 256Bargs length ∈ {80,112,128,160}; script buffer 256B10
- inputs输入中既无 owner_lock_hash 也无 session_lock_hashneither owner nor session lock hash among inputs11
N → ≤1Session 花费(CKB,开放收款方)Session spend (CKB, any payee)
Inputs 输入Inputs
session-lock cell(s)(group)session-lock cell(s) (group)Cell{
lock: SESSION_LOCK(args 80B),
type: 无,
since: min_interval>0 时:相对区块 ≥ min_interval
}Cell{
lock: SESSION_LOCK(args 80B),
type: none,
since: if min_interval>0: relative blocks ≥ min_interval
}
session key cellsession key cellCell{
lock: lock hash = session_lock_hash
}Cell{
lock: lock hash = session_lock_hash
}
Outputs 输出Outputs
找零(最多 1 个)change (at most 1)Cell{
lock: 同一 SESSION_LOCK script,
type: 无
}Cell{
lock: same SESSION_LOCK script,
type: none
}
付款paymentCell{ lock: 任意 } // 无收款方限制Cell{ lock: any } // no recipient set
限制Constraints
- sincemin_interval>0 且任一 group 输入 since 非相对区块数或 < min_intervalmin_interval>0 and a group input since is not relative-block or < min_interval14
- typegroup 输入或找零带 type scriptgroup input or change has a type script18
- outputs回到本 lock 的输出 > 1more than 1 output back to this lock16
- capacityΣgroup 输入容量 − 找零容量(饱和减)> max_per_tx(手续费也算流出)Σ group input capacity − change (saturating) > max_per_tx (fee counts)12
- capacity累加溢出checked add overflow15
recipientSession 花费(限定收款方,112B / 160B)Session spend (recipient-scoped, 112B / 160B)
Inputs 输入Inputs
session-lock cell(s)session-lock cell(s)Cell{
lock: { codeHash: SESSION_LOCK (data2),
args: owner ‖ session ‖ max_per_tx ‖ min_interval ‖ {{recipient 32B}} }
}
session key cellsession key cellCell{ lock: session_lock_hash }Cell{ lock: session_lock_hash }
Outputs 输出Outputs
找零 ≤ 1change ≤ 1Cell{ lock: 同一 SESSION_LOCK }Cell{ lock: same SESSION_LOCK }
付款paymentCell{
lock: recipient 或 owner,
type: 无(token 会话可为 token type)
}Cell{
lock: recipient or owner,
type: none (token type allowed in token sessions)
}
session key 找零session key changeCell{ lock: session_lock_hash } // 容量 / token 不得增加Cell{ lock: session_lock_hash } // capacity / tokens must not grow
限制Constraints
- lock其它输出 lock ∉ {本 lock, session key, recipient, owner}other output lock ∉ {this lock, session key, recipient, owner}13
- typerecipient / owner 输出带非 token 的 typerecipient / owner output has a non-token type18
- capacitysession key lock 输出总容量 > session key lock 输入总容量(防止把额度转给 key)session-key outputs capacity > session-key inputs capacity (no siphon to the key)17
- capacity同上:流出 > max_per_txas above: outflow > max_per_tx12
tokenToken 会话(128B / 160B,xUDT/sUDT 类 u128 金额)Token session (128B / 160B, u128 xUDT/sUDT-like amounts)
Inputs 输入Inputs
session-lock token cell(s)session-lock token cell(s)Cell{
lock: SESSION_LOCK(… ‖ token_type_hash ‖ max_per_tx_token),
type: token type,hash = token_type_hash,
data: amount u128 LE(≥16B)
}Cell{
lock: SESSION_LOCK(… ‖ token_type_hash ‖ max_per_tx_token),
type: token type, hash = token_type_hash,
data: amount u128 LE (≥16B)
}
Outputs 输出Outputs
token 找零 ≤ 1token change ≤ 1Cell{
lock: 同一 SESSION_LOCK,
type: 无或 token type,
data: token 时恰好 16B
}Cell{
lock: same SESSION_LOCK,
type: none or the token type,
data: exactly 16B if token
}
限制Constraints
- typegroup 输入 / 找零带其它 typegroup input / change has another type18
- datatoken 输入 data < 16B,或 token 找零 data ≠ 16Btoken input data < 16B, or token change data ≠ 16B19
- dataΣtoken 输入 − token 找零 > max_per_tx_tokenΣ token in − token change > max_per_tx_token20
- data限定收款方时 session key 的 token 输出 > 输入recipient set and session-key token out > in17
- capacityCKB 容量仍受 max_per_tx 约束CKB capacity still bounded by max_per_tx12
部署与来源Deployments & source 未核验unverified
源码source
luongthanhtung03/ckb-session-kit@8157a644 · contracts/session-lock/src/main.rs · src/lock.ts · deployment/testnet.json · docs/SECURITY-EVIDENCE.md (commit bumped after docs/SDK work (58 commits); contracts/session-lock/src/main.rs unchanged since before f51f07cc)
二进制核验binary check
未核验unverified hash appears in the repo only as a deployment record or doc, which does not prove the recorded commit builds this binary (reproducible build not attempted)
0xab41946652…c64c08ce: listed in deployment/testnet.json
0xab41946652…c64c08ce: listed in deployment/testnet.json
| 网络network | code_hash | cell_dep | type_id args | 数据哈希data hash | 部署交易deploy tx |
|---|---|---|---|---|---|
| testnet | 0xab419466529ea479590d4be7b23580ce2ddc640ba902735c9ad9a22dc64c08ce data2 | 0xf3098bdb9a…284877f2:0 code | — | 0xab41946652…c64c08ce | 0xf3098bdb9a…284877f2 #22736207 |
链上数据核对于 on-chain data checked 2026-10-31
本 lock 不验签:owner / session key 的签名由它们各自 lock 在同一交易中验证(输入中出现其 lock hash 即视为授权)。This lock verifies no signature: owner / session key signatures are checked by their own locks in the same tx (an input with that lock hash counts as authorization).
过期时间(expiry)只在链下 SDK 中,链上不检查;撤销 = owner 模式花掉 cell。Expiry is off-chain (SDK) only, not enforced on chain; revoking = spending the cell in owner mode.
错误码:1 IndexOutOfBound · 2 ItemMissing · 3 LengthNotEnough · 4 Encoding · 10 BadArgs · 11 NotAuthorized · 12 OutflowExceeded · 13 RecipientNotAllowed · 14 RateLimited · 15 CapacityOverflow · 16 TooManyChangeCells · 17 KeyCellGrew · 18 TypedCell · 19 TokenData · 20 TokenOutflowExceeded。Error codes: 1 IndexOutOfBound · 2 ItemMissing · 3 LengthNotEnough · 4 Encoding · 10 BadArgs · 11 NotAuthorized · 12 OutflowExceeded · 13 RecipientNotAllowed · 14 RateLimited · 15 CapacityOverflow · 16 TooManyChangeCells · 17 KeyCellGrew · 18 TypedCell · 19 TokenData · 20 TokenOutflowExceeded.
仓库还记录了更早的测试网部署(10/8 0x1ae8…bc20、10/13 0x1cb7…90cd),规则不同,本页不匹配。The repo also lists older testnet deployments (8 Oct 0x1ae8…bc20, 13 Oct 0x1cb7…90cd) with different rules; they are not matched here.
过期时间(expiry)只在链下 SDK 中,链上不检查;撤销 = owner 模式花掉 cell。Expiry is off-chain (SDK) only, not enforced on chain; revoking = spending the cell in owner mode.
错误码:1 IndexOutOfBound · 2 ItemMissing · 3 LengthNotEnough · 4 Encoding · 10 BadArgs · 11 NotAuthorized · 12 OutflowExceeded · 13 RecipientNotAllowed · 14 RateLimited · 15 CapacityOverflow · 16 TooManyChangeCells · 17 KeyCellGrew · 18 TypedCell · 19 TokenData · 20 TokenOutflowExceeded。Error codes: 1 IndexOutOfBound · 2 ItemMissing · 3 LengthNotEnough · 4 Encoding · 10 BadArgs · 11 NotAuthorized · 12 OutflowExceeded · 13 RecipientNotAllowed · 14 RateLimited · 15 CapacityOverflow · 16 TooManyChangeCells · 17 KeyCellGrew · 18 TypedCell · 19 TokenData · 20 TokenOutflowExceeded.
仓库还记录了更早的测试网部署(10/8 0x1ae8…bc20、10/13 0x1cb7…90cd),规则不同,本页不匹配。The repo also lists older testnet deployments (8 Oct 0x1ae8…bc20, 13 Oct 0x1cb7…90cd) with different rules; they are not matched here.