Skip to content

Commit b54a596

Browse files
committed
更新
1 parent 71bf45b commit b54a596

34 files changed

+4083
-12
lines changed

cryptobin/bip0340/bip0340.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package bip0340
2+
3+
import (
4+
"hash"
5+
"crypto/elliptic"
6+
"crypto/sha256"
7+
8+
"github.com/deatil/go-cryptobin/pubkey/bip0340"
9+
"github.com/deatil/go-cryptobin/elliptic/secp256k1"
10+
)
11+
12+
type (
13+
// HashFunc
14+
HashFunc = func() hash.Hash
15+
)
16+
17+
// 数据编码方式
18+
// marshal data type
19+
type EncodingType uint
20+
21+
const (
22+
EncodingASN1 EncodingType = 1 + iota
23+
EncodingBytes
24+
)
25+
26+
/**
27+
* BIP0340
28+
*
29+
* @create 2024-12-24
30+
* @author deatil
31+
*/
32+
type BIP0340 struct {
33+
// 私钥
34+
privateKey *bip0340.PrivateKey
35+
36+
// 公钥
37+
publicKey *bip0340.PublicKey
38+
39+
// 生成类型
40+
curve elliptic.Curve
41+
42+
// 签名验证类型
43+
signHash HashFunc
44+
45+
// 数据编码方式
46+
encoding EncodingType
47+
48+
// [私钥/公钥]数据
49+
keyData []byte
50+
51+
// 传入数据
52+
data []byte
53+
54+
// 解析后的数据
55+
parsedData []byte
56+
57+
// 验证结果
58+
verify bool
59+
60+
// 错误
61+
Errors []error
62+
}
63+
64+
// 构造函数
65+
func NewBIP0340() BIP0340 {
66+
return BIP0340{
67+
curve: secp256k1.S256(),
68+
signHash: sha256.New,
69+
verify: false,
70+
Errors: make([]error, 0),
71+
}
72+
}
73+
74+
// 构造函数
75+
func New() BIP0340 {
76+
return NewBIP0340()
77+
}
78+
79+
var (
80+
// 默认
81+
defaultBIP0340 = NewBIP0340()
82+
)

0 commit comments

Comments
 (0)