-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
61 lines (38 loc) · 1 KB
/
new.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
package tapcards
import (
"errors"
"log/slog"
)
func (satscard *Satscard) NewRequest(cvc string) ([]byte, error) {
slog.Debug("Request new")
if satscard.currentCardNonce == [16]byte{} {
satscard.queue.enqueue("status")
}
satscard.queue.enqueue("new")
satscard.cvc = cvc
return satscard.nextCommand()
}
func (satscard *Satscard) newRequest() ([]byte, error) {
// Check if we can open the next slot
if satscard.ActiveSlot+1 >= satscard.NumberOfSlots {
return nil, errors.New("no more slots available")
}
command := command{Cmd: "new"}
auth, err := satscard.authenticate(satscard.cvc, command)
if err != nil {
return nil, err
}
newCommand := newCommand{
command: command,
Slot: satscard.ActiveSlot,
auth: *auth,
}
return apduWrap(newCommand)
}
func (satscard *Satscard) parseNewData(newData newData) error {
slog.Debug("Parse new")
slog.Debug("NEW", "Slot", newData.Slot)
satscard.currentCardNonce = newData.CardNonce
satscard.ActiveSlot = newData.Slot
return nil
}