auth

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BCE_AUTH_VERSION        = "bce-auth-v1"
	SIGN_JOINER             = "\n"
	SIGN_HEADER_JOINER      = ";"
	DEFAULT_EXPIRE_SECONDS  = 1800
	DEFAULT_HEADERS_TO_SIGN = map[string]struct{}{
		strings.ToLower("Host"):           {},
		strings.ToLower("Content-Length"): {},
		strings.ToLower("Content-Type"):   {},
		strings.ToLower("Content-Md5"):    {},
	}
)

Functions

func AesDecrypt added in v1.0.12

func AesDecrypt(crypted, key []byte) ([]byte, error)

解密

func AesEncrypt added in v1.0.12

func AesEncrypt(origData, key []byte) ([]byte, error)

加密

func Base64UrlDecode added in v1.0.12

func Base64UrlDecode(content string) ([]byte, error)

func Base64UrlEncode added in v1.0.12

func Base64UrlEncode(content []byte) string

func CheckSign

func CheckSign(req *http.Request, cred *Credentials) error

CheckSign - 校验签名

func DecodeSign

func DecodeSign(signature string) ([]byte, error)

将16进制字符串显示转换为byte

func EncodeSign

func EncodeSign(src []byte) string

将byte转换为16进制字符串显示

func GetAddrByPubKey

func GetAddrByPubKey(key *ecdsa.PublicKey) (string, error)

使用单个公钥来生成钱包地址

func GetEcdsaPriKeyByJsStr

func GetEcdsaPriKeyByJsStr(keyStr string) (*ecdsa.PrivateKey, error)

从json格式私钥内容字符串产生ECC私钥

func GetEcdsaPubKeyByJsStr

func GetEcdsaPubKeyByJsStr(keyStr string) (*ecdsa.PublicKey, error)

从json格式公钥内容字符串产生ECC公钥

func HashBySha256

func HashBySha256(data []byte) []byte

使用SHA256做单次哈希运算

func InferLanguage added in v1.0.42

func InferLanguage(mnemonic string) int

InferLanguage 根据助记词推测语言

如果推测失败,返回 0
这里不做合法性检查,仅推测可能值

func PKCS7Padding added in v1.0.12

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding added in v1.0.12

func PKCS7UnPadding(origData []byte) []byte

func Sign

func Sign(req *http.Request, cred *Credentials, opt *SignOptions) (string, error)

Sign - 签名

PARAMS:

  • req: *http.Request for this sign
  • cred: *BceCredentials to access the serice
  • opt: *SignOptions for this sign algorithm

func SignECDSA

func SignECDSA(k *ecdsa.PrivateKey, msg []byte) ([]byte, error)

使用ECC私钥来签名

func VerifyAddrByPubKey

func VerifyAddrByPubKey(address string, pub *ecdsa.PublicKey) (bool, uint8)

验证钱包地址和公钥是否匹配

func VerifyECDSA

func VerifyECDSA(k *ecdsa.PublicKey, signature, msg []byte) (bool, error)

使用ECC公钥来验证签名,验证统一签名的新签名函数

func XassetSignECDSA

func XassetSignECDSA(jsPrivtKey string, oriMsg []byte) (string, error)

xasset签名完整方法 @jsPrivtKey: json格式的private key @oriMsg: 签名的原始数据

func XassetVerifyECDSA

func XassetVerifyECDSA(jsPubKey, signature string, oriMsg []byte) (bool, error)

xasset校验签名完整方法 @jsPubKey: json格式public key @oriMsg: 签名的原始数据

Types

type Account

type Account struct {
	// 钱包地址
	Address string `json:"address,omitempy"`
	// 私钥
	PrivateKey string `json:"private_key,omitempy"`
	// 公钥
	PublicKey string `json:"public_key,omitempy"`
	// 助记词
	Mnemonic string `json:"mnemonic,omitempy"`
}

func NewXchainEcdsaAccount

func NewXchainEcdsaAccount(strg MnemStrgth, lang MnemLang) (*Account, error)

新创建xuperchain ecdsa账户

func RetrieveAccountByMnemonic added in v1.0.2

func RetrieveAccountByMnemonic(mnemonic string, language int) (*Account, error)

根据助记词生成历史账户

type Credentials

type Credentials struct {
	AppId           int64  // app id
	AccessKeyId     string // access key id to the service
	SecretAccessKey string // secret access key to the service
}

func (*Credentials) String

func (t *Credentials) String() string

type MnemLang

type MnemLang int

助记词语言:英文、中文

const (

	// 1:中文
	MnemLangCN MnemLang
	// 2:英文
	MnemLangEN
)

type MnemStrgth

type MnemStrgth int

助记词强度:弱、中、强

const (

	// 1:弱(12个助记词)
	MnemStrgthWeak MnemStrgth
	// 2:中(18个助记词)
	MnemStrgthMedium
	// 3:强(24个助记词)
	MnemStrgthStrong
)

type SignOptions

type SignOptions struct {
	HeadersToSign map[string]struct{}
	Timestamp     int64
	ExpireSeconds int
}

SignOptions defines the data structure used by Signer

func (*SignOptions) String

func (t *SignOptions) String() string

Jump to

Keyboard shortcuts

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