|
| 1 | +/** |
| 2 | + * @see https://wicg.github.io/web-smart-card |
| 3 | + */ |
| 4 | + |
| 5 | +export interface SmartCardResourceManager { |
| 6 | + establishContext(): Promise<SmartCardContext>; |
| 7 | +} |
| 8 | + |
| 9 | +export type SmartCardResponseCode = |
| 10 | + | "no-service" |
| 11 | + | "no-smartcard" |
| 12 | + | "not-ready" |
| 13 | + | "not-transacted" |
| 14 | + | "proto-mismatch" |
| 15 | + | "reader-unavailable" |
| 16 | + | "removed-card" |
| 17 | + | "reset-card" |
| 18 | + | "server-too-busy" |
| 19 | + | "sharing-violation" |
| 20 | + | "system-cancelled" |
| 21 | + | "unknown-reader" |
| 22 | + | "unpowered-card" |
| 23 | + | "unresponsive-card" |
| 24 | + | "unsupported-card" |
| 25 | + | "unsupported-feature"; |
| 26 | + |
| 27 | +export interface SmartCardErrorOptions { |
| 28 | + responseCode: SmartCardResponseCode; |
| 29 | +} |
| 30 | + |
| 31 | +export class SmartCardError extends DOMException { |
| 32 | + constructor(message: string, options: SmartCardErrorOptions); |
| 33 | + readonly responseCode: SmartCardResponseCode; |
| 34 | +} |
| 35 | + |
| 36 | +export interface SmartCardReaderStateIn { |
| 37 | + readerName: string; |
| 38 | + currentState: SmartCardReaderStateFlagsIn; |
| 39 | + currentCount?: number; |
| 40 | +} |
| 41 | + |
| 42 | +export interface SmartCardReaderStateOut { |
| 43 | + readerName: string; |
| 44 | + eventState: SmartCardReaderStateFlagsOut; |
| 45 | + eventCount: number; |
| 46 | + answerToReset: ArrayBuffer; |
| 47 | +} |
| 48 | + |
| 49 | +export interface SmartCardReaderStateFlags { |
| 50 | + /** @default false */ |
| 51 | + ignore?: boolean; |
| 52 | + /** @default false */ |
| 53 | + unavailable?: boolean; |
| 54 | + /** @default false */ |
| 55 | + empty?: boolean; |
| 56 | + /** @default false */ |
| 57 | + present?: boolean; |
| 58 | + /** @default false */ |
| 59 | + exclusive?: boolean; |
| 60 | + /** @default false */ |
| 61 | + inuse?: boolean; |
| 62 | + /** @default false */ |
| 63 | + mute?: boolean; |
| 64 | + /** @default false */ |
| 65 | + unpowered?: boolean; |
| 66 | +} |
| 67 | + |
| 68 | +export interface SmartCardReaderStateFlagsIn extends SmartCardReaderStateFlags { |
| 69 | + /** @default false */ |
| 70 | + unaware?: boolean; |
| 71 | +} |
| 72 | + |
| 73 | +export interface SmartCardReaderStateFlagsOut extends SmartCardReaderStateFlags { |
| 74 | + /** @default false */ |
| 75 | + changed?: boolean; |
| 76 | + /** @default false */ |
| 77 | + unknown?: boolean; |
| 78 | +} |
| 79 | + |
| 80 | +export type SmartCardProtocol = |
| 81 | + | "raw" |
| 82 | + | "t0" |
| 83 | + | "t1"; |
| 84 | + |
| 85 | +export interface SmartCardConnectResult { |
| 86 | + connection: SmartCardConnection; |
| 87 | + activeProtocol?: SmartCardProtocol; |
| 88 | +} |
| 89 | + |
| 90 | +export type SmartCardAccessMode = |
| 91 | + | "shared" |
| 92 | + | "exclusive" |
| 93 | + | "direct"; |
| 94 | + |
| 95 | +export interface SmartCardGetStatusChangeOptions { |
| 96 | + timeout?: DOMHighResTimeStamp; |
| 97 | + signal?: AbortSignal; |
| 98 | +} |
| 99 | + |
| 100 | +export interface SmartCardConnectOptions { |
| 101 | + preferredProtocols?: SmartCardProtocol[]; |
| 102 | +} |
| 103 | + |
| 104 | +export interface SmartCardContext { |
| 105 | + listReaders(): Promise<string[]>; |
| 106 | + getStatusChange( |
| 107 | + readerStates: SmartCardReaderStateIn[], |
| 108 | + options?: SmartCardGetStatusChangeOptions, |
| 109 | + ): Promise<SmartCardReaderStateOut[]>; |
| 110 | + connect( |
| 111 | + readerName: string, |
| 112 | + accessMode: SmartCardAccessMode, |
| 113 | + options?: SmartCardConnectOptions, |
| 114 | + ): Promise<SmartCardConnectResult>; |
| 115 | +} |
| 116 | + |
| 117 | +export type SmartCardConnectionState = |
| 118 | + | "absent" |
| 119 | + | "present" |
| 120 | + | "swallowed" |
| 121 | + | "powered" |
| 122 | + | "negotiable" |
| 123 | + | "t0" |
| 124 | + | "t1" |
| 125 | + | "raw"; |
| 126 | + |
| 127 | +export interface SmartCardConnectionStatus { |
| 128 | + readerName: string; |
| 129 | + state: SmartCardConnectionState; |
| 130 | + answerToReset?: ArrayBuffer; |
| 131 | +} |
| 132 | + |
| 133 | +export type SmartCardDisposition = |
| 134 | + | "leave" |
| 135 | + | "reset" |
| 136 | + | "unpower" |
| 137 | + | "eject"; |
| 138 | + |
| 139 | +export interface SmartCardTransactionOptions { |
| 140 | + signal?: AbortSignal; |
| 141 | +} |
| 142 | + |
| 143 | +export interface SmartCardTransmitOptions { |
| 144 | + protocol?: SmartCardProtocol; |
| 145 | +} |
| 146 | + |
| 147 | +export type SmartCardTransactionCallback = () => Promise<SmartCardDisposition | null>; |
| 148 | + |
| 149 | +export interface SmartCardConnection { |
| 150 | + disconnect(disposition?: SmartCardDisposition): Promise<undefined>; |
| 151 | + transmit(sendBuffer: BufferSource, options?: SmartCardTransmitOptions): Promise<ArrayBuffer>; |
| 152 | + status(): Promise<SmartCardConnectionStatus>; |
| 153 | + control(controlCode: number, data: BufferSource): Promise<ArrayBuffer>; |
| 154 | + getAttribute(tag: number): Promise<ArrayBuffer>; |
| 155 | + setAttribute(tag: number, value: BufferSource): Promise<undefined>; |
| 156 | + startTransaction( |
| 157 | + transaction: SmartCardTransactionCallback, |
| 158 | + options?: SmartCardTransactionOptions, |
| 159 | + ): Promise<undefined>; |
| 160 | +} |
| 161 | + |
| 162 | +declare global { |
| 163 | + interface Navigator { |
| 164 | + readonly smartCard: SmartCardResourceManager; |
| 165 | + } |
| 166 | +} |
0 commit comments