@@ -3,54 +3,41 @@ import * as base64 from 'base64-js';
3
3
import { KeyPair } from '../../internal/KeyPair' ;
4
4
5
5
describe ( 'KeyPair tests' , ( ) => {
6
- it ( 'should create private key from seed and back' , async function ( ) {
7
- // arrange
8
- const sk = 'z1x3cVXhk9nJKE1pZaX9KxccUBzxu3aGlaUjDdAB2oY=' ;
9
-
10
- // act
11
- const keyPair = await KeyPair . fromEd25519SK ( sk ) ;
12
- const privateKey = keyPair . toEd25519PrivateKey ( ) ;
13
- const sk2 = base64 . fromByteArray ( privateKey )
14
-
15
- // assert
16
- expect ( sk2 ) . toBe ( sk ) ;
17
- } ) ;
18
-
19
6
it ( 'generate keypair from seed' , async function ( ) {
20
7
// arrange
21
8
const random = await KeyPair . randomEd25519 ( ) ;
22
9
const privateKey = random . toEd25519PrivateKey ( ) ;
23
10
24
11
// act
25
- const keyPair = await KeyPair . fromBytes ( privateKey ) ;
12
+ const keyPair = await KeyPair . fromEd25519SK ( privateKey ) ;
26
13
const privateKey2 = keyPair . toEd25519PrivateKey ( ) ;
27
14
28
15
// assert
29
16
expect ( privateKey ) . toStrictEqual ( privateKey2 ) ;
30
17
} ) ;
31
18
32
- it ( 'create keypair from ed25519 private key' , async function ( ) {
19
+ it ( 'create keypair from ed25519 private key' , async function ( ) {
33
20
// arrange
34
- const rustSK = " jDaxLJzYtzgwTMrELJCAqavtmx85ktQNfB2rLcK7MhH" ;
21
+ const rustSK = ' jDaxLJzYtzgwTMrELJCAqavtmx85ktQNfB2rLcK7MhH' ;
35
22
const sk = bs58 . decode ( rustSK ) ;
36
23
37
24
// act
38
- const keyPair = await KeyPair . fromBytes ( sk ) ;
25
+ const keyPair = await KeyPair . fromEd25519SK ( sk ) ;
39
26
40
27
// assert
41
- const expectedPeerId = " 12D3KooWH1W3VznVZ87JH4FwABK4mkntcspTVWJDta6c2xg9Pzbp" ;
28
+ const expectedPeerId = ' 12D3KooWH1W3VznVZ87JH4FwABK4mkntcspTVWJDta6c2xg9Pzbp' ;
42
29
expect ( keyPair . Libp2pPeerId . toB58String ( ) ) . toStrictEqual ( expectedPeerId ) ;
43
30
} ) ;
44
31
45
- it ( 'create keypair from a seed phrase' , async function ( ) {
32
+ it ( 'create keypair from a seed phrase' , async function ( ) {
46
33
// arrange
47
34
const seedArray = new Uint8Array ( 32 ) . fill ( 1 ) ;
48
-
35
+
49
36
// act
50
- const keyPair = await KeyPair . fromBytes ( seedArray ) ;
37
+ const keyPair = await KeyPair . fromEd25519SK ( seedArray ) ;
51
38
52
39
// assert
53
- const expectedPeerId = " 12D3KooWK99VoVxNE7XzyBwXEzW7xhK7Gpv85r9F3V3fyKSUKPH5" ;
40
+ const expectedPeerId = ' 12D3KooWK99VoVxNE7XzyBwXEzW7xhK7Gpv85r9F3V3fyKSUKPH5' ;
54
41
expect ( keyPair . Libp2pPeerId . toB58String ( ) ) . toStrictEqual ( expectedPeerId ) ;
55
42
} ) ;
56
43
} ) ;
0 commit comments