当前位置: 首页>>代码示例>>Golang>>正文


Golang chainec.PublicKey类代码示例

本文整理汇总了Golang中github.com/decred/dcrd/chaincfg/chainec.PublicKey的典型用法代码示例。如果您正苦于以下问题:Golang PublicKey类的具体用法?Golang PublicKey怎么用?Golang PublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PublicKey类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newManagedAddressWithoutPrivKey

// newManagedAddressWithoutPrivKey returns a new managed address based on the
// passed account, public key, and whether or not the public key should be
// compressed.
func newManagedAddressWithoutPrivKey(m *Manager, account uint32, pubKey chainec.PublicKey, compressed bool) (*managedAddress, error) {
	// Create a pay-to-pubkey-hash address from the public key.
	var pubKeyHash []byte
	if compressed {
		pubKeyHash = dcrutil.Hash160(pubKey.SerializeCompressed())
	} else {
		pubKeyHash = dcrutil.Hash160(pubKey.SerializeUncompressed())
	}
	address, err := dcrutil.NewAddressPubKeyHash(pubKeyHash, m.chainParams,
		chainec.ECTypeSecp256k1)
	if err != nil {
		return nil, err
	}

	return &managedAddress{
		manager:          m,
		address:          address,
		account:          account,
		imported:         false,
		internal:         false,
		multisig:         false,
		compressed:       compressed,
		pubKey:           pubKey,
		privKeyEncrypted: nil,
		privKeyCT:        nil,
	}, nil
}
开发者ID:decred,项目名称:dcrwallet,代码行数:30,代码来源:address.go

示例2: Exists

// Exists returns true if an existing entry of 'sig' over 'sigHash' for public
// key 'pubKey' is found within the SigCache. Otherwise, false is returned.
//
// NOTE: This function is safe for concurrent access. Readers won't be blocked
// unless there exists a writer, adding an entry to the SigCache.
func (s *SigCache) Exists(sigHash chainhash.Hash, sig chainec.Signature, pubKey chainec.PublicKey) bool {
	info := sigInfo{sigHash, string(sig.Serialize()),
		string(pubKey.SerializeCompressed())}

	s.RLock()
	_, ok := s.validSigs[info]
	s.RUnlock()
	return ok
}
开发者ID:alexlyp,项目名称:dcrd,代码行数:14,代码来源:sigcache.go

示例3: Exists

// Exists returns true if an existing entry of 'sig' over 'sigHash' for public
// key 'pubKey' is found within the SigCache. Otherwise, false is returned.
//
// NOTE: This function is safe for concurrent access. Readers won't be blocked
// unless there exists a writer, adding an entry to the SigCache.
func (s *SigCache) Exists(sigHash chainhash.Hash, sig chainec.Signature, pubKey chainec.PublicKey) bool {
	s.RLock()
	defer s.RUnlock()

	if entry, ok := s.validSigs[sigHash]; ok {
		pkEqual := bytes.Equal(entry.pubKey.SerializeCompressed(),
			pubKey.SerializeCompressed())
		sigEqual := bytes.Equal(entry.sig.Serialize(), sig.Serialize())
		return pkEqual && sigEqual
	}

	return false
}
开发者ID:decred,项目名称:dcrd,代码行数:18,代码来源:sigcache.go

示例4: SerializePubKey

// SerializePubKey serializes the associated public key of the imported or
// exported private key in compressed format.  The serialization format
// chosen depends on the value of w.ecType.
func (w *WIF) SerializePubKey() []byte {
	pkx, pky := w.PrivKey.Public()
	var pk chainec.PublicKey

	switch w.ecType {
	case chainec.ECTypeSecp256k1:
		pk = chainec.Secp256k1.NewPublicKey(pkx, pky)
	case chainec.ECTypeEdwards:
		pk = chainec.Edwards.NewPublicKey(pkx, pky)
	case chainec.ECTypeSecSchnorr:
		pk = chainec.SecSchnorr.NewPublicKey(pkx, pky)
	}

	return pk.SerializeCompressed()
}
开发者ID:alexlyp,项目名称:dcrutil,代码行数:18,代码来源:wif.go

示例5: Add

// Add adds an entry for a signature over 'sigHash' under public key 'pubKey'
// to the signature cache. In the event that the SigCache is 'full', an
// existing entry it randomly chosen to be evicted in order to make space for
// the new entry.
//
// NOTE: This function is safe for concurrent access. Writers will block
// simultaneous readers until function execution has concluded.
func (s *SigCache) Add(sigHash chainhash.Hash, sig chainec.Signature, pubKey chainec.PublicKey) {
	s.Lock()
	defer s.Unlock()

	if s.maxEntries <= 0 {
		return
	}

	// If adding this new entry will put us over the max number of allowed
	// entries, then evict an entry.
	if uint(len(s.validSigs)+1) > s.maxEntries {
		// Generate a cryptographically random hash.
		randHashBytes := make([]byte, chainhash.HashSize)
		_, err := rand.Read(randHashBytes)
		if err != nil {
			// Failure to read a random hash results in the proposed
			// entry not being added to the cache since we are
			// unable to evict any existing entries.
			return
		}

		// Try to find the first entry that is greater than the random
		// hash. Use the first entry (which is already pseudo random due
		// to Go's range statement over maps) as a fall back if none of
		// the hashes in the rejected transactions pool are larger than
		// the random hash.
		var foundEntry sigInfo
		for sigEntry := range s.validSigs {
			if foundEntry.sig == "" {
				foundEntry = sigEntry
			}
			if bytes.Compare(sigEntry.sigHash.Bytes(), randHashBytes) > 0 {
				foundEntry = sigEntry
				break
			}
		}
		delete(s.validSigs, foundEntry)
	}

	info := sigInfo{sigHash, string(sig.Serialize()),
		string(pubKey.SerializeCompressed())}
	s.validSigs[info] = struct{}{}
}
开发者ID:alexlyp,项目名称:dcrd,代码行数:50,代码来源:sigcache.go

示例6: SignatureScriptAlt

// SignatureScriptAlt creates an input signature script for tx to spend coins sent
// from a previous output to the owner of privKey. tx must include all
// transaction inputs and outputs, however txin scripts are allowed to be filled
// or empty. The returned script is calculated to be used as the idx'th txin
// sigscript for tx. subscript is the PkScript of the previous output being used
// as the idx'th input. privKey is serialized in the respective format for the
// ECDSA type. This format must match the same format used to generate the payment
// address, or the script validation will fail.
func SignatureScriptAlt(tx *wire.MsgTx, idx int, subscript []byte,
	hashType SigHashType, privKey chainec.PrivateKey, compress bool,
	sigType int) ([]byte,
	error) {
	sig, err := RawTxInSignatureAlt(tx, idx, subscript, hashType, privKey,
		sigTypes(sigType))
	if err != nil {
		return nil, err
	}

	pubx, puby := privKey.Public()
	var pub chainec.PublicKey
	switch sigTypes(sigType) {
	case edwards:
		pub = chainec.Edwards.NewPublicKey(pubx, puby)
	case secSchnorr:
		pub = chainec.SecSchnorr.NewPublicKey(pubx, puby)
	}
	pkData := pub.Serialize()

	return NewScriptBuilder().AddData(sig).AddData(pkData).Script()
}
开发者ID:ironbits,项目名称:dcrd,代码行数:30,代码来源:sign.go


注:本文中的github.com/decred/dcrd/chaincfg/chainec.PublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。