script

package
v1.67.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

README

脚本使用

钱包资产找回

操作步骤

获取钱包找回地址X

  • 已知钱包找回控制地址A,找回地址B,相对延时时长T
  • 调用接口获取获取钱包找回地址X,相关rpc
  • 用户使用链上转账功能,将需要被钱包找回控制的的资产转入到地址X
  • X对应的私钥未知,需要由地址A或B的私钥构造比特币脚本签名,进行资产操作

控制地址提取X资产

  • 控制地址A可以随时对X的资产进行提取,即构造发送方为X的原始转账交易
  • 交易需要采用比特币脚本类型签名, 相关rpc
  • 发送交易到链上执行

找回地址提取X资产

  • 找回地址B可以基于延时交易提取X的资产, 即构造发送方为X的原始转账交易tx1, 但tx1需要提交到链上并等待延时打包
  • 交易tx1需要采用比特币脚本类型签名, 相关rpc
  • 基于tx1, 相对延时T, 构造延时存证交易tx2,构造方法
  • 将tx2签名并发送至链上执行,tx1将作为tx2的交易内容, 暂存于链上等待延时打包
  • 通过tx1哈希, 查询tx1是否被打包执行
rpc接口
chain33.GetWalletRecoverAddress

请求结构 ReqGetWalletRecoverAddr

字段名称 类型 含义
ctrPubKey string 控制地址公钥, secp256k1算法, 16进制
recoverPubKey string 找回地址公钥, secp256k1算法, 16进制
relativeDelayHeight int64 钱包找回相对延时时长, 区块高度值

响应

名称 类型 含义
result string 钱包找回地址
chain33.SignWalletRecoverTx

请求结构 ReqSignWalletRecoverTx

字段名称 类型 含义
walletRecoverParam ReqGetWalletRecoverAddr 钱包找回信息结构
signAddr string 签名地址
privKey string 签名地址的私钥, secp256k1算法, 16进制, 不指定私钥时,将从本地钱包获取对应私钥
rawTx string 原始交易, 16进制

响应

名称 类型 含义
result string 签名后的交易, hex格式

Documentation

Index

Constants

View Source
const (
	// TyPay2PubKey Pay to pub key
	TyPay2PubKey = iota
	// TyPay2PubKeyHash Pay to pub key Hash
	TyPay2PubKeyHash
	// TyPay2ScriptHash Pay to Script Hash
	TyPay2ScriptHash
)

Variables

View Source
var (

	// ErrInvalidMultiSigRequiredNum error required multi sig pub key num
	ErrInvalidMultiSigRequiredNum = errors.New("ErrInvalidMultiSigRequiredNum")
	// ErrInvalidBtcPubKey invalid bitcoin pubkey
	ErrInvalidBtcPubKey = errors.New("ErrInvalidBtcPubKey")
	// ErrBuildBtcScript build btc script error
	ErrBuildBtcScript = errors.New("ErrBuildBtcScript")
	// ErrNewBtcAddress new btc address pub key error
	ErrNewBtcAddress = errors.New("ErrNewBtcAddress")
	// ErrGetBtcTxInSig get btc tx input signature error
	ErrGetBtcTxInSig = errors.New("ErrGetBtcTxInSig")
	// ErrNewBtcScriptSig new btc script sig error
	ErrNewBtcScriptSig = errors.New("ErrNewBtcScriptSig")

	// ErrBtcKeyNotExist btc key not exist when sign
	ErrBtcKeyNotExist = errors.New("ErrBtcKeyNotExist")
	// ErrBtcScriptNotExist btc script not exist when sign
	ErrBtcScriptNotExist = errors.New("ErrBtcScriptNotExist")
)
View Source
var Chain33BtcParams = &chaincfg.Params{
	Name: "chain33-btc-Script",

	PubKeyHashAddrID:        0x00,
	ScriptHashAddrID:        0x05,
	PrivateKeyID:            0x80,
	WitnessPubKeyHashAddrID: 0x06,
	WitnessScriptHashAddrID: 0x0A,
}

Chain33BtcParams 比特币相关区块链参数

Functions

func CheckBtcScript

func CheckBtcScript(msg []byte, sig *Signature) error

CheckBtcScript check btc Script signature

func GetBtcLockScript

func GetBtcLockScript(scriptTy int32, pkScript []byte) (btcutil.Address, []byte, error)

GetBtcLockScript 根据地址类型,生成锁定脚本

func GetBtcUnlockScript

func GetBtcUnlockScript(signMsg, lockScript, prevScript []byte,
	kdb txscript.KeyDB, sdb txscript.ScriptDB) ([]byte, error)

GetBtcUnlockScript 生成比特币解锁脚本

func GetWalletRecoverySignature

func GetWalletRecoverySignature(isRetrieve bool, signMsg, privKey, walletRecoverScript []byte, utxoSequence int64) (sig []byte, pubKey []byte, err error)

GetWalletRecoverySignature get wallet asset recover signature isRetrieve set false when input control address private key, set true for wallet recovery signMsg msg for sign privKey private key of control address or recover address walletRecoverScript result of NewWalletRecoveryScript utxoSequence utxo sequence, set relative delay time for wallet recovery

func MakeKeyDB

func MakeKeyDB(keyAddr ...*BtcAddr2Key) txscript.KeyDB

MakeKeyDB make btc script key db

func MakeScriptDB

func MakeScriptDB(scriptArr ...*BtcAddr2Script) txscript.ScriptDB

MakeScriptDB make btc script db

func NewBtcKeyFromBytes

func NewBtcKeyFromBytes(priv []byte) (*btcec.PrivateKey, *btcec.PublicKey)

NewBtcKeyFromBytes 获取比特币公私钥

func NewBtcScriptSig

func NewBtcScriptSig(lockScript, unlockScript []byte) ([]byte, error)

NewBtcScriptSig new btc script signature

func NewBtcScriptSigWithDelay

func NewBtcScriptSigWithDelay(lockScript, unlockScript []byte, lockTime, utxoSeq int64) ([]byte, error)

NewBtcScriptSigWithDelay new btc script signature with lockTime or sequence

func NewMultiSigScript

func NewMultiSigScript(pubKeys [][]byte, required int) (script []byte, err error)

NewMultiSigScript multi-sig pubKey script

func NewWalletRecoveryScript

func NewWalletRecoveryScript(controlPubKey, recoverPubKey []byte, relativeDelayTime int64) (script []byte, err error)

NewWalletRecoveryScript wallet assets recovery pubKey script controlPubKey secp256k1 pub key recoverPubKey secp256k1 pub key relativeDelayTime relative time of second or block height IF <A's Pubkey> CHECKSIG ELSE <sequence> CHECKSEQUENCEVERIFY DROP <B's Pubkey> CHECKSIGVERIFY ENDIF

func Script2PubKey

func Script2PubKey(lockScript []byte) []byte

Script2PubKey transform script to fixed length public key

Types

type BtcAddr2Key

type BtcAddr2Key struct {
	Addr string
	Key  *btcec.PrivateKey
}

BtcAddr2Key 比特币编码地址及对应的私钥,用于签名KeyDB

type BtcAddr2Script

type BtcAddr2Script struct {
	Addr   string
	Script []byte
}

BtcAddr2Script 比特币编码地址及对应的脚本,用于签名ScriptDB

type Signature

type Signature struct {
	LockScript   []byte `protobuf:"bytes,1,opt,name=lockScript,proto3" json:"lockScript,omitempty"`
	UnlockScript []byte `protobuf:"bytes,2,opt,name=unlockScript,proto3" json:"unlockScript,omitempty"`
	LockTime     int64  `protobuf:"varint,3,opt,name=lockTime,proto3" json:"lockTime,omitempty"`
	UtxoSequence int64  `protobuf:"varint,4,opt,name=utxoSequence,proto3" json:"utxoSequence,omitempty"`
	// contains filtered or unexported fields
}

func (*Signature) Descriptor deprecated

func (*Signature) Descriptor() ([]byte, []int)

Deprecated: Use Signature.ProtoReflect.Descriptor instead.

func (*Signature) GetLockScript

func (x *Signature) GetLockScript() []byte

func (*Signature) GetLockTime

func (x *Signature) GetLockTime() int64

func (*Signature) GetUnlockScript

func (x *Signature) GetUnlockScript() []byte

func (*Signature) GetUtxoSequence

func (x *Signature) GetUtxoSequence() int64

func (*Signature) ProtoMessage

func (*Signature) ProtoMessage()

func (*Signature) ProtoReflect

func (x *Signature) ProtoReflect() protoreflect.Message

func (*Signature) Reset

func (x *Signature) Reset()

func (*Signature) String

func (x *Signature) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL