Skip to content

Commit 27e8b68

Browse files
authored
[w3c-web-smart-card] Add type definitions for web-smart-card (DefinitelyTyped#74152)
1 parent 1813ca1 commit 27e8b68

5 files changed

Lines changed: 402 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"private": true,
3+
"nonNpm": true,
4+
"nonNpmDescription": "Implementation of Isolated Web App (IWA) APIs resides in Chromium.",
5+
"name": "@types/w3c-web-smart-card",
6+
"version": "0.0.9999",
7+
"projects": [
8+
"https://wicg.github.io/web-smart-card/"
9+
],
10+
"devDependencies": {
11+
"@types/web": "*",
12+
"@types/w3c-web-smart-card": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "Paulina Gacek",
17+
"githubUsername": "paulinagacek"
18+
},
19+
{
20+
"name": "Zgroza (Luke) Klimek",
21+
"githubUsername": "zgroza"
22+
},
23+
{
24+
"name": "Andrew Rayskiy",
25+
"githubUsername": "GrapeGreen"
26+
},
27+
{
28+
"name": "Simon Hangl",
29+
"githubUsername": "shangl"
30+
}
31+
]
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6",
6+
"dom"
7+
],
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictFunctionTypes": true,
11+
"strictNullChecks": true,
12+
"types": [],
13+
"noEmit": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"paths": {
16+
"w3c-web-smart-card": [
17+
"./index.d.ts"
18+
]
19+
}
20+
},
21+
"files": [
22+
"index.d.ts",
23+
"w3c-web-smart-card-tests.ts"
24+
]
25+
}

0 commit comments

Comments
 (0)