File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,27 @@ library Secp256r1 {
6
6
function isScalar (uint256 scalar ) internal pure returns (bool ) {
7
7
return scalar > 0 && scalar < ORDER;
8
8
}
9
+
10
+ function encodeScalarPkcs8Der (uint256 scalar ) internal pure returns (bytes memory ) {
11
+ // PrivateKeyInfo ::= SEQUENCE {
12
+ // version Version,
13
+ // privateKeyAlgorithm AlgorithmIdentifier,
14
+ // privateKey OCTET STRING,
15
+ // attributes [0] IMPLICIT Attributes OPTIONAL }
16
+ //
17
+ // 30 81 41 ; SEQUENCE (0x41 bytes)
18
+ // 02 01 00 ; INTEGER (0)
19
+ // 30 13 ; SEQUENCE (0x13 bytes)
20
+ // 06 07 ; OBJECT IDENTIFIER (ecdsaWithSHA1)
21
+ // 2A 86 48 CE 3D 02 01
22
+ // 06 08 ; OBJECT IDENTIFIER (prime256v1)
23
+ // 2A 86 48 CE 3D 03 01 07
24
+ // 04 27 ; OCTET STRING (0x27 bytes)
25
+ // 30 25 ; SEQUENCE (0x25 bytes)
26
+ // 02 01 01 ; INTEGER (1)
27
+ // 04 20 ; OCTET STRING (32 bytes)
28
+ // <32 byte private key>
29
+ return
30
+ bytes .concat (hex "308141020100301306072a8648ce3d020106082a8648ce3d030107042730250201010420 " , bytes32 (scalar));
31
+ }
9
32
}
You can’t perform that action at this time.
0 commit comments