区块链芝士丨隔离验证钱包开发指南(2)

Standard script types

标准脚本类型

Pay-to-Public-Key-Hash (P2PKH)

P2PKH是最常用的模板 scriptPubKey 被中本聪定义,允许简单的支付给一个单一的公钥.格式为:

scriptPubKey (25 bytes): OP_DUP OP_HASH160 < 20-byte-pubkey-hash > OP_EQUALVERIFY OP_CHECKSIG

花费P2PKH的输出,scriptSig格式为

scriptSig: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于scriptPubKey 中的 20-byte-pubkey-hash.

Pay-to-Script-Hash (P2SH)

P2SH定义在BIP16.它允许付款到任意复杂的脚本用一个修改长度的scriptPubKey. 格式为:

scriptPubKey (23 bytes): OP_HASH160 <20-byte-script-hash> OP_EQUAL

花费P2SH的输出,scriptSig格式为

scriptSig: <...> <...> <...> < redeemScript >

RIPEMD160(SHA256(redeemScript)) 等于在scriptPubKey中的 20-byte-script-hash. redeemScript是反序列化并且当作剩下的数据在scriptSig中

Pay-to-Witness-Public-Key-Hash (P2WPKH)

P2WPKH是BIP141新定义的. 类似P2PKH, 它允许简单支付到一个公钥, 格式为:

scriptPubKey (22 bytes): OP_0 < 20-byte-pubkey-hash >

花费P2WPKH的输出,scriptSig必须是空的,并且witness为

witness: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于scriptPubKey 中的 20-byte-pubkey-hash.

P2WPKH in P2SH (P2SH-P2WPKH)

P2SH-P2WPKH 是一个使用P2WPKH 脚本作为 redeemScript 的 P2SH. P2SH-P2WPKH的 scriptPubKey 看起来和通常的P2SH是相同的:

scriptPubKey (23 bytes): OP_HASH160 < 20-byte-script-hash > OP_EQUAL

花费P2SH-P2WPKH 的输出,scriptSig必须只包含一个 redeemScript, 并且witness 是和P2WPKH相同的:

scriptSig (23 bytes): < OP_0 < 20-byte-pubkey-hash > >
witness: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于 20-byte-pubkey-hash, 并且RIPEMD160(0x0014{20-byte-pubkey-hash}) 等于 20-byte-script-hash.

本文由 零点财经 作者:tao 发表,其版权均为 零点财经 所有,文章内容系作者个人观点,不代表 零点财经 对观点赞同或支持。如需转载,请注明文章来源。
分享生成图片
35

发表回复

区块链芝士丨隔离验证钱包开发指南(2)

2021-06-22 11:02:21

Standard script types

标准脚本类型

Pay-to-Public-Key-Hash (P2PKH)

P2PKH是最常用的模板 scriptPubKey 被中本聪定义,允许简单的支付给一个单一的公钥.格式为:

scriptPubKey (25 bytes): OP_DUP OP_HASH160 < 20-byte-pubkey-hash > OP_EQUALVERIFY OP_CHECKSIG

花费P2PKH的输出,scriptSig格式为

scriptSig: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于scriptPubKey 中的 20-byte-pubkey-hash.

Pay-to-Script-Hash (P2SH)

P2SH定义在BIP16.它允许付款到任意复杂的脚本用一个修改长度的scriptPubKey. 格式为:

scriptPubKey (23 bytes): OP_HASH160 <20-byte-script-hash> OP_EQUAL

花费P2SH的输出,scriptSig格式为

scriptSig: <...> <...> <...> < redeemScript >

RIPEMD160(SHA256(redeemScript)) 等于在scriptPubKey中的 20-byte-script-hash. redeemScript是反序列化并且当作剩下的数据在scriptSig中

Pay-to-Witness-Public-Key-Hash (P2WPKH)

P2WPKH是BIP141新定义的. 类似P2PKH, 它允许简单支付到一个公钥, 格式为:

scriptPubKey (22 bytes): OP_0 < 20-byte-pubkey-hash >

花费P2WPKH的输出,scriptSig必须是空的,并且witness为

witness: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于scriptPubKey 中的 20-byte-pubkey-hash.

P2WPKH in P2SH (P2SH-P2WPKH)

P2SH-P2WPKH 是一个使用P2WPKH 脚本作为 redeemScript 的 P2SH. P2SH-P2WPKH的 scriptPubKey 看起来和通常的P2SH是相同的:

scriptPubKey (23 bytes): OP_HASH160 < 20-byte-script-hash > OP_EQUAL

花费P2SH-P2WPKH 的输出,scriptSig必须只包含一个 redeemScript, 并且witness 是和P2WPKH相同的:

scriptSig (23 bytes): < OP_0 < 20-byte-pubkey-hash > >
witness: < sig > < pubkey >

RIPEMD160(SHA256(pubkey)) 等于 20-byte-pubkey-hash, 并且RIPEMD160(0x0014{20-byte-pubkey-hash}) 等于 20-byte-script-hash.