Documentation
¶
Index ¶
- Constants
- Variables
- func ErrDevice(msg string) error
- func ErrIndexMissing(index []byte) error
- func GetBigInt() *big.Int
- func PutBigInt(in *big.Int)
- func RegisterPairing(p Pairing)
- type AlgebraicSys
- type CA
- type Cert
- type CertType
- type ChainSDK
- type ChainType
- type Cryptor
- type DecKey
- type Decryptor
- type EncKey
- type Encryptor
- type Event
- type EventCompute
- type EventFinish
- type EventType
- type FieldElement
- type FlagReader
- type Hasher
- type Key
- type Level
- type Logger
- type MPC
- type Marshaller
- type NewSDKFunc
- type Pairing
- type PluginCryptFunc
- type PluginGenerateSessionKeyFunc
- type PluginHashFunc
- type PluginRandomFunc
- type PluginSignFuncL0
- type PluginSignFuncL1
- type PluginSignFuncL2
- type PluginSignFuncL3
- type Point
- type Position
- type PrivateKey
- type ProveKey
- type ProverInfo
- type PublicKey
- type R1CS
- type R1CSIterator
- type Response
- type SecretKey
- type SignKey
- type Signer
- type Snarks
- type VCMetrics
- type Verifier
- type VerifyKey
- type VerifyProofKey
Constants ¶
const ( //Hash message digest algorithm Hash = 0 //Asymmetric asymmetric encryption algorithm Asymmetric = 8 //Symmetrical symmetric encryption algorithm Symmetrical = 16 )
const ( //None unknown algorithm type, type information is hidden in the content, for example PKCS8 None = 0x0 //Hash FakeHash = 0x00 << Hash SHA1 = 0x10 << Hash SHA2 = 0x20 << Hash SHA3 = 0x30 << Hash KECCAK = 0x40 << Hash SM3 = 0x50 << Hash Sm3WithPublicKey = 0x60 << Hash //with default SM2 userID: 1234567812345678 SelfDefinedHash = 0x70 << Hash Size224 = 0x01 << Hash Size256 = 0x00 << Hash Size384 = 0x02 << Hash Size512 = 0x03 << Hash SHA2_224 = SHA2 | Size224 SHA2_256 = SHA2 | Size256 SHA2_384 = SHA2 | Size384 SHA2_512 = SHA2 | Size512 SHA3_224 = SHA3 | Size224 SHA3_256 = SHA3 | Size256 SHA3_384 = SHA3 | Size384 SHA3_512 = SHA3 | Size512 KECCAK_224 = KECCAK | Size224 KECCAK_256 = KECCAK | Size256 KECCAK_384 = KECCAK | Size384 KECCAK_512 = KECCAK | Size512 //Asymmetric Algo Sm2p256v1 = 0x01 << Asymmetric Secp256k1 = 0x02 << Asymmetric Secp256r1 = 0x03 << Asymmetric Secp384r1 = 0x04 << Asymmetric Secp521r1 = 0x05 << Asymmetric Secp256k1Recover = 0x06 << Asymmetric SelfDefinedSign = 0x07 << Asymmetric Rsa2048 = 0x10 << Asymmetric Rsa3072 = 0x11 << Asymmetric Rsa4096 = 0x12 << Asymmetric Ed25519 = 0x20 << Asymmetric //Symmetrical Algo for Encrypt and Decrypt Sm4 = 0x01 << Symmetrical Aes = 0x02 << Symmetrical Des3 = 0x03 << Symmetrical TEE = 0x04 << Symmetrical SelfDefinedCrypt = 0x05 << Symmetrical WhiteBox = 0x06 << Symmetrical CBC = 0x10 << Symmetrical ECB = 0x20 << Symmetrical GCM = 0x30 << Symmetrical )
algorithm identifier const value table
const ( DEBUG = iota Info Notice Warning Error )
context status
const ( CurveNameBN254 = "bn254" CurveNameSM9 = "sm9" CurveNameCurve101 = "testCurve101" CurveNameCurve101NonFFT = "testCurve101NonFFT" )
curve name
const ( ST_ONE = 1 + iota ST_OUTPUT ST_PUBINPUT ST_PRVINPUT ST_INTERNAL //除1、输入和输出外的骨干信号 ST_DISCARDED //边缘信号,总是依附于某个骨干信号; 无用的信号 ST_CONSTANT //常量信号,即被赋值为N的信号 )
nolint
const ( Groth16 = 0x00 AlgoTypeOffset = 32 )
zkp algo
const ( AlgoGroth16 = "groth16" AlgoPlonk = "plonk" )
algo name
const MethodName = "NewSDK"
MethodName plugin function name
const (
ProofVersion1 = 0x01 << iota
)
ProofVersion1 version for proof unmarshal
const (
VerifyVersion1 = 0x01 << iota
)
VerifyVersion1 version for evm unmarshal
Variables ¶
var ErrFFT = errors.New("not support fft")
ErrFFT not support fft
var ErrNotSupport = fmt.Errorf("engine: this algo is not support")
ErrNotSupport this algo is not support
Functions ¶
Types ¶
type AlgebraicSys ¶
type AlgebraicSys interface { Marshaller GetModule() *big.Int Name() string NewScalar() FieldElement //fr //NewField() FieldElement //fp PutScalar(FieldElement) GetRootOfUnity(uint64) (FieldElement, uint64, error) }
AlgebraicSys algebra system
type CertType ¶
type CertType int
CertType a data type to present cert type,like tcert,ecert and so on to install stringer: go install golang.org/x/tools/cmd/...@v0.1.12
type ChainSDK ¶
type ChainSDK interface { //ChainType 返回链的类型 ChainType() string //InvokeFinish 调用Finish方法, namespace是分区(通道),address是合约地址(名称) InvokeFinish(nodes []string, address, taskID, proof, result, error string) ([]byte, error) //RegisterListening 注册监听EVENT_FINISH和EVENT_COMPUTE事件 RegisterListening(proxyAddress, businessAddress []string) (chan *Event, error) //UnregisterListening 解注册事件 UnregisterListening(address string) error }
ChainSDK sdk for specific blockchain
type Decryptor ¶
type Decryptor interface { // Decrypt decrypts ciphertext using key k. Decrypt(k, cipherText []byte) (plaintext []byte, err error) }
Decryptor is a interface that provides decryption algorithms
type EncKey ¶
type EncKey interface { GetKeyInfo() int Encrypt(msg []byte, reader io.Reader) ([]byte, error) //Bytes for more information, see comment of VerifyKey.Bytes Bytes() []byte }
EncKey public key which can encrypt
type Encryptor ¶
type Encryptor interface { // Encrypt encrypts plaintext using key k. Encrypt(k, plaintext []byte, reader io.Reader) (cipherText []byte, err error) }
Encryptor is a interface that provides encryption algorithms
type Event ¶
type Event struct { ChannelID string `json:"channelID"` Type EventType `json:"type"` Event []byte `json:"event"` //json content TxHash string `json:"txHash"` BlockNum int `json:"blockNum"` }
Event event
type EventCompute ¶
type EventCompute struct { TaskID string `json:"taskID"` CircuitID [32]byte `json:"circuitID"` CCName string `json:"ccName"` WebHook string `json:"webHook"` WebHookBodyPattern string `json:"webHookBodyPattern"` BusinessContractAddr string `json:"businessContractAddr"` BusinessContractMethod string `json:"businessContractMethod"` Input string `json:"input"` }
EventCompute event compute
type EventFinish ¶
type EventFinish struct { TaskID string `json:"taskID"` CircuitID [32]byte `json:"circuitID"` Proof string `json:"proof"` Result string `json:"result"` Error string `json:"error"` Response []byte `json:"response"` NextCompute []byte `json:"nextCompute"` }
EventFinish event finish
type FieldElement ¶
type FieldElement interface { UnmarshalJSON([]byte) error MarshalJSON() ([]byte, error) Add(a1, a2 FieldElement) FieldElement Double(FieldElement) FieldElement Sub(a1, a2 FieldElement) FieldElement Neg(FieldElement) FieldElement Mul(a1, a2 FieldElement) FieldElement Square(FieldElement) FieldElement Div(a1, a2 FieldElement) FieldElement Inv(FieldElement) FieldElement Exp(FieldElement, []byte) FieldElement Equal(FieldElement) bool IsZero() bool IsOne() bool IsNeg() bool Set(FieldElement) FieldElement SetOne() FieldElement SetZero() FieldElement SetInt64(int64) FieldElement SetUint64(uint64) FieldElement SetRandom(io.Reader) FieldElement // From sets self to v (regular form) and returns self (Montgomery form) From(rat *big.Int) FieldElement //Regular append regular bytes to 'in', keep 'z' unchanged Regular(in []byte) []byte //FromRegular interprets 'content' as the bytes of a big-endian unsigned integer, // sets z to that value (in Montgomery form), and returns z. FromRegular(content []byte) FieldElement //MontBytes set and return 'res' with bytes in Montgomery form MontBytes(res []byte) []byte //GetModule set 'b' to 21888242871839275222246405745257275088548364400416034343698204186575808495617 GetModule(*big.Int) String() string //Copy get a clone Copy() FieldElement }
FieldElement in Montgomery From
type FlagReader ¶
FlagReader reader use as flag
type Hasher ¶
type Hasher interface { hash.Hash // Hash hashes messages msg. Hash(msg []byte) (hash []byte, err error) // BatchHash If you need to hash a series of bytes slices, calling BachHash can reduce one copy. BenchHash implies a loop. // example: a,b,c,d are four big byte slice // BenchHash([][]bytes{a,b,c,d}) faster than Hash(bytes.Join([][]bytes{a,b,c,d},nil)) // It reduce one join(...). Join implies one copy. BatchHash(msg [][]byte) (hash []byte, err error) }
Hasher is a interface that provides hash algorithms
type Key ¶
type Key interface { // Bytes converts this key to its byte representation, // if this operation is allowed. Bytes() ([]byte, error) //FromBytes It's revert method to Bytes() //K is a byte that needs to be parsed, and the meaning of opt depend on Keys, for example, it's maybe an algorithm type. If the parsing fails, return empty Key or nil. FromBytes(k []byte, opt int) error }
Key represents a cryptographic key
type Level ¶
type Level interface { //GetLevel the second return value is reserved and has NO effect at present! GetLevel() ([]int, uint8) }
Level priority of plugins
type Logger ¶
type Logger interface { Debug(v ...interface{}) Debugf(format string, v ...interface{}) Info(v ...interface{}) Infof(format string, v ...interface{}) Notice(v ...interface{}) Noticef(format string, v ...interface{}) Warning(v ...interface{}) Warningf(format string, v ...interface{}) Error(v ...interface{}) Errorf(format string, v ...interface{}) Critical(v ...interface{}) Criticalf(format string, v ...interface{}) }
Logger interface
type MPC ¶
type MPC interface { New(curve string, power uint) []byte Contribute(entropy, name string) error Verify() (bool, error) Beacon(string, int) error GetPower() int GetG1() []Point GetG2() []Point GetPairing() string GetHash() string VerifyWithHistory(srsBefore MPC) (bool, error) Marshaller }
MPC mpc
type Marshaller ¶
Marshaller marshal and unmarshal
type NewSDKFunc ¶
NewSDKFunc plugin function type
type Pairing ¶
type Pairing interface { AlgebraicSys Pair([]Point, []Point) Point PairCheck(P []Point, Q []Point) bool IsOnCurve(Point) error //GetBase never change result's value for GetBase, GetModule and GetOlder! GetBase(Position) Point NewPoint(Position) Point BatchScalarMultiplicationG1(scalars []*big.Int, ret []Point) BatchScalarMultiplicationG2(scalars []*big.Int, ret []Point) }
Pairing pairing of elliptic
func UnMarshalPairing ¶
UnMarshalPairing unmarshal pairing
type PluginCryptFunc ¶
PluginCryptFunc symmetric encryption and decryption function
type PluginHashFunc ¶
PluginHashFunc hash function
type PluginRandomFunc ¶
PluginRandomFunc random function
type PluginSignFuncL0 ¶
type PluginSignFuncL0 interface { Level //GetVerifyKey enter a raw publicKey and mod, return a VerifyKey //a raw publicKey means: // 1) for sm2, key is 65bytes and in 0x04||X||Y form, see GMT0009-2012 7.1 // http://www.gmbz.org.cn/main/viewfile/2018011001400692565.html may help // 2) for ecdsa, key is in 0x04||X||Y. The length depends on the curve, for example, // 65 bytes for secp256k1 and 133 for secp521r1, see 2.3.3 in [SEC1] uncompressed form. // https://www.rfc-editor.org/rfc/rfc5480.txt may help GetVerifyKey(key []byte, mode int) (VerifyKey, error) }
PluginSignFuncL0 sign function
type PluginSignFuncL1 ¶
type PluginSignFuncL1 interface { PluginSignFuncL0 //GetSignKey parse printable keyIndex to SignKey GetSignKey(keyIndex string) (SignKey, error) }
type PluginSignFuncL2 ¶
type PluginSignFuncL3 ¶
type Point ¶
type Point interface { Marshaller Add(Point, Point) Point Set(Point) Point Double(Point) Point //Neg neg Neg(Point) Point ScalarMult(Point, *big.Int) Point //scalar is at Z+ ScalarBaseMult(*big.Int) Point //GetPosition get position GetPosition() Position GetPairing() Pairing SetInfinity() IsInfinity() bool }
Point elliptic point
type PrivateKey ¶
PrivateKey represents the private key, able to sign and decrypt
type ProveKey ¶
type ProveKey interface { Prove(cs R1CS, witness []FieldElement, mpc MPC) ([]byte, error) GetSnark() string GetPairing() string GetVKTag() string Marshaller }
ProveKey zk-SNARKs algorithm prove key
type R1CS ¶
type R1CS interface { fmt.Stringer R1CSIterator SignalNum() int //m InputNum() (privateInput, publicInput int) OutputNum() int // l = publicInput + OutputNum() + 1 = m - privateInput Marshal() []byte GetPairing() Pairing }
R1CS r1cs
type R1CSIterator ¶
type R1CSIterator interface { ConstraintsNum() uint64 Next(pos *int) (index int, a, b, c map[int]FieldElement) GetSignalByID(nowid int) (id, reoffset int, prefix string, value FieldElement) }
R1CSIterator r1cs iterator
type Response ¶
type Response struct { Continue bool `json:"continue"` //NextParam: proxyContractAddr, input, businessContractAddr, businessContractMethod, WebHook and WebHookBodyPattern NextParam [6]string `json:"nextParam"` //response Response []byte `json:"response"` }
Response callback response
type SecretKey ¶
type SecretKey interface { Encrypt(src []byte, reader io.Reader) []byte Decrypt(src []byte) []byte Destroy() }
SecretKey sym
type SignKey ¶
type SignKey interface { VerifyKey Sign(msg []byte, hasher hash.Hash, rand io.Reader) ([]byte, error) Destroy() }
SignKey private key which can sign
type Snarks ¶
type Snarks interface { Name() string Setup(r1cs R1CS) (ProveKey, VerifyProofKey, error) GenCode(p, v []byte, circuitID [32]byte, t ChainType) []byte UnmarshalVK(in []byte) (VerifyProofKey, error) UnmarshalPK(in []byte) (ProveKey, error) }
Snarks zk-SNARKS
type VCMetrics ¶
type VCMetrics interface { UpdateGetDataTime(s, e int64) UpdateWaitTime(s, e int64) UpdateProveTime(s, e int64) UpdateVerifyTime(s, e int64) UpdateComputerTime(s, e int64) UpdateG1TPS(s, e int64, n int) UpdateG2TPS(s, e int64, n int) }
VCMetrics metrics for prove and verify
type Verifier ¶
type Verifier interface { Key // Verify verifies signature against key k and digest Verify(k, signature, digest []byte) (valid bool, err error) }
Verifier is a interface that provides verifying algorithms
type VerifyKey ¶
type VerifyKey interface { GetKeyInfo() int Verify(msg []byte, hasher hash.Hash, sig []byte) bool //Bytes return a raw key bytes without algorithm information //sm2: SM2PublicKey::=BIT STRING, 04||X||Y, 65 Bytes, GMT0009-2012 7.1 //ecdsa: PublicKeyBytes in PKIX publicKey //rsa: asn1{N, e} //matching public and private key pairs need to return the same result Bytes() []byte //RichBytes return a bytes with algorithm information RichBytes() []byte }
VerifyKey public key which can verify for more information, see GetVerifyKey's comment
type VerifyProofKey ¶
type VerifyProofKey interface { Verify(in []byte, limit string, mpc MPC) error GetSnark() string GetPairing() string Marshaller }
VerifyProofKey vk