1
1
import * as Crypto from '@cardano-sdk/crypto' ;
2
2
import { AsyncKeyAgent } from '@cardano-sdk/key-management' ;
3
- import { Cardano } from '@cardano-sdk/core' ;
3
+ import { Cardano , Serialization } from '@cardano-sdk/core' ;
4
4
5
+ import { HexBlob } from '@cardano-sdk/util' ;
5
6
import { getWalletId } from '../../src' ;
6
7
7
8
describe ( 'getWalletId' , ( ) => {
@@ -22,27 +23,48 @@ describe('getWalletId', () => {
22
23
) ;
23
24
} ) ;
24
25
25
- it ( 'creates unique id for different networkId ' , async ( ) => {
26
+ it ( 'can create unique id for key agents ' , async ( ) => {
26
27
const id1 = await getWalletId ( mockKeyAgent ) ;
27
- chainId . networkId = Cardano . NetworkId . Mainnet ;
28
+ pubKey = Crypto . Bip32PublicKeyHex (
29
+ // eslint-disable-next-line max-len
30
+ '4e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
31
+ ) ;
28
32
const id2 = await getWalletId ( mockKeyAgent ) ;
29
33
expect ( id1 ) . not . toEqual ( id2 ) ;
30
34
} ) ;
31
35
32
- it ( 'creates unique id for different networkMagic' , async ( ) => {
33
- const id1 = await getWalletId ( mockKeyAgent ) ;
34
- chainId . networkMagic = Cardano . NetworkMagics . Mainnet ;
35
- const id2 = await getWalletId ( mockKeyAgent ) ;
36
+ it ( 'can create unique id for public keys' , async ( ) => {
37
+ const id1 = await getWalletId (
38
+ Crypto . Bip32PublicKeyHex (
39
+ // eslint-disable-next-line max-len
40
+ '3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
41
+ )
42
+ ) ;
43
+ const id2 = await getWalletId (
44
+ Crypto . Bip32PublicKeyHex (
45
+ // eslint-disable-next-line max-len
46
+ '4e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
47
+ )
48
+ ) ;
36
49
expect ( id1 ) . not . toEqual ( id2 ) ;
37
50
} ) ;
38
51
39
- it ( 'create unique id for different public keys' , async ( ) => {
40
- const id1 = await getWalletId ( mockKeyAgent ) ;
41
- pubKey = Crypto . Bip32PublicKeyHex (
42
- // eslint-disable-next-line max-len
43
- '4e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
44
- ) ;
45
- const id2 = await getWalletId ( mockKeyAgent ) ;
52
+ it ( 'can create unique id for scripts' , async ( ) => {
53
+ const script = Serialization . Script . fromCbor (
54
+ HexBlob (
55
+ '82008202828200581cb275b08c999097247f7c17e77007c7010cd19f20cc086ad99d3985388201838205190bb88200581c966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c378204190fa0'
56
+ )
57
+ ) . toCore ( ) ;
58
+
59
+ const nativeScript : Cardano . Script = {
60
+ __type : Cardano . ScriptType . Native ,
61
+ keyHash : Crypto . Ed25519KeyHashHex ( 'b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538' ) ,
62
+ kind : Cardano . NativeScriptKind . RequireSignature
63
+ } ;
64
+
65
+ const id1 = await getWalletId ( script ) ;
66
+ const id2 = await getWalletId ( nativeScript ) ;
67
+
46
68
expect ( id1 ) . not . toEqual ( id2 ) ;
47
69
} ) ;
48
70
} ) ;
0 commit comments