forked from hyperledger-archives/aries-framework-go
/
secp256k1_key_templates.go
64 lines (54 loc) · 2.17 KB
/
secp256k1_key_templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package secp256k1
import (
"github.com/golang/protobuf/proto"
commonpb "github.com/google/tink/go/proto/common_go_proto"
tinkpb "github.com/google/tink/go/proto/tink_go_proto"
secp256k1pb "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/proto/secp256k1_go_proto"
)
// This file contains pre-generated KeyTemplates for Signer and Verifier.
// One can use these templates to generate new Keysets.
// DERKeyTemplate is a KeyTemplate that generates a new ECDSA secp256k1 private key with the following parameters:
// - Hash function: SHA256
// - Curve: secp256k1
// - Signature encoding: DER
// - Output prefix type: TINK
func DERKeyTemplate() (*tinkpb.KeyTemplate, error) {
return createECDSAKeyTemplate(commonpb.HashType_SHA256,
secp256k1pb.BitcoinCurveType_SECP256K1,
secp256k1pb.Secp256K1SignatureEncoding_Bitcoin_DER,
tinkpb.OutputPrefixType_TINK)
}
// IEEEP1363KeyTemplate is a KeyTemplate that generates a new ECDSA secp256k1 private key with the following parameters:
// - Hash function: SHA256
// - Curve: secp256k1
// - Signature encoding: IEEE-P1363
// - Output prefix type: TINK
func IEEEP1363KeyTemplate() (*tinkpb.KeyTemplate, error) {
return createECDSAKeyTemplate(commonpb.HashType_SHA256,
secp256k1pb.BitcoinCurveType_SECP256K1,
secp256k1pb.Secp256K1SignatureEncoding_Bitcoin_IEEE_P1363,
tinkpb.OutputPrefixType_TINK)
}
// createECDSAKeyTemplate creates a KeyTemplate containing a Secp256K1KeyFormat with the given parameters.
func createECDSAKeyTemplate(hashType commonpb.HashType, curve secp256k1pb.BitcoinCurveType,
encoding secp256k1pb.Secp256K1SignatureEncoding, prefixType tinkpb.OutputPrefixType) (*tinkpb.KeyTemplate, error) {
params := &secp256k1pb.Secp256K1Params{
HashType: hashType,
Curve: curve,
Encoding: encoding,
}
format := &secp256k1pb.Secp256K1KeyFormat{Params: params}
serializedFormat, err := proto.Marshal(format)
if err != nil {
return nil, err
}
return &tinkpb.KeyTemplate{
TypeUrl: secp256k1SignerTypeURL,
Value: serializedFormat,
OutputPrefixType: prefixType,
}, nil
}