@prove-identity/prove-auth 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +404 -0
- package/README.md +17 -0
- package/build/lib/index.d.ts +12 -0
- package/build/lib/index.js +47 -0
- package/build/lib/proveauth/auth-finish-step.d.ts +7 -0
- package/build/lib/proveauth/auth-finish-step.js +2 -0
- package/build/lib/proveauth/authenticator-builder.d.ts +42 -0
- package/build/lib/proveauth/authenticator-builder.js +126 -0
- package/build/lib/proveauth/authenticator.d.ts +12 -0
- package/build/lib/proveauth/authenticator.js +2 -0
- package/build/lib/proveauth/common/base64.d.ts +5 -0
- package/build/lib/proveauth/common/base64.js +19 -0
- package/build/lib/proveauth/common/cancelable-promise.d.ts +5 -0
- package/build/lib/proveauth/common/cancelable-promise.js +15 -0
- package/build/lib/proveauth/common/logger.d.ts +25 -0
- package/build/lib/proveauth/common/logger.js +85 -0
- package/build/lib/proveauth/instantlink.d.ts +4 -0
- package/build/lib/proveauth/instantlink.js +2 -0
- package/build/lib/proveauth/internal/auth-error.d.ts +7 -0
- package/build/lib/proveauth/internal/auth-error.js +27 -0
- package/build/lib/proveauth/internal/auth-message.d.ts +12 -0
- package/build/lib/proveauth/internal/auth-message.js +2 -0
- package/build/lib/proveauth/internal/auth-request.d.ts +90 -0
- package/build/lib/proveauth/internal/auth-request.js +2 -0
- package/build/lib/proveauth/internal/auth-response-status.d.ts +8 -0
- package/build/lib/proveauth/internal/auth-response-status.js +12 -0
- package/build/lib/proveauth/internal/auth-response.d.ts +61 -0
- package/build/lib/proveauth/internal/auth-response.js +2 -0
- package/build/lib/proveauth/internal/auth-session.d.ts +30 -0
- package/build/lib/proveauth/internal/auth-session.js +156 -0
- package/build/lib/proveauth/internal/auth-step.d.ts +5 -0
- package/build/lib/proveauth/internal/auth-step.js +2 -0
- package/build/lib/proveauth/internal/auth-token-claims.d.ts +46 -0
- package/build/lib/proveauth/internal/auth-token-claims.js +9 -0
- package/build/lib/proveauth/internal/base-authenticator.d.ts +28 -0
- package/build/lib/proveauth/internal/base-authenticator.js +129 -0
- package/build/lib/proveauth/internal/device-auth.d.ts +22 -0
- package/build/lib/proveauth/internal/device-auth.js +2 -0
- package/build/lib/proveauth/internal/device-passive-register-step.d.ts +10 -0
- package/build/lib/proveauth/internal/device-passive-register-step.js +97 -0
- package/build/lib/proveauth/internal/device-passive-silent-step.d.ts +10 -0
- package/build/lib/proveauth/internal/device-passive-silent-step.js +98 -0
- package/build/lib/proveauth/internal/device-passive-step.d.ts +17 -0
- package/build/lib/proveauth/internal/device-passive-step.js +133 -0
- package/build/lib/proveauth/internal/device-passive-stepup-step.d.ts +9 -0
- package/build/lib/proveauth/internal/device-passive-stepup-step.js +25 -0
- package/build/lib/proveauth/internal/device-passive-verify-step.d.ts +8 -0
- package/build/lib/proveauth/internal/device-passive-verify-step.js +54 -0
- package/build/lib/proveauth/internal/error-code.d.ts +9 -0
- package/build/lib/proveauth/internal/error-code.js +12 -0
- package/build/lib/proveauth/internal/mobile-instant-step.d.ts +15 -0
- package/build/lib/proveauth/internal/mobile-instant-step.js +100 -0
- package/build/lib/proveauth/internal/mobile-instantlink-step.d.ts +14 -0
- package/build/lib/proveauth/internal/mobile-instantlink-step.js +108 -0
- package/build/lib/proveauth/internal/mobile-otp-step.d.ts +14 -0
- package/build/lib/proveauth/internal/mobile-otp-step.js +141 -0
- package/build/lib/proveauth/internal/phone-number-input.d.ts +11 -0
- package/build/lib/proveauth/internal/phone-number-input.js +13 -0
- package/build/lib/proveauth/internal/platform.d.ts +45 -0
- package/build/lib/proveauth/internal/platform.js +20 -0
- package/build/lib/proveauth/internal/primary-authenticator.d.ts +14 -0
- package/build/lib/proveauth/internal/primary-authenticator.js +64 -0
- package/build/lib/proveauth/internal/report-error-step.d.ts +16 -0
- package/build/lib/proveauth/internal/report-error-step.js +88 -0
- package/build/lib/proveauth/internal/request-signer-v3.d.ts +10 -0
- package/build/lib/proveauth/internal/request-signer-v3.js +104 -0
- package/build/lib/proveauth/internal/scan-message-step.d.ts +11 -0
- package/build/lib/proveauth/internal/scan-message-step.js +45 -0
- package/build/lib/proveauth/internal/secondary-authenticator.d.ts +10 -0
- package/build/lib/proveauth/internal/secondary-authenticator.js +65 -0
- package/build/lib/proveauth/internal/settings.d.ts +18 -0
- package/build/lib/proveauth/internal/settings.js +50 -0
- package/build/lib/proveauth/internal/user-mobileactive-step.d.ts +7 -0
- package/build/lib/proveauth/internal/user-mobileactive-step.js +18 -0
- package/build/lib/proveauth/internal/user-present-step.d.ts +7 -0
- package/build/lib/proveauth/internal/user-present-step.js +18 -0
- package/build/lib/proveauth/internal/web-device-auth.d.ts +32 -0
- package/build/lib/proveauth/internal/web-device-auth.js +242 -0
- package/build/lib/proveauth/internal/web-platform.d.ts +30 -0
- package/build/lib/proveauth/internal/web-platform.js +160 -0
- package/build/lib/proveauth/otp.d.ts +23 -0
- package/build/lib/proveauth/otp.js +18 -0
- package/build/lib/proveauth/version.d.ts +3 -0
- package/build/lib/proveauth/version.js +6 -0
- package/package.json +75 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebDeviceRegistration = void 0;
|
|
7
|
+
const logger_1 = require("../common/logger");
|
|
8
|
+
const auth_error_1 = __importDefault(require("./auth-error"));
|
|
9
|
+
const platform_1 = require("./platform");
|
|
10
|
+
class WebDeviceRegistration {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.deviceId = null;
|
|
13
|
+
this.namespace = options.namespace;
|
|
14
|
+
this.endpoint = options.endpoint;
|
|
15
|
+
if (options.createdAt) {
|
|
16
|
+
this.createdAt = options.createdAt;
|
|
17
|
+
this.keyId = options.keyId;
|
|
18
|
+
this.deviceId = options.deviceId;
|
|
19
|
+
this.algorithm = options.algorithm;
|
|
20
|
+
this.keys = options.keys;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.keyId = crypto.randomUUID();
|
|
24
|
+
this.algorithm = 'ES256';
|
|
25
|
+
this.createdAt = (0, platform_1.getUnixTime)();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
sign(data) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
this.initialize()
|
|
31
|
+
.then(() => {
|
|
32
|
+
if (this.keys) {
|
|
33
|
+
crypto.subtle
|
|
34
|
+
.sign({
|
|
35
|
+
name: 'ECDSA',
|
|
36
|
+
hash: { name: 'SHA-256' },
|
|
37
|
+
}, this.keys.privateKey, (0, platform_1.stringToArrayBuffer)(data))
|
|
38
|
+
.then((signature) => resolve(btoa((0, platform_1.arrayBufferToString)(this.p1363ToDer(signature)))))
|
|
39
|
+
.catch(reject);
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
.catch(reject);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getPublicKey() {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
this.initialize()
|
|
48
|
+
.then(() => {
|
|
49
|
+
if (this.keys) {
|
|
50
|
+
crypto.subtle
|
|
51
|
+
.exportKey('spki', this.keys.publicKey)
|
|
52
|
+
.then((key) => {
|
|
53
|
+
const encodedKey = btoa((0, platform_1.arrayBufferToString)(key));
|
|
54
|
+
resolve('-----BEGIN PUBLIC KEY-----\n' + encodedKey + '\n-----END PUBLIC KEY-----');
|
|
55
|
+
})
|
|
56
|
+
.catch(reject);
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.catch(reject);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getAuthRegistration(challenge) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
this.sign(challenge)
|
|
65
|
+
.then((signature) => {
|
|
66
|
+
this.getPublicKey()
|
|
67
|
+
.then((key) => {
|
|
68
|
+
resolve({
|
|
69
|
+
publicKey: {
|
|
70
|
+
id: this.keyId,
|
|
71
|
+
alg: this.algorithm,
|
|
72
|
+
key: key,
|
|
73
|
+
uvLevel: 0,
|
|
74
|
+
},
|
|
75
|
+
signature: signature,
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.catch(reject);
|
|
79
|
+
})
|
|
80
|
+
.catch(reject);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
initialize() {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
if (this.keys) {
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
crypto.subtle
|
|
90
|
+
.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign', 'verify'])
|
|
91
|
+
.then((keyPair) => {
|
|
92
|
+
this.keys = keyPair;
|
|
93
|
+
resolve();
|
|
94
|
+
})
|
|
95
|
+
.catch(reject);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
p1363ToDer(sig) {
|
|
100
|
+
const signature = (0, platform_1.arrayBufferToHexString)(sig);
|
|
101
|
+
let r = signature.substring(0, signature.length / 2);
|
|
102
|
+
let s = signature.substring(signature.length / 2);
|
|
103
|
+
r = r.replace(/^(00)+/, '');
|
|
104
|
+
s = s.replace(/^(00)+/, '');
|
|
105
|
+
if (parseInt(r.charAt(0), 16) >= 8)
|
|
106
|
+
r = `00${r}`;
|
|
107
|
+
if (parseInt(s.charAt(0), 16) >= 8)
|
|
108
|
+
s = `00${s}`;
|
|
109
|
+
const rString = `02${(r.length / 2).toString(16).padStart(2, '0')}${r}`;
|
|
110
|
+
const sString = `02${(s.length / 2).toString(16).padStart(2, '0')}${s}`;
|
|
111
|
+
const derSig = `30${((rString.length + sString.length) / 2)
|
|
112
|
+
.toString(16)
|
|
113
|
+
.padStart(2, '0')}${rString}${sString}`;
|
|
114
|
+
const matchSig = derSig.match(/[\da-f]{2}/gi);
|
|
115
|
+
return matchSig ? new Uint8Array(matchSig.map((h) => parseInt(h, 16))) : new Uint8Array();
|
|
116
|
+
}
|
|
117
|
+
lenVal(val) {
|
|
118
|
+
if (typeof val === 'string' || val instanceof String) {
|
|
119
|
+
const vs = val;
|
|
120
|
+
return `[${vs.length}]: ${vs}`;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const ab = val;
|
|
124
|
+
return `[${ab.byteLength}]: ${Array.from(new Uint8Array(ab), (x) => x.toString(16)).join(',')}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.WebDeviceRegistration = WebDeviceRegistration;
|
|
129
|
+
class WebDeviceAuth {
|
|
130
|
+
constructor(dbFactory) {
|
|
131
|
+
this.log = logger_1.LoggerFactory.getLogger('web-device-auth');
|
|
132
|
+
this.dbFactory = dbFactory;
|
|
133
|
+
}
|
|
134
|
+
createRegistration(options) {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
resolve(new WebDeviceRegistration(options));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getRegistration(namespace) {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
const openReq = this.openDatabase();
|
|
142
|
+
openReq.onerror = (e) => {
|
|
143
|
+
reject('Failed to open registration database: ' + e);
|
|
144
|
+
};
|
|
145
|
+
openReq.onsuccess = (e) => {
|
|
146
|
+
const db = openReq.result;
|
|
147
|
+
const tx = db.transaction([WebDeviceAuth.DB_STORE], 'readonly');
|
|
148
|
+
tx.oncomplete = () => db.close();
|
|
149
|
+
const store = tx.objectStore(WebDeviceAuth.DB_STORE);
|
|
150
|
+
const getReq = store.get(namespace);
|
|
151
|
+
getReq.onsuccess = () => {
|
|
152
|
+
if (getReq.result) {
|
|
153
|
+
resolve(new WebDeviceRegistration(getReq.result));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
resolve(null);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
getReq.onerror = (e) => {
|
|
160
|
+
reject(new Error('Failed to access registration'));
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
storeRegistration(registration) {
|
|
166
|
+
return new Promise((resolve, reject) => {
|
|
167
|
+
const openReq = this.openDatabase();
|
|
168
|
+
openReq.onerror = (e) => {
|
|
169
|
+
reject('Failed to open registration database: ' + e);
|
|
170
|
+
};
|
|
171
|
+
openReq.onsuccess = (e) => {
|
|
172
|
+
const db = openReq.result;
|
|
173
|
+
const tx = db.transaction([WebDeviceAuth.DB_STORE], 'readwrite');
|
|
174
|
+
tx.oncomplete = () => db.close();
|
|
175
|
+
const store = tx.objectStore(WebDeviceAuth.DB_STORE);
|
|
176
|
+
this.log.trace('Saving registration');
|
|
177
|
+
const addReq = store.put(registration);
|
|
178
|
+
addReq.onsuccess = () => {
|
|
179
|
+
this.log.trace('Registration saved');
|
|
180
|
+
};
|
|
181
|
+
addReq.onerror = (e) => {
|
|
182
|
+
reject(new auth_error_1.default('Failed to store registration'));
|
|
183
|
+
};
|
|
184
|
+
resolve();
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
deleteRegistration(namespace) {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
var openReq = this.openDatabase();
|
|
191
|
+
openReq.onerror = (e) => {
|
|
192
|
+
reject('Failed to open registration database: ' + e);
|
|
193
|
+
};
|
|
194
|
+
openReq.onsuccess = (e) => {
|
|
195
|
+
var db = openReq.result;
|
|
196
|
+
var tx = db.transaction([WebDeviceAuth.DB_STORE], 'readwrite');
|
|
197
|
+
tx.oncomplete = () => db.close();
|
|
198
|
+
if (!db.objectStoreNames.contains(WebDeviceAuth.DB_STORE)) {
|
|
199
|
+
this.log.debug('Registration not found, store is missing');
|
|
200
|
+
resolve();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
var store = tx.objectStore(WebDeviceAuth.DB_STORE);
|
|
204
|
+
var delReq = store.delete(namespace);
|
|
205
|
+
delReq.onsuccess = () => {
|
|
206
|
+
resolve();
|
|
207
|
+
};
|
|
208
|
+
delReq.onerror = (e) => {
|
|
209
|
+
reject(new Error('Failed to delete registration'));
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
reset() {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
var delReq = this.dbFactory.deleteDatabase(WebDeviceAuth.DB_NAME);
|
|
217
|
+
delReq.onsuccess = (e) => {
|
|
218
|
+
resolve();
|
|
219
|
+
};
|
|
220
|
+
delReq.onerror = (e) => {
|
|
221
|
+
this.log.warn('Failed to delete registration database: ' + e);
|
|
222
|
+
resolve();
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
openDatabase() {
|
|
227
|
+
const openReq = this.dbFactory.open(WebDeviceAuth.DB_NAME, WebDeviceAuth.DB_VERSION);
|
|
228
|
+
openReq.onupgradeneeded = (e) => {
|
|
229
|
+
const db = openReq.result;
|
|
230
|
+
this.log.debug('Registration not found, database is missing, initializing');
|
|
231
|
+
const store = db.createObjectStore(WebDeviceAuth.DB_STORE, { keyPath: 'namespace' });
|
|
232
|
+
store.transaction.oncomplete = (e) => {
|
|
233
|
+
this.log.trace('Store initialization completed');
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
return openReq;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
WebDeviceAuth.DB_VERSION = 1;
|
|
240
|
+
WebDeviceAuth.DB_NAME = 'ProveAuth';
|
|
241
|
+
WebDeviceAuth.DB_STORE = 'Registrations';
|
|
242
|
+
exports.default = WebDeviceAuth;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="webappsec-credential-management" />
|
|
2
|
+
import { AuthenticatorBuilder } from '@prove-identity/mobile-auth';
|
|
3
|
+
import Platform, { AuthSessionIntegration, MessageChannel, RequestSigner } from './platform';
|
|
4
|
+
import WebDeviceAuth from './web-device-auth';
|
|
5
|
+
export declare class WebSocketMessageChannel implements MessageChannel {
|
|
6
|
+
private readonly webSocket;
|
|
7
|
+
constructor(endpointUrl: string);
|
|
8
|
+
addEventListener(type: string, listener: (event: Event) => void): void;
|
|
9
|
+
send(data: string): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class WebPlatform implements Platform {
|
|
13
|
+
readonly webauthn: {
|
|
14
|
+
getCredentials: (options?: CredentialRequestOptions) => Promise<CredentialType | null>;
|
|
15
|
+
createCredentials: (options: CredentialCreationOptions) => Promise<CredentialType | null>;
|
|
16
|
+
};
|
|
17
|
+
readonly deviceAuth: WebDeviceAuth;
|
|
18
|
+
getPlatformName(): string;
|
|
19
|
+
getUserAgent(): string | null;
|
|
20
|
+
isFidoSupported(): boolean;
|
|
21
|
+
fetch(input: string, init?: RequestInit): Promise<Response>;
|
|
22
|
+
createMessageChannel(endpointUrl: string): MessageChannel;
|
|
23
|
+
createRequestSigner(session: AuthSessionIntegration): RequestSigner;
|
|
24
|
+
private getBrowserName;
|
|
25
|
+
private getBrowserVersion;
|
|
26
|
+
getOSName(): string;
|
|
27
|
+
getDeviceCapabilities(): string[];
|
|
28
|
+
getMobileAuthBuilder(): AuthenticatorBuilder<any>;
|
|
29
|
+
exit(code?: number): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebPlatform = exports.WebSocketMessageChannel = void 0;
|
|
7
|
+
const mobile_auth_1 = require("@prove-identity/mobile-auth");
|
|
8
|
+
const platform_1 = require("./platform");
|
|
9
|
+
const request_signer_v3_1 = __importDefault(require("./request-signer-v3"));
|
|
10
|
+
const web_device_auth_1 = __importDefault(require("./web-device-auth"));
|
|
11
|
+
class WebSocketMessageChannel {
|
|
12
|
+
constructor(endpointUrl) {
|
|
13
|
+
this.webSocket = new WebSocket(endpointUrl);
|
|
14
|
+
}
|
|
15
|
+
addEventListener(type, listener) {
|
|
16
|
+
this.webSocket.addEventListener(type, listener);
|
|
17
|
+
}
|
|
18
|
+
send(data) {
|
|
19
|
+
this.webSocket.send(data);
|
|
20
|
+
}
|
|
21
|
+
close() {
|
|
22
|
+
this.webSocket.close();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.WebSocketMessageChannel = WebSocketMessageChannel;
|
|
26
|
+
class WebPlatform {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.webauthn = {
|
|
29
|
+
getCredentials: (options) => {
|
|
30
|
+
return navigator.credentials.get(options);
|
|
31
|
+
},
|
|
32
|
+
createCredentials: (options) => {
|
|
33
|
+
return navigator.credentials.create(options);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
this.deviceAuth = new web_device_auth_1.default(window.indexedDB);
|
|
37
|
+
}
|
|
38
|
+
getPlatformName() {
|
|
39
|
+
return `${this.getBrowserName()} ${this.getBrowserVersion()} on ${this.getOSName()}`;
|
|
40
|
+
}
|
|
41
|
+
getUserAgent() {
|
|
42
|
+
return navigator.userAgent;
|
|
43
|
+
}
|
|
44
|
+
isFidoSupported() {
|
|
45
|
+
return window.PublicKeyCredential != undefined;
|
|
46
|
+
}
|
|
47
|
+
fetch(input, init) {
|
|
48
|
+
return fetch(input, init);
|
|
49
|
+
}
|
|
50
|
+
createMessageChannel(endpointUrl) {
|
|
51
|
+
return new WebSocketMessageChannel(endpointUrl);
|
|
52
|
+
}
|
|
53
|
+
createRequestSigner(session) {
|
|
54
|
+
return new request_signer_v3_1.default(session);
|
|
55
|
+
}
|
|
56
|
+
getBrowserName() {
|
|
57
|
+
const agent = navigator.userAgent;
|
|
58
|
+
let browserName;
|
|
59
|
+
if (agent.indexOf('Firefox') > -1) {
|
|
60
|
+
browserName = 'Firefox';
|
|
61
|
+
}
|
|
62
|
+
else if (agent.indexOf('Opera') > -1 || agent.indexOf('OPR') > -1) {
|
|
63
|
+
browserName = 'Opera';
|
|
64
|
+
}
|
|
65
|
+
else if (agent.indexOf('DuckDuckGo') > -1) {
|
|
66
|
+
browserName = 'DuckDuckGo';
|
|
67
|
+
}
|
|
68
|
+
else if (agent.indexOf('SamsungBrowser') > -1) {
|
|
69
|
+
browserName = 'Samsung Browser';
|
|
70
|
+
}
|
|
71
|
+
else if (agent.indexOf('Trident') > -1) {
|
|
72
|
+
browserName = 'Internet Explorer';
|
|
73
|
+
}
|
|
74
|
+
else if (agent.indexOf('Edge') > -1) {
|
|
75
|
+
browserName = 'Edge';
|
|
76
|
+
}
|
|
77
|
+
else if (agent.indexOf('Chrome') > -1) {
|
|
78
|
+
browserName = 'Chrome';
|
|
79
|
+
}
|
|
80
|
+
else if (agent.indexOf('Safari') > -1) {
|
|
81
|
+
browserName = 'Safari';
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
browserName = 'Unknown';
|
|
85
|
+
}
|
|
86
|
+
return browserName;
|
|
87
|
+
}
|
|
88
|
+
getBrowserVersion() {
|
|
89
|
+
const agent = navigator.userAgent;
|
|
90
|
+
const verRegex = /(?:Firefox|Opera|OPR|SamsungBrowser|DuckDuckGo|Internet Explorer|Edge|Chrome|Safari)[\/|\s](\d+(\.\d+)?)/i;
|
|
91
|
+
const matches = agent.match(verRegex);
|
|
92
|
+
return matches ? matches[1] : 'Unknown';
|
|
93
|
+
}
|
|
94
|
+
getOSName() {
|
|
95
|
+
const platform = navigator.platform;
|
|
96
|
+
const agent = navigator.userAgent;
|
|
97
|
+
let osName;
|
|
98
|
+
if (/Win/i.test(platform)) {
|
|
99
|
+
osName = 'Windows';
|
|
100
|
+
const matches = agent.match(/Win(?:dows )?NT (\d+\.\d+)/i);
|
|
101
|
+
if (matches) {
|
|
102
|
+
const windowsVersion = parseFloat(matches[1]);
|
|
103
|
+
if (windowsVersion === 11) {
|
|
104
|
+
osName += ' 11';
|
|
105
|
+
}
|
|
106
|
+
else if (windowsVersion === 10) {
|
|
107
|
+
osName += ' 10';
|
|
108
|
+
}
|
|
109
|
+
else if (windowsVersion === 6.3) {
|
|
110
|
+
osName += ' 8.1';
|
|
111
|
+
}
|
|
112
|
+
else if (windowsVersion === 6.2) {
|
|
113
|
+
osName += ' 8';
|
|
114
|
+
}
|
|
115
|
+
else if (windowsVersion === 6.1) {
|
|
116
|
+
osName += ' 7';
|
|
117
|
+
}
|
|
118
|
+
else if (windowsVersion === 6.0) {
|
|
119
|
+
osName += ' Vista';
|
|
120
|
+
}
|
|
121
|
+
else if (windowsVersion === 5.1 || windowsVersion === 5.2) {
|
|
122
|
+
osName += ' XP';
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
osName += ' (Unknown Version)';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (platform.match(/Mac/i)) {
|
|
130
|
+
osName = 'Mac OS';
|
|
131
|
+
const matches = agent.match(/Mac OS X (\d+[_.]\d+([_.]\d+)?)/i);
|
|
132
|
+
if (matches) {
|
|
133
|
+
const macVersion = matches[1].replace(/_/g, '.');
|
|
134
|
+
osName += ' ' + macVersion;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (agent.match(/Android/i)) {
|
|
138
|
+
osName = 'Android';
|
|
139
|
+
}
|
|
140
|
+
else if (agent.match(/iOS|iPhone|iPad|iPod/i)) {
|
|
141
|
+
osName = 'iOS';
|
|
142
|
+
}
|
|
143
|
+
else if (platform.match(/Linux/i)) {
|
|
144
|
+
osName = 'Linux';
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
osName = 'Unknown';
|
|
148
|
+
}
|
|
149
|
+
return osName;
|
|
150
|
+
}
|
|
151
|
+
getDeviceCapabilities() {
|
|
152
|
+
return this.isFidoSupported() ? [platform_1.DEVICE_CAPABILITY_WEBAUTHN] : [];
|
|
153
|
+
}
|
|
154
|
+
getMobileAuthBuilder() {
|
|
155
|
+
return new mobile_auth_1.AuthenticatorBuilder();
|
|
156
|
+
}
|
|
157
|
+
exit(code) {
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.WebPlatform = WebPlatform;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AuthError from './internal/auth-error';
|
|
2
|
+
import PhoneNumberInput, { PhoneNumberStep, PhoneNumberStepFn } from './internal/phone-number-input';
|
|
3
|
+
export declare class OtpError extends AuthError {
|
|
4
|
+
constructor(message?: string, code?: number);
|
|
5
|
+
}
|
|
6
|
+
export type OtpStartInput = PhoneNumberInput;
|
|
7
|
+
export type OtpStartStep = PhoneNumberStep;
|
|
8
|
+
export type OtpStartStepFn = PhoneNumberStepFn;
|
|
9
|
+
export declare enum OtpFinishResultType {
|
|
10
|
+
OnSuccess = 0,
|
|
11
|
+
OnResendOtp = 1
|
|
12
|
+
}
|
|
13
|
+
export interface OtpFinishResult {
|
|
14
|
+
resultType: OtpFinishResultType;
|
|
15
|
+
input?: OtpFinishInput;
|
|
16
|
+
}
|
|
17
|
+
export interface OtpFinishInput {
|
|
18
|
+
otp: string;
|
|
19
|
+
}
|
|
20
|
+
export interface OtpFinishStep {
|
|
21
|
+
execute: (otpError?: OtpError) => Promise<OtpFinishResult>;
|
|
22
|
+
}
|
|
23
|
+
export type OtpFinishStepFn = (otpError?: OtpError) => Promise<OtpFinishResult>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OtpFinishResultType = exports.OtpError = void 0;
|
|
7
|
+
const auth_error_1 = __importDefault(require("./internal/auth-error"));
|
|
8
|
+
class OtpError extends auth_error_1.default {
|
|
9
|
+
constructor(message, code) {
|
|
10
|
+
super(message, code);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.OtpError = OtpError;
|
|
14
|
+
var OtpFinishResultType;
|
|
15
|
+
(function (OtpFinishResultType) {
|
|
16
|
+
OtpFinishResultType[OtpFinishResultType["OnSuccess"] = 0] = "OnSuccess";
|
|
17
|
+
OtpFinishResultType[OtpFinishResultType["OnResendOtp"] = 1] = "OnResendOtp";
|
|
18
|
+
})(OtpFinishResultType = exports.OtpFinishResultType || (exports.OtpFinishResultType = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USER_AGENT_VERSIONS = exports.API_CONTRACT_VERSION = exports.VERSION = void 0;
|
|
4
|
+
exports.VERSION = '2.3.2';
|
|
5
|
+
exports.API_CONTRACT_VERSION = '2.7.0';
|
|
6
|
+
exports.USER_AGENT_VERSIONS = `ProveAuth/${exports.VERSION} Contract/${exports.API_CONTRACT_VERSION} WEB/1`;
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prove-identity/prove-auth",
|
|
3
|
+
"version": "2.3.2",
|
|
4
|
+
"description": "Prove Auth SDK for Web",
|
|
5
|
+
"main": "build/lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"LICENSE",
|
|
8
|
+
"README.md",
|
|
9
|
+
"build/lib/index.js",
|
|
10
|
+
"build/lib/index.js.map",
|
|
11
|
+
"build/lib/index.d.ts",
|
|
12
|
+
"build/lib/proveauth/**/*.js",
|
|
13
|
+
"build/lib/proveauth/**/*.js.map",
|
|
14
|
+
"build/lib/proveauth/**/*.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"types": "build/lib/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clean": "rm -rf build && rm -f prove-auth-*.tgz",
|
|
19
|
+
"build": "tsc --build",
|
|
20
|
+
"doc": "typedoc --out build/doc src && tar -C build/doc -zcvf build/doc.tgz .",
|
|
21
|
+
"bundle": "webpack --config webpack.prod.config.js",
|
|
22
|
+
"bundle-dev": "webpack --config webpack.dev.config.js",
|
|
23
|
+
"watch-compile": "tsc --watch",
|
|
24
|
+
"watch-bundle": "webpack --watch",
|
|
25
|
+
"serve": "webpack serve --config webpack.dev.config.js",
|
|
26
|
+
"test": "webpack serve --config webpack.dev.config.js --open tests.html",
|
|
27
|
+
"test-with-node": "mocha --require init-test.js build/lib/tests",
|
|
28
|
+
"test-runner": "node build/lib/testrunner/main.js",
|
|
29
|
+
"dist": "npm run clean && npm run build && npm pack && npm run bundle && npm run bundle-dev && npm run doc",
|
|
30
|
+
"prepare": "husky install"
|
|
31
|
+
},
|
|
32
|
+
"lint-staged": {
|
|
33
|
+
"**/*": "prettier --check --ignore-unknown"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/prove-identity/prove-auth-client-web-sdk.git"
|
|
38
|
+
},
|
|
39
|
+
"author": "Prove Identity, Inc.",
|
|
40
|
+
"license": "CC BY-NC-ND 4.0",
|
|
41
|
+
"homepage": "https://www.prove.com/solutions/auth",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@babel/plugin-transform-modules-commonjs": "^7.21.5",
|
|
44
|
+
"@types/chai": "4.3.5",
|
|
45
|
+
"@types/jest": "^29.5.1",
|
|
46
|
+
"@types/mocha": "10.0.1",
|
|
47
|
+
"@types/react": "^18.2.6",
|
|
48
|
+
"@types/webappsec-credential-management": "^0.6.4",
|
|
49
|
+
"@types/ws": "^8.5.6",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
|
51
|
+
"@typescript-eslint/parser": "^6.1.0",
|
|
52
|
+
"cbor-x": "^1.5.4",
|
|
53
|
+
"chai": "4.3.7",
|
|
54
|
+
"eslint": "^8.41.0",
|
|
55
|
+
"eslint-config-prettier": "^8.8.0",
|
|
56
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
57
|
+
"eslint-plugin-react": "^7.32.2",
|
|
58
|
+
"husky": "^8.0.3",
|
|
59
|
+
"isomorphic-fetch": "3.0.0",
|
|
60
|
+
"lint-staged": "^13.2.2",
|
|
61
|
+
"mocha": "10.2.0",
|
|
62
|
+
"prettier": "^2.8.8",
|
|
63
|
+
"ts-loader": "9.4.3",
|
|
64
|
+
"typedoc": "^0.24.7",
|
|
65
|
+
"typescript": "^5.0.4",
|
|
66
|
+
"webpack": "5.83.1",
|
|
67
|
+
"webpack-cli": "5.1.1",
|
|
68
|
+
"webpack-dev-server": "4.15.0",
|
|
69
|
+
"webpack-node-externals": "3.0.0",
|
|
70
|
+
"ws": "^8.14.2"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@prove-identity/mobile-auth": "^3.0.0"
|
|
74
|
+
}
|
|
75
|
+
}
|