@@ -9,63 +9,92 @@ const CommandApdu = api.CommandApdu;
9
9
10
10
const devices = new Devices ( ) ;
11
11
12
-
13
- devices . on ( 'device-activated' , event => {
14
- const currentDevices = event . devices ;
15
- let device = event . device ;
16
- console . log ( `Device '${ device } ' activated, devices: ${ currentDevices } ` ) ;
17
- currentDevices . map ( ( device , index ) => {
18
- console . log ( `Device #${ index + 1 } : ${ device . name } ` ) ;
12
+ devices . on ( 'device-activated' , ( event ) => {
13
+ const currentDevices = event . devices ;
14
+ let device = event . device ;
15
+ console . log ( `Device '${ device } ' activated, devices: ${ currentDevices } ` ) ;
16
+ currentDevices . map ( ( device , index ) => {
17
+ console . log ( `Device #${ index + 1 } : ${ device . name } ` ) ;
18
+ } ) ;
19
+
20
+ device . on ( 'card-inserted' , ( event ) => {
21
+ let card = event . card ;
22
+ console . log ( `\nCard '${ card . getAtr ( ) } ' inserted into '${ event . device } '` ) ;
23
+
24
+ card . on ( 'command-issued' , ( event ) => {
25
+ console . log ( `Command '${ event . command } ' issued to '${ event . card } ' ` ) ;
19
26
} ) ;
20
27
28
+ card . on ( 'response-received' , ( event ) => {
29
+ console . log (
30
+ `Response '${ event . response } ' received from '${ event . card } ' in response to '${ event . command } '`
31
+ ) ;
32
+ } ) ;
21
33
22
- device . on ( 'card-inserted' , event => {
23
- let card = event . card ;
24
- console . log ( `\nCard '${ card . getAtr ( ) } ' inserted into '${ event . device } '` ) ;
25
-
26
- card . on ( 'command-issued' , event => {
27
- console . log ( `Command '${ event . command } ' issued to '${ event . card } ' ` ) ;
28
- } ) ;
29
-
30
- card . on ( 'response-received' , event => {
31
- console . log ( `Response '${ event . response } ' received from '${ event . card } ' in response to '${ event . command } '` ) ;
32
- } ) ;
33
-
34
- // card
35
- // .issueCommand('00A404000E315041592E5359532E444446303100')
36
- // .then((response) => {
37
- // console.log(`Response '${response.toString('hex')}`);
38
- // }).catch((error) => {
39
- // console.error(error);
40
- // });
41
-
42
- const application = new Iso7816Application ( card ) ;
34
+ // card
35
+ // .issueCommand('00A404000E315041592E5359532E444446303100')
36
+ // .then((response) => {
37
+ // console.log(`Response '${response.toString('hex')}`);
38
+ // }).catch((error) => {
39
+ // console.error(error);
40
+ // });
43
41
44
- application . on ( 'application-selected' , event => {
45
- console . log ( `Application Selected ${ event . application } ` ) ;
46
- } ) ;
42
+ const application = new Iso7816Application ( card ) ;
47
43
48
- application . selectFile ( [ 0x31 , 0x50 , 0x41 , 0x59 , 0x2E , 0x53 , 0x59 , 0x53 , 0x2E , 0x44 , 0x44 , 0x46 , 0x30 , 0x31 ] )
49
- . then ( ( response ) => {
50
- console . info ( `Select PSE Response: '${ response } ' '${ response . meaning ( ) } '` ) ;
51
- return application . selectFile ( hexify . toByteArray ( 'a0000000041010' ) ) ;
52
- } ) . then ( ( response ) => {
53
- console . info ( `Select Application Response: '${ response } ' '${ response . meaning ( ) } '` ) ;
54
- return application . issueCommand ( new CommandApdu ( { bytes : [ 0x80 , 0xa8 , 0x00 , 0x00 , 0x02 , 0x83 , 0x00 , 0x00 ] } ) ) ;
55
- } ) . then ( ( response ) => {
56
- console . info ( `Get Processing Options Response: '${ response } ' '${ response . meaning ( ) } '` ) ;
57
- return response ;
58
- } ) . catch ( ( error ) => {
59
- console . error ( 'Error:' , error , error . stack ) ;
60
- } ) ;
61
- } ) ;
62
- device . on ( 'card-removed' , event => {
63
- console . log ( `Card ${ event . card } removed from '${ event . name } ' ` ) ;
44
+ application . on ( 'application-selected' , ( event ) => {
45
+ console . log ( `Application Selected ${ event . application } ` ) ;
64
46
} ) ;
65
47
48
+ application
49
+ . selectFile ( [
50
+ 0x31 ,
51
+ 0x50 ,
52
+ 0x41 ,
53
+ 0x59 ,
54
+ 0x2e ,
55
+ 0x53 ,
56
+ 0x59 ,
57
+ 0x53 ,
58
+ 0x2e ,
59
+ 0x44 ,
60
+ 0x44 ,
61
+ 0x46 ,
62
+ 0x30 ,
63
+ 0x31 ,
64
+ ] )
65
+ . then ( ( response ) => {
66
+ console . info (
67
+ `Select PSE Response: '${ response } ' '${ response . meaning ( ) } '`
68
+ ) ;
69
+ return application . selectFile ( hexify . toByteArray ( 'a0000000041010' ) ) ;
70
+ } )
71
+ . then ( ( response ) => {
72
+ console . info (
73
+ `Select Application Response: '${ response } ' '${ response . meaning ( ) } '`
74
+ ) ;
75
+ return application . issueCommand (
76
+ new CommandApdu ( {
77
+ bytes : [ 0x80 , 0xa8 , 0x00 , 0x00 , 0x02 , 0x83 , 0x00 , 0x00 ] ,
78
+ } )
79
+ ) ;
80
+ } )
81
+ . then ( ( response ) => {
82
+ console . info (
83
+ `Get Processing Options Response: '${ response } ' '${ response . meaning ( ) } '`
84
+ ) ;
85
+ return response ;
86
+ } )
87
+ . catch ( ( error ) => {
88
+ console . error ( 'Error:' , error , error . stack ) ;
89
+ } ) ;
90
+ } ) ;
91
+ device . on ( 'card-removed' , ( event ) => {
92
+ console . log ( `Card ${ event . card } removed from '${ event . name } ' ` ) ;
93
+ } ) ;
66
94
} ) ;
67
95
68
- devices . on ( 'device-deactivated' , event => {
69
- console . log ( `Device '${ event . device } ' deactivated, devices: [${ event . devices } ]` ) ;
96
+ devices . on ( 'device-deactivated' , ( event ) => {
97
+ console . log (
98
+ `Device '${ event . device } ' deactivated, devices: [${ event . devices } ]`
99
+ ) ;
70
100
} ) ;
71
-
0 commit comments