├── .gitignore ├── integration_test ├── scripts │ ├── build.sh │ ├── setup.sh │ ├── clean.sh │ ├── node │ │ ├── root_cert.srl │ │ ├── data │ │ │ └── priv_validator_state.json │ │ ├── config │ │ │ ├── node_key.json │ │ │ ├── key.pem │ │ │ ├── priv_validator_key.json │ │ │ ├── cer.pem │ │ │ └── cert.pem │ │ ├── root_key.pem │ │ └── root_cert.pem │ ├── start.sh │ ├── Dockerfile │ └── priv.key ├── election.wasm ├── params_test.go ├── record_test.go ├── wasm_test.go └── perm_test.go ├── crypto ├── keys │ ├── secp256k1 │ │ ├── internal │ │ │ └── secp256k1 │ │ │ │ ├── libsecp256k1 │ │ │ │ ├── obj │ │ │ │ │ └── .gitignore │ │ │ │ ├── autogen.sh │ │ │ │ ├── TODO │ │ │ │ ├── src │ │ │ │ │ ├── modules │ │ │ │ │ │ ├── ecdh │ │ │ │ │ │ │ ├── Makefile.am.include │ │ │ │ │ │ │ └── main_impl.h │ │ │ │ │ │ └── recovery │ │ │ │ │ │ │ └── Makefile.am.include │ │ │ │ │ ├── java │ │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.c │ │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.h │ │ │ │ │ │ └── org │ │ │ │ │ │ │ └── bitcoin │ │ │ │ │ │ │ ├── NativeSecp256k1Util.java │ │ │ │ │ │ │ └── Secp256k1Context.java │ │ │ │ │ ├── scalar_low.h │ │ │ │ │ ├── ecmult_const.h │ │ │ │ │ ├── num_gmp.h │ │ │ │ │ ├── num_impl.h │ │ │ │ │ ├── scalar_8x32.h │ │ │ │ │ ├── scalar_4x64.h │ │ │ │ │ ├── basic-config.h │ │ │ │ │ ├── ecdsa.h │ │ │ │ │ ├── eckey.h │ │ │ │ │ ├── ecmult.h │ │ │ │ │ ├── testrand.h │ │ │ │ │ ├── bench_sign.c │ │ │ │ │ ├── hash.h │ │ │ │ │ ├── bench_ecdh.c │ │ │ │ │ ├── field_5x52.h │ │ │ │ │ ├── bench.h │ │ │ │ │ ├── field_10x26.h │ │ │ │ │ ├── bench_recover.c │ │ │ │ │ └── ecmult_gen.h │ │ │ │ ├── libsecp256k1.pc.in │ │ │ │ ├── .gitignore │ │ │ │ ├── COPYING │ │ │ │ └── include │ │ │ │ │ └── secp256k1_ecdh.h │ │ │ │ ├── .gitignore │ │ │ │ ├── README.md │ │ │ │ ├── panic_cb.go │ │ │ │ └── LICENSE │ │ ├── bench_test.go │ │ ├── secp256k1_cgo.go │ │ ├── secp256k1_cgo_test.go │ │ ├── secp256k1_nocgo_test.go │ │ └── secp256k1_internal_test.go │ └── multisig │ │ └── codec.go ├── types │ ├── types.go │ └── multisig │ │ └── pubkey.go ├── key_manager_test.go └── codec │ └── proto.go ├── modules ├── wasm │ ├── params.go │ └── codec.go ├── auth │ └── params.go ├── service │ ├── params.go │ └── codec.go ├── token │ ├── params.go │ ├── codec.go │ └── export.go ├── params │ ├── export.go │ ├── codec.go │ ├── params.go │ └── types.go ├── keys │ ├── export.go │ ├── doc.go │ └── keys.go ├── bank │ ├── params.go │ ├── codec.go │ ├── export.go │ └── doc.go ├── store.go ├── record │ ├── codec.go │ ├── export.go │ ├── types.go │ └── record.go ├── identity │ ├── codec.go │ └── export.go ├── perm │ ├── export.go │ └── codec.go ├── oracle │ ├── codec.go │ └── export.go ├── nft │ └── codec.go ├── node │ ├── codec.go │ └── export.go └── grpc_client.go ├── codec ├── legacy │ ├── doc.go │ └── codec.go ├── types │ └── doc.go ├── json.go ├── unknownproto │ └── doc.go ├── any.go └── codec.go ├── third_party ├── proto │ ├── tendermint │ │ ├── libs │ │ │ └── bits │ │ │ │ └── types.proto │ │ ├── crypto │ │ │ ├── keys.proto │ │ │ └── proof.proto │ │ ├── types │ │ │ ├── block.proto │ │ │ ├── validator.proto │ │ │ └── evidence.proto │ │ ├── version │ │ │ └── types.proto │ │ └── p2p │ │ │ └── types.proto │ ├── cosmos_proto │ │ └── cosmos.proto │ └── google │ │ └── api │ │ └── annotations.proto └── protocgen.sh ├── types ├── proof.go ├── account.go ├── codec.go ├── address_test.go ├── sig_verifiable_tx.go ├── token.go ├── store │ ├── codec.go │ ├── memory.go │ └── aes.go ├── module.go ├── tm_types.go ├── tx │ ├── mode_handler.go │ ├── encoder.go │ ├── signing │ │ └── signature_data.go │ ├── tx.go │ ├── direct.go │ ├── config.go │ └── decoder.go ├── sign_mode_handler.go ├── tx_config.go ├── client.go ├── handler_map.go ├── utils.go ├── coin_type.go └── tx_msg.go ├── utils ├── log │ ├── type.go │ └── logger_test.go ├── common_test.go ├── commom.go ├── bech32 │ └── bech32.go └── cache │ └── cache.go ├── proto ├── params │ ├── params.proto │ └── tx.proto ├── cosmos │ ├── base │ │ ├── kv │ │ │ └── v1beta1 │ │ │ │ └── kv.proto │ │ ├── simulate │ │ │ └── v1beta1 │ │ │ │ └── simlate.proto │ │ ├── v1beta1 │ │ │ └── coin.proto │ │ ├── reflection │ │ │ └── v1beta1 │ │ │ │ └── reflection.proto │ │ └── query │ │ │ └── v1beta1 │ │ │ └── pagination.proto │ ├── crypto │ │ ├── multisig │ │ │ ├── keys.proto │ │ │ └── v1beta1 │ │ │ │ └── multisig.proto │ │ ├── sm2 │ │ │ └── keys.proto │ │ ├── secp256k1 │ │ │ └── keys.proto │ │ └── ed25519 │ │ │ └── keys.proto │ ├── bank │ │ └── v1beta1 │ │ │ └── tx.proto │ └── auth │ │ └── v1beta1 │ │ ├── query.proto │ │ └── auth.proto ├── slashing │ ├── tx.proto │ └── slashing.proto ├── record │ ├── record.proto │ ├── query.proto │ └── tx.proto ├── identity │ ├── query.proto │ ├── tx.proto │ └── identity.proto ├── oracle │ └── oracle.proto ├── random │ ├── random.proto │ ├── tx.proto │ └── query.proto ├── perm │ ├── query.proto │ ├── perm.proto │ └── tx.proto ├── nft │ └── nft.proto ├── node │ └── node.proto └── token │ └── token.proto ├── doc.go ├── Makefile ├── CHANGELOG.md ├── client └── tx │ └── tx.go └── go.mod /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | .idea 3 | .vscode 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /integration_test/scripts/build.sh: -------------------------------------------------------------------------------- 1 | docker build -t irita-sdk-go . -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/obj/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /integration_test/scripts/setup.sh: -------------------------------------------------------------------------------- 1 | cp -r ./scripts/node/ ~/.irita -------------------------------------------------------------------------------- /integration_test/scripts/clean.sh: -------------------------------------------------------------------------------- 1 | docker stop sdk-test 2 | docker rmi irita-sdk-go -------------------------------------------------------------------------------- /integration_test/scripts/node/root_cert.srl: -------------------------------------------------------------------------------- 1 | 241A359FE32EA142B13A943E10BBE38AC1885B66 2 | -------------------------------------------------------------------------------- /integration_test/scripts/start.sh: -------------------------------------------------------------------------------- 1 | docker run -d -it --rm -p 26657:26657 -p 9090:9090 --name sdk-test irita-sdk-go -------------------------------------------------------------------------------- /integration_test/election.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bianjieai/irita-sdk-go/HEAD/integration_test/election.wasm -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /integration_test/scripts/node/data/priv_validator_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "height": "0", 3 | "round": 0, 4 | "step": 0 5 | } -------------------------------------------------------------------------------- /integration_test/scripts/node/config/node_key.json: -------------------------------------------------------------------------------- 1 | {"priv_key":{"type":"tendermint/PrivKeySm2","value":"c9/ImZZGYmBs3RDe1AM6xCUMXZVilhruG7/ezOsaRI8="}} -------------------------------------------------------------------------------- /modules/wasm/params.go: -------------------------------------------------------------------------------- 1 | package wasm 2 | 3 | import "gopkg.in/yaml.v2" 4 | 5 | func (p Params) String() string { 6 | out, _ := yaml.Marshal(p) 7 | return string(out) 8 | } 9 | -------------------------------------------------------------------------------- /integration_test/scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bianjie/irita:latest 2 | 3 | COPY . /scripts 4 | 5 | RUN sh /scripts/setup.sh 6 | 7 | EXPOSE 26657 8 | EXPOSE 9090 9 | 10 | CMD irita start -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/TODO: -------------------------------------------------------------------------------- 1 | * Unit tests for fieldelem/groupelem, including ones intended to 2 | trigger fieldelem's boundary cases. 3 | * Complete constant-time operations for signing/keygen 4 | -------------------------------------------------------------------------------- /modules/auth/params.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | import ( 4 | yaml "gopkg.in/yaml.v2" 5 | ) 6 | 7 | // String implements the stringer interface. 8 | func (p Params) String() string { 9 | out, _ := yaml.Marshal(p) 10 | return string(out) 11 | } 12 | -------------------------------------------------------------------------------- /modules/service/params.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | yaml "gopkg.in/yaml.v2" 5 | ) 6 | 7 | // String implements the stringer interface. 8 | func (p Params) String() string { 9 | out, _ := yaml.Marshal(p) 10 | return string(out) 11 | } 12 | -------------------------------------------------------------------------------- /codec/legacy/doc.go: -------------------------------------------------------------------------------- 1 | // Package legacy contains a global amino Cdc which is deprecated but 2 | // still used in several places within the SDK. This package is intended 3 | // to be removed at some point in the future when the global Cdc is removed. 4 | package legacy 5 | -------------------------------------------------------------------------------- /codec/types/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package types defines a custom wrapper for google.protobuf.Any which supports 3 | cached values as well as InterfaceRegistry which keeps track of types which can 4 | be used with Any for both security and introspection 5 | */ 6 | package types 7 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/libs/bits/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.libs.bits; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/libs/bits"; 5 | 6 | message BitArray { 7 | int64 bits = 1; 8 | repeated uint64 elems = 2; 9 | } 10 | -------------------------------------------------------------------------------- /integration_test/scripts/priv.key: -------------------------------------------------------------------------------- 1 | -----BEGIN TENDERMINT PRIVATE KEY----- 2 | kdf: bcrypt 3 | salt: 94F791BA5CA59D53D352F73136E4291A 4 | type: sm2 5 | 6 | NEugTiMlsXyr/LgWHq3HvavWCdgD+2oUtPZqMaeW9Bg9aRQbA7cpwWOYXg+/Tei/ 7 | brcFWVIrCfCES2w7NAKZyXSp6j1dgI/oMTbGJ/8= 8 | =i3/x 9 | -----END TENDERMINT PRIVATE KEY----- -------------------------------------------------------------------------------- /integration_test/scripts/node/config/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgotbU6VlwxO6Dw55M 3 | K4xfk4ZLRATE2reJyNAzNe91TkCgCgYIKoEcz1UBgi2hRANCAAThQEKStl3MJYiR 4 | Gv3UmceccUMBdPCwiiobUofOfMlFjIN5W3QUvABCbgeX9B4Kubvztbw/QrPvIGdg 5 | kg+yi0WR 6 | -----END PRIVATE KEY----- 7 | -------------------------------------------------------------------------------- /types/proof.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import "github.com/tendermint/tendermint/proto/tendermint/crypto" 4 | 5 | type ProofValue struct { 6 | Proof []byte `json:"proof"` 7 | Path []string `json:"path"` 8 | Value []byte `json:"value"` 9 | } 10 | 11 | type MerkleProof struct { 12 | Proof *crypto.ProofOps `json:"proof"` 13 | } 14 | -------------------------------------------------------------------------------- /utils/log/type.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | const ( 4 | DebugLevel = "debug" 5 | InfoLevel = "info" 6 | WarnLevel = "warn" 7 | ErrorLevel = "error" 8 | 9 | FormatText = "text" 10 | FormatJSON = "json" 11 | ) 12 | 13 | type Config struct { 14 | Format string `json:"format" yaml:"format" ` 15 | Level string `json:"level" yaml:"level"` 16 | } 17 | -------------------------------------------------------------------------------- /modules/token/params.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | yaml "gopkg.in/yaml.v2" 5 | ) 6 | 7 | // String implements the stringer interface. 8 | func (p Params) String() string { 9 | out, _ := yaml.Marshal(p) 10 | return string(out) 11 | } 12 | 13 | func (t Token) String() string { 14 | bz, _ := yaml.Marshal(t) 15 | return string(bz) 16 | } 17 | -------------------------------------------------------------------------------- /integration_test/scripts/node/root_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BggqgRzPVQGCLQ== 3 | -----END EC PARAMETERS----- 4 | -----BEGIN EC PRIVATE KEY----- 5 | MHcCAQEEIM73jqbBQ3S7PEkFbT77eNUrC3m0NK16wV9Q0jW1LQCboAoGCCqBHM9V 6 | AYItoUQDQgAEkMJKG8pOA63xdceBdXLKn+IRQD9VdA7zlhzrH2Ow18ESrjbmJsEQ 7 | Usgx7/oXabl3tu7TqPPUNOo0EtQLDyHZEw== 8 | -----END EC PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /types/account.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // BaseAccount defines the basic structure of the account 4 | type BaseAccount struct { 5 | Address AccAddress `json:"address"` 6 | Coins Coins `json:"coins"` 7 | PubKey string `json:"public_key"` 8 | AccountNumber uint64 `json:"account_number"` 9 | Sequence uint64 `json:"sequence"` 10 | } 11 | -------------------------------------------------------------------------------- /integration_test/scripts/node/config/priv_validator_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "address": "50F518372E1587EA88FAA816EC34D9184683C745", 3 | "pub_key": { 4 | "type": "tendermint/PubKeySm2", 5 | "value": "A+FAQpK2XcwliJEa/dSZx5xxQwF08LCKKhtSh858yUWM" 6 | }, 7 | "priv_key": { 8 | "type": "tendermint/PrivKeySm2", 9 | "value": "otbU6VlwxO6Dw55MK4xfk4ZLRATE2reJyNAzNe91TkA=" 10 | } 11 | } -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_ecdh 6 | bench_ecdh_SOURCES = src/bench_ecdh.c 7 | bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /utils/log/logger_test.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNewLogger(t *testing.T) { 8 | log1 := NewLogger(Config{ 9 | Format: "json", 10 | Level: "info", 11 | }) 12 | 13 | log1.Info("Hello World", "foo", "bar") 14 | log1.Info("Hello World", "foo1", "bar") 15 | log1.Info("Hello World", "foo2", "bar") 16 | log1.Info("Hello World", "foo3", "bar") 17 | } 18 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | *~ 25 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/README.md: -------------------------------------------------------------------------------- 1 | This package is copied from https://github.com/ethereum/go-ethereum/tree/729bf365b5f17325be9107b63b233da54100eec6/crypto/secp256k1 2 | 3 | Unlike the rest of go-ethereum it is MIT licensed so compatible with our Apache2.0 license. We opt to copy in here rather than depend on go-ethereum to avoid issues with vendoring of the GPL parts of that repository by downstream. 4 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_recover 6 | bench_recover_SOURCES = src/bench_recover.c 7 | bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/libsecp256k1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsecp256k1 7 | Description: Optimized C library for EC operations on curve secp256k1 8 | URL: https://github.com/bitcoin-core/secp256k1 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs.private: @SECP_LIBS@ 12 | Libs: -L${libdir} -lsecp256k1 13 | 14 | -------------------------------------------------------------------------------- /third_party/proto/cosmos_proto/cosmos.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos_proto; 3 | 4 | import "google/protobuf/descriptor.proto"; 5 | 6 | option go_package = "github.com/regen-network/cosmos-proto"; 7 | 8 | extend google.protobuf.MessageOptions { 9 | string interface_type = 93001; 10 | 11 | string implements_interface = 93002; 12 | } 13 | 14 | extend google.protobuf.FieldOptions { 15 | string accepts_interface = 93001; 16 | } 17 | -------------------------------------------------------------------------------- /proto/params/params.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.params; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/params"; 7 | option (gogoproto.goproto_getters_all) = false; 8 | 9 | // ParamChange defines a parameter change. 10 | message ParamChange { 11 | option (gogoproto.equal) = true; 12 | 13 | string subspace = 1; 14 | string key = 2; 15 | string value = 3; 16 | } -------------------------------------------------------------------------------- /proto/cosmos/base/kv/v1beta1/kv.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.base.kv.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/types/kv"; 7 | 8 | // Pairs defines a repeated slice of Pair objects. 9 | message Pairs { 10 | repeated Pair pairs = 1 [(gogoproto.nullable) = false]; 11 | } 12 | 13 | // Pair defines a key/value bytes tuple. 14 | message Pair { 15 | bytes key = 1; 16 | bytes value = 2; 17 | } 18 | -------------------------------------------------------------------------------- /integration_test/scripts/node/config/cer.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBFTCBuwIBADBZMQswCQYDVQQGEwJDTjENMAsGA1UECAwEdGVzdDENMAsGA1UE 3 | BwwEdGVzdDENMAsGA1UECgwEdGVzdDENMAsGA1UECwwEdGVzdDEOMAwGA1UEAwwF 4 | bm9kZTAwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAThQEKStl3MJYiRGv3Umcec 5 | cUMBdPCwiiobUofOfMlFjIN5W3QUvABCbgeX9B4Kubvztbw/QrPvIGdgkg+yi0WR 6 | oAAwCgYIKoEcz1UBg3UDSQAwRgIhALEFfm5t/ddsfbZa4FPBmF1flmCgztGix2+a 7 | vjU8XILNAiEA7vlQO6T7Oi+LM8Fl0g+gJPPQLcLftb5eliUp3butOUY= 8 | -----END CERTIFICATE REQUEST----- 9 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/crypto/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.crypto; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | // PublicKey defines the keys available for use with Tendermint Validators 9 | message PublicKey { 10 | option (gogoproto.compare) = true; 11 | option (gogoproto.equal) = true; 12 | 13 | oneof sum { 14 | bytes ed25519 = 1; 15 | bytes secp256k1 = 2; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /modules/params/export.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | var ( 8 | _ Client = paramsClient{} 9 | ) 10 | 11 | // expose params module api for user 12 | type Client interface { 13 | sdk.Module 14 | 15 | UpdateParams(request []UpdateParamRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 16 | } 17 | 18 | type UpdateParamRequest struct { 19 | Module string `json:"module"` 20 | Key string `json:"key"` 21 | Value string `json:"value"` 22 | } 23 | -------------------------------------------------------------------------------- /types/codec.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | ) 7 | 8 | // EncodingConfig specifies the concrete encoding types to use for a given app. 9 | // This is provided for compatibility between protobuf and amino implementations. 10 | type EncodingConfig struct { 11 | InterfaceRegistry types.InterfaceRegistry 12 | Marshaler codec.Marshaler 13 | TxConfig TxConfig 14 | Amino *codec.LegacyAmino 15 | } 16 | -------------------------------------------------------------------------------- /utils/common_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | 8 | sdk "github.com/bianjieai/irita-sdk-go/types" 9 | ) 10 | 11 | func TestSplitArray(t *testing.T) { 12 | data := Ints{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 13 | subData := SubArray(4, data) 14 | require.Len(t, subData, 3) 15 | } 16 | 17 | type Ints []int 18 | 19 | func (i Ints) Len() int { 20 | return len(i) 21 | } 22 | 23 | func (i Ints) Sub(begin, end int) sdk.SplitAble { 24 | return i[begin:end] 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "org_bitcoin_Secp256k1Context.h" 4 | #include "include/secp256k1.h" 5 | 6 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 7 | (JNIEnv* env, jclass classObject) 8 | { 9 | secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 10 | 11 | (void)classObject;(void)env; 12 | 13 | return (uintptr_t)ctx; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /modules/keys/export.go: -------------------------------------------------------------------------------- 1 | package keys 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | type Client interface { 8 | Add(name, password string) (address string, mnemonic string, err sdk.Error) 9 | Recover(name, password, mnemonic string) (address string, err sdk.Error) 10 | Import(name, password, privKeyArmor string) (address string, err sdk.Error) 11 | Export(name, password string) (privKeyArmor string, err sdk.Error) 12 | Delete(name, password string) sdk.Error 13 | Show(name, password string) (string, sdk.Error) 14 | } 15 | -------------------------------------------------------------------------------- /codec/legacy/codec.go: -------------------------------------------------------------------------------- 1 | package legacy 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 6 | ) 7 | 8 | // Cdc defines a global generic sealed Amino codec to be used throughout sdk. It 9 | // has all Tendermint crypto and evidence types registered. 10 | // 11 | // TODO: Deprecated - remove this global. 12 | var Cdc *codec.LegacyAmino 13 | 14 | func init() { 15 | Cdc = codec.NewLegacyAmino() 16 | cryptocodec.RegisterCrypto(Cdc) 17 | codec.RegisterEvidences(Cdc) 18 | Cdc.Seal() 19 | } 20 | -------------------------------------------------------------------------------- /modules/keys/doc.go: -------------------------------------------------------------------------------- 1 | // Package keys allows you to manage your local tendermint keystore (wallets) for iris. 2 | // 3 | // **NOTE:** You need to implement the [[KeyDAO]] Interface first. 4 | // 5 | // As a quick start: 6 | // 7 | // CreateRecord a new key. 8 | // 9 | // client := test.NewClient() 10 | // name, password := "test2", "1234567890" 11 | // 12 | // address, mnemonic, err := client.KeyI.Add(name, password) 13 | // require.NoError(client.T(), err) 14 | // require.NotEmpty(client.T(), address) 15 | // require.NotEmpty(client.T(), mnemonic) 16 | // 17 | package keys 18 | -------------------------------------------------------------------------------- /modules/bank/params.go: -------------------------------------------------------------------------------- 1 | package bank 2 | 3 | import ( 4 | yaml "gopkg.in/yaml.v2" 5 | ) 6 | 7 | // String implements the stringer interface. 8 | func (p Params) String() string { 9 | out, _ := yaml.Marshal(p) 10 | return string(out) 11 | } 12 | 13 | // String implements stringer insterface 14 | func (se SendEnabled) String() string { 15 | out, _ := yaml.Marshal(se) 16 | return string(out) 17 | } 18 | 19 | // String returns a human readable string representation of a supplier. 20 | func (supply Supply) String() string { 21 | bz, _ := yaml.Marshal(supply) 22 | return string(bz) 23 | } 24 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Package sdk is the entrance of the entire SDK function. SDKConfig is used to configure SDK parameters. 2 | // 3 | // The SDK mainly provides the functions of the following modules, including: 4 | // perm, bank, keys, nft, params, record, service, token, validator 5 | // 6 | // As a quick start: 7 | // 8 | // options := []types.Option{ 9 | // types.KeyDAOOption(store.NewMemory(nil)), 10 | // } 11 | // cfg, err := types.NewClientConfig(nodeURI, chainID, options...) 12 | // if err != nil { 13 | // panic(err) 14 | // } 15 | // 16 | // client := sdk.NewIRITAClient(cfg) 17 | package sdk 18 | -------------------------------------------------------------------------------- /third_party/protocgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) 6 | for dir in $proto_dirs; do 7 | protoc \ 8 | -I "proto" \ 9 | -I "third_party/proto" \ 10 | --gocosmos_out=plugins=interfacetype+grpc,\ 11 | Mgoogle/protobuf/any.proto=github.com/bianjieai/irita-sdk-go/codec/types:. \ 12 | $(find "${dir}" -maxdepth 1 -name '*.proto') 13 | 14 | done 15 | 16 | # move proto files to the right places 17 | cp -r github.com/bianjieai/irita-sdk-go/* ./ 18 | rm -fr github.com 19 | -------------------------------------------------------------------------------- /modules/store.go: -------------------------------------------------------------------------------- 1 | package modules 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | rpcclient "github.com/tendermint/tendermint/rpc/client" 8 | ) 9 | 10 | func (base baseClient) QueryWithData(path string, key []byte) ([]byte, int64, error) { 11 | opts := rpcclient.ABCIQueryOptions{ 12 | Prove: true, 13 | } 14 | 15 | result, err := base.ABCIQueryWithOptions(context.Background(), path, key, opts) 16 | if err != nil { 17 | return nil, 0, err 18 | } 19 | 20 | if !result.Response.IsOK() { 21 | return nil, 0, errors.New(result.Response.Log) 22 | } 23 | return result.Response.Value, result.Response.Height, nil 24 | } 25 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/types/block.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/types/types.proto"; 8 | import "tendermint/types/evidence.proto"; 9 | 10 | message Block { 11 | Header header = 1 [(gogoproto.nullable) = false]; 12 | Data data = 2 [(gogoproto.nullable) = false]; 13 | tendermint.types.EvidenceList evidence = 3 [(gogoproto.nullable) = false]; 14 | Commit last_commit = 4; 15 | } 16 | -------------------------------------------------------------------------------- /modules/params/codec.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgUpdateParams{}, 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /modules/record/codec.go: -------------------------------------------------------------------------------- 1 | package record 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgCreateRecord{}, 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/scalar_low.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef uint32_t secp256k1_scalar; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /modules/identity/codec.go: -------------------------------------------------------------------------------- 1 | package identity 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgCreateIdentity{}, 24 | &MsgUpdateIdentity{}, 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /modules/perm/export.go: -------------------------------------------------------------------------------- 1 | package perm 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | // Client export a group api for Admin module 8 | type Client interface { 9 | sdk.Module 10 | 11 | AssignRoles(address string, roles []Role, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 12 | UnassignRoles(address string, roles []Role, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 13 | BlockAccount(address string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 14 | UnblockAccount(address string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 15 | 16 | QueryRoles(address string) ([]Role, sdk.Error) 17 | QueryBlacklist(page, limit int) ([]string, sdk.Error) 18 | } 19 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_CONST_ 8 | #define _SECP256K1_ECMULT_CONST_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_Secp256k1Context */ 5 | 6 | #ifndef _Included_org_bitcoin_Secp256k1Context 7 | #define _Included_org_bitcoin_Secp256k1Context 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_Secp256k1Context 13 | * Method: secp256k1_init_context 14 | * Signature: ()J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 17 | (JNIEnv *, jclass); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /modules/oracle/codec.go: -------------------------------------------------------------------------------- 1 | package oracle 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgCreateFeed{}, 24 | &MsgStartFeed{}, 25 | &MsgPauseFeed{}, 26 | &MsgEditFeed{}, 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /crypto/types/types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | proto "github.com/gogo/protobuf/proto" 5 | tmcrypto "github.com/tendermint/tendermint/crypto" 6 | ) 7 | 8 | // PubKey interface extends proto.Message 9 | // and tendermint crypto.PubKey 10 | type PubKey interface { 11 | proto.Message 12 | tmcrypto.PubKey 13 | } 14 | 15 | // PrivKey interface extends proto.Message 16 | // and tendermint crypto.PrivKey 17 | type PrivKey interface { 18 | proto.Message 19 | tmcrypto.PrivKey 20 | } 21 | 22 | type ( 23 | Address = tmcrypto.Address 24 | ) 25 | 26 | // IntoTmPubKey allows our own PubKey types be converted into Tendermint's 27 | // pubkey types. 28 | type IntoTmPubKey interface { 29 | AsTmPubKey() tmcrypto.PubKey 30 | } 31 | -------------------------------------------------------------------------------- /integration_test/scripts/node/config/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBrTCCAVICFCQaNZ/jLqFCsTqUPhC744rBiFtmMAoGCCqBHM9VAYN1MFgxCzAJ 3 | BgNVBAYTAkNOMQ0wCwYDVQQIDARyb290MQ0wCwYDVQQHDARyb290MQ0wCwYDVQQK 4 | DARyb290MQ0wCwYDVQQLDARyb290MQ0wCwYDVQQDDARyb290MB4XDTIxMDMxNjEw 5 | MTYyOVoXDTIyMDMxNjEwMTYyOVowWTELMAkGA1UEBhMCQ04xDTALBgNVBAgMBHRl 6 | c3QxDTALBgNVBAcMBHRlc3QxDTALBgNVBAoMBHRlc3QxDTALBgNVBAsMBHRlc3Qx 7 | DjAMBgNVBAMMBW5vZGUwMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE4UBCkrZd 8 | zCWIkRr91JnHnHFDAXTwsIoqG1KHznzJRYyDeVt0FLwAQm4Hl/QeCrm787W8P0Kz 9 | 7yBnYJIPsotFkTAKBggqgRzPVQGDdQNJADBGAiEA91/JWtmnQnUxPUJShqdJDx4y 10 | HuT1SSjjIoys0eAsfQICIQD3aGXzwwubPGNzFet2iHwcnsO33pGIx3yc8aaiuDqa 11 | 3A== 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /modules/perm/codec.go: -------------------------------------------------------------------------------- 1 | package perm 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgAssignRoles{}, 24 | &MsgUnassignRoles{}, 25 | &MsgBlockAccount{}, 26 | &MsgUnblockAccount{}, 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /modules/nft/codec.go: -------------------------------------------------------------------------------- 1 | package nft 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgIssueDenom{}, 24 | &MsgMintNFT{}, 25 | &MsgEditNFT{}, 26 | &MsgTransferNFT{}, 27 | &MsgBurnNFT{}, 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_REPR_ 8 | #define _SECP256K1_NUM_REPR_ 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /types/address_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | 9 | "github.com/bianjieai/irita-sdk-go/utils/bech32" 10 | ) 11 | 12 | func TestGetFromBech32(t *testing.T) { 13 | addBz, err := bech32.GetFromBech32("caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5", "caa") 14 | require.NoError(t, err) 15 | addr, err := bech32.ConvertAndEncode("iaa", addBz) 16 | require.NoError(t, err) 17 | fmt.Println(addr) 18 | 19 | addBz, err = bech32.GetFromBech32("ccp1ulx45dfpqdnyust0a8ezcdhjjn3cekla9wx9lnpqmer9httzvstx64mns5njqzr4fdd", "ccp") 20 | require.NoError(t, err) 21 | 22 | addr, err = bech32.ConvertAndEncode("icp", addBz) 23 | require.NoError(t, err) 24 | fmt.Println(addr) 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/panic_cb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be found in 3 | // the LICENSE file. 4 | 5 | package secp256k1 6 | 7 | import "C" 8 | import "unsafe" 9 | 10 | // Callbacks for converting libsecp256k1 internal faults into 11 | // recoverable Go panics. 12 | 13 | //export secp256k1GoPanicIllegal 14 | func secp256k1GoPanicIllegal(msg *C.char, data unsafe.Pointer) { 15 | panic("illegal argument: " + C.GoString(msg)) 16 | } 17 | 18 | //export secp256k1GoPanicError 19 | func secp256k1GoPanicError(msg *C.char, data unsafe.Pointer) { 20 | panic("internal error: " + C.GoString(msg)) 21 | } 22 | -------------------------------------------------------------------------------- /modules/node/codec.go: -------------------------------------------------------------------------------- 1 | package node 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgCreateValidator{}, 24 | &MsgUpdateValidator{}, 25 | &MsgRemoveValidator{}, 26 | &MsgGrantNode{}, 27 | &MsgRevokeNode{}, 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /proto/cosmos/crypto/multisig/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.crypto.multisig; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/any.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/crypto/keys/multisig"; 8 | 9 | // LegacyAminoPubKey specifies a public key type 10 | // which nests multiple public keys and a threshold, 11 | // it uses legacy amino address rules. 12 | message LegacyAminoPubKey { 13 | option (gogoproto.goproto_getters) = false; 14 | 15 | uint32 threshold = 1 [(gogoproto.moretags) = "yaml:\"threshold\""]; 16 | repeated google.protobuf.Any public_keys = 2 17 | [(gogoproto.customname) = "PubKeys", (gogoproto.moretags) = "yaml:\"pubkeys\""]; 18 | } 19 | -------------------------------------------------------------------------------- /proto/cosmos/crypto/sm2/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.crypto.sm2; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/crypto/keys/sm2"; 7 | 8 | // PubKey defines a secp256k1 public key 9 | // Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte 10 | // if the y-coordinate is the lexicographically largest of the two associated with 11 | // the x-coordinate. Otherwise the first byte is a 0x03. 12 | // This prefix is followed with the x-coordinate. 13 | message PubKey { 14 | option (gogoproto.goproto_stringer) = false; 15 | 16 | bytes key = 1; 17 | } 18 | 19 | // PrivKey defines a secp256k1 private key. 20 | message PrivKey { 21 | bytes key = 1; 22 | } 23 | -------------------------------------------------------------------------------- /proto/slashing/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.slashing; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/slashing"; 7 | option (gogoproto.goproto_getters_all) = false; 8 | 9 | 10 | // Msg defines the bank Msg service. 11 | service Msg { 12 | // Unjail defines a method for unjail a validator. 13 | rpc UnjailValidator(MsgUnjailValidator) returns (MsgUnjailValidatorResponse); 14 | } 15 | 16 | // MsgUnjailValidator - struct for unjailing jailed validator 17 | message MsgUnjailValidator { 18 | string id = 1 ; 19 | string operator = 2 ; 20 | } 21 | 22 | // MsgUnjailValidatorResponse defines the Msg/Unjail response type. 23 | message MsgUnjailValidatorResponse { } -------------------------------------------------------------------------------- /crypto/keys/secp256k1/bench_test.go: -------------------------------------------------------------------------------- 1 | package secp256k1 2 | 3 | import ( 4 | "io" 5 | "testing" 6 | 7 | "github.com/tendermint/tendermint/crypto" 8 | 9 | "github.com/bianjieai/irita-sdk-go/crypto/keys/internal/benchmarking" 10 | ) 11 | 12 | func BenchmarkKeyGeneration(b *testing.B) { 13 | benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey { 14 | return &PrivKey{Key: genPrivKey(crypto.CReader())} 15 | } 16 | benchmarking.BenchmarkKeyGeneration(b, benchmarkKeygenWrapper) 17 | } 18 | 19 | func BenchmarkSigning(b *testing.B) { 20 | priv := GenPrivKey() 21 | benchmarking.BenchmarkSigning(b, priv) 22 | } 23 | 24 | func BenchmarkVerification(b *testing.B) { 25 | priv := GenPrivKey() 26 | benchmarking.BenchmarkVerification(b, priv) 27 | } 28 | -------------------------------------------------------------------------------- /proto/cosmos/crypto/secp256k1/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.crypto.secp256k1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/crypto/keys/secp256k1"; 7 | 8 | // PubKey defines a secp256k1 public key 9 | // Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte 10 | // if the y-coordinate is the lexicographically largest of the two associated with 11 | // the x-coordinate. Otherwise the first byte is a 0x03. 12 | // This prefix is followed with the x-coordinate. 13 | message PubKey { 14 | option (gogoproto.goproto_stringer) = false; 15 | 16 | bytes key = 1; 17 | } 18 | 19 | // PrivKey defines a secp256k1 private key. 20 | message PrivKey { 21 | bytes key = 1; 22 | } 23 | -------------------------------------------------------------------------------- /types/sig_verifiable_tx.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/tendermint/tendermint/crypto" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types/tx/signing" 7 | ) 8 | 9 | // SigVerifiableTx defines a transaction interface for all signature verification 10 | // handlers. 11 | type SigVerifiableTx interface { 12 | Tx 13 | GetSigners() []AccAddress 14 | GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place 15 | GetSignaturesV2() ([]signing.SignatureV2, error) 16 | } 17 | 18 | // Tx defines a transaction interface that supports all standard message, signature 19 | // fee, memo, and auxiliary interfaces. 20 | type SigTx interface { 21 | SigVerifiableTx 22 | 23 | TxWithMemo 24 | FeeTx 25 | TxWithTimeoutHeight 26 | } 27 | -------------------------------------------------------------------------------- /proto/record/record.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.record; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/record"; 7 | option (gogoproto.goproto_getters_all) = false; 8 | 9 | // Content defines the detailed information for a record. 10 | message Content { 11 | option (gogoproto.equal) = true; 12 | 13 | string digest = 1; 14 | string digest_algo = 2 [(gogoproto.moretags) = "yaml:\"digest_algo\""]; 15 | string uri = 3 [(gogoproto.customname) = "URI"]; 16 | string meta = 4; 17 | } 18 | 19 | message Record { 20 | option (gogoproto.equal) = true; 21 | 22 | string tx_hash = 1 [(gogoproto.moretags) = "yaml:\"tx_hash\""]; 23 | repeated Content contents = 2 [(gogoproto.nullable) = false]; 24 | string creator = 3; 25 | } 26 | -------------------------------------------------------------------------------- /modules/grpc_client.go: -------------------------------------------------------------------------------- 1 | package modules 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types" 7 | "github.com/prometheus/common/log" 8 | "google.golang.org/grpc" 9 | ) 10 | 11 | var clientConnSingleton *grpc.ClientConn 12 | var once sync.Once 13 | 14 | type grpcClient struct { 15 | } 16 | 17 | func NewGRPCClient(url string) types.GRPCClient { 18 | once.Do(func() { 19 | 20 | dialOpts := []grpc.DialOption{ 21 | grpc.WithInsecure(), 22 | } 23 | clientConn, err := grpc.Dial(url, dialOpts...) 24 | if err != nil { 25 | log.Error(err.Error()) 26 | panic(err) 27 | } 28 | clientConnSingleton = clientConn 29 | }) 30 | 31 | return &grpcClient{} 32 | } 33 | 34 | func (g grpcClient) GenConn() (*grpc.ClientConn, error) { 35 | 36 | return clientConnSingleton, nil 37 | } 38 | -------------------------------------------------------------------------------- /modules/bank/codec.go: -------------------------------------------------------------------------------- 1 | package bank 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | "github.com/bianjieai/irita-sdk-go/modules/auth" 8 | sdk "github.com/bianjieai/irita-sdk-go/types" 9 | ) 10 | 11 | var ( 12 | amino = codec.NewLegacyAmino() 13 | ModuleCdc = codec.NewAminoCodec(amino) 14 | ) 15 | 16 | func init() { 17 | cryptocodec.RegisterCrypto(amino) 18 | amino.Seal() 19 | } 20 | 21 | func RegisterInterfaces(registry types.InterfaceRegistry) { 22 | registry.RegisterImplementations( 23 | (*sdk.Msg)(nil), 24 | &MsgSend{}, 25 | &MsgMultiSend{}, 26 | ) 27 | 28 | registry.RegisterImplementations( 29 | (*auth.Account)(nil), 30 | &auth.BaseAccount{}, 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_IMPL_H_ 8 | #define _SECP256K1_NUM_IMPL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PACKAGES=$(shell go list ./...) 2 | PACKAGES_UNITTEST=$(shell go list ./... | grep -v integration_test) 3 | export GO111MODULE = on 4 | 5 | format: 6 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs gofmt -w -s 7 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs misspell -w 8 | find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*.pb.go" | xargs goimports -w -local github.com/bianjieai/irita-sdk-go 9 | 10 | test-unit: 11 | @go test -v $(PACKAGES_UNITTEST) 12 | 13 | test-integration: 14 | cd integration_test/scripts/ && sh build.sh && sh start.sh 15 | sleep 2s 16 | @go test -v $(PACKAGES) 17 | cd integration_test/scripts/ && sh clean.sh 18 | 19 | proto-gen: 20 | @./third_party/protocgen.sh -------------------------------------------------------------------------------- /modules/token/codec.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgIssueToken{}, 24 | &MsgEditToken{}, 25 | &MsgMintToken{}, 26 | &MsgBurnToken{}, 27 | &MsgTransferTokenOwner{}, 28 | ) 29 | registry.RegisterInterface("irismod.token.TokenI", (*TokenInterface)(nil), &Token{}) 30 | } 31 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/version/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.version; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/version"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | // App includes the protocol and software version for the application. 9 | // This information is included in ResponseInfo. The App.Protocol can be 10 | // updated in ResponseEndBlock. 11 | message App { 12 | uint64 protocol = 1; 13 | string software = 2; 14 | } 15 | 16 | // Consensus captures the consensus rules for processing a block in the blockchain, 17 | // including all blockchain data structures and the rules of the application's 18 | // state transition machine. 19 | message Consensus { 20 | option (gogoproto.equal) = true; 21 | 22 | uint64 block = 1; 23 | uint64 app = 2; 24 | } 25 | -------------------------------------------------------------------------------- /integration_test/scripts/node/root_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICBDCCAaugAwIBAgIUOXW65eK84IOoyuQ3EP4Ukq+XevAwCgYIKoEcz1UBg3Uw 3 | WDELMAkGA1UEBhMCQ04xDTALBgNVBAgMBHJvb3QxDTALBgNVBAcMBHJvb3QxDTAL 4 | BgNVBAoMBHJvb3QxDTALBgNVBAsMBHJvb3QxDTALBgNVBAMMBHJvb3QwHhcNMjEw 5 | MzE2MTAxNjI5WhcNMjIwMzE2MTAxNjI5WjBYMQswCQYDVQQGEwJDTjENMAsGA1UE 6 | CAwEcm9vdDENMAsGA1UEBwwEcm9vdDENMAsGA1UECgwEcm9vdDENMAsGA1UECwwE 7 | cm9vdDENMAsGA1UEAwwEcm9vdDBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABJDC 8 | ShvKTgOt8XXHgXVyyp/iEUA/VXQO85Yc6x9jsNfBEq425ibBEFLIMe/6F2m5d7bu 9 | 06jz1DTqNBLUCw8h2ROjUzBRMB0GA1UdDgQWBBS1B/RJhawZ0qm6xv8ZAo2inUSe 10 | JjAfBgNVHSMEGDAWgBS1B/RJhawZ0qm6xv8ZAo2inUSeJjAPBgNVHRMBAf8EBTAD 11 | AQH/MAoGCCqBHM9VAYN1A0cAMEQCIEILyjp7cOHZwuqDp3yhXeEu3p81b/q59v6q 12 | D0qo30+nAiBu4gilD42Ny2SjJB5r1zjLJT9LZ/vIlcyptCI5IfDQzw== 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /proto/record/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.record; 3 | 4 | import "record/record.proto"; 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/record"; 8 | 9 | // Query defines the gRPC querier service for record module 10 | service Query { 11 | // Record queries the record by the given record ID 12 | rpc Record (QueryRecordRequest) returns (QueryRecordResponse) { 13 | option (google.api.http).get = "/irismod/record/records/{record_id}"; 14 | } 15 | } 16 | 17 | // QueryRecordRequest is the request type for the Query/Record RPC method 18 | message QueryRecordRequest { 19 | string record_id = 1; 20 | } 21 | 22 | // QueryRecordResponse is the response type for the Query/Record RPC method 23 | message QueryRecordResponse { 24 | record.Record record = 1; 25 | } 26 | -------------------------------------------------------------------------------- /proto/cosmos/crypto/ed25519/keys.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.crypto.ed25519; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/crypto/keys/ed25519"; 7 | 8 | // PubKey defines a ed25519 public key 9 | // Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte 10 | // if the y-coordinate is the lexicographically largest of the two associated with 11 | // the x-coordinate. Otherwise the first byte is a 0x03. 12 | // This prefix is followed with the x-coordinate. 13 | message PubKey { 14 | option (gogoproto.goproto_stringer) = false; 15 | 16 | bytes key = 1 [(gogoproto.casttype) = "crypto/ed25519.PublicKey"]; 17 | } 18 | 19 | // PrivKey defines a ed25519 private key. 20 | message PrivKey { 21 | bytes key = 1 [(gogoproto.casttype) = "crypto/ed25519.PrivateKey"]; 22 | } 23 | -------------------------------------------------------------------------------- /proto/identity/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.identity; 3 | 4 | import "identity/identity.proto"; 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/identity"; 8 | 9 | // Query defines the gRPC querier service for identity module 10 | service Query { 11 | // Identity queries the identity by the given id 12 | rpc Identity(QueryIdentityRequest) returns (QueryIdentityResponse) { 13 | option (google.api.http).get = "/iritamod/identity/identities/{id}"; 14 | } 15 | } 16 | 17 | // QueryIdentityRequest is request type for the Query/Identity RPC method 18 | message QueryIdentityRequest { 19 | string id = 1; 20 | } 21 | 22 | // QueryIdentityResponse is response type for the Query/Identity RPC method 23 | message QueryIdentityResponse { 24 | Identity identity = 1; 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/secp256k1_cgo.go: -------------------------------------------------------------------------------- 1 | // +build libsecp256k1 2 | 3 | package secp256k1 4 | 5 | import ( 6 | "github.com/tendermint/tendermint/crypto" 7 | 8 | "github.com/bianjieai/irita-sdk-go/crypto/keys/secp256k1/internal/secp256k1" 9 | ) 10 | 11 | // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. 12 | func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) { 13 | rsv, err := secp256k1.Sign(crypto.Sha256(msg), privKey.Key) 14 | if err != nil { 15 | return nil, err 16 | } 17 | // we do not need v in r||s||v: 18 | rs := rsv[:len(rsv)-1] 19 | return rs, nil 20 | } 21 | 22 | // VerifySignature validates the signature. 23 | // The msg will be hashed prior to signature verification. 24 | func (pubKey *PrivKey) VerifySignature(msg []byte, sig []byte) bool { 25 | return secp256k1.VerifySignature(pubKey.Key, crypto.Sha256(msg), sig) 26 | } 27 | -------------------------------------------------------------------------------- /proto/params/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.params; 3 | 4 | import "params/params.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/params"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | 11 | // Msg defines the bank Msg service. 12 | service Msg { 13 | // UpdateParams defines a method for update a set of system params. 14 | rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); 15 | } 16 | 17 | // MsgUpdateParams defines an SDK message for updating params. 18 | message MsgUpdateParams { 19 | option (gogoproto.equal) = true; 20 | 21 | repeated ParamChange changes = 1 [(gogoproto.nullable) = false]; 22 | string operator = 2; 23 | } 24 | 25 | // MsgUpdateParamsResponse defines the Msg/UpdateParams response type. 26 | message MsgUpdateParamsResponse { } -------------------------------------------------------------------------------- /third_party/proto/tendermint/types/validator.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "tendermint/crypto/keys.proto"; 8 | 9 | message ValidatorSet { 10 | repeated Validator validators = 1; 11 | Validator proposer = 2; 12 | int64 total_voting_power = 3; 13 | } 14 | 15 | message Validator { 16 | bytes address = 1; 17 | tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false]; 18 | int64 voting_power = 3; 19 | int64 proposer_priority = 4; 20 | } 21 | 22 | message SimpleValidator { 23 | tendermint.crypto.PublicKey pub_key = 1; 24 | int64 voting_power = 2; 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /integration_test/params_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | "github.com/stretchr/testify/require" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types" 7 | 8 | "github.com/bianjieai/irita-sdk-go/modules/params" 9 | ) 10 | 11 | func (s IntegrationTestSuite) TestParams() { 12 | baseTx := types.BaseTx{ 13 | From: s.Account().Name, 14 | Gas: 200000, 15 | Memo: "test", 16 | Mode: types.Commit, 17 | Password: s.Account().Password, 18 | } 19 | 20 | var request = []params.UpdateParamRequest{{ 21 | Module: "service", 22 | Key: "MaxRequestTimeout", 23 | Value: `"200"`, 24 | }} 25 | 26 | rs, err := s.Params.UpdateParams(request, baseTx) 27 | require.NoError(s.T(), err) 28 | require.NotEmpty(s.T(), rs.Hash) 29 | 30 | p, err := s.Service.QueryParams() 31 | require.NoError(s.T(), err) 32 | require.Equal(s.T(), int64(200), p.MaxRequestTimeout) 33 | } 34 | -------------------------------------------------------------------------------- /proto/record/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.record; 3 | 4 | import "record/record.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/record"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | 11 | // Msg defines the oracle Msg service. 12 | service Msg { 13 | // CreateRecord defines a method for creating a new record. 14 | rpc CreateRecord(MsgCreateRecord) returns (MsgCreateRecordResponse); 15 | } 16 | 17 | // MsgCreateRecord defines an SDK message for creating a new record. 18 | message MsgCreateRecord { 19 | option (gogoproto.equal) = true; 20 | 21 | repeated Content contents = 1 [(gogoproto.nullable) = false]; 22 | string creator = 2; 23 | } 24 | 25 | // MsgCreateRecordResponse defines the Msg/CreateRecord response type. 26 | message MsgCreateRecordResponse { 27 | string id = 1; 28 | } -------------------------------------------------------------------------------- /codec/json.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "bytes" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec/types" 7 | 8 | "github.com/gogo/protobuf/jsonpb" 9 | "github.com/gogo/protobuf/proto" 10 | ) 11 | 12 | // ProtoMarshalJSON provides an auxiliary function to return Proto3 JSON encoded 13 | // bytes of a message. 14 | func ProtoMarshalJSON(msg proto.Message, resolver jsonpb.AnyResolver) ([]byte, error) { 15 | // We use the OrigName because camel casing fields just doesn't make sense. 16 | // EmitDefaults is also often the more expected behavior for CLI users 17 | jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: resolver} 18 | err := types.UnpackInterfaces(msg, types.ProtoJSONPacker{JSONPBMarshaler: jm}) 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | buf := new(bytes.Buffer) 24 | 25 | if err := jm.Marshal(buf, msg); err != nil { 26 | return nil, err 27 | } 28 | 29 | return buf.Bytes(), nil 30 | } 31 | -------------------------------------------------------------------------------- /crypto/key_manager_test.go: -------------------------------------------------------------------------------- 1 | package crypto_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | 8 | "github.com/bianjieai/irita-sdk-go/crypto" 9 | sdk "github.com/bianjieai/irita-sdk-go/types" 10 | ) 11 | 12 | func TestNewMnemonicKeyManager(t *testing.T) { 13 | mnemonic := "nerve leader thank marriage spice task van start piece crowd run hospital control outside cousin romance left choice poet wagon rude climb leisure spring" 14 | 15 | km, err := crypto.NewMnemonicKeyManager(mnemonic, "sm2") 16 | assert.NoError(t, err) 17 | 18 | pubKey := km.ExportPubKey() 19 | pubkeyBech32, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) 20 | assert.NoError(t, err) 21 | assert.Equal(t, "iap1qg0f84wcp06t5ajvdf6dxhnwu0hhgjv3ulvpvy9cklqp374t5sty55dw3ps", pubkeyBech32) 22 | 23 | address := sdk.AccAddress(pubKey.Address()).String() 24 | assert.Equal(t, "iaa1yh6ke44anmv92g9w3r3rf0lpaxhjrenrshc4am", address) 25 | } 26 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/.gitignore: -------------------------------------------------------------------------------- 1 | bench_inv 2 | bench_ecdh 3 | bench_sign 4 | bench_verify 5 | bench_schnorr_verify 6 | bench_recover 7 | bench_internal 8 | tests 9 | exhaustive_tests 10 | gen_context 11 | *.exe 12 | *.so 13 | *.a 14 | !.gitignore 15 | 16 | Makefile 17 | configure 18 | .libs/ 19 | Makefile.in 20 | aclocal.m4 21 | autom4te.cache/ 22 | config.log 23 | config.status 24 | *.tar.gz 25 | *.la 26 | libtool 27 | .deps/ 28 | .dirstamp 29 | *.lo 30 | *.o 31 | *~ 32 | src/libsecp256k1-config.h 33 | src/libsecp256k1-config.h.in 34 | src/ecmult_static_context.h 35 | build-aux/config.guess 36 | build-aux/config.sub 37 | build-aux/depcomp 38 | build-aux/install-sh 39 | build-aux/ltmain.sh 40 | build-aux/m4/libtool.m4 41 | build-aux/m4/lt~obsolete.m4 42 | build-aux/m4/ltoptions.m4 43 | build-aux/m4/ltsugar.m4 44 | build-aux/m4/ltversion.m4 45 | build-aux/missing 46 | build-aux/compile 47 | build-aux/test-driver 48 | src/stamp-h1 49 | libsecp256k1.pc 50 | -------------------------------------------------------------------------------- /modules/record/export.go: -------------------------------------------------------------------------------- 1 | package record 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | // expose Record module api for user 8 | type Client interface { 9 | sdk.Module 10 | 11 | CreateRecord(request CreateRecordRequest, baseTx sdk.BaseTx) (string, sdk.Error) 12 | QueryRecord(request QueryRecordReq) (QueryRecordResp, sdk.Error) 13 | } 14 | 15 | type CreateRecordRequest struct { 16 | Contents []Content 17 | } 18 | 19 | type QueryRecordReq struct { 20 | RecordID string `json:"record_id"` 21 | Prove bool `json:"prove"` 22 | Height int64 `json:"height"` 23 | } 24 | 25 | type QueryRecordResp struct { 26 | Record Data `json:"record"` 27 | Proof sdk.ProofValue `json:"proof"` 28 | Height int64 `json:"height"` 29 | } 30 | 31 | type Data struct { 32 | TxHash string `json:"tx_hash" yaml:"tx_hash"` 33 | Contents []Content `json:"contents" yaml:"contents"` 34 | Creator string `json:"creator" yaml:"creator"` 35 | } 36 | -------------------------------------------------------------------------------- /proto/cosmos/crypto/multisig/v1beta1/multisig.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.crypto.multisig.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/crypto/types"; 7 | 8 | // MultiSignature wraps the signatures from a multisig.LegacyAminoPubKey. 9 | // See cosmos.tx.v1betata1.ModeInfo.Multi for how to specify which signers 10 | // signed and with which modes. 11 | message MultiSignature { 12 | option (gogoproto.goproto_unrecognized) = true; 13 | repeated bytes signatures = 1; 14 | } 15 | 16 | // CompactBitArray is an implementation of a space efficient bit array. 17 | // This is used to ensure that the encoded data takes up a minimal amount of 18 | // space after proto encoding. 19 | // This is not thread safe, and is not intended for concurrent usage. 20 | message CompactBitArray { 21 | option (gogoproto.goproto_stringer) = false; 22 | 23 | uint32 extra_bits_stored = 1; 24 | bytes elems = 2; 25 | } 26 | -------------------------------------------------------------------------------- /types/token.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | var ( 4 | POINT = Token{ 5 | Symbol: "point", 6 | Name: "Network staking token", 7 | Scale: 0, 8 | MinUnit: "point", 9 | InitialSupply: 2000000000, 10 | MaxSupply: 1000000000000, 11 | Mintable: true, 12 | Owner: "", 13 | } 14 | ) 15 | 16 | type Token struct { 17 | Symbol string `json:"symbol"` 18 | Name string `json:"name"` 19 | Scale uint32 `json:"scale"` 20 | MinUnit string `json:"min_unit"` 21 | InitialSupply uint64 `json:"initial_supply"` 22 | MaxSupply uint64 `json:"max_supply"` 23 | Mintable bool `json:"mintable"` 24 | Owner string `json:"owner"` 25 | } 26 | 27 | // GetCoinType returns CnType 28 | func (t Token) GetCoinType() CoinType { 29 | return CoinType{ 30 | Name: t.Name, 31 | MinUnit: NewUnit(t.MinUnit, uint8(t.Scale)), 32 | MainUnit: NewUnit(t.Symbol, 0), 33 | Desc: t.Name, 34 | } 35 | } 36 | 37 | type Tokens []Token 38 | -------------------------------------------------------------------------------- /modules/wasm/codec.go: -------------------------------------------------------------------------------- 1 | package wasm 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | const ( 11 | // ModuleName define the module name 12 | ModuleName = "wasm" 13 | ) 14 | 15 | var ( 16 | amino = codec.NewLegacyAmino() 17 | // ModuleCdc define the codec for wasm module 18 | ModuleCdc = codec.NewAminoCodec(amino) 19 | ) 20 | 21 | func init() { 22 | cryptocodec.RegisterCrypto(amino) 23 | amino.Seal() 24 | } 25 | 26 | // RegisterInterfaces regisger the implement of the msg interface for InterfaceRegistry 27 | func RegisterInterfaces(registry types.InterfaceRegistry) { 28 | registry.RegisterImplementations( 29 | (*sdk.Msg)(nil), 30 | &MsgStoreCode{}, 31 | &MsgInstantiateContract{}, 32 | &MsgExecuteContract{}, 33 | &MsgMigrateContract{}, 34 | &MsgUpdateAdmin{}, 35 | &MsgClearAdmin{}, 36 | ) 37 | } 38 | -------------------------------------------------------------------------------- /types/store/codec.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | import ( 4 | "github.com/tendermint/tendermint/crypto" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec" 7 | cryptoAmino "github.com/bianjieai/irita-sdk-go/crypto/codec" 8 | "github.com/bianjieai/irita-sdk-go/crypto/hd" 9 | ) 10 | 11 | var cdc *codec.LegacyAmino 12 | 13 | func init() { 14 | cdc = codec.NewLegacyAmino() 15 | cryptoAmino.RegisterCrypto(cdc) 16 | RegisterCodec(cdc) 17 | cdc.Seal() 18 | } 19 | 20 | // RegisterCodec registers concrete types and interfaces on the given codec. 21 | func RegisterCodec(cdc *codec.LegacyAmino) { 22 | cdc.RegisterInterface((*Info)(nil), nil) 23 | cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil) 24 | cdc.RegisterConcrete(localInfo{}, "crypto/keys/localInfo", nil) 25 | } 26 | 27 | // PubKeyFromBytes unmarshals public key bytes and returns a PubKey 28 | func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) { 29 | err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey) 30 | return 31 | } 32 | -------------------------------------------------------------------------------- /types/store/memory.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | // Use memory as storage, use with caution in build environment 4 | type MemoryDAO struct { 5 | store map[string]KeyInfo 6 | Crypto 7 | } 8 | 9 | func NewMemory(crypto Crypto) MemoryDAO { 10 | if crypto == nil { 11 | crypto = AES{} 12 | } 13 | return MemoryDAO{ 14 | store: make(map[string]KeyInfo), 15 | Crypto: crypto, 16 | } 17 | } 18 | func (m MemoryDAO) Write(name, password string, store KeyInfo) error { 19 | m.store[name] = store 20 | return nil 21 | } 22 | 23 | func (m MemoryDAO) Read(name, password string) (KeyInfo, error) { 24 | return m.store[name], nil 25 | } 26 | 27 | // ReadMetadata read a key information from the local store 28 | func (m MemoryDAO) ReadMetadata(name string) (store KeyInfo, err error) { 29 | return m.store[name], nil 30 | } 31 | 32 | func (m MemoryDAO) Delete(name, password string) error { 33 | delete(m.store, name) 34 | return nil 35 | } 36 | 37 | func (m MemoryDAO) Has(name string) bool { 38 | _, ok := m.store[name] 39 | return ok 40 | } 41 | -------------------------------------------------------------------------------- /proto/oracle/oracle.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.oracle; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/timestamp.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/oracle"; 8 | 9 | // Feed defines the feed standard 10 | message Feed { 11 | string feed_name = 1 [ (gogoproto.moretags) = "yaml:\"feed_name\"" ]; 12 | string description = 2; 13 | string aggregate_func = 3 [ (gogoproto.moretags) = "yaml:\"aggregate_func\"" ]; 14 | string value_json_path = 4 [ (gogoproto.moretags) = "yaml:\"value_json_path\"" ]; 15 | uint64 latest_history = 5 [ (gogoproto.moretags) = "yaml:\"latest_history\"" ]; 16 | string request_context_id = 6 [ (gogoproto.customname) = "RequestContextID", (gogoproto.moretags) = "yaml:\"request_context_id\"" ]; 17 | string creator = 7; 18 | } 19 | 20 | // FeedValue defines the feed result standard 21 | message FeedValue { 22 | string data = 1; 23 | google.protobuf.Timestamp timestamp = 2 [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; 24 | } 25 | -------------------------------------------------------------------------------- /proto/random/random.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.random; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cosmos/base/v1beta1/coin.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/random"; 8 | 9 | // Random defines the feed standard 10 | message Random { 11 | string request_tx_hash = 1 [ (gogoproto.moretags) = "yaml:\"request_tx_hash\"" ]; 12 | int64 height = 2; 13 | string value = 3; 14 | } 15 | 16 | // Request defines the random request standard 17 | message Request { 18 | int64 height = 1; 19 | string consumer = 2; 20 | string tx_hash = 3 [ (gogoproto.moretags) = "yaml:\"tx_hash\"" ]; 21 | bool oracle = 4; 22 | repeated cosmos.base.v1beta1.Coin service_fee_cap = 5 [ (gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/bianjieai/irita-sdk-go/types.Coins", (gogoproto.moretags) = "yaml:\"service_fee_cap\"" ]; 23 | string service_context_id = 6 [ (gogoproto.customname) = "ServiceContextID", (gogoproto.moretags) = "yaml:\"service_context_id\"" ]; 24 | } 25 | -------------------------------------------------------------------------------- /modules/service/codec.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | cryptocodec "github.com/bianjieai/irita-sdk-go/crypto/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | var ( 11 | amino = codec.NewLegacyAmino() 12 | ModuleCdc = codec.NewAminoCodec(amino) 13 | ) 14 | 15 | func init() { 16 | cryptocodec.RegisterCrypto(amino) 17 | amino.Seal() 18 | } 19 | 20 | func RegisterInterfaces(registry types.InterfaceRegistry) { 21 | registry.RegisterImplementations( 22 | (*sdk.Msg)(nil), 23 | &MsgDefineService{}, 24 | &MsgBindService{}, 25 | &MsgUpdateServiceBinding{}, 26 | &MsgSetWithdrawAddress{}, 27 | &MsgDisableServiceBinding{}, 28 | &MsgEnableServiceBinding{}, 29 | &MsgRefundServiceDeposit{}, 30 | &MsgCallService{}, 31 | &MsgRespondService{}, 32 | &MsgPauseRequestContext{}, 33 | &MsgStartRequestContext{}, 34 | &MsgKillRequestContext{}, 35 | &MsgUpdateRequestContext{}, 36 | &MsgWithdrawEarnedFees{}, 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /proto/random/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.random; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cosmos/base/v1beta1/coin.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/random"; 8 | 9 | // Msg defines the oracle Msg service. 10 | service Msg { 11 | // RequestRandom defines a method for requesting a new random number. 12 | rpc RequestRandom(MsgRequestRandom) returns (MsgRequestRandomResponse); 13 | } 14 | 15 | // MsgRequestRandom defines an sdk.Msg type that supports requesting a random number 16 | message MsgRequestRandom { 17 | uint64 block_interval = 1 [ (gogoproto.moretags) = "yaml:\"block_interval\"" ]; 18 | string consumer = 2; 19 | bool oracle = 3; 20 | repeated cosmos.base.v1beta1.Coin service_fee_cap = 4 [ (gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/bianjieai/irita-sdk-go/types.Coins", (gogoproto.moretags) = "yaml:\"service_fee_cap\"" ]; 21 | } 22 | 23 | 24 | // MsgRequestRandomResponse defines the Msg/RequestRandom response type. 25 | message MsgRequestRandomResponse {} 26 | 27 | -------------------------------------------------------------------------------- /types/module.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/tendermint/tendermint/crypto" 5 | 6 | cdctypes "github.com/bianjieai/irita-sdk-go/codec/types" 7 | ) 8 | 9 | //The purpose of this interface is to convert the irita system type to the user receiving type 10 | // and standardize the user interface 11 | type Response interface { 12 | Convert() interface{} 13 | } 14 | 15 | type SplitAble interface { 16 | Len() int 17 | Sub(begin, end int) SplitAble 18 | } 19 | 20 | type Module interface { 21 | Name() string 22 | RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) 23 | } 24 | 25 | type KeyManager interface { 26 | Sign(name, password string, data []byte) ([]byte, crypto.PubKey, error) 27 | Insert(name, password string) (string, string, error) 28 | Recover(name, password, mnemonic string) (string, error) 29 | Import(name, password string, privKeyArmor string) (address string, err error) 30 | Export(name, password string) (privKeyArmor string, err error) 31 | Delete(name, password string) error 32 | Find(name, password string) (crypto.PubKey, AccAddress, error) 33 | } 34 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/crypto/proof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.crypto; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | message Proof { 9 | int64 total = 1; 10 | int64 index = 2; 11 | bytes leaf_hash = 3; 12 | repeated bytes aunts = 4; 13 | } 14 | 15 | message ValueOp { 16 | // Encoded in ProofOp.Key. 17 | bytes key = 1; 18 | 19 | // To encode in ProofOp.Data 20 | Proof proof = 2; 21 | } 22 | 23 | message DominoOp { 24 | string key = 1; 25 | string input = 2; 26 | string output = 3; 27 | } 28 | 29 | // ProofOp defines an operation used for calculating Merkle root 30 | // The data could be arbitrary format, providing nessecary data 31 | // for example neighbouring node hash 32 | message ProofOp { 33 | string type = 1; 34 | bytes key = 2; 35 | bytes data = 3; 36 | } 37 | 38 | // ProofOps is Merkle proof defined by the list of ProofOps 39 | message ProofOps { 40 | repeated ProofOp ops = 1 [(gogoproto.nullable) = false]; 41 | } 42 | -------------------------------------------------------------------------------- /codec/unknownproto/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | unknownproto implements functionality to "type check" protobuf serialized byte sequences 3 | against an expected proto.Message to report: 4 | 5 | a) Unknown fields in the stream -- this is indicative of mismatched services, perhaps a malicious actor 6 | 7 | b) Mismatched wire types for a field -- this is indicative of mismatched services 8 | 9 | Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case 10 | 11 | if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil { 12 | // Handle the error. 13 | } 14 | 15 | and ideally should be added before invoking proto.Unmarshal, if you'd like to enforce the features mentioned above. 16 | 17 | By default, for security we report every single field that's unknown, whether a non-critical field or not. To customize 18 | this behavior, please set the boolean parameter allowUnknownNonCriticals to true to RejectUnknownFields: 19 | 20 | if err := RejectUnknownFields(protoBlob, protoMessage, true); err != nil { 21 | // Handle the error. 22 | } 23 | */ 24 | package unknownproto 25 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/basic-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BASIC_CONFIG_ 8 | #define _SECP256K1_BASIC_CONFIG_ 9 | 10 | #ifdef USE_BASIC_CONFIG 11 | 12 | #undef USE_ASM_X86_64 13 | #undef USE_ENDOMORPHISM 14 | #undef USE_FIELD_10X26 15 | #undef USE_FIELD_5X52 16 | #undef USE_FIELD_INV_BUILTIN 17 | #undef USE_FIELD_INV_NUM 18 | #undef USE_NUM_GMP 19 | #undef USE_NUM_NONE 20 | #undef USE_SCALAR_4X64 21 | #undef USE_SCALAR_8X32 22 | #undef USE_SCALAR_INV_BUILTIN 23 | #undef USE_SCALAR_INV_NUM 24 | 25 | #define USE_NUM_NONE 1 26 | #define USE_FIELD_INV_BUILTIN 1 27 | #define USE_SCALAR_INV_BUILTIN 1 28 | #define USE_FIELD_10X26 1 29 | #define USE_SCALAR_8X32 1 30 | 31 | #endif // USE_BASIC_CONFIG 32 | #endif // _SECP256K1_BASIC_CONFIG_ 33 | -------------------------------------------------------------------------------- /crypto/keys/multisig/codec.go: -------------------------------------------------------------------------------- 1 | package multisig 2 | 3 | import ( 4 | amino "github.com/tendermint/go-amino" 5 | "github.com/tendermint/tendermint/crypto" 6 | "github.com/tendermint/tendermint/crypto/sr25519" 7 | 8 | "github.com/bianjieai/irita-sdk-go/crypto/keys/ed25519" 9 | "github.com/bianjieai/irita-sdk-go/crypto/keys/secp256k1" 10 | cryptotypes "github.com/bianjieai/irita-sdk-go/crypto/types" 11 | ) 12 | 13 | // TODO: Figure out API for others to either add their own pubkey types, or 14 | // to make verify / marshal accept a Cdc. 15 | const ( 16 | PubKeyAminoRoute = "tendermint/PubKeyMultisigThreshold" 17 | ) 18 | 19 | var AminoCdc = amino.NewCodec() 20 | 21 | func init() { 22 | AminoCdc.RegisterInterface((*crypto.PubKey)(nil), nil) 23 | AminoCdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil) 24 | AminoCdc.RegisterConcrete(ed25519.PubKey{}, 25 | ed25519.PubKeyName, nil) 26 | AminoCdc.RegisterConcrete(sr25519.PubKey{}, 27 | sr25519.PubKeyName, nil) 28 | AminoCdc.RegisterConcrete(&secp256k1.PubKey{}, 29 | secp256k1.PubKeyName, nil) 30 | AminoCdc.RegisterConcrete(&LegacyAminoPubKey{}, 31 | PubKeyAminoRoute, nil) 32 | } 33 | -------------------------------------------------------------------------------- /proto/perm/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.perm; 3 | 4 | import "perm/perm.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/perm"; 7 | 8 | // Query defines the gRPC querier service for perm module 9 | service Query { 10 | // Roles queries the roles of a given address 11 | rpc Roles (QueryRolesRequest) returns (QueryRolesResponse) { 12 | } 13 | 14 | // Blacklist queries the black list 15 | rpc Blacklist (QueryBlacklistRequest) returns (QueryBlacklistResponse) { 16 | } 17 | } 18 | 19 | // QueryRolesRequest is request type for the Query/Roles RPC method 20 | message QueryRolesRequest { 21 | string address = 1; 22 | } 23 | 24 | // QueryRolesResponse is response type for the Query/Roles RPC method 25 | message QueryRolesResponse { 26 | repeated Role roles = 1; 27 | } 28 | 29 | // QueryBlacklistRequest is request type for the Query/Blacklist RPC method 30 | message QueryBlacklistRequest { 31 | } 32 | 33 | // QueryBlacklistResponse is response type for the Query/Blacklist RPC method 34 | message QueryBlacklistResponse { 35 | repeated string addresses = 1; 36 | } 37 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Pieter Wuille 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /codec/any.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gogo/protobuf/proto" 7 | 8 | "github.com/bianjieai/irita-sdk-go/codec/types" 9 | ) 10 | 11 | // MarshalAny is a convenience function for packing the provided value in an 12 | // Any and then proto marshaling it to bytes 13 | func MarshalAny(m BinaryMarshaler, x interface{}) ([]byte, error) { 14 | msg, ok := x.(proto.Message) 15 | if !ok { 16 | return nil, fmt.Errorf("can't proto marshal %T", x) 17 | } 18 | 19 | any := &types.Any{} 20 | if err := any.Pack(msg); err != nil { 21 | return nil, err 22 | } 23 | 24 | return m.MarshalBinaryBare(any) 25 | } 26 | 27 | // UnmarshalAny is a convenience function for proto unmarshaling an Any from 28 | // bz and then unpacking it to the interface pointer passed in as iface using 29 | // the provided AnyUnpacker or returning an error 30 | // 31 | // Ex: 32 | // var x MyInterface 33 | // err := UnmarshalAny(unpacker, &x, bz) 34 | func UnmarshalAny(m BinaryMarshaler, iface interface{}, bz []byte) error { 35 | any := &types.Any{} 36 | 37 | if err := m.UnmarshalBinaryBare(bz, any); err != nil { 38 | return err 39 | } 40 | 41 | return m.UnpackAny(any, iface) 42 | } 43 | -------------------------------------------------------------------------------- /utils/commom.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "crypto/rand" 5 | 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | ) 8 | 9 | // GenerateRandomBytes returns securely generated random bytes. 10 | // It will return an error if the system's secure random 11 | // number generator fails to function correctly, in which 12 | // case the caller should not continue. 13 | func GenerateRandomBytes(n int) ([]byte, error) { 14 | b := make([]byte, n) 15 | _, err := rand.Read(b) 16 | // Note that err == nil only if we read len(b) bytes. 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | return b, nil 22 | } 23 | 24 | func SubArray(subLen int, array sdk.SplitAble) (segments []sdk.SplitAble) { 25 | maxLen := array.Len() 26 | if maxLen <= subLen { 27 | return []sdk.SplitAble{array} 28 | } 29 | 30 | batch := maxLen / subLen 31 | if maxLen%subLen > 0 { 32 | batch++ 33 | } 34 | 35 | for i := 1; i <= batch; i++ { 36 | start := (i - 1) * subLen 37 | end := i * subLen 38 | if i != batch { 39 | segments = append(segments, array.Sub(start, end)) 40 | } else { 41 | segments = append(segments, array.Sub(start, array.Len())) 42 | } 43 | } 44 | return segments 45 | } 46 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/secp256k1_cgo_test.go: -------------------------------------------------------------------------------- 1 | // +build libsecp256k1 2 | 3 | package secp256k1 4 | 5 | import ( 6 | "testing" 7 | 8 | "github.com/magiconair/properties/assert" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestPrivKeySecp256k1SignVerify(t *testing.T) { 14 | msg := []byte("A.1.2 ECC Key Pair Generation by Testing Candidates") 15 | priv := GenPrivKey() 16 | tests := []struct { 17 | name string 18 | privKey *PrivKey 19 | wantSignErr bool 20 | wantVerifyPasses bool 21 | }{ 22 | {name: "valid sign-verify round", privKey: priv, wantSignErr: false, wantVerifyPasses: true}, 23 | {name: "invalid private key", privKey: &*PrivKey{Key: [32]byte{}}, wantSignErr: true, wantVerifyPasses: false}, 24 | } 25 | for _, tt := range tests { 26 | t.Run(tt.name, func(t *testing.T) { 27 | got, err := tt.privKey.Sign(msg) 28 | if tt.wantSignErr { 29 | require.Error(t, err) 30 | t.Logf("Got error: %s", err) 31 | return 32 | } 33 | require.NoError(t, err) 34 | require.NotNil(t, got) 35 | 36 | pub := tt.privKey.PubKey() 37 | assert.Equal(t, tt.wantVerifyPasses, pub.VerifyBytes(msg, got)) 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef _SECP256K1_ECDH_ 2 | # define _SECP256K1_ECDH_ 3 | 4 | # include "secp256k1.h" 5 | 6 | # ifdef __cplusplus 7 | extern "C" { 8 | # endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | # ifdef __cplusplus 28 | } 29 | # endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/secp256k1_nocgo_test.go: -------------------------------------------------------------------------------- 1 | // +build !libsecp256k1 2 | 3 | package secp256k1 4 | 5 | import ( 6 | "testing" 7 | 8 | secp256k1 "github.com/btcsuite/btcd/btcec" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | // Ensure that signature verification works, and that 13 | // non-canonical signatures fail. 14 | // Note: run with CGO_ENABLED=0 or go test -tags !cgo. 15 | func TestSignatureVerificationAndRejectUpperS(t *testing.T) { 16 | msg := []byte("We have lingered long enough on the shores of the cosmic ocean.") 17 | for i := 0; i < 500; i++ { 18 | priv := GenPrivKey() 19 | sigStr, err := priv.Sign(msg) 20 | require.NoError(t, err) 21 | sig := signatureFromBytes(sigStr) 22 | require.False(t, sig.S.Cmp(secp256k1halfN) > 0) 23 | 24 | pub := priv.PubKey() 25 | require.True(t, pub.VerifySignature(msg, sigStr)) 26 | 27 | // malleate: 28 | sig.S.Sub(secp256k1.S256().CurveParams.N, sig.S) 29 | require.True(t, sig.S.Cmp(secp256k1halfN) > 0) 30 | malSigStr := serializeSig(sig) 31 | 32 | require.False(t, pub.VerifySignature(msg, malSigStr), 33 | "VerifyBytes incorrect with malleated & invalid S. sig=%v, key=%v", 34 | sig, 35 | priv, 36 | ) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third_party/proto/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/p2p/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.p2p; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/p2p"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | 8 | message NetAddress { 9 | string id = 1 [(gogoproto.customname) = "ID"]; 10 | string ip = 2 [(gogoproto.customname) = "IP"]; 11 | uint32 port = 3; 12 | } 13 | 14 | message ProtocolVersion { 15 | uint64 p2p = 1 [(gogoproto.customname) = "P2P"]; 16 | uint64 block = 2; 17 | uint64 app = 3; 18 | } 19 | 20 | message DefaultNodeInfo { 21 | ProtocolVersion protocol_version = 1 [(gogoproto.nullable) = false]; 22 | string default_node_id = 2 [(gogoproto.customname) = "DefaultNodeID"]; 23 | string listen_addr = 3; 24 | string network = 4; 25 | string version = 5; 26 | bytes channels = 6; 27 | string moniker = 7; 28 | DefaultNodeInfoOther other = 8 [(gogoproto.nullable) = false]; 29 | } 30 | 31 | message DefaultNodeInfoOther { 32 | string tx_index = 1; 33 | string rpc_address = 2 [(gogoproto.customname) = "RPCAddress"]; 34 | } 35 | -------------------------------------------------------------------------------- /crypto/types/multisig/pubkey.go: -------------------------------------------------------------------------------- 1 | package multisig 2 | 3 | import ( 4 | "github.com/tendermint/tendermint/crypto" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types/tx/signing" 7 | ) 8 | 9 | // PubKey defines a type which supports multi-signature verification via MultiSignatureData 10 | // which supports multiple SignMode's. 11 | type PubKey interface { 12 | crypto.PubKey 13 | 14 | // VerifyMultisignature verifies the provide multi-signature represented by MultiSignatureData 15 | // using getSignBytes to retrieve the sign bytes to verify against for the provided mode. 16 | VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *signing.MultiSignatureData) error 17 | 18 | // GetPubKeys returns the crypto.PubKey's nested within the multi-sig PubKey 19 | GetPubKeys() []crypto.PubKey 20 | 21 | // GetThreshold returns the threshold number of signatures that must be obtained to verify a signature. 22 | GetThreshold() uint 23 | } 24 | 25 | // GetSignBytesFunc defines a function type which returns sign bytes for a given SignMode or an error. 26 | // It will generally be implemented as a closure which wraps whatever signable object signatures are 27 | // being verified against. 28 | type GetSignBytesFunc func(mode signing.SignMode) ([]byte, error) 29 | -------------------------------------------------------------------------------- /modules/bank/export.go: -------------------------------------------------------------------------------- 1 | package bank 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | // Client export a group api for Perm module 8 | type Client interface { 9 | sdk.Module 10 | 11 | Send(to string, amount sdk.DecCoins, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 12 | MultiSend(receipts MultiSendRequest, baseTx sdk.BaseTx) ([]sdk.ResultTx, sdk.Error) 13 | SubscribeSendTx(from, to string, callback EventMsgSendCallback) sdk.Subscription 14 | 15 | QueryAccount(address string) (sdk.BaseAccount, sdk.Error) 16 | } 17 | 18 | type Receipt struct { 19 | Address string `json:"address"` 20 | Amount sdk.DecCoins `json:"amount"` 21 | } 22 | 23 | type MultiSendRequest struct { 24 | Receipts []Receipt 25 | } 26 | 27 | func (msr MultiSendRequest) Len() int { 28 | return len(msr.Receipts) 29 | } 30 | 31 | func (msr MultiSendRequest) Sub(begin, end int) sdk.SplitAble { 32 | return MultiSendRequest{Receipts: msr.Receipts[begin:end]} 33 | } 34 | 35 | type EventDataMsgSend struct { 36 | Height int64 `json:"height"` 37 | Hash string `json:"hash"` 38 | From string `json:"from"` 39 | To string `json:"to"` 40 | Amount []sdk.Coin `json:"amount"` 41 | } 42 | 43 | type EventMsgSendCallback func(EventDataMsgSend) 44 | -------------------------------------------------------------------------------- /types/tm_types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/hex" 5 | "strings" 6 | 7 | "github.com/tendermint/tendermint/crypto" 8 | tmbytes "github.com/tendermint/tendermint/libs/bytes" 9 | tmclient "github.com/tendermint/tendermint/rpc/client" 10 | tmtypes "github.com/tendermint/tendermint/types" 11 | 12 | cryptoAmino "github.com/bianjieai/irita-sdk-go/crypto/codec" 13 | "github.com/bianjieai/irita-sdk-go/types/kv" 14 | ) 15 | 16 | type ( 17 | HexBytes = tmbytes.HexBytes 18 | ABCIClient = tmclient.ABCIClient 19 | SignClient = tmclient.SignClient 20 | StatusClient = tmclient.StatusClient 21 | NetworkClient = tmclient.NetworkClient 22 | Header = tmtypes.Header 23 | Pair = kv.Pair 24 | 25 | TmPubKey = crypto.PubKey 26 | ) 27 | 28 | var ( 29 | PubKeyFromBytes = cryptoAmino.PubKeyFromBytes 30 | ) 31 | 32 | func MustHexBytesFrom(hexStr string) HexBytes { 33 | v, _ := hex.DecodeString(hexStr) 34 | return HexBytes(v) 35 | } 36 | 37 | func HexBytesFrom(hexStr string) (HexBytes, error) { 38 | v, err := hex.DecodeString(hexStr) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return HexBytes(v), nil 43 | } 44 | 45 | func HexStringFrom(bz []byte) string { 46 | return strings.ToUpper(hex.EncodeToString(bz)) 47 | } 48 | -------------------------------------------------------------------------------- /types/tx/mode_handler.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types" 7 | signingtypes "github.com/bianjieai/irita-sdk-go/types/tx/signing" 8 | ) 9 | 10 | // DefaultSignModes are the default sign modes enabled for protobuf transactions. 11 | var DefaultSignModes = []signingtypes.SignMode{ 12 | signingtypes.SignMode_SIGN_MODE_DIRECT, 13 | //signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, 14 | } 15 | 16 | // makeSignModeHandler returns the default protobuf SignModeHandler supporting 17 | // SIGN_MODE_DIRECT and SIGN_MODE_LEGACY_AMINO_JSON. 18 | func MakeSignModeHandler(modes []signingtypes.SignMode) types.SignModeHandler { 19 | if len(modes) < 1 { 20 | panic(fmt.Errorf("no sign modes enabled")) 21 | } 22 | 23 | handlers := make([]types.SignModeHandler, len(modes)) 24 | 25 | for i, mode := range modes { 26 | switch mode { 27 | case signingtypes.SignMode_SIGN_MODE_DIRECT: 28 | handlers[i] = signModeDirectHandler{} 29 | case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: 30 | //handlers[i] = signModeLegacyAminoJSONHandler{} 31 | default: 32 | panic(fmt.Errorf("unsupported sign mode %+v", mode)) 33 | } 34 | } 35 | 36 | return types.NewSignModeHandlerMap( 37 | modes[0], 38 | handlers, 39 | ) 40 | } 41 | -------------------------------------------------------------------------------- /types/tx/encoder.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gogo/protobuf/proto" 7 | 8 | "github.com/bianjieai/irita-sdk-go/codec" 9 | sdk "github.com/bianjieai/irita-sdk-go/types" 10 | ) 11 | 12 | // DefaultTxEncoder returns a default protobuf TxEncoder using the provided Marshaler 13 | func DefaultTxEncoder() sdk.TxEncoder { 14 | return func(tx sdk.Tx) ([]byte, error) { 15 | txWrapper, ok := tx.(*wrapper) 16 | if !ok { 17 | return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, tx) 18 | } 19 | 20 | raw := &TxRaw{ 21 | BodyBytes: txWrapper.getBodyBytes(), 22 | AuthInfoBytes: txWrapper.getAuthInfoBytes(), 23 | Signatures: txWrapper.tx.Signatures, 24 | } 25 | 26 | return proto.Marshal(raw) 27 | } 28 | } 29 | 30 | // DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler. 31 | func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder { 32 | return func(tx sdk.Tx) ([]byte, error) { 33 | txWrapper, ok := tx.(*wrapper) 34 | if ok { 35 | return cdc.MarshalJSON(txWrapper.tx) 36 | } 37 | 38 | protoTx, ok := tx.(*Tx) 39 | if ok { 40 | return cdc.MarshalJSON(protoTx) 41 | } 42 | 43 | return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, tx) 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECDSA_ 8 | #define _SECP256K1_ECDSA_ 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /types/tx/signing/signature_data.go: -------------------------------------------------------------------------------- 1 | package signing 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/crypto/types" 5 | ) 6 | 7 | // SignatureData represents either a *SingleSignatureData or *MultiSignatureData. 8 | // It is a convenience type that is easier to use in business logic than the encoded 9 | // protobuf ModeInfo's and raw signatures. 10 | type SignatureData interface { 11 | isSignatureData() 12 | } 13 | 14 | // SingleSignatureData represents the signature and SignMode of a single (non-multisig) signer 15 | type SingleSignatureData struct { 16 | // SignMode represents the SignMode of the signature 17 | SignMode SignMode 18 | 19 | // SignMode represents the SignMode of the signature 20 | Signature []byte 21 | } 22 | 23 | // MultiSignatureData represents the nested SignatureData of a multisig signature 24 | type MultiSignatureData struct { 25 | // BitArray is a compact way of indicating which signers from the multisig key 26 | // have signed 27 | BitArray *types.CompactBitArray 28 | 29 | // Signatures is the nested SignatureData's for each signer 30 | Signatures []SignatureData 31 | } 32 | 33 | var _, _ SignatureData = &SingleSignatureData{}, &MultiSignatureData{} 34 | 35 | func (m *SingleSignatureData) isSignatureData() {} 36 | func (m *MultiSignatureData) isSignatureData() {} 37 | -------------------------------------------------------------------------------- /proto/cosmos/base/simulate/v1beta1/simlate.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.base.simulate.v1beta1; 3 | 4 | import "google/api/annotations.proto"; 5 | import "cosmos/base/abci/v1beta1/abci.proto"; 6 | import "cosmos/tx/v1beta1/tx.proto"; 7 | 8 | option go_package = "github.com/bianjieai/irita-sdk-go/client/grpc/simulate"; 9 | 10 | // SimulateService defines a gRPC service for simulating transactions. 11 | // It may also support querying and broadcasting in the future. 12 | service SimulateService { 13 | // Simulate simulates executing a transaction for estimating gas usage. 14 | rpc Simulate(SimulateRequest) returns (SimulateResponse) { 15 | option (google.api.http).post = "/cosmos/base/simulate/v1beta1/simulate"; 16 | } 17 | } 18 | 19 | // SimulateRequest is the request type for the SimulateServiceService.Simulate 20 | // RPC method. 21 | message SimulateRequest { 22 | // tx is the transaction to simulate. 23 | cosmos.tx.v1beta1.Tx tx = 1; 24 | } 25 | 26 | // SimulateResponse is the response type for the 27 | // SimulateServiceService.SimulateRPC method. 28 | message SimulateResponse { 29 | // gas_info is the information about gas used in the simulation. 30 | cosmos.base.abci.v1beta1.GasInfo gas_info = 1; 31 | // result is the result of the simulation. 32 | cosmos.base.abci.v1beta1.Result result = 2; 33 | } -------------------------------------------------------------------------------- /crypto/keys/secp256k1/secp256k1_internal_test.go: -------------------------------------------------------------------------------- 1 | package secp256k1 2 | 3 | import ( 4 | "bytes" 5 | "math/big" 6 | "testing" 7 | 8 | btcSecp256k1 "github.com/btcsuite/btcd/btcec" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func Test_genPrivKey(t *testing.T) { 13 | 14 | empty := make([]byte, 32) 15 | oneB := big.NewInt(1).Bytes() 16 | onePadded := make([]byte, 32) 17 | copy(onePadded[32-len(oneB):32], oneB) 18 | t.Logf("one padded: %v, len=%v", onePadded, len(onePadded)) 19 | 20 | validOne := append(empty, onePadded...) 21 | tests := []struct { 22 | name string 23 | notSoRand []byte 24 | shouldPanic bool 25 | }{ 26 | {"empty bytes (panics because 1st 32 bytes are zero and 0 is not a valid field element)", empty, true}, 27 | {"curve order: N", btcSecp256k1.S256().N.Bytes(), true}, 28 | {"valid because 0 < 1 < N", validOne, false}, 29 | } 30 | for _, tt := range tests { 31 | tt := tt 32 | t.Run(tt.name, func(t *testing.T) { 33 | if tt.shouldPanic { 34 | require.Panics(t, func() { 35 | genPrivKey(bytes.NewReader(tt.notSoRand)) 36 | }) 37 | return 38 | } 39 | got := genPrivKey(bytes.NewReader(tt.notSoRand)) 40 | fe := new(big.Int).SetBytes(got[:]) 41 | require.True(t, fe.Cmp(btcSecp256k1.S256().N) < 0) 42 | require.True(t, fe.Sign() > 0) 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/eckey.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_ 8 | #define _SECP256K1_ECKEY_ 9 | 10 | #include 11 | 12 | #include "group.h" 13 | #include "scalar.h" 14 | #include "ecmult.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size); 18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed); 19 | 20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak); 21 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak); 23 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /modules/identity/export.go: -------------------------------------------------------------------------------- 1 | package identity 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | type Client interface { 8 | sdk.Module 9 | 10 | CreateIdentity(request CreateIdentityRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 11 | UpdateIdentity(request UpdateIdentityRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 12 | 13 | QueryIdentity(id string) (QueryIdentityResp, sdk.Error) 14 | } 15 | 16 | type PubkeyInfo struct { 17 | PubKey string `json:"pub_key"` 18 | PubKeyAlgo PubKeyAlgorithm `json:"pub_key_algo"` 19 | } 20 | 21 | type CreateIdentityRequest struct { 22 | ID string `json:"id"` 23 | PubkeyInfo *PubkeyInfo `json:"pubkey_info"` 24 | Certificate string `json:"certificate"` 25 | Credentials *string `json:"credentials"` 26 | } 27 | 28 | type UpdateIdentityRequest struct { 29 | ID string `json:"id"` 30 | PubkeyInfo *PubkeyInfo `json:"pubkey_info"` 31 | Certificate string `json:"certificate"` 32 | Credentials *string `json:"credentials"` 33 | } 34 | 35 | type QueryIdentityResp struct { 36 | ID string `json:"id"` 37 | PubkeyInfos []PubkeyInfo `json:"pubkey_infos"` 38 | Certificates []string `json:"certificates"` 39 | Credentials string `json:"credentials"` 40 | Owner string `json:"owner"` 41 | } 42 | -------------------------------------------------------------------------------- /modules/params/params.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/types" 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | ) 8 | 9 | type paramsClient struct { 10 | sdk.BaseClient 11 | codec.Marshaler 12 | } 13 | 14 | func NewClient(bc sdk.BaseClient, cdc codec.Marshaler) Client { 15 | return paramsClient{ 16 | BaseClient: bc, 17 | Marshaler: cdc, 18 | } 19 | } 20 | 21 | func (p paramsClient) Name() string { 22 | return ModuleName 23 | } 24 | 25 | func (p paramsClient) RegisterInterfaceTypes(registry types.InterfaceRegistry) { 26 | RegisterInterfaces(registry) 27 | } 28 | 29 | func (p paramsClient) UpdateParams(requests []UpdateParamRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) { 30 | sender, err := p.QueryAddress(baseTx.From, baseTx.Password) 31 | if err != nil { 32 | return sdk.ResultTx{}, sdk.Wrapf("%s not found", baseTx.From) 33 | } 34 | 35 | var changes []ParamChange 36 | for _, req := range requests { 37 | if err != nil { 38 | return sdk.ResultTx{}, sdk.Wrap(err) 39 | } 40 | changes = append(changes, ParamChange{ 41 | Subspace: req.Module, 42 | Key: req.Key, 43 | Value: req.Value, 44 | }) 45 | } 46 | 47 | msg := &MsgUpdateParams{ 48 | Changes: changes, 49 | Operator: sender.String(), 50 | } 51 | return p.BuildAndSend([]sdk.Msg{msg}, baseTx) 52 | } 53 | -------------------------------------------------------------------------------- /utils/bech32/bech32.go: -------------------------------------------------------------------------------- 1 | package bech32 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | 7 | "github.com/btcsuite/btcutil/bech32" 8 | ) 9 | 10 | // GetFromBech32 decodes a byte string from a Bech32 encoded string. 11 | func GetFromBech32(bech32str, prefix string) ([]byte, error) { 12 | if len(bech32str) == 0 { 13 | return nil, errors.New("decoding Bech32 address failed: must provide an address") 14 | } 15 | 16 | hrp, bz, err := DecodeAndConvert(bech32str) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | if hrp != prefix { 22 | return nil, fmt.Errorf("invalid Bech32 prefix; expected %s, got %s", prefix, hrp) 23 | } 24 | 25 | return bz, nil 26 | } 27 | 28 | //ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32 29 | func ConvertAndEncode(hrp string, data []byte) (string, error) { 30 | converted, err := bech32.ConvertBits(data, 8, 5, true) 31 | if err != nil { 32 | return "", err 33 | } 34 | return bech32.Encode(hrp, converted) 35 | 36 | } 37 | 38 | //DecodeAndConvert decodes a bech32 encoded string and converts to base64 encoded bytes 39 | func DecodeAndConvert(bech string) (string, []byte, error) { 40 | hrp, data, err := bech32.Decode(bech) 41 | if err != nil { 42 | return "", nil, err 43 | } 44 | converted, err := bech32.ConvertBits(data, 5, 8, false) 45 | if err != nil { 46 | return "", nil, err 47 | } 48 | return hrp, converted, nil 49 | } 50 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 33 | 34 | # Changelog 35 | 36 | ## [Unreleased] 37 | 38 | ## [v2.0.0] - 2021-04-26 39 | 40 | ### Features 41 | 42 | * Support irita [v2.0.0](https://github.com/bianjieai/irita/releases/tag/v2.0.0) 43 | 44 | 45 | 46 | [v2.0.0]: https://github.com/bianjieai/irita-sdk-go/releases/tag/v2.0.0 -------------------------------------------------------------------------------- /integration_test/record_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/stretchr/testify/require" 7 | 8 | "github.com/bianjieai/irita-sdk-go/modules/record" 9 | sdk "github.com/bianjieai/irita-sdk-go/types" 10 | ) 11 | 12 | func (s IntegrationTestSuite) TestRecord() { 13 | baseTx := sdk.BaseTx{ 14 | From: s.Account().Name, 15 | Gas: 200000, 16 | Memo: "test", 17 | Mode: sdk.Commit, 18 | Password: s.Account().Password, 19 | } 20 | 21 | num := 5 22 | contents := make([]record.Content, num) 23 | for i := 0; i < num; i++ { 24 | contents[i] = record.Content{ 25 | Digest: s.RandStringOfLength(10), 26 | DigestAlgo: s.RandStringOfLength(5), 27 | URI: fmt.Sprintf("https://%s", s.RandStringOfLength(10)), 28 | Meta: s.RandStringOfLength(20), 29 | } 30 | } 31 | 32 | req := record.CreateRecordRequest{ 33 | Contents: contents, 34 | } 35 | 36 | recordID, err := s.Record.CreateRecord(req, baseTx) 37 | require.NoError(s.T(), err) 38 | require.NotEmpty(s.T(), recordID) 39 | 40 | request := record.QueryRecordReq{ 41 | RecordID: recordID, 42 | Prove: true, 43 | Height: 0, 44 | } 45 | 46 | result, err := s.Record.QueryRecord(request) 47 | require.NoError(s.T(), err) 48 | require.NotEmpty(s.T(), result.Record.Contents) 49 | 50 | for i := 0; i < num; i++ { 51 | require.EqualValues(s.T(), contents[i], result.Record.Contents[i]) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /modules/keys/keys.go: -------------------------------------------------------------------------------- 1 | package keys 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | ) 6 | 7 | type keysClient struct { 8 | sdk.KeyManager 9 | } 10 | 11 | func NewClient(keyManager sdk.KeyManager) Client { 12 | return keysClient{keyManager} 13 | } 14 | 15 | func (k keysClient) Add(name, password string) (string, string, sdk.Error) { 16 | address, mnemonic, err := k.Insert(name, password) 17 | return address, mnemonic, sdk.Wrap(err) 18 | } 19 | 20 | func (k keysClient) Recover(name, password, mnemonic string) (string, sdk.Error) { 21 | address, err := k.KeyManager.Recover(name, password, mnemonic) 22 | return address, sdk.Wrap(err) 23 | } 24 | 25 | func (k keysClient) Import(name, password, privKeyArmor string) (string, sdk.Error) { 26 | address, err := k.KeyManager.Import(name, password, privKeyArmor) 27 | return address, sdk.Wrap(err) 28 | } 29 | 30 | func (k keysClient) Export(name, password string) (string, sdk.Error) { 31 | keystore, err := k.KeyManager.Export(name, password) 32 | return keystore, sdk.Wrap(err) 33 | } 34 | 35 | func (k keysClient) Delete(name, password string) sdk.Error { 36 | err := k.KeyManager.Delete(name, password) 37 | return sdk.Wrap(err) 38 | } 39 | 40 | func (k keysClient) Show(name, password string) (string, sdk.Error) { 41 | _, address, err := k.KeyManager.Find(name, password) 42 | if err != nil { 43 | return "", sdk.Wrap(err) 44 | } 45 | return address.String(), nil 46 | } 47 | -------------------------------------------------------------------------------- /types/sign_mode_handler.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/types/tx/signing" 5 | ) 6 | 7 | // SignModeHandler defines a interface to be implemented by types which will handle 8 | // SignMode's by generating sign bytes from a Tx and SignerData 9 | type SignModeHandler interface { 10 | // DefaultMode is the default mode that is to be used with this handler if no 11 | // other mode is specified. This can be useful for testing and CLI usage 12 | DefaultMode() signing.SignMode 13 | 14 | // Modes is the list of modes supporting by this handler 15 | Modes() []signing.SignMode 16 | 17 | // GetSignBytes returns the sign bytes for the provided SignMode, SignerData and Tx, 18 | // or an error 19 | GetSignBytes(mode signing.SignMode, data SignerData, tx Tx) ([]byte, error) 20 | } 21 | 22 | // SignerData is the specific information needed to sign a transaction that generally 23 | // isn't included in the transaction body itself 24 | type SignerData struct { 25 | // ChainID is the chain that this transaction is targeted 26 | ChainID string 27 | 28 | // AccountNumber is the account number of the signer 29 | AccountNumber uint64 30 | 31 | // Sequence is the account sequence number of the signer that is used 32 | // for replay protection. This field is only useful for Legacy Amino signing, 33 | // since in SIGN_MODE_DIRECT the account sequence is already in the signer 34 | // info. 35 | Sequence uint64 36 | } 37 | -------------------------------------------------------------------------------- /proto/nft/nft.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.nft; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/nft"; 7 | option(gogoproto.goproto_getters_all) = false; 8 | 9 | // BaseNFT defines a non fungible token. 10 | message BaseNFT { 11 | option (gogoproto.equal) = true; 12 | 13 | string id = 1; 14 | string name = 2; 15 | string uri = 3 [ (gogoproto.customname) = "URI" ]; 16 | string data = 4; 17 | string owner = 5; 18 | } 19 | 20 | // Denom defines a type of NFT. 21 | message Denom { 22 | option (gogoproto.equal) = true; 23 | 24 | string id = 1; 25 | string name = 2; 26 | string schema = 3; 27 | string creator = 4; 28 | } 29 | 30 | message IDCollection { 31 | option (gogoproto.equal) = true; 32 | 33 | string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ]; 34 | repeated string token_ids = 2 [ (gogoproto.moretags) = "yaml:\"token_ids\"" ]; 35 | } 36 | 37 | message Owner { 38 | option (gogoproto.equal) = true; 39 | 40 | string address = 1; 41 | repeated IDCollection id_collections = 2 [ (gogoproto.moretags) = "yaml:\"idcs\"", (gogoproto.customname) = "IDCollections", (gogoproto.nullable) = false ]; 42 | } 43 | 44 | message Collection { 45 | option (gogoproto.equal) = true; 46 | 47 | Denom denom = 1 [ (gogoproto.nullable) = false ]; 48 | repeated BaseNFT nfts = 2 [ (gogoproto.customname) = "NFTs", (gogoproto.nullable) = false ]; 49 | } -------------------------------------------------------------------------------- /proto/cosmos/base/v1beta1/coin.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.base.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/types"; 7 | option (gogoproto.goproto_stringer_all) = false; 8 | option (gogoproto.stringer_all) = false; 9 | 10 | // Coin defines a token with a denomination and an amount. 11 | // 12 | // NOTE: The amount field is an Int which implements the custom method 13 | // signatures required by gogoproto. 14 | message Coin { 15 | option (gogoproto.equal) = true; 16 | 17 | string denom = 1; 18 | string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; 19 | } 20 | 21 | // DecCoin defines a token with a denomination and a decimal amount. 22 | // 23 | // NOTE: The amount field is an Dec which implements the custom method 24 | // signatures required by gogoproto. 25 | message DecCoin { 26 | option (gogoproto.equal) = true; 27 | 28 | string denom = 1; 29 | string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; 30 | } 31 | 32 | // IntProto defines a Protobuf wrapper around an Int object. 33 | message IntProto { 34 | string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; 35 | } 36 | 37 | // DecProto defines a Protobuf wrapper around a Dec object. 38 | message DecProto { 39 | string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; 40 | } 41 | -------------------------------------------------------------------------------- /types/tx/tx.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "fmt" 5 | 6 | codectypes "github.com/bianjieai/irita-sdk-go/codec/types" 7 | 8 | sdk "github.com/bianjieai/irita-sdk-go/types" 9 | ) 10 | 11 | func Unwrap(anyUnpacker codectypes.AnyUnpacker, tx sdk.Tx) (*sdk.UnwrappedTx, error) { 12 | txWrapper, ok := tx.(*wrapper) 13 | if !ok { 14 | return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, tx) 15 | } 16 | 17 | txBody := sdk.UnwrappedTxBody{ 18 | Msgs: txWrapper.tx.GetMsgs(), 19 | Memo: txWrapper.tx.Body.Memo, 20 | TimeoutHeight: txWrapper.tx.Body.TimeoutHeight, 21 | } 22 | 23 | var signatures []sdk.UnwrappedSignature 24 | for i, pubKey := range txWrapper.GetPubKeys(anyUnpacker) { 25 | bech32PubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey) 26 | if err != nil { 27 | return nil, err 28 | } 29 | signatures = append(signatures, sdk.UnwrappedSignature{ 30 | PubKey: sdk.UnwrappedPubKey{ 31 | Type: pubKey.Type(), 32 | Value: bech32PubKey, 33 | }, 34 | Sig: txWrapper.tx.Signatures[i], 35 | Sequence: txWrapper.tx.AuthInfo.SignerInfos[i].Sequence, 36 | }) 37 | } 38 | 39 | authInfo := sdk.UnwrappedAuthInfo{ 40 | Signatures: signatures, 41 | Fee: &sdk.StdFee{ 42 | Amount: txWrapper.tx.AuthInfo.Fee.Amount, 43 | Gas: txWrapper.tx.AuthInfo.Fee.GasLimit, 44 | }, 45 | } 46 | 47 | return &sdk.UnwrappedTx{ 48 | Body: txBody, 49 | AuthInfo: authInfo, 50 | }, nil 51 | } 52 | -------------------------------------------------------------------------------- /proto/node/node.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.node; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "tendermint/types/types.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/node"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | // Request defines a standard for validator. The validator will participate the 11 | // blockchain consensus, power determines the probability of proposing a new block. 12 | message Validator { 13 | option (gogoproto.equal) = true; 14 | 15 | string id = 1; 16 | string name = 2; 17 | string pubkey = 3; 18 | string certificate = 4; 19 | int64 power = 5; 20 | string description = 6; 21 | bool jailed = 7; 22 | string operator = 8; 23 | } 24 | 25 | // HistoricalInfo contains the historical information that gets stored at 26 | // each height. 27 | message HistoricalInfo { 28 | tendermint.types.Header header = 1 [(gogoproto.nullable) = false]; 29 | repeated Validator valset = 2 [(gogoproto.nullable) = false]; 30 | } 31 | 32 | // Node defines a struct to represent a node identity 33 | message Node { 34 | option (gogoproto.equal) = true; 35 | 36 | string id = 1; 37 | string name = 2; 38 | string certificate = 3; 39 | } 40 | 41 | // Params defines the parameters for the node module. 42 | message Params { 43 | option (gogoproto.equal) = true; 44 | 45 | uint32 historical_entries = 1 [(gogoproto.moretags) = "yaml:\"historical_entries\""]; 46 | } 47 | -------------------------------------------------------------------------------- /modules/params/types.go: -------------------------------------------------------------------------------- 1 | package params 2 | 3 | import ( 4 | "errors" 5 | 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | ) 8 | 9 | const ( 10 | ModuleName = "params" 11 | ) 12 | 13 | var ( 14 | _ sdk.Msg = &MsgUpdateParams{} 15 | ) 16 | 17 | func (m MsgUpdateParams) Route() string { 18 | return ModuleName 19 | } 20 | 21 | func (m MsgUpdateParams) Type() string { 22 | return "update_params" 23 | } 24 | 25 | func (m MsgUpdateParams) ValidateBasic() error { 26 | if len(m.Operator) == 0 { 27 | return errors.New("operator missing") 28 | } 29 | return validateChanges(m.Changes) 30 | } 31 | 32 | func (m MsgUpdateParams) GetSignBytes() []byte { 33 | bz := ModuleCdc.MustMarshalJSON(&m) 34 | return sdk.MustSortJSON(bz) 35 | } 36 | 37 | func (m MsgUpdateParams) GetSigners() []sdk.AccAddress { 38 | return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Operator)} 39 | } 40 | 41 | // ValidateChanges performs basic validation checks over a set of ParamChange. It 42 | // returns an error if any ParamChange is invalid. 43 | func validateChanges(changes []ParamChange) error { 44 | if len(changes) == 0 { 45 | return errors.New("no change params") 46 | } 47 | 48 | for _, pc := range changes { 49 | if len(pc.Subspace) == 0 { 50 | return errors.New("empty subspace") 51 | } 52 | if len(pc.Key) == 0 { 53 | return errors.New("empty params key") 54 | } 55 | if len(pc.Value) == 0 { 56 | return errors.New("empty params value") 57 | } 58 | } 59 | 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /types/tx_config.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | signingtypes "github.com/bianjieai/irita-sdk-go/types/tx/signing" 5 | ) 6 | 7 | type ( 8 | // TxBuilder defines an interface which an application-defined concrete transaction 9 | // type must implement. Namely, it must be able to set messages, generate 10 | // signatures, and provide canonical bytes to sign over. The transaction must 11 | // also know how to encode itself. 12 | TxBuilder interface { 13 | GetTx() Tx 14 | 15 | SetMsgs(msgs ...Msg) error 16 | SetSignatures(signatures ...signingtypes.SignatureV2) error 17 | SetMemo(memo string) 18 | SetFeeAmount(amount Coins) 19 | SetGasLimit(limit uint64) 20 | SetTimeoutHeight(height uint64) 21 | } 22 | 23 | // TxEncodingConfig defines an interface that contains transaction 24 | // encoders and decoders 25 | TxEncodingConfig interface { 26 | TxEncoder() TxEncoder 27 | TxDecoder() TxDecoder 28 | TxJSONEncoder() TxEncoder 29 | TxJSONDecoder() TxDecoder 30 | MarshalSignatureJSON([]signingtypes.SignatureV2) ([]byte, error) 31 | UnmarshalSignatureJSON([]byte) ([]signingtypes.SignatureV2, error) 32 | } 33 | 34 | // TxConfig defines an interface a client can utilize to generate an 35 | // application-defined concrete transaction type. The type returned must 36 | // implement TxBuilder. 37 | TxConfig interface { 38 | TxEncodingConfig 39 | 40 | NewTxBuilder() TxBuilder 41 | WrapTxBuilder(Tx) (TxBuilder, error) 42 | SignModeHandler() SignModeHandler 43 | } 44 | ) 45 | -------------------------------------------------------------------------------- /proto/random/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.random; 3 | 4 | import "random/random.proto"; 5 | import "gogoproto/gogo.proto"; 6 | import "google/api/annotations.proto"; 7 | 8 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/random"; 9 | 10 | // Query creates service with guardian as rpc 11 | service Query { 12 | // Random queries the random result 13 | rpc Random(QueryRandomRequest) returns (QueryRandomResponse) { 14 | option (google.api.http).get = "/irismod/random/randoms/{req_id}"; 15 | } 16 | 17 | // RandomRequestQueue queries the random request queue 18 | rpc RandomRequestQueue(QueryRandomRequestQueueRequest) returns (QueryRandomRequestQueueResponse) { 19 | option (google.api.http).get = "/irismod/random/queue"; 20 | } 21 | } 22 | 23 | // QueryRandomRequest is request type for the Query/Random RPC method 24 | message QueryRandomRequest { 25 | string req_id = 1; 26 | } 27 | 28 | // QueryParametersResponse is response type for the Query/Random RPC method 29 | message QueryRandomResponse { 30 | Random random = 1; 31 | } 32 | 33 | // QueryRandomRequestQueueRequest is request type for the Query/RandomRequestQueue RPC method 34 | message QueryRandomRequestQueueRequest { 35 | int64 height = 1; 36 | } 37 | 38 | // QueryRandomRequestQueueResponse is response type for the Query/RandomRequestQueue RPC method 39 | message QueryRandomRequestQueueResponse { 40 | repeated Request requests = 1 [ (gogoproto.nullable) = false ]; 41 | } -------------------------------------------------------------------------------- /proto/token/token.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package irismod.token; 3 | 4 | import "cosmos/base/v1beta1/coin.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/token"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | // Token defines a standard for the fungible token 11 | message Token { 12 | option (gogoproto.goproto_stringer) = false; 13 | option (gogoproto.goproto_getters) = false; 14 | 15 | string symbol = 1; 16 | string name = 2; 17 | uint32 scale = 3; 18 | string min_unit = 4 [(gogoproto.moretags) = "yaml:\"min_unit\""]; 19 | uint64 initial_supply = 5 [(gogoproto.moretags) = "yaml:\"initial_supply\""]; 20 | uint64 max_supply = 6 [(gogoproto.moretags) = "yaml:\"max_supply\""]; 21 | bool mintable = 7; 22 | string owner = 8; 23 | } 24 | 25 | // token parameters 26 | message Params { 27 | option (gogoproto.equal) = true; 28 | option (gogoproto.goproto_stringer) = false; 29 | 30 | string token_tax_rate = 1 [(gogoproto.moretags) = "yaml:\"token_tax_rate\"", (gogoproto.customtype) = "github.com/bianjieai/irita-sdk-go/types.Dec", (gogoproto.nullable) = false]; 31 | 32 | cosmos.base.v1beta1.Coin issue_token_base_fee = 2 [(gogoproto.moretags) = "yaml:\"issue_token_base_fee\"", (gogoproto.nullable) = false]; 33 | 34 | string mint_token_fee_ratio = 3 [(gogoproto.moretags) = "yaml:\"mint_token_fee_ratio\"", (gogoproto.customtype) = "github.com/bianjieai/irita-sdk-go/types.Dec", (gogoproto.nullable) = false]; 35 | } 36 | -------------------------------------------------------------------------------- /utils/cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "errors" 5 | "time" 6 | 7 | "github.com/bluele/gcache" 8 | ) 9 | 10 | type Cache interface { 11 | Set(key, value interface{}) error 12 | SetWithExpire(key, value interface{}, expiration time.Duration) error 13 | Get(key interface{}) (interface{}, error) 14 | Remove(key interface{}) bool 15 | } 16 | 17 | type LRU struct { 18 | cache gcache.Cache 19 | enabled bool 20 | } 21 | 22 | func NewCache(capacity int, enable bool) Cache { 23 | return &LRU{ 24 | cache: gcache.New(capacity).LRU().Build(), 25 | enabled: enable, 26 | } 27 | } 28 | 29 | func (l *LRU) Set(key, value interface{}) error { 30 | if !l.enabled { 31 | return nil 32 | } 33 | return l.cache.Set(key, value) 34 | } 35 | 36 | func (l *LRU) SetWithExpire(key, value interface{}, expiration time.Duration) error { 37 | if !l.enabled { 38 | return nil 39 | } 40 | return l.cache.SetWithExpire(key, value, expiration) 41 | } 42 | 43 | func (l LRU) Get(key interface{}) (interface{}, error) { 44 | if !l.enabled { 45 | return nil, errors.New("cache not enabled") 46 | } 47 | return l.cache.Get(key) 48 | } 49 | 50 | func (l *LRU) Remove(key interface{}) bool { 51 | if !l.enabled { 52 | return false 53 | } 54 | return l.cache.Remove(key) 55 | } 56 | 57 | func (l *LRU) Expire(key interface{}) bool { 58 | if !l.enabled { 59 | return true 60 | } 61 | return l.Remove(key) 62 | } 63 | 64 | func (l *LRU) Enable() { 65 | l.enabled = true 66 | } 67 | 68 | func (l *LRU) Disable() { 69 | l.enabled = false 70 | } 71 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/ecmult.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_ 8 | #define _SECP256K1_ECMULT_ 9 | 10 | #include "num.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*P + b*G: */ 15 | secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */ 16 | #ifdef USE_ENDOMORPHISM 17 | secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */ 18 | #endif 19 | } secp256k1_ecmult_context; 20 | 21 | static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx); 22 | static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb); 23 | static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, 24 | const secp256k1_ecmult_context *src, const secp256k1_callback *cb); 25 | static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx); 26 | static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx); 27 | 28 | /** Double multiply: R = na*A + ng*G */ 29 | static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /third_party/proto/tendermint/types/evidence.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tendermint.types; 3 | 4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; 5 | 6 | import "gogoproto/gogo.proto"; 7 | import "google/protobuf/timestamp.proto"; 8 | import "tendermint/types/types.proto"; 9 | import "tendermint/types/validator.proto"; 10 | 11 | message Evidence { 12 | oneof sum { 13 | DuplicateVoteEvidence duplicate_vote_evidence = 1; 14 | LightClientAttackEvidence light_client_attack_evidence = 2; 15 | } 16 | } 17 | 18 | // DuplicateVoteEvidence contains evidence of a validator signed two conflicting votes. 19 | message DuplicateVoteEvidence { 20 | tendermint.types.Vote vote_a = 1; 21 | tendermint.types.Vote vote_b = 2; 22 | int64 total_voting_power = 3; 23 | int64 validator_power = 4; 24 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 25 | } 26 | 27 | // LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client. 28 | message LightClientAttackEvidence { 29 | tendermint.types.LightBlock conflicting_block = 1; 30 | int64 common_height = 2; 31 | repeated tendermint.types.Validator byzantine_validators = 3; 32 | int64 total_voting_power = 4; 33 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; 34 | } 35 | 36 | message EvidenceList { 37 | repeated Evidence evidence = 1 [(gogoproto.nullable) = false]; 38 | } 39 | -------------------------------------------------------------------------------- /crypto/codec/proto.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | tmcrypto "github.com/tendermint/tendermint/crypto" 5 | 6 | codectypes "github.com/bianjieai/irita-sdk-go/codec/types" 7 | "github.com/bianjieai/irita-sdk-go/crypto/keys/ed25519" 8 | "github.com/bianjieai/irita-sdk-go/crypto/keys/multisig" 9 | "github.com/bianjieai/irita-sdk-go/crypto/keys/secp256k1" 10 | "github.com/bianjieai/irita-sdk-go/crypto/keys/sm2" 11 | cryptotypes "github.com/bianjieai/irita-sdk-go/crypto/types" 12 | ) 13 | 14 | // RegisterInterfaces registers the sdk.Tx interface. 15 | func RegisterInterfaces(registry codectypes.InterfaceRegistry) { 16 | // TODO We now register both Tendermint's PubKey and our own PubKey. In the 17 | // long-term, we should move away from Tendermint's PubKey, and delete 18 | // these lines. 19 | registry.RegisterInterface("tendermint.crypto.Pubkey", (*tmcrypto.PubKey)(nil)) 20 | registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &sm2.PubKey{}) 21 | registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &ed25519.PubKey{}) 22 | registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &secp256k1.PubKey{}) 23 | registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &multisig.LegacyAminoPubKey{}) 24 | 25 | registry.RegisterInterface("cosmos.crypto.Pubkey", (*cryptotypes.PubKey)(nil)) 26 | registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &sm2.PubKey{}) 27 | registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &ed25519.PubKey{}) 28 | registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{}) 29 | registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &multisig.LegacyAminoPubKey{}) 30 | } 31 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/testrand.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_TESTRAND_H_ 8 | #define _SECP256K1_TESTRAND_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | /* A non-cryptographic RNG used only for test infrastructure. */ 15 | 16 | /** Seed the pseudorandom number generator for testing. */ 17 | SECP256K1_INLINE static void secp256k1_rand_seed(const unsigned char *seed16); 18 | 19 | /** Generate a pseudorandom number in the range [0..2**32-1]. */ 20 | static uint32_t secp256k1_rand32(void); 21 | 22 | /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or 23 | * more. */ 24 | static uint32_t secp256k1_rand_bits(int bits); 25 | 26 | /** Generate a pseudorandom number in the range [0..range-1]. */ 27 | static uint32_t secp256k1_rand_int(uint32_t range); 28 | 29 | /** Generate a pseudorandom 32-byte array. */ 30 | static void secp256k1_rand256(unsigned char *b32); 31 | 32 | /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */ 33 | static void secp256k1_rand256_test(unsigned char *b32); 34 | 35 | /** Generate pseudorandom bytes with long sequences of zero and one bits. */ 36 | static void secp256k1_rand_bytes_test(unsigned char *bytes, size_t len); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /modules/bank/doc.go: -------------------------------------------------------------------------------- 1 | // Package bank is mainly used to transfer coins between accounts,query account balances, and implement interface rpc.BankI 2 | // 3 | // 4 | // As a quick start: 5 | // 6 | // TransferNFT coins to other account 7 | // 8 | // client := test.NewClient() 9 | // amt := types.NewIntWithDecimal(1, 18) 10 | // coins := types.NewCoins(types.NewCoin("point", amt)) 11 | // to := "iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz" 12 | // baseTx := types.BaseTx{ 13 | // From: "test1", 14 | // Gas: 20000, 15 | // Memo: "test", 16 | // Mode: types.Commit, 17 | // } 18 | // result,err := client.BankI.Send(to,coins,baseTx) 19 | // fmt.Println(result) 20 | // 21 | // BurnNFT some coins from your account 22 | // 23 | // client := test.NewClient() 24 | // amt := types.NewIntWithDecimal(1, 18) 25 | // coins := types.NewCoins(types.NewCoin("point", amt)) 26 | // baseTx := types.BaseTx{ 27 | // From: "test1", 28 | // Gas: 20000, 29 | // Memo: "test", 30 | // Mode: types.Commit, 31 | // } 32 | // result,err := client.BankI.BurnNFT(coins, baseTx) 33 | // fmt.Println(result) 34 | // 35 | // Set account memo 36 | // 37 | // client := test.NewClient() 38 | // result,err := client.BankI.SetMemoRegexp("testMemo", baseTx) 39 | // fmt.Println(result) 40 | // 41 | // Queries account information 42 | // 43 | // client := test.NewClient() 44 | // result,err := client.BankI.QueryAccount("iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz") 45 | // fmt.Println(result) 46 | // 47 | // Queries the token information 48 | // 49 | // client := test.NewClient() 50 | // result,err := client.BankI.QueryTokenStats("point") 51 | // fmt.Println(result) 52 | // 53 | package bank 54 | -------------------------------------------------------------------------------- /types/store/aes.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | import ( 4 | "crypto/aes" 5 | "crypto/cipher" 6 | "crypto/rand" 7 | "encoding/base64" 8 | "fmt" 9 | "io" 10 | ) 11 | 12 | type AES struct{} 13 | 14 | func (AES) Encrypt(text string, key string) (string, error) { 15 | plaintext := []byte(text) 16 | k := generateKey(key) 17 | 18 | block, err := aes.NewCipher(k) 19 | if err != nil { 20 | return "", err 21 | } 22 | 23 | cipherText := make([]byte, aes.BlockSize+len(plaintext)) 24 | iv := cipherText[:aes.BlockSize] 25 | if _, err := io.ReadFull(rand.Reader, iv); err != nil { 26 | return "", err 27 | } 28 | 29 | stream := cipher.NewCFBEncrypter(block, iv) 30 | stream.XORKeyStream(cipherText[aes.BlockSize:], plaintext) 31 | 32 | return base64.URLEncoding.EncodeToString(cipherText), nil 33 | } 34 | 35 | func (AES) Decrypt(cryptoText string, key string) (string, error) { 36 | cipherText, _ := base64.URLEncoding.DecodeString(cryptoText) 37 | k := generateKey(key) 38 | block, err := aes.NewCipher(k) 39 | if err != nil { 40 | return "", err 41 | } 42 | 43 | if len(cipherText) < aes.BlockSize { 44 | return "", err 45 | } 46 | iv := cipherText[:aes.BlockSize] 47 | cipherText = cipherText[aes.BlockSize:] 48 | 49 | stream := cipher.NewCFBDecrypter(block, iv) 50 | stream.XORKeyStream(cipherText, cipherText) 51 | return fmt.Sprintf("%s", cipherText), nil 52 | } 53 | 54 | func generateKey(key string) (genKey []byte) { 55 | keyBz := []byte(key) 56 | genKey = make([]byte, 32) 57 | copy(genKey, keyBz) 58 | for i := 32; i < len(keyBz); { 59 | for j := 0; j < 32 && i < len(keyBz); j, i = j+1, i+1 { 60 | genKey[j] ^= keyBz[i] 61 | } 62 | } 63 | return genKey 64 | } 65 | -------------------------------------------------------------------------------- /client/tx/tx.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "github.com/tendermint/tendermint/crypto" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | ) 9 | 10 | type ( 11 | // Generator defines an interface a client can utilize to generate an 12 | // application-defined concrete transaction type. The type returned must 13 | // implement ClientTx. 14 | Generator interface { 15 | NewTx() ClientTx 16 | NewFee() ClientFee 17 | NewSignature() ClientSignature 18 | } 19 | 20 | ClientFee interface { 21 | sdk.Fee 22 | SetGas(uint64) 23 | SetAmount(sdk.Coins) 24 | } 25 | 26 | ClientSignature interface { 27 | sdk.Signature 28 | SetPubKey(crypto.PubKey) error 29 | SetSignature([]byte) 30 | } 31 | 32 | // ClientTx defines an interface which an application-defined concrete transaction 33 | // type must implement. Namely, it must be able to set messages, generate 34 | // signatures, and provide canonical bytes to sign over. The transaction must 35 | // also know how to encode itself. 36 | ClientTx interface { 37 | sdk.Tx 38 | codec.ProtoMarshaler 39 | 40 | SetMsgs(...sdk.Msg) error 41 | GetSignatures() []sdk.Signature 42 | SetSignatures(...ClientSignature) error 43 | GetFee() sdk.Fee 44 | SetFee(ClientFee) error 45 | GetMemo() string 46 | SetMemo(string) 47 | 48 | // CanonicalSignBytes returns the canonical JSON bytes to sign over, given a 49 | // chain ID, along with an account and sequence number. The JSON encoding 50 | // ensures all field names adhere to their proto definition, default values 51 | // are omitted, and follows the JSON Canonical Form. 52 | CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) 53 | } 54 | ) 55 | -------------------------------------------------------------------------------- /proto/cosmos/bank/v1beta1/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.bank.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "cosmos/base/v1beta1/coin.proto"; 6 | import "cosmos/bank/v1beta1/bank.proto"; 7 | 8 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/bank"; 9 | 10 | // Msg defines the bank Msg service. 11 | service Msg { 12 | // Send defines a method for sending coins from one account to another account. 13 | rpc Send(MsgSend) returns (MsgSendResponse); 14 | 15 | // MultiSend defines a method for sending coins from some accounts to other accounts. 16 | rpc MultiSend(MsgMultiSend) returns (MsgMultiSendResponse); 17 | } 18 | 19 | // MsgSend represents a message to send coins from one account to another. 20 | message MsgSend { 21 | option (gogoproto.equal) = false; 22 | option (gogoproto.goproto_getters) = false; 23 | 24 | string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""]; 25 | string to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""]; 26 | repeated cosmos.base.v1beta1.Coin amount = 3 27 | [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/bianjieai/irita-sdk-go/types.Coins"]; 28 | } 29 | 30 | // MsgSendResponse defines the Msg/Send response type. 31 | message MsgSendResponse {} 32 | 33 | // MsgMultiSend represents an arbitrary multi-in, multi-out send message. 34 | message MsgMultiSend { 35 | option (gogoproto.equal) = false; 36 | 37 | repeated Input inputs = 1 [(gogoproto.nullable) = false]; 38 | repeated Output outputs = 2 [(gogoproto.nullable) = false]; 39 | } 40 | 41 | // MsgMultiSendResponse defines the Msg/MultiSend response type. 42 | message MsgMultiSendResponse {} 43 | -------------------------------------------------------------------------------- /proto/perm/perm.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.perm; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/perm"; 7 | option (gogoproto.goproto_getters_all) = false; 8 | option (gogoproto.goproto_registration) = true; 9 | 10 | // Role represents a role 11 | enum Role { 12 | option (gogoproto.enum_stringer) = true; 13 | option (gogoproto.goproto_enum_stringer) = false; 14 | option (gogoproto.goproto_enum_prefix) = false; 15 | 16 | // ROOT_ADMIN defines the root admin role index. 17 | ROOT_ADMIN = 0 [(gogoproto.enumvalue_customname) = "RoleRootAdmin"]; 18 | // PERM_ADMIN defines the permission admin role index. 19 | PERM_ADMIN = 1 [(gogoproto.enumvalue_customname) = "RolePermAdmin"]; 20 | // BLACKLIST_ADMIN defines the blacklist admin role index. 21 | BLACKLIST_ADMIN = 2 [(gogoproto.enumvalue_customname) = "RoleBlacklistAdmin"]; 22 | // NODE_ADMIN defines the node admin role index. 23 | NODE_ADMIN = 3 [(gogoproto.enumvalue_customname) = "RoleNodeAdmin"]; 24 | // PARAM_ADMIN defines the param admin role index. 25 | PARAM_ADMIN = 4 [(gogoproto.enumvalue_customname) = "RoleParamAdmin"]; 26 | // POWER_USER defines the power user role index. 27 | POWER_USER = 5 [(gogoproto.enumvalue_customname) = "RolePowerUser"]; 28 | // RELAYER_USER defines the relayer user role index. 29 | RELAYER_USER = 6 [(gogoproto.enumvalue_customname) = "RoleRelayerUser"]; 30 | // ID_ADMIN defines the identity admin role index. 31 | ID_ADMIN = 7 [(gogoproto.enumvalue_customname) = "RoleIDAdmin"]; 32 | // BASE_M1_ADMIN defines the base M1 admin role index. 33 | BASE_M1_ADMIN = 8 [(gogoproto.enumvalue_customname) = "RoleBaseM1Admin"]; 34 | } 35 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/java/org/bitcoin/NativeSecp256k1Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | public class NativeSecp256k1Util{ 20 | 21 | public static void assertEquals( int val, int val2, String message ) throws AssertFailException{ 22 | if( val != val2 ) 23 | throw new AssertFailException("FAIL: " + message); 24 | } 25 | 26 | public static void assertEquals( boolean val, boolean val2, String message ) throws AssertFailException{ 27 | if( val != val2 ) 28 | throw new AssertFailException("FAIL: " + message); 29 | else 30 | System.out.println("PASS: " + message); 31 | } 32 | 33 | public static void assertEquals( String val, String val2, String message ) throws AssertFailException{ 34 | if( !val.equals(val2) ) 35 | throw new AssertFailException("FAIL: " + message); 36 | else 37 | System.out.println("PASS: " + message); 38 | } 39 | 40 | public static class AssertFailException extends Exception { 41 | public AssertFailException(String message) { 42 | super( message ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /proto/cosmos/auth/v1beta1/query.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.auth.v1beta1; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/any.proto"; 6 | import "google/api/annotations.proto"; 7 | import "cosmos/auth/v1beta1/auth.proto"; 8 | import "cosmos_proto/cosmos.proto"; 9 | 10 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/auth"; 11 | 12 | // Query defines the gRPC querier service. 13 | service Query { 14 | // Account returns account details based on address. 15 | rpc Account(QueryAccountRequest) returns (QueryAccountResponse) { 16 | option (google.api.http).get = "/cosmos/auth/v1beta1/accounts/{address}"; 17 | } 18 | 19 | // Params queries all parameters. 20 | rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { 21 | option (google.api.http).get = "/cosmos/auth/v1beta1/params"; 22 | } 23 | } 24 | 25 | // QueryAccountRequest is the request type for the Query/Account RPC method. 26 | message QueryAccountRequest { 27 | option (gogoproto.equal) = false; 28 | option (gogoproto.goproto_getters) = false; 29 | 30 | // address defines the address to query for. 31 | string address = 1; 32 | } 33 | 34 | // QueryAccountResponse is the response type for the Query/Account RPC method. 35 | message QueryAccountResponse { 36 | // account defines the account of the corresponding address. 37 | google.protobuf.Any account = 1 [(cosmos_proto.accepts_interface) = "AccountI"]; 38 | } 39 | 40 | // QueryParamsRequest is the request type for the Query/Params RPC method. 41 | message QueryParamsRequest {} 42 | 43 | // QueryParamsResponse is the response type for the Query/Params RPC method. 44 | message QueryParamsResponse { 45 | // params defines the parameters of the module. 46 | Params params = 1 [(gogoproto.nullable) = false]; 47 | } 48 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/java/org/bitcoin/Secp256k1Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | /** 20 | * This class holds the context reference used in native methods 21 | * to handle ECDSA operations. 22 | */ 23 | public class Secp256k1Context { 24 | private static final boolean enabled; //true if the library is loaded 25 | private static final long context; //ref to pointer to context obj 26 | 27 | static { //static initializer 28 | boolean isEnabled = true; 29 | long contextRef = -1; 30 | try { 31 | System.loadLibrary("secp256k1"); 32 | contextRef = secp256k1_init_context(); 33 | } catch (UnsatisfiedLinkError e) { 34 | System.out.println("UnsatisfiedLinkError: " + e.toString()); 35 | isEnabled = false; 36 | } 37 | enabled = isEnabled; 38 | context = contextRef; 39 | } 40 | 41 | public static boolean isEnabled() { 42 | return enabled; 43 | } 44 | 45 | public static long getContext() { 46 | if(!enabled) return -1; //sanity check 47 | return context; 48 | } 49 | 50 | private static native long secp256k1_init_context(); 51 | } 52 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 The Go Authors. All rights reserved. 2 | Copyright (c) 2011 ThePiachu. All rights reserved. 3 | Copyright (c) 2015 Jeffrey Wilcke. All rights reserved. 4 | Copyright (c) 2015 Felix Lange. All rights reserved. 5 | Copyright (c) 2015 Gustav Simonsson. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other materials provided with the 16 | distribution. 17 | * Neither the name of the copyright holder. nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /proto/cosmos/base/reflection/v1beta1/reflection.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.base.reflection.v1beta1; 3 | 4 | import "google/api/annotations.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/client/grpc/reflection"; 7 | 8 | // ReflectionService defines a service for interface reflection. 9 | service ReflectionService { 10 | // ListAllInterfaces lists all the interfaces registered in the interface 11 | // registry. 12 | rpc ListAllInterfaces(ListAllInterfacesRequest) returns (ListAllInterfacesResponse) { 13 | option (google.api.http).get = "/cosmos/base/reflection/v1beta1/interfaces"; 14 | }; 15 | 16 | // ListImplementations list all the concrete types that implement a given 17 | // interface. 18 | rpc ListImplementations(ListImplementationsRequest) returns (ListImplementationsResponse) { 19 | option (google.api.http).get = "/cosmos/base/reflection/v1beta1/interfaces/" 20 | "{interface_name}/implementations"; 21 | }; 22 | } 23 | 24 | // ListAllInterfacesRequest is the request type of the ListAllInterfaces RPC. 25 | message ListAllInterfacesRequest {} 26 | 27 | // ListAllInterfacesResponse is the response type of the ListAllInterfaces RPC. 28 | message ListAllInterfacesResponse { 29 | // interface_names is an array of all the registered interfaces. 30 | repeated string interface_names = 1; 31 | } 32 | 33 | // ListImplementationsRequest is the request type of the ListImplementations 34 | // RPC. 35 | message ListImplementationsRequest { 36 | // interface_name defines the interface to query the implementations for. 37 | string interface_name = 1; 38 | } 39 | 40 | // ListImplementationsResponse is the response type of the ListImplementations 41 | // RPC. 42 | message ListImplementationsResponse { 43 | repeated string implementation_message_names = 1; 44 | } 45 | -------------------------------------------------------------------------------- /proto/identity/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.identity; 3 | 4 | import "identity/identity.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/identity"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | // Msg defines the bank Msg service. 11 | service Msg { 12 | // CreateIdentity defines a method for creating a new identity. 13 | rpc CreateIdentity(MsgCreateIdentity) returns (MsgCreateIdentityResponse); 14 | 15 | // UpdateIdentity defines a method for Updating a identity. 16 | rpc UpdateIdentity(MsgUpdateIdentity) returns (MsgUpdateIdentityResponse); 17 | } 18 | 19 | // MsgCreateIdentity defines a message to create an identity 20 | message MsgCreateIdentity { 21 | option (gogoproto.equal) = true; 22 | 23 | string id = 1 ; 24 | PubKeyInfo pub_key = 2 [ 25 | (gogoproto.moretags) = "yaml:\"pubkey\"", 26 | (gogoproto.jsontag) = "pubkey" 27 | ]; 28 | string certificate = 3; 29 | string credentials = 4; 30 | string owner = 5; 31 | } 32 | 33 | // MsgCreateIdentityResponse defines the Msg/Create response type. 34 | message MsgCreateIdentityResponse { } 35 | 36 | // MsgUpdateIdentity defines a message to update an identity 37 | message MsgUpdateIdentity { 38 | option (gogoproto.equal) = true; 39 | 40 | string id = 1 ; 41 | PubKeyInfo pub_key = 2 [ 42 | (gogoproto.moretags) = "yaml:\"pubkey\"", 43 | (gogoproto.jsontag) = "pubkey" 44 | ]; 45 | string certificate = 3; 46 | string credentials = 4; 47 | string owner = 5; 48 | } 49 | 50 | 51 | // MsgUpdateIdentityResponse defines the Msg/Update response type. 52 | message MsgUpdateIdentityResponse { } -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/bench_sign.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "util.h" 9 | #include "bench.h" 10 | 11 | typedef struct { 12 | secp256k1_context* ctx; 13 | unsigned char msg[32]; 14 | unsigned char key[32]; 15 | } bench_sign_t; 16 | 17 | static void bench_sign_setup(void* arg) { 18 | int i; 19 | bench_sign_t *data = (bench_sign_t*)arg; 20 | 21 | for (i = 0; i < 32; i++) { 22 | data->msg[i] = i + 1; 23 | } 24 | for (i = 0; i < 32; i++) { 25 | data->key[i] = i + 65; 26 | } 27 | } 28 | 29 | static void bench_sign(void* arg) { 30 | int i; 31 | bench_sign_t *data = (bench_sign_t*)arg; 32 | 33 | unsigned char sig[74]; 34 | for (i = 0; i < 20000; i++) { 35 | size_t siglen = 74; 36 | int j; 37 | secp256k1_ecdsa_signature signature; 38 | CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); 39 | CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); 40 | for (j = 0; j < 32; j++) { 41 | data->msg[j] = sig[j]; 42 | data->key[j] = sig[j + 32]; 43 | } 44 | } 45 | } 46 | 47 | int main(void) { 48 | bench_sign_t data; 49 | 50 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); 51 | 52 | run_benchmark("ecdsa_sign", bench_sign, bench_sign_setup, NULL, &data, 10, 20000); 53 | 54 | secp256k1_context_destroy(data.ctx); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /types/tx/direct.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "fmt" 5 | 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | signingtypes "github.com/bianjieai/irita-sdk-go/types/tx/signing" 8 | ) 9 | 10 | // signModeDirectHandler defines the SIGN_MODE_DIRECT SignModeHandler 11 | type signModeDirectHandler struct{} 12 | 13 | var _ sdk.SignModeHandler = signModeDirectHandler{} 14 | 15 | // DefaultMode implements SignModeHandler.DefaultMode 16 | func (signModeDirectHandler) DefaultMode() signingtypes.SignMode { 17 | return signingtypes.SignMode_SIGN_MODE_DIRECT 18 | } 19 | 20 | // Modes implements SignModeHandler.Modes 21 | func (signModeDirectHandler) Modes() []signingtypes.SignMode { 22 | return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_DIRECT} 23 | } 24 | 25 | // GetSignBytes implements SignModeHandler.GetSignBytes 26 | func (signModeDirectHandler) GetSignBytes(mode signingtypes.SignMode, data sdk.SignerData, tx sdk.Tx) ([]byte, error) { 27 | if mode != signingtypes.SignMode_SIGN_MODE_DIRECT { 28 | return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_DIRECT, mode) 29 | } 30 | 31 | protoTx, ok := tx.(*wrapper) 32 | if !ok { 33 | return nil, fmt.Errorf("can only handle a protobuf Tx, got %T", tx) 34 | } 35 | 36 | bodyBz := protoTx.getBodyBytes() 37 | authInfoBz := protoTx.getAuthInfoBytes() 38 | 39 | return DirectSignBytes(bodyBz, authInfoBz, data.ChainID, data.AccountNumber) 40 | } 41 | 42 | // DirectSignBytes returns the SIGN_MODE_DIRECT sign bytes for the provided TxBody bytes, AuthInfo bytes, chain ID, 43 | // account number and sequence. 44 | func DirectSignBytes(bodyBytes, authInfoBytes []byte, chainID string, accnum uint64) ([]byte, error) { 45 | signDoc := SignDoc{ 46 | BodyBytes: bodyBytes, 47 | AuthInfoBytes: authInfoBytes, 48 | ChainId: chainID, 49 | AccountNumber: accnum, 50 | } 51 | return signDoc.Marshal() 52 | } 53 | -------------------------------------------------------------------------------- /types/client.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "google.golang.org/grpc" 5 | 6 | abci "github.com/tendermint/tendermint/abci/types" 7 | "github.com/tendermint/tendermint/libs/log" 8 | ) 9 | 10 | type TxManager interface { 11 | TmQuery 12 | BuildAndSend(msg []Msg, baseTx BaseTx) (ResultTx, Error) 13 | BuildAndSign(msg []Msg, baseTx BaseTx) ([]byte, Error) 14 | SendBatch(msgs Msgs, baseTx BaseTx) ([]ResultTx, Error) 15 | } 16 | 17 | type Queries interface { 18 | StoreQuery 19 | AccountQuery 20 | TmQuery 21 | } 22 | 23 | type GRPCClient interface { 24 | GenConn() (*grpc.ClientConn, error) 25 | } 26 | 27 | type ParamQuery interface { 28 | QueryParams(module string, res Response) Error 29 | } 30 | 31 | type StoreQuery interface { 32 | QueryWithResponse(path string, data interface{}, result Response) error 33 | Query(path string, data interface{}) ([]byte, error) 34 | QueryStore(key HexBytes, storeName string, height int64, prove bool) (abci.ResponseQuery, error) 35 | } 36 | 37 | type AccountQuery interface { 38 | QueryAccount(address string) (BaseAccount, Error) 39 | QueryAddress(name, password string) (AccAddress, Error) 40 | } 41 | 42 | type TmQuery interface { 43 | QueryTx(hash string) (ResultQueryTx, error) 44 | QueryTxs(builder *EventQueryBuilder, page, size int) (ResultSearchTxs, error) 45 | QueryBlock(height int64) (BlockDetail, error) 46 | } 47 | 48 | type TokenManager interface { 49 | QueryToken(denom string) (Token, error) 50 | SaveTokens(tokens ...Token) 51 | } 52 | 53 | type TokenConvert interface { 54 | ToMinCoin(coin ...DecCoin) (Coins, Error) 55 | ToMainCoin(coin ...Coin) (DecCoins, Error) 56 | } 57 | 58 | type Logger interface { 59 | Logger() log.Logger 60 | SetLogger(log.Logger) 61 | } 62 | 63 | type BaseClient interface { 64 | TxManager 65 | TokenManager 66 | KeyManager 67 | Queries 68 | TokenConvert 69 | TmClient 70 | Logger 71 | GRPCClient 72 | } 73 | -------------------------------------------------------------------------------- /types/handler_map.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types/tx/signing" 7 | ) 8 | 9 | // SignModeHandlerMap is SignModeHandler that aggregates multiple SignModeHandler's into 10 | // a single handler 11 | type SignModeHandlerMap struct { 12 | defaultMode signing.SignMode 13 | modes []signing.SignMode 14 | signModeHandlers map[signing.SignMode]SignModeHandler 15 | } 16 | 17 | var _ SignModeHandler = SignModeHandlerMap{} 18 | 19 | // NewSignModeHandlerMap returns a new SignModeHandlerMap with the provided defaultMode and handlers 20 | func NewSignModeHandlerMap(defaultMode signing.SignMode, handlers []SignModeHandler) SignModeHandlerMap { 21 | handlerMap := make(map[signing.SignMode]SignModeHandler) 22 | var modes []signing.SignMode 23 | 24 | for _, h := range handlers { 25 | for _, m := range h.Modes() { 26 | if _, have := handlerMap[m]; have { 27 | panic(fmt.Errorf("duplicate sign mode handler for mode %s", m)) 28 | } 29 | handlerMap[m] = h 30 | modes = append(modes, m) 31 | } 32 | } 33 | 34 | return SignModeHandlerMap{ 35 | defaultMode: defaultMode, 36 | modes: modes, 37 | signModeHandlers: handlerMap, 38 | } 39 | } 40 | 41 | // DefaultMode implements SignModeHandler.DefaultMode 42 | func (h SignModeHandlerMap) DefaultMode() signing.SignMode { 43 | return h.defaultMode 44 | } 45 | 46 | // Modes implements SignModeHandler.Modes 47 | func (h SignModeHandlerMap) Modes() []signing.SignMode { 48 | return h.modes 49 | } 50 | 51 | // DefaultMode implements SignModeHandler.GetSignBytes 52 | func (h SignModeHandlerMap) GetSignBytes(mode signing.SignMode, data SignerData, tx Tx) ([]byte, error) { 53 | handler, found := h.signModeHandlers[mode] 54 | if !found { 55 | return nil, fmt.Errorf("can't verify sign mode %s", mode.String()) 56 | } 57 | return handler.GetSignBytes(mode, data, tx) 58 | } 59 | -------------------------------------------------------------------------------- /proto/cosmos/base/query/v1beta1/pagination.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.base.query.v1beta1; 3 | 4 | option go_package = "github.com/bianjieai/irita-sdk-go/types/query"; 5 | 6 | // PageRequest is to be embedded in gRPC request messages for efficient 7 | // pagination. Ex: 8 | // 9 | // message SomeRequest { 10 | // Foo some_parameter = 1; 11 | // PageRequest pagination = 2; 12 | // } 13 | message PageRequest { 14 | // key is a value returned in PageResponse.next_key to begin 15 | // querying the next page most efficiently. Only one of offset or key 16 | // should be set. 17 | bytes key = 1; 18 | 19 | // offset is a numeric offset that can be used when key is unavailable. 20 | // It is less efficient than using key. Only one of offset or key should 21 | // be set. 22 | uint64 offset = 2; 23 | 24 | // limit is the total number of results to be returned in the result page. 25 | // If left empty it will default to a value to be set by each app. 26 | uint64 limit = 3; 27 | 28 | // count_total is set to true to indicate that the result set should include 29 | // a count of the total number of items available for pagination in UIs. 30 | // count_total is only respected when offset is used. It is ignored when key 31 | // is set. 32 | bool count_total = 4; 33 | } 34 | 35 | // PageResponse is to be embedded in gRPC response messages where the 36 | // corresponding request message has used PageRequest. 37 | // 38 | // message SomeResponse { 39 | // repeated Bar results = 1; 40 | // PageResponse page = 2; 41 | // } 42 | message PageResponse { 43 | // next_key is the key to be passed to PageRequest.key to 44 | // query the next page most efficiently 45 | bytes next_key = 1; 46 | 47 | // total is total number of results available if PageRequest.count_total 48 | // was set, its value is undefined otherwise 49 | uint64 total = 2; 50 | } 51 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/hash.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_HASH_ 8 | #define _SECP256K1_HASH_ 9 | 10 | #include 11 | #include 12 | 13 | typedef struct { 14 | uint32_t s[8]; 15 | uint32_t buf[16]; /* In big endian */ 16 | size_t bytes; 17 | } secp256k1_sha256_t; 18 | 19 | static void secp256k1_sha256_initialize(secp256k1_sha256_t *hash); 20 | static void secp256k1_sha256_write(secp256k1_sha256_t *hash, const unsigned char *data, size_t size); 21 | static void secp256k1_sha256_finalize(secp256k1_sha256_t *hash, unsigned char *out32); 22 | 23 | typedef struct { 24 | secp256k1_sha256_t inner, outer; 25 | } secp256k1_hmac_sha256_t; 26 | 27 | static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256_t *hash, const unsigned char *key, size_t size); 28 | static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256_t *hash, const unsigned char *data, size_t size); 29 | static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256_t *hash, unsigned char *out32); 30 | 31 | typedef struct { 32 | unsigned char v[32]; 33 | unsigned char k[32]; 34 | int retry; 35 | } secp256k1_rfc6979_hmac_sha256_t; 36 | 37 | static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen); 38 | static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen); 39 | static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /types/tx/config.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | signingtypes "github.com/bianjieai/irita-sdk-go/types/tx/signing" 9 | ) 10 | 11 | type config struct { 12 | handler sdk.SignModeHandler 13 | decoder sdk.TxDecoder 14 | encoder sdk.TxEncoder 15 | jsonDecoder sdk.TxDecoder 16 | jsonEncoder sdk.TxEncoder 17 | protoCodec *codec.ProtoCodec 18 | } 19 | 20 | // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec, PublicKeyCodec and sign modes. The 21 | // first enabled sign mode will become the default sign mode. 22 | func NewTxConfig(protoCodec *codec.ProtoCodec, enabledSignModes []signingtypes.SignMode) sdk.TxConfig { 23 | return &config{ 24 | handler: MakeSignModeHandler(enabledSignModes), 25 | decoder: DefaultTxDecoder(protoCodec), 26 | encoder: DefaultTxEncoder(), 27 | jsonDecoder: DefaultJSONTxDecoder(protoCodec), 28 | jsonEncoder: DefaultJSONTxEncoder(protoCodec), 29 | protoCodec: protoCodec, 30 | } 31 | } 32 | 33 | func (g config) NewTxBuilder() sdk.TxBuilder { 34 | return newBuilder() 35 | } 36 | 37 | // WrapTxBuilder returns a builder from provided transaction 38 | func (g config) WrapTxBuilder(newTx sdk.Tx) (sdk.TxBuilder, error) { 39 | newBuilder, ok := newTx.(*wrapper) 40 | if !ok { 41 | return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, newTx) 42 | } 43 | 44 | return newBuilder, nil 45 | } 46 | 47 | func (g config) SignModeHandler() sdk.SignModeHandler { 48 | return g.handler 49 | } 50 | 51 | func (g config) TxEncoder() sdk.TxEncoder { 52 | return g.encoder 53 | } 54 | 55 | func (g config) TxDecoder() sdk.TxDecoder { 56 | return g.decoder 57 | } 58 | 59 | func (g config) TxJSONEncoder() sdk.TxEncoder { 60 | return g.jsonEncoder 61 | } 62 | 63 | func (g config) TxJSONDecoder() sdk.TxDecoder { 64 | return g.jsonDecoder 65 | } 66 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/bench_ecdh.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | 9 | #include "include/secp256k1.h" 10 | #include "include/secp256k1_ecdh.h" 11 | #include "util.h" 12 | #include "bench.h" 13 | 14 | typedef struct { 15 | secp256k1_context *ctx; 16 | secp256k1_pubkey point; 17 | unsigned char scalar[32]; 18 | } bench_ecdh_t; 19 | 20 | static void bench_ecdh_setup(void* arg) { 21 | int i; 22 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 23 | const unsigned char point[] = { 24 | 0x03, 25 | 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, 26 | 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, 27 | 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, 28 | 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f 29 | }; 30 | 31 | /* create a context with no capabilities */ 32 | data->ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); 33 | for (i = 0; i < 32; i++) { 34 | data->scalar[i] = i + 1; 35 | } 36 | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); 37 | } 38 | 39 | static void bench_ecdh(void* arg) { 40 | int i; 41 | unsigned char res[32]; 42 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 43 | 44 | for (i = 0; i < 20000; i++) { 45 | CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); 46 | } 47 | } 48 | 49 | int main(void) { 50 | bench_ecdh_t data; 51 | 52 | run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/field_5x52.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..4, elem[i]*2^52) mod n */ 14 | uint64_t n[5]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \ 24 | ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \ 25 | ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \ 26 | ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \ 27 | ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \ 28 | } 29 | 30 | #ifdef VERIFY 31 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 32 | #else 33 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 34 | #endif 35 | 36 | typedef struct { 37 | uint64_t n[4]; 38 | } secp256k1_fe_storage; 39 | 40 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \ 41 | (d0) | (((uint64_t)(d1)) << 32), \ 42 | (d2) | (((uint64_t)(d3)) << 32), \ 43 | (d4) | (((uint64_t)(d5)) << 32), \ 44 | (d6) | (((uint64_t)(d7)) << 32) \ 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /modules/token/export.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | "github.com/bianjieai/irita-sdk-go/types/query" 6 | ) 7 | 8 | type Client interface { 9 | sdk.Module 10 | 11 | IssueToken(req IssueTokenRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 12 | EditToken(req EditTokenRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 13 | TransferToken(to string, symbol string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 14 | MintToken(symbol string, amount uint64, to string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 15 | 16 | QueryToken(symbol string) (sdk.Token, error) 17 | QueryTokens(owner string, pageReq *query.PageRequest) (sdk.Tokens, error) 18 | QueryFees(symbol string) (QueryFeesResp, error) 19 | QueryParams() (QueryParamsResp, error) 20 | } 21 | 22 | type IssueTokenRequest struct { 23 | Symbol string `json:"symbol"` 24 | Name string `json:"name"` 25 | Scale uint32 `json:"scale"` 26 | MinUnit string `json:"min_unit"` 27 | InitialSupply uint64 `json:"initial_supply"` 28 | MaxSupply uint64 `json:"max_supply"` 29 | Mintable bool `json:"mintable"` 30 | } 31 | 32 | type EditTokenRequest struct { 33 | Symbol string `json:"symbol"` 34 | Name string `json:"name"` 35 | MaxSupply uint64 `json:"max_supply"` 36 | Mintable bool `json:"mintable"` 37 | } 38 | 39 | // QueryFeesResp is for the token fees query output 40 | type QueryFeesResp struct { 41 | Exist bool `json:"exist"` // indicate if the token has existed 42 | IssueFee sdk.Coin `json:"issue_fee"` // issue fee 43 | MintFee sdk.Coin `json:"mint_fee"` // mint fee 44 | } 45 | 46 | // token params 47 | type QueryParamsResp struct { 48 | TokenTaxRate string `json:"token_tax_rate"` // e.g., 40% 49 | IssueTokenBaseFee string `json:"issue_token_base_fee"` // e.g., 300000*10^18iris-atto 50 | MintTokenFeeRatio string `json:"mint_token_fee_ratio"` // e.g., 10% 51 | } 52 | -------------------------------------------------------------------------------- /integration_test/wasm_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/stretchr/testify/require" 7 | 8 | "github.com/bianjieai/irita-sdk-go/modules/wasm" 9 | "github.com/bianjieai/irita-sdk-go/types" 10 | ) 11 | 12 | func (s IntegrationTestSuite) TestWasm() { 13 | baseTx := types.BaseTx{ 14 | From: s.Account().Name, 15 | Gas: 4000000, 16 | Fee: types.NewDecCoins(types.NewInt64DecCoin("point", 24)), 17 | Memo: "test", 18 | Mode: types.Commit, 19 | Password: s.Account().Password, 20 | } 21 | 22 | request := wasm.StoreRequest{ 23 | WASMFile: "./election.wasm", 24 | } 25 | 26 | codeID, err := s.WASM.Store(request, baseTx) 27 | require.NoError(s.T(), err) 28 | require.NotEmpty(s.T(), codeID) 29 | 30 | args := wasm.NewArgs(). 31 | Put("start", 1). 32 | Put("end", 1000). 33 | Put("candidates", []string{"iaa1qvty8x0c78am8c44zv2n7tgm6gfqt78j0verqa", "iaa1zk2tse0pkk87p2v8tcsfs0ytfw3t88kejecye5"}) 34 | 35 | initReq := wasm.InstantiateRequest{ 36 | CodeID: codeID, 37 | Label: "test wasm", 38 | InitMsg: args, 39 | } 40 | 41 | contractAddress, err := s.WASM.Instantiate(initReq, baseTx) 42 | require.NoError(s.T(), err) 43 | require.NotEmpty(s.T(), contractAddress) 44 | 45 | info, err := s.WASM.QueryContractInfo(contractAddress) 46 | require.NoError(s.T(), err) 47 | require.NotEmpty(s.T(), info) 48 | require.Equal(s.T(), fmt.Sprintf("%d", info.CodeID), codeID) 49 | require.Equal(s.T(), info.Label, initReq.Label) 50 | 51 | execAbi := wasm.NewContractABI(). 52 | WithMethod("vote"). 53 | WithArgs("candidate", "iaa1qvty8x0c78am8c44zv2n7tgm6gfqt78j0verqa") 54 | _, err = s.WASM.Execute(contractAddress, execAbi, nil, baseTx) 55 | require.NoError(s.T(), err) 56 | 57 | queryAbi := wasm.NewContractABI(). 58 | WithMethod("get_vote_info") 59 | bz, err := s.WASM.QueryContract(contractAddress, queryAbi) 60 | require.NoError(s.T(), err) 61 | require.NotEmpty(s.T(), bz) 62 | } 63 | -------------------------------------------------------------------------------- /integration_test/perm_test.go: -------------------------------------------------------------------------------- 1 | package integration_test 2 | 3 | import ( 4 | "github.com/stretchr/testify/require" 5 | 6 | "github.com/bianjieai/irita-sdk-go/types" 7 | 8 | "github.com/bianjieai/irita-sdk-go/modules/perm" 9 | ) 10 | 11 | func (s IntegrationTestSuite) TestPerm() { 12 | baseTx := types.BaseTx{ 13 | From: s.Account().Name, 14 | Gas: 200000, 15 | Memo: "test", 16 | Mode: types.Commit, 17 | Password: s.Account().Password, 18 | } 19 | 20 | acc := s.GetRandAccount() 21 | roles := []perm.Role{ 22 | perm.RoleBlacklistAdmin, 23 | } 24 | 25 | //test AddRoles 26 | rs, err := s.Perm.AssignRoles(acc.Address.String(), roles, baseTx) 27 | require.NoError(s.T(), err) 28 | require.NotEmpty(s.T(), rs.Hash) 29 | 30 | // test QueryRoles 31 | roles2, err := s.Perm.QueryRoles(acc.Address.String()) 32 | require.NoError(s.T(), err) 33 | require.NotEmpty(s.T(), roles2) 34 | require.EqualValues(s.T(), roles, roles2) 35 | 36 | // test RemoveRoles 37 | rs, err = s.Perm.UnassignRoles(acc.Address.String(), roles, baseTx) 38 | require.NoError(s.T(), err) 39 | require.NotEmpty(s.T(), rs.Hash) 40 | 41 | // test QueryRoles again 42 | roles2, err = s.Perm.QueryRoles(acc.Address.String()) 43 | require.NoError(s.T(), err) 44 | require.Empty(s.T(), roles2) 45 | 46 | // test BlockAccount 47 | rs, err = s.Perm.BlockAccount(acc.Address.String(), baseTx) 48 | require.NoError(s.T(), err) 49 | require.NotEmpty(s.T(), rs.Hash) 50 | 51 | // test QueryBlacklist 52 | bl, err := s.Perm.QueryBlacklist(1, 10) 53 | require.NoError(s.T(), err) 54 | require.NotEmpty(s.T(), bl) 55 | require.EqualValues(s.T(), []string{acc.Address.String()}, bl) 56 | 57 | // test UnblockAccount 58 | rs, err = s.Perm.UnblockAccount(acc.Address.String(), baseTx) 59 | require.NoError(s.T(), err) 60 | require.NotEmpty(s.T(), rs.Hash) 61 | 62 | // test QueryBlacklist again 63 | bl, err = s.Perm.QueryBlacklist(1, 10) 64 | require.NoError(s.T(), err) 65 | require.Empty(s.T(), bl) 66 | } 67 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bianjieai/irita-sdk-go 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/99designs/keyring v1.1.6 7 | github.com/DataDog/zstd v1.4.5 // indirect 8 | github.com/avast/retry-go v2.6.0+incompatible 9 | github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833 10 | github.com/btcsuite/btcd v0.21.0-beta 11 | github.com/btcsuite/btcutil v1.0.2 12 | github.com/cosmos/go-bip39 v1.0.0 13 | github.com/cosmos/iavl v0.15.3 // indirect 14 | github.com/dgraph-io/ristretto v0.0.3 // indirect 15 | github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect 16 | github.com/dvsekhvalnov/jose2go v0.0.0-20201001154944-b09cfaf05951 17 | github.com/gogo/protobuf v1.3.3 18 | github.com/golang/protobuf v1.5.2 19 | github.com/golang/snappy v0.0.2 // indirect 20 | github.com/magiconair/properties v1.8.4 21 | github.com/mitchellh/go-homedir v1.1.0 22 | github.com/mtibben/percent v0.2.1 23 | github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect 24 | github.com/pkg/errors v0.9.1 25 | github.com/prometheus/common v0.15.0 26 | github.com/regen-network/cosmos-proto v0.3.1 27 | github.com/sirupsen/logrus v1.6.0 28 | github.com/spf13/cast v1.3.1 29 | github.com/stretchr/testify v1.7.0 30 | github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 31 | github.com/tendermint/go-amino v0.16.0 32 | github.com/tendermint/tendermint v0.34.9 33 | github.com/tendermint/tm-db v0.6.4 34 | github.com/tjfoc/gmsm v1.4.0 35 | golang.org/x/crypto v0.1.0 36 | golang.org/x/net v0.7.0 // indirect 37 | google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f 38 | google.golang.org/grpc v1.35.0 39 | google.golang.org/protobuf v1.28.0 40 | gopkg.in/yaml.v2 v2.4.0 41 | ) 42 | 43 | replace ( 44 | github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 45 | github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 46 | github.com/tendermint/tendermint => github.com/bianjieai/tendermint v0.34.1-irita-210113 47 | ) 48 | -------------------------------------------------------------------------------- /modules/record/types.go: -------------------------------------------------------------------------------- 1 | package record 2 | 3 | import ( 4 | "fmt" 5 | 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | ) 8 | 9 | const ( 10 | ModuleName = "record" 11 | 12 | attributeKeyRecordID = "record_id" 13 | eventTypeCreateRecord = "create_record" 14 | ) 15 | 16 | var ( 17 | _ sdk.Msg = &MsgCreateRecord{} 18 | 19 | recordKey = []byte{0x01} // record key 20 | ) 21 | 22 | // Route implements Msg. 23 | func (msg MsgCreateRecord) Route() string { return ModuleName } 24 | 25 | // Type implements Msg. 26 | func (msg MsgCreateRecord) Type() string { return "create_record" } 27 | 28 | // GetSignBytes implements Msg. 29 | func (msg MsgCreateRecord) GetSignBytes() []byte { 30 | b, err := ModuleCdc.MarshalJSON(&msg) 31 | if err != nil { 32 | panic(err) 33 | } 34 | return sdk.MustSortJSON(b) 35 | } 36 | 37 | // ValidateBasic implements Msg. 38 | func (msg MsgCreateRecord) ValidateBasic() error { 39 | if len(msg.Contents) == 0 { 40 | return fmt.Errorf("contents missing") 41 | } 42 | if len(msg.Creator) == 0 { 43 | return fmt.Errorf("creator missing") 44 | } 45 | 46 | if err := sdk.ValidateAccAddress(msg.Creator); err != nil { 47 | return sdk.Wrap(err) 48 | } 49 | 50 | for i, content := range msg.Contents { 51 | if len(content.Digest) == 0 { 52 | return fmt.Errorf("content[%d] digest missing", i) 53 | } 54 | if len(content.DigestAlgo) == 0 { 55 | return fmt.Errorf("content[%d] digest algo missing", i) 56 | } 57 | } 58 | return nil 59 | } 60 | 61 | // GetSigners implements Msg. 62 | func (msg MsgCreateRecord) GetSigners() []sdk.AccAddress { 63 | return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Creator)} 64 | } 65 | 66 | func (this Record) Convert() interface{} { 67 | return QueryRecordResp{ 68 | Record: Data{ 69 | TxHash: this.TxHash, 70 | Contents: this.Contents, 71 | Creator: this.Creator, 72 | }, 73 | } 74 | } 75 | 76 | // GetRecordKey returns record key bytes 77 | func GetRecordKey(recordID []byte) []byte { 78 | return append(recordKey, recordID...) 79 | } 80 | -------------------------------------------------------------------------------- /proto/identity/identity.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.identity; 3 | 4 | import "gogoproto/gogo.proto"; 5 | 6 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/identity"; 7 | option (gogoproto.goproto_getters_all) = false; 8 | 9 | // Identity defines a struct for an identity 10 | message Identity { 11 | option (gogoproto.equal) = true; 12 | 13 | string id = 1 ; 14 | repeated PubKeyInfo pub_keys = 2 [ 15 | (gogoproto.nullable) = false, 16 | (gogoproto.moretags) = "yaml:\"pubkeys\"", 17 | (gogoproto.jsontag) = "pubkeys" 18 | ]; 19 | repeated string certificates = 3; 20 | string credentials = 4; 21 | string owner = 5; 22 | } 23 | 24 | // PubKey represents a public key along with the corresponding algorithm 25 | message PubKeyInfo { 26 | option (gogoproto.equal) = true; 27 | 28 | string pub_key = 1 [ 29 | (gogoproto.moretags) = "yaml:\"pubkey\"", 30 | (gogoproto.jsontag) = "pubkey" 31 | ]; 32 | PubKeyAlgorithm algorithm = 2; 33 | } 34 | 35 | // PubKeyAlgorithm defines the algorithm names for the public key 36 | enum PubKeyAlgorithm { 37 | option (gogoproto.enum_stringer) = true; 38 | option (gogoproto.goproto_enum_stringer) = false; 39 | option (gogoproto.goproto_enum_prefix) = false; 40 | 41 | // UnknownPubKeyAlgorithm defines an unknown algorithm name 42 | UnknownPubKeyAlgorithm = 0 [(gogoproto.enumvalue_customname) = "UnknownPubKeyAlgorithm"]; 43 | // RSA defines a RSA algorithm name 44 | RSA = 1 [(gogoproto.enumvalue_customname) = "RSA"]; 45 | // DSA defines a DSA algorithm name. 46 | DSA = 2 [(gogoproto.enumvalue_customname) = "DSA"]; 47 | // ECDSA defines an ECDSA algorithm name. 48 | ECDSA = 3 [(gogoproto.enumvalue_customname) = "ECDSA"]; 49 | // ED25519 defines an ED25519 algorithm name. 50 | ED25519 = 4 [(gogoproto.enumvalue_customname) = "ED25519"]; 51 | // SM2 defines an SM2 algorithm name. 52 | SM2 = 5 [(gogoproto.enumvalue_customname) = "SM2"]; 53 | } 54 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/bench.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BENCH_H_ 8 | #define _SECP256K1_BENCH_H_ 9 | 10 | #include 11 | #include 12 | #include "sys/time.h" 13 | 14 | static double gettimedouble(void) { 15 | struct timeval tv; 16 | gettimeofday(&tv, NULL); 17 | return tv.tv_usec * 0.000001 + tv.tv_sec; 18 | } 19 | 20 | void print_number(double x) { 21 | double y = x; 22 | int c = 0; 23 | if (y < 0.0) { 24 | y = -y; 25 | } 26 | while (y < 100.0) { 27 | y *= 10.0; 28 | c++; 29 | } 30 | printf("%.*f", c, x); 31 | } 32 | 33 | void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { 34 | int i; 35 | double min = HUGE_VAL; 36 | double sum = 0.0; 37 | double max = 0.0; 38 | for (i = 0; i < count; i++) { 39 | double begin, total; 40 | if (setup != NULL) { 41 | setup(data); 42 | } 43 | begin = gettimedouble(); 44 | benchmark(data); 45 | total = gettimedouble() - begin; 46 | if (teardown != NULL) { 47 | teardown(data); 48 | } 49 | if (total < min) { 50 | min = total; 51 | } 52 | if (total > max) { 53 | max = total; 54 | } 55 | sum += total; 56 | } 57 | printf("%s: min ", name); 58 | print_number(min * 1000000.0 / iter); 59 | printf("us / avg "); 60 | print_number((sum / count) * 1000000.0 / iter); 61 | printf("us / max "); 62 | print_number(max * 1000000.0 / iter); 63 | printf("us\n"); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /modules/oracle/export.go: -------------------------------------------------------------------------------- 1 | package oracle 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/bianjieai/irita-sdk-go/modules/service" 7 | sdk "github.com/bianjieai/irita-sdk-go/types" 8 | types "github.com/bianjieai/irita-sdk-go/types" 9 | ) 10 | 11 | var ( 12 | _ Client = oracleClient{} 13 | ) 14 | 15 | // expose Oracle module api for user 16 | type Client interface { 17 | sdk.Module 18 | 19 | CreateFeed(request CreateFeedRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 20 | StartFeed(feedName string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 21 | PauseFeed(feedName string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 22 | EditFeedRequest(request EditFeedRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 23 | 24 | QueryFeed(feedName string) (QueryFeedResp, sdk.Error) 25 | QueryFeeds(state string) ([]QueryFeedResp, sdk.Error) 26 | QueryFeedValue(feedName string) ([]QueryFeedValueResp, sdk.Error) 27 | } 28 | 29 | type CreateFeedRequest struct { 30 | FeedName string 31 | LatestHistory uint64 32 | Description string 33 | ServiceName string 34 | Providers []string 35 | Input string 36 | Timeout int64 37 | ServiceFeeCap []types.Coin 38 | RepeatedFrequency uint64 39 | AggregateFunc string 40 | ValueJsonPath string 41 | ResponseThreshold uint32 42 | } 43 | 44 | type EditFeedRequest struct { 45 | FeedName string 46 | Description string 47 | LatestHistory uint64 48 | Providers []string 49 | Timeout int64 50 | ServiceFeeCap []types.Coin 51 | RepeatedFrequency uint64 52 | ResponseThreshold uint32 53 | } 54 | 55 | type QueryFeedResp struct { 56 | Feed *Feed 57 | ServiceName string 58 | Providers []string 59 | Input string 60 | Timeout int64 61 | ServiceFeeCap []types.Coin 62 | RepeatedFrequency uint64 63 | ResponseThreshold uint32 64 | State service.RequestContextState 65 | } 66 | 67 | type QueryFeedValueResp struct { 68 | Data string 69 | Timestamp time.Time 70 | } 71 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/field_10x26.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..9, elem[i]*2^26) mod n */ 14 | uint32_t n[10]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) & 0x3FFFFFFUL, \ 24 | (((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \ 25 | (((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \ 26 | (((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \ 27 | (((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \ 28 | (((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \ 29 | (((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \ 30 | (((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \ 31 | (((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \ 32 | (((uint32_t)d7) >> 10) \ 33 | } 34 | 35 | #ifdef VERIFY 36 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 37 | #else 38 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 39 | #endif 40 | 41 | typedef struct { 42 | uint32_t n[8]; 43 | } secp256k1_fe_storage; 44 | 45 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }} 46 | #define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0] 47 | #endif 48 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/modules/ecdh/main_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_MODULE_ECDH_MAIN_ 8 | #define _SECP256K1_MODULE_ECDH_MAIN_ 9 | 10 | #include "include/secp256k1_ecdh.h" 11 | #include "ecmult_const_impl.h" 12 | 13 | int secp256k1_ecdh(const secp256k1_context* ctx, unsigned char *result, const secp256k1_pubkey *point, const unsigned char *scalar) { 14 | int ret = 0; 15 | int overflow = 0; 16 | secp256k1_gej res; 17 | secp256k1_ge pt; 18 | secp256k1_scalar s; 19 | VERIFY_CHECK(ctx != NULL); 20 | ARG_CHECK(result != NULL); 21 | ARG_CHECK(point != NULL); 22 | ARG_CHECK(scalar != NULL); 23 | 24 | secp256k1_pubkey_load(ctx, &pt, point); 25 | secp256k1_scalar_set_b32(&s, scalar, &overflow); 26 | if (overflow || secp256k1_scalar_is_zero(&s)) { 27 | ret = 0; 28 | } else { 29 | unsigned char x[32]; 30 | unsigned char y[1]; 31 | secp256k1_sha256_t sha; 32 | 33 | secp256k1_ecmult_const(&res, &pt, &s); 34 | secp256k1_ge_set_gej(&pt, &res); 35 | /* Compute a hash of the point in compressed form 36 | * Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not 37 | * expect its output to be secret and has a timing sidechannel. */ 38 | secp256k1_fe_normalize(&pt.x); 39 | secp256k1_fe_normalize(&pt.y); 40 | secp256k1_fe_get_b32(x, &pt.x); 41 | y[0] = 0x02 | secp256k1_fe_is_odd(&pt.y); 42 | 43 | secp256k1_sha256_initialize(&sha); 44 | secp256k1_sha256_write(&sha, y, sizeof(y)); 45 | secp256k1_sha256_write(&sha, x, sizeof(x)); 46 | secp256k1_sha256_finalize(&sha, result); 47 | ret = 1; 48 | } 49 | 50 | secp256k1_scalar_clear(&s); 51 | return ret; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /types/utils.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/binary" 5 | "encoding/json" 6 | "time" 7 | ) 8 | 9 | // SortedJSON takes any JSON and returns it sorted by keys. Also, all white-spaces 10 | // are removed. 11 | // This method can be used to canonicalize JSON to be returned by GetSignBytes, 12 | // e.g. for the ledger integration. 13 | // If the passed JSON isn't valid it will return an error. 14 | func SortJSON(toSortJSON []byte) ([]byte, error) { 15 | var c interface{} 16 | if err := json.Unmarshal(toSortJSON, &c); err != nil { 17 | return nil, err 18 | } 19 | return json.Marshal(c) 20 | } 21 | 22 | // MustSortJSON is like SortJSON but panic if an error occurs, e.g., if 23 | // the passed JSON isn't valid. 24 | func MustSortJSON(toSortJSON []byte) []byte { 25 | js, err := SortJSON(toSortJSON) 26 | if err != nil { 27 | panic(err) 28 | } 29 | return js 30 | } 31 | 32 | // Uint64ToBigEndian - marshals uint64 to a bigendian byte slice so it can be sorted 33 | func Uint64ToBigEndian(i uint64) []byte { 34 | b := make([]byte, 8) 35 | binary.BigEndian.PutUint64(b, i) 36 | return b 37 | } 38 | 39 | // BigEndianToUint64 returns an uint64 from big endian encoded bytes. If encoding 40 | // is empty, zero is returned. 41 | func BigEndianToUint64(bz []byte) uint64 { 42 | if len(bz) == 0 { 43 | return 0 44 | } 45 | 46 | return binary.BigEndian.Uint64(bz) 47 | } 48 | 49 | // Slight modification of the RFC3339Nano but it right pads all zeros and drops the time zone info 50 | const SortableTimeFormat = "2006-01-02T15:04:05.000000000" 51 | 52 | // Formats a time.Time into a []byte that can be sorted 53 | func FormatTimeBytes(t time.Time) []byte { 54 | return []byte(t.UTC().Round(0).Format(SortableTimeFormat)) 55 | } 56 | 57 | // Parses a []byte encoded using FormatTimeKey back into a time.Time 58 | func ParseTimeBytes(bz []byte) (time.Time, error) { 59 | str := string(bz) 60 | t, err := time.Parse(SortableTimeFormat, str) 61 | if err != nil { 62 | return t, err 63 | } 64 | return t.UTC().Round(0), nil 65 | } 66 | 67 | // copy bytes 68 | func CopyBytes(bz []byte) (ret []byte) { 69 | if bz == nil { 70 | return nil 71 | } 72 | ret = make([]byte, len(bz)) 73 | copy(ret, bz) 74 | return ret 75 | } 76 | -------------------------------------------------------------------------------- /types/tx/decoder.go: -------------------------------------------------------------------------------- 1 | package tx 2 | 3 | import ( 4 | "github.com/bianjieai/irita-sdk-go/codec" 5 | "github.com/bianjieai/irita-sdk-go/codec/unknownproto" 6 | sdk "github.com/bianjieai/irita-sdk-go/types" 7 | ) 8 | 9 | // DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler and PublicKeyCodec 10 | func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder { 11 | return func(txBytes []byte) (sdk.Tx, error) { 12 | var raw TxRaw 13 | 14 | // reject all unknown proto fields in the root TxRaw 15 | if err := unknownproto.RejectUnknownFieldsStrict(txBytes, &raw); err != nil { 16 | return nil, err 17 | } 18 | 19 | if err := cdc.UnmarshalBinaryBare(txBytes, &raw); err != nil { 20 | return nil, err 21 | } 22 | 23 | var body TxBody 24 | 25 | // allow non-critical unknown fields in TxBody 26 | txBodyHasUnknownNonCriticals, err := unknownproto.RejectUnknownFields(raw.BodyBytes, &body, true) 27 | if err != nil { 28 | return nil, err 29 | } 30 | 31 | if err = cdc.UnmarshalBinaryBare(raw.BodyBytes, &body); err != nil { 32 | return nil, err 33 | } 34 | 35 | var authInfo AuthInfo 36 | 37 | // reject all unknown proto fields in AuthInfo 38 | if err = unknownproto.RejectUnknownFieldsStrict(raw.AuthInfoBytes, &authInfo); err != nil { 39 | return nil, err 40 | } 41 | 42 | if err = cdc.UnmarshalBinaryBare(raw.AuthInfoBytes, &authInfo); err != nil { 43 | return nil, err 44 | } 45 | 46 | theTx := &Tx{ 47 | Body: &body, 48 | AuthInfo: &authInfo, 49 | Signatures: raw.Signatures, 50 | } 51 | 52 | return &wrapper{ 53 | tx: theTx, 54 | bodyBz: raw.BodyBytes, 55 | authInfoBz: raw.AuthInfoBytes, 56 | txBodyHasUnknownNonCriticals: txBodyHasUnknownNonCriticals, 57 | }, nil 58 | } 59 | } 60 | 61 | // DefaultTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler and PublicKeyCodec 62 | func DefaultJSONTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder { 63 | return func(txBytes []byte) (sdk.Tx, error) { 64 | var theTx Tx 65 | if err := cdc.UnmarshalJSON(txBytes, &theTx); err != nil { 66 | return nil, err 67 | } 68 | 69 | return &wrapper{ 70 | tx: &theTx, 71 | }, nil 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/bench_recover.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014-2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "include/secp256k1_recovery.h" 9 | #include "util.h" 10 | #include "bench.h" 11 | 12 | typedef struct { 13 | secp256k1_context *ctx; 14 | unsigned char msg[32]; 15 | unsigned char sig[64]; 16 | } bench_recover_t; 17 | 18 | void bench_recover(void* arg) { 19 | int i; 20 | bench_recover_t *data = (bench_recover_t*)arg; 21 | secp256k1_pubkey pubkey; 22 | unsigned char pubkeyc[33]; 23 | 24 | for (i = 0; i < 20000; i++) { 25 | int j; 26 | size_t pubkeylen = 33; 27 | secp256k1_ecdsa_recoverable_signature sig; 28 | CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); 29 | CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); 30 | CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); 31 | for (j = 0; j < 32; j++) { 32 | data->sig[j + 32] = data->msg[j]; /* Move former message to S. */ 33 | data->msg[j] = data->sig[j]; /* Move former R to message. */ 34 | data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */ 35 | } 36 | } 37 | } 38 | 39 | void bench_recover_setup(void* arg) { 40 | int i; 41 | bench_recover_t *data = (bench_recover_t*)arg; 42 | 43 | for (i = 0; i < 32; i++) { 44 | data->msg[i] = 1 + i; 45 | } 46 | for (i = 0; i < 64; i++) { 47 | data->sig[i] = 65 + i; 48 | } 49 | } 50 | 51 | int main(void) { 52 | bench_recover_t data; 53 | 54 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); 55 | 56 | run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, 20000); 57 | 58 | secp256k1_context_destroy(data.ctx); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /modules/node/export.go: -------------------------------------------------------------------------------- 1 | package node 2 | 3 | import ( 4 | sdk "github.com/bianjieai/irita-sdk-go/types" 5 | "github.com/bianjieai/irita-sdk-go/types/query" 6 | ) 7 | 8 | var ( 9 | _ Client = nodeClient{} 10 | ) 11 | 12 | // expose Record module api for user 13 | type Client interface { 14 | sdk.Module 15 | 16 | CreateValidator(request CreateValidatorRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 17 | UpdateValidator(request UpdateValidatorRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 18 | RemoveValidator(id string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 19 | 20 | GrantNode(request GrantNodeRequest, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 21 | RevokeNode(nodeId string, baseTx sdk.BaseTx) (sdk.ResultTx, sdk.Error) 22 | 23 | QueryValidators(pageReq *query.PageRequest) ([]QueryValidatorResp, sdk.Error) 24 | QueryValidator(id string) (QueryValidatorResp, sdk.Error) 25 | QueryNodes(pageReq *query.PageRequest) ([]QueryNodeResp, sdk.Error) 26 | QueryNode(id string) (QueryNodeResp, sdk.Error) 27 | QueryParams() (QueryParamsResp, sdk.Error) 28 | } 29 | 30 | type CreateValidatorRequest struct { 31 | Name string `json:"name"` 32 | Certificate string `json:"certificate"` 33 | Power int64 `json:"power"` 34 | Details string `json:"details"` 35 | } 36 | 37 | type UpdateValidatorRequest struct { 38 | ID string `json:"id"` 39 | Name string `json:"name"` 40 | Certificate string `json:"certificate"` 41 | Power int64 `json:"power"` 42 | Details string `json:"details"` 43 | } 44 | 45 | type GrantNodeRequest struct { 46 | Name string `json:"name"` 47 | Certificate string `json:"certificate"` 48 | Details string `json:"details"` 49 | } 50 | 51 | type QueryValidatorResp struct { 52 | ID string `json:"id"` 53 | Name string `json:"name"` 54 | Pubkey string `json:"pubkey"` 55 | Certificate string `json:"certificate"` 56 | Power int64 `json:"power"` 57 | Details string `json:"details"` 58 | Jailed bool `json:"jailed"` 59 | Operator string `json:"operator"` 60 | } 61 | 62 | type QueryNodeResp struct { 63 | ID string `json:"id"` 64 | Name string `json:"name"` 65 | Certificate string `json:"certificate"` 66 | } 67 | 68 | // token params 69 | type QueryParamsResp struct { 70 | HistoricalEntries uint32 `json:"historical_entries"` 71 | } 72 | -------------------------------------------------------------------------------- /modules/record/record.go: -------------------------------------------------------------------------------- 1 | package record 2 | 3 | import ( 4 | "encoding/hex" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec" 7 | "github.com/bianjieai/irita-sdk-go/codec/types" 8 | sdk "github.com/bianjieai/irita-sdk-go/types" 9 | ) 10 | 11 | type recordClient struct { 12 | sdk.BaseClient 13 | codec.Marshaler 14 | } 15 | 16 | func NewClient(bc sdk.BaseClient, cdc codec.Marshaler) Client { 17 | return recordClient{ 18 | BaseClient: bc, 19 | Marshaler: cdc, 20 | } 21 | } 22 | 23 | func (r recordClient) Name() string { 24 | return ModuleName 25 | } 26 | 27 | func (r recordClient) RegisterInterfaceTypes(registry types.InterfaceRegistry) { 28 | RegisterInterfaces(registry) 29 | } 30 | 31 | func (r recordClient) CreateRecord(request CreateRecordRequest, baseTx sdk.BaseTx) (string, sdk.Error) { 32 | creator, err := r.QueryAddress(baseTx.From, baseTx.Password) 33 | if err != nil { 34 | return "", sdk.Wrap(err) 35 | } 36 | 37 | msg := &MsgCreateRecord{ 38 | Contents: request.Contents, 39 | Creator: creator.String(), 40 | } 41 | 42 | res, err := r.BuildAndSend([]sdk.Msg{msg}, baseTx) 43 | if err != nil { 44 | return "", err 45 | } 46 | 47 | recordID, er := res.Events.GetValue(eventTypeCreateRecord, attributeKeyRecordID) 48 | if er != nil { 49 | return "", sdk.Wrap(er) 50 | } 51 | 52 | return recordID, nil 53 | } 54 | 55 | func (r recordClient) QueryRecord(request QueryRecordReq) (QueryRecordResp, sdk.Error) { 56 | rID, err := hex.DecodeString(request.RecordID) 57 | if err != nil { 58 | return QueryRecordResp{}, sdk.Wrapf("invalid record id, must be hex encoded string,but got %s", request.RecordID) 59 | } 60 | 61 | recordKey := GetRecordKey(rID) 62 | 63 | res, err := r.QueryStore(recordKey, ModuleName, request.Height, request.Prove) 64 | if err != nil { 65 | return QueryRecordResp{}, sdk.Wrap(err) 66 | } 67 | 68 | var record Record 69 | if err := r.Marshaler.UnmarshalBinaryBare(res.Value, &record); err != nil { 70 | return QueryRecordResp{}, sdk.Wrap(err) 71 | } 72 | 73 | result := record.Convert().(QueryRecordResp) 74 | 75 | var proof []byte 76 | if request.Prove { 77 | proof = r.MustMarshalJSON(res.ProofOps) 78 | } 79 | 80 | result.Proof = sdk.ProofValue{ 81 | Proof: proof, 82 | Path: []string{ModuleName, string(recordKey)}, 83 | Value: res.Value, 84 | } 85 | result.Height = res.Height 86 | return result, nil 87 | } 88 | -------------------------------------------------------------------------------- /proto/perm/tx.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.perm; 3 | 4 | import "perm/perm.proto"; 5 | import "gogoproto/gogo.proto"; 6 | 7 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/perm"; 8 | option (gogoproto.goproto_getters_all) = false; 9 | 10 | // Msg defines the perm Msg service. 11 | service Msg { 12 | // AssignRoles defines a method for assigning roles for the operator. 13 | rpc AssignRoles(MsgAssignRoles) returns (MsgAssignRolesResponse); 14 | 15 | // UnassignRoles defines a method for unassigning roles from the operator. 16 | rpc UnassignRoles(MsgUnassignRoles) returns (MsgUnassignRolesResponse); 17 | 18 | // BlockAccount defines a method for blocking an account 19 | rpc BlockAccount(MsgBlockAccount) returns (MsgBlockAccountResponse); 20 | 21 | // UnblockAccount defines a method for unblocking a blocked account 22 | rpc UnblockAccount(MsgUnblockAccount) returns (MsgUnblockAccountResponse); 23 | } 24 | 25 | // MsgAssignRoles defines an SDK message for assigning roles to an address. 26 | message MsgAssignRoles { 27 | option (gogoproto.equal) = true; 28 | 29 | string address = 1; 30 | repeated Role roles = 2; 31 | string operator = 3; 32 | } 33 | 34 | // MsgAssignRolesResponse defines the Msg/AssignRoles response type. 35 | message MsgAssignRolesResponse { } 36 | 37 | // MsgUnassignRoles defines an SDK message for unassigning roles from an address. 38 | message MsgUnassignRoles { 39 | option (gogoproto.equal) = true; 40 | 41 | string address = 1; 42 | repeated Role roles = 2; 43 | string operator = 3; 44 | } 45 | 46 | // MsgUnassignRolesResponse defines the Msg/UnassignRoles response type. 47 | message MsgUnassignRolesResponse { } 48 | 49 | // MsgBlockAccount defines an SDK message for blocking an account. 50 | message MsgBlockAccount { 51 | option (gogoproto.equal) = true; 52 | 53 | string address = 1; 54 | string operator = 2; 55 | } 56 | 57 | // MsgBlockAccountResponse defines the Msg/BlockAccount response type. 58 | message MsgBlockAccountResponse { } 59 | 60 | // MsgUnblockAccount defines an SDK message for unblocking an account. 61 | message MsgUnblockAccount { 62 | option (gogoproto.equal) = true; 63 | 64 | string address = 1; 65 | string operator = 2; 66 | } 67 | 68 | // MsgUnblockAccountResponse defines the Msg/UnblockAccount response type. 69 | message MsgUnblockAccountResponse { } 70 | -------------------------------------------------------------------------------- /codec/codec.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "github.com/gogo/protobuf/proto" 5 | 6 | "github.com/bianjieai/irita-sdk-go/codec/types" 7 | ) 8 | 9 | type ( 10 | // Marshaler defines the interface module codecs must implement in order to support 11 | // backwards compatibility with Amino while allowing custom Protobuf-based 12 | // serialization. Note, Amino can still be used without any dependency on 13 | // Protobuf. There are two typical implementations that fulfill this contract: 14 | // 15 | // 1. AminoCodec: Provides full Amino serialization compatibility. 16 | // 2. ProtoCodec: Provides full Protobuf serialization compatibility. 17 | Marshaler interface { 18 | BinaryMarshaler 19 | JSONMarshaler 20 | } 21 | 22 | BinaryMarshaler interface { 23 | MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) 24 | MustMarshalBinaryBare(o ProtoMarshaler) []byte 25 | 26 | MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) 27 | MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte 28 | 29 | UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error 30 | MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) 31 | 32 | UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error 33 | MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) 34 | 35 | types.AnyUnpacker 36 | } 37 | 38 | JSONMarshaler interface { 39 | MarshalJSON(o proto.Message) ([]byte, error) 40 | MustMarshalJSON(o proto.Message) []byte 41 | 42 | UnmarshalJSON(bz []byte, ptr proto.Message) error 43 | MustUnmarshalJSON(bz []byte, ptr proto.Message) 44 | } 45 | 46 | // ProtoMarshaler defines an interface a type must implement as protocol buffer 47 | // defined message. 48 | ProtoMarshaler interface { 49 | proto.Message // for JSON serialization 50 | 51 | Marshal() ([]byte, error) 52 | MarshalTo(data []byte) (n int, err error) 53 | MarshalToSizedBuffer(dAtA []byte) (int, error) 54 | Size() int 55 | Unmarshal(data []byte) error 56 | } 57 | 58 | // AminoMarshaler defines an interface where Amino marshalling can be 59 | // overridden by custom marshalling. 60 | AminoMarshaler interface { 61 | MarshalAmino() ([]byte, error) 62 | UnmarshalAmino([]byte) error 63 | MarshalAminoJSON() ([]byte, error) 64 | UnmarshalAminoJSON([]byte) error 65 | } 66 | 67 | // RegisterInterfaces defines an method for regisger inteface for registry 68 | RegisterInterfaces func(registry types.InterfaceRegistry) 69 | ) 70 | -------------------------------------------------------------------------------- /crypto/keys/secp256k1/internal/secp256k1/libsecp256k1/src/ecmult_gen.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_GEN_ 8 | #define _SECP256K1_ECMULT_GEN_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*G: 15 | * To harden against timing attacks, use the following mechanism: 16 | * * Break up the multiplicand into groups of 4 bits, called n_0, n_1, n_2, ..., n_63. 17 | * * Compute sum(n_i * 16^i * G + U_i, i=0..63), where: 18 | * * U_i = U * 2^i (for i=0..62) 19 | * * U_i = U * (1-2^63) (for i=63) 20 | * where U is a point with no known corresponding scalar. Note that sum(U_i, i=0..63) = 0. 21 | * For each i, and each of the 16 possible values of n_i, (n_i * 16^i * G + U_i) is 22 | * precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0..63). 23 | * None of the resulting prec group elements have a known scalar, and neither do any of 24 | * the intermediate sums while computing a*G. 25 | */ 26 | secp256k1_ge_storage (*prec)[64][16]; /* prec[j][i] = 16^j * i * G + U_i */ 27 | secp256k1_scalar blind; 28 | secp256k1_gej initial; 29 | } secp256k1_ecmult_gen_context; 30 | 31 | static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx); 32 | static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb); 33 | static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst, 34 | const secp256k1_ecmult_gen_context* src, const secp256k1_callback* cb); 35 | static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx); 36 | static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context* ctx); 37 | 38 | /** Multiply with the generator: R = a*G */ 39 | static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context* ctx, secp256k1_gej *r, const secp256k1_scalar *a); 40 | 41 | static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /proto/cosmos/auth/v1beta1/auth.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos.auth.v1beta1; 3 | 4 | import "cosmos_proto/cosmos.proto"; 5 | import "gogoproto/gogo.proto"; 6 | import "google/protobuf/any.proto"; 7 | 8 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/auth"; 9 | 10 | // BaseAccount defines a base account type. It contains all the necessary fields 11 | // for basic account functionality. Any custom account type should extend this 12 | // type for additional functionality (e.g. vesting). 13 | message BaseAccount { 14 | option (gogoproto.goproto_getters) = false; 15 | option (gogoproto.goproto_stringer) = false; 16 | option (gogoproto.equal) = false; 17 | 18 | option (cosmos_proto.implements_interface) = "AccountI"; 19 | 20 | string address = 1; 21 | google.protobuf.Any pub_key = 2 22 | [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""]; 23 | uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; 24 | uint64 sequence = 4; 25 | } 26 | 27 | // ModuleAccount defines an account for modules that holds coins on a pool. 28 | message ModuleAccount { 29 | option (gogoproto.goproto_getters) = false; 30 | option (gogoproto.goproto_stringer) = false; 31 | option (cosmos_proto.implements_interface) = "ModuleAccountI"; 32 | 33 | BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; 34 | string name = 2; 35 | repeated string permissions = 3; 36 | } 37 | 38 | // Params defines the parameters for the auth module. 39 | message Params { 40 | option (gogoproto.equal) = true; 41 | option (gogoproto.goproto_stringer) = false; 42 | 43 | uint64 max_memo_characters = 1 [(gogoproto.moretags) = "yaml:\"max_memo_characters\""]; 44 | uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; 45 | uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; 46 | uint64 sig_verify_cost_ed25519 = 4 47 | [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; 48 | uint64 sig_verify_cost_secp256k1 = 5 49 | [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; 50 | uint64 sig_verify_cost_sm2 = 6 51 | [(gogoproto.customname) = "SigVerifyCostSm2", (gogoproto.moretags) = "yaml:\"sig_verify_cost_sm2\""]; 52 | } 53 | -------------------------------------------------------------------------------- /proto/slashing/slashing.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package iritamod.slashing; 3 | 4 | import "gogoproto/gogo.proto"; 5 | import "google/protobuf/duration.proto"; 6 | import "google/protobuf/timestamp.proto"; 7 | 8 | option go_package = "github.com/bianjieai/irita-sdk-go/modules/slashing"; 9 | option (gogoproto.goproto_getters_all) = false; 10 | 11 | // ValidatorSigningInfo defines a validator's signing info for monitoring their liveness activity. 12 | message ValidatorSigningInfo { 13 | option (gogoproto.equal) = true; 14 | 15 | string address = 1 ; 16 | // height at which validator was first a candidate OR was unjailed 17 | int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; 18 | // index offset into signed block bit array 19 | int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; 20 | // timestamp validator cannot be unjailed until 21 | google.protobuf.Timestamp jailed_until = 4 22 | [(gogoproto.moretags) = "yaml:\"jailed_until\"", (gogoproto.stdtime) = true, (gogoproto.nullable) = false]; 23 | // whether or not a validator has been tombstoned (killed out of validator set) 24 | bool tombstoned = 5; 25 | // missed blocks counter (to avoid scanning the array every time) 26 | int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; 27 | } 28 | 29 | // Params represents the parameters used for by the slashing module. 30 | message Params { 31 | int64 signed_blocks_window = 1 [(gogoproto.moretags) = "yaml:\"signed_blocks_window\""]; 32 | bytes min_signed_per_window = 2 [ 33 | (gogoproto.moretags) = "yaml:\"min_signed_per_window\"", 34 | (gogoproto.customtype) = "github.com/bianjieai/irita-sdk-go/types.Dec", 35 | (gogoproto.nullable) = false 36 | ]; 37 | google.protobuf.Duration downtime_jail_duration = 3 [ 38 | (gogoproto.nullable) = false, 39 | (gogoproto.stdduration) = true, 40 | (gogoproto.moretags) = "yaml:\"downtime_jail_duration\"" 41 | ]; 42 | bytes slash_fraction_double_sign = 4 [ 43 | (gogoproto.moretags) = "yaml:\"slash_fraction_double_sign\"", 44 | (gogoproto.customtype) = "github.com/bianjieai/irita-sdk-go/types.Dec", 45 | (gogoproto.nullable) = false 46 | ]; 47 | bytes slash_fraction_downtime = 5 [ 48 | (gogoproto.moretags) = "yaml:\"slash_fraction_downtime\"", 49 | (gogoproto.customtype) = "github.com/bianjieai/irita-sdk-go/types.Dec", 50 | (gogoproto.nullable) = false 51 | ]; 52 | } -------------------------------------------------------------------------------- /types/coin_type.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | ) 7 | 8 | type Unit struct { 9 | Denom string `json:"denom"` //denom of unit 10 | Scale uint8 `json:"scale"` //scale of unit 11 | } 12 | 13 | func NewUnit(denom string, scale uint8) Unit { 14 | return Unit{ 15 | Denom: denom, 16 | Scale: scale, 17 | } 18 | } 19 | 20 | //GetScaleFactor return 1 * 10^scale 21 | func (u Unit) GetScaleFactor() Int { 22 | return NewIntWithDecimal(1, int(u.Scale)) 23 | } 24 | 25 | type CoinType struct { 26 | Name string `json:"name"` //description name of CoinType 27 | MinUnit Unit `json:"min_unit"` //the min unit of CoinType 28 | MainUnit Unit `json:"main_unit"` //the max unit of CoinType 29 | Desc string `json:"desc"` //the description of CoinType 30 | } 31 | 32 | //ToMainCoin return the main denom coin from args 33 | func (ct CoinType) ConvertToMainCoin(coin Coin) (DecCoin, error) { 34 | if !ct.hasUnit(coin.Denom) { 35 | return DecCoin{}, errors.New("coinType unit (%s) not defined" + coin.Denom) 36 | } 37 | 38 | if ct.isMainUnit(coin.Denom) { 39 | return DecCoin{}, nil 40 | } 41 | 42 | // dest amount = src amount * (10^(dest scale) / 10^(src scale)) 43 | dstScale := NewDecFromInt(ct.MainUnit.GetScaleFactor()) 44 | srcScale := NewDecFromInt(ct.MinUnit.GetScaleFactor()) 45 | amount := NewDecFromInt(coin.Amount) 46 | 47 | amt := amount.Mul(dstScale).Quo(srcScale) 48 | return NewDecCoinFromDec(ct.MainUnit.Denom, amt), nil 49 | } 50 | 51 | //ToMinCoin return the min denom coin from args 52 | func (ct CoinType) ConvertToMinCoin(coin DecCoin) (newCoin Coin, err error) { 53 | if !ct.hasUnit(coin.Denom) { 54 | return newCoin, errors.New("coinType unit (%s) not defined" + coin.Denom) 55 | } 56 | 57 | if ct.isMinUnit(coin.Denom) { 58 | newCoin, _ := coin.TruncateDecimal() 59 | return newCoin, nil 60 | } 61 | 62 | // dest amount = src amount * (10^(dest scale) / 10^(src scale)) 63 | srcScale := NewDecFromInt(ct.MainUnit.GetScaleFactor()) 64 | dstScale := NewDecFromInt(ct.MinUnit.GetScaleFactor()) 65 | amount := coin.Amount 66 | 67 | amt := amount.Mul(dstScale).Quo(srcScale) 68 | return NewCoin(ct.MinUnit.Denom, amt.RoundInt()), nil 69 | } 70 | 71 | func (ct CoinType) isMainUnit(name string) bool { 72 | return ct.MainUnit.Denom == strings.TrimSpace(name) 73 | } 74 | 75 | func (ct CoinType) isMinUnit(name string) bool { 76 | return ct.MinUnit.Denom == strings.TrimSpace(name) 77 | } 78 | 79 | func (ct CoinType) hasUnit(name string) bool { 80 | return ct.isMainUnit(name) || ct.isMinUnit(name) 81 | } 82 | -------------------------------------------------------------------------------- /types/tx_msg.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/gogo/protobuf/proto" 5 | 6 | "github.com/tendermint/tendermint/crypto" 7 | ) 8 | 9 | type ( 10 | // Msg defines the interface a transaction message must fulfill. 11 | Msg interface { 12 | proto.Message 13 | 14 | // Return the message type. 15 | // Must be alphanumeric or empty. 16 | Route() string 17 | 18 | // Returns a human-readable string for the message, intended for utilization 19 | // within tags 20 | Type() string 21 | 22 | // ValidateBasic does a simple validation check that 23 | // doesn't require access to any other information. 24 | ValidateBasic() error 25 | 26 | // Get the canonical byte representation of the Msg. 27 | GetSignBytes() []byte 28 | 29 | // Signers returns the addrs of signers that must sign. 30 | // CONTRACT: All signatures must be present to be valid. 31 | // CONTRACT: Returns addrs in some deterministic order. 32 | GetSigners() []AccAddress 33 | } 34 | 35 | // Fee defines an interface for an application application-defined concrete 36 | // transaction type to be able to set and return the transaction fee. 37 | Fee interface { 38 | GetGas() uint64 39 | GetAmount() Coins 40 | } 41 | 42 | // Signature defines an interface for an application application-defined 43 | // concrete transaction type to be able to set and return transaction signatures. 44 | Signature interface { 45 | GetPubKey() crypto.PubKey 46 | GetSignature() []byte 47 | } 48 | 49 | // Tx defines the interface a transaction must fulfill. 50 | Tx interface { 51 | // Gets the all the transaction's messages. 52 | GetMsgs() []Msg 53 | 54 | // ValidateBasic does a simple and lightweight validation check that doesn't 55 | // require access to any other information. 56 | ValidateBasic() error 57 | } 58 | 59 | // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators 60 | FeeTx interface { 61 | Tx 62 | GetGas() uint64 63 | GetFee() Coins 64 | FeePayer() AccAddress 65 | } 66 | 67 | // Tx must have GetMemo() method to use ValidateMemoDecorator 68 | TxWithMemo interface { 69 | Tx 70 | GetMemo() string 71 | } 72 | 73 | // TxWithTimeoutHeight extends the Tx interface by allowing a transaction to 74 | // set a height timeout. 75 | TxWithTimeoutHeight interface { 76 | Tx 77 | 78 | GetTimeoutHeight() uint64 79 | } 80 | ) 81 | 82 | // TxDecoder unmarshals transaction bytes 83 | type TxDecoder func(txBytes []byte) (Tx, error) 84 | 85 | // TxEncoder marshals transaction to bytes 86 | type TxEncoder func(tx Tx) ([]byte, error) 87 | --------------------------------------------------------------------------------