@ideem/zsm-client-sdk 2.2.4 → 2.2.5
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/package.json +44 -24
- package/zsm-client-sdk.js +79 -99
package/package.json
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name"
|
|
3
|
-
"version"
|
|
4
|
-
"description"
|
|
5
|
-
"author"
|
|
6
|
-
"keywords"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
2
|
+
"name": "@ideem/zsm-client-sdk",
|
|
3
|
+
"version": "2.2.5",
|
|
4
|
+
"description": "A monolithic library exporting UMFAClient and FIDO2Client.",
|
|
5
|
+
"author": "@JJ (Jason Jurusz) <jj@useideem.com>/<nerdy.deeds@done.cheap>",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ideem",
|
|
8
|
+
"zsm",
|
|
9
|
+
"zsm-client-sdk",
|
|
10
|
+
"UMFAClient",
|
|
11
|
+
"FIDO2Client",
|
|
12
|
+
"library",
|
|
13
|
+
"UMFA",
|
|
14
|
+
"FIDO2",
|
|
15
|
+
"client",
|
|
16
|
+
"authentication",
|
|
17
|
+
"javascript",
|
|
18
|
+
"multi-factor",
|
|
19
|
+
"webauthn",
|
|
20
|
+
"authentication",
|
|
21
|
+
"security"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"start": "echo 'This is a library, not an application. No start script defined. To use, import the library.'",
|
|
25
|
+
"inc": "npm version patch && cd ..; sleep 1; npm pack ./npm-package"
|
|
10
26
|
},
|
|
11
|
-
"collaborators"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
"collaborators": [
|
|
28
|
+
"Joel Teply <joel@useideem.com>",
|
|
29
|
+
"Todd Decker <todd@useideem.com>",
|
|
30
|
+
"Brian Koziel <brian@useideem.com>",
|
|
31
|
+
"@JJ <jj@useideem.com>"
|
|
16
32
|
],
|
|
17
|
-
"main"
|
|
18
|
-
"module"
|
|
19
|
-
"browser"
|
|
20
|
-
"license"
|
|
21
|
-
"repository"
|
|
22
|
-
"type"
|
|
23
|
-
"url"
|
|
33
|
+
"main": "zsm-client-sdk.js",
|
|
34
|
+
"module": "zsm-client-sdk.js",
|
|
35
|
+
"browser": "zsm-client-sdk.js",
|
|
36
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/useideem/vHSM.git"
|
|
24
40
|
},
|
|
25
|
-
"bugs"
|
|
26
|
-
"homepage"
|
|
27
|
-
"files"
|
|
28
|
-
|
|
41
|
+
"bugs": "https://github.com/useideem/vHSM/issues",
|
|
42
|
+
"homepage": "http://useideem.com",
|
|
43
|
+
"files": [
|
|
44
|
+
"zsm-client-sdk.js"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20.0.0"
|
|
48
|
+
}
|
|
29
49
|
}
|
package/zsm-client-sdk.js
CHANGED
|
@@ -1421,7 +1421,7 @@ let wasm_bindgen;
|
|
|
1421
1421
|
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1422
1422
|
({module} = module)
|
|
1423
1423
|
} else {
|
|
1424
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1424
|
+
// console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1425
1425
|
}
|
|
1426
1426
|
}
|
|
1427
1427
|
|
|
@@ -1527,8 +1527,6 @@ function base64ToArrayBuffer(base64) {
|
|
|
1527
1527
|
|
|
1528
1528
|
#makePostRequest = (url, body={}, headers={}, method='POST') => {
|
|
1529
1529
|
url = `${this.host.endsWith('/') ? this.host.slice(0,-1) : this.host}/${url.startsWith('/') ? url.slice(1) : url}`;
|
|
1530
|
-
console.log('url :', url);
|
|
1531
|
-
|
|
1532
1530
|
body = ((typeof body === 'object') ? body : {});
|
|
1533
1531
|
body = Object.assign({customer_defined_identifier: this.customerDefinedIdentifier, application_id: this.applicationId}, body);
|
|
1534
1532
|
let fetchObj = {
|
|
@@ -1536,15 +1534,10 @@ function base64ToArrayBuffer(base64) {
|
|
|
1536
1534
|
headers : Object.assign(this.xhrHeaders, ((!headers?.Authorization) ? {'Authorization': `Bearer ${this.#apiKey}`} : {}), headers),
|
|
1537
1535
|
body : JSON.stringify(body)
|
|
1538
1536
|
};
|
|
1539
|
-
return
|
|
1540
|
-
.then(response =>
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
let responseJSON = response.json();
|
|
1544
|
-
console.log('responseJSON :', responseJSON);
|
|
1545
|
-
return responseJSON;
|
|
1546
|
-
})
|
|
1547
|
-
.catch(response => console.error('makePostRequest ERROR :: ', response)
|
|
1537
|
+
return fetch(url, fetchObj)
|
|
1538
|
+
.then(response => response.ok
|
|
1539
|
+
? response.json()
|
|
1540
|
+
: response.json().then(errData => { throw new Error(`Request failed: ${response.statusText}, ${JSON.stringify(errData)}`) })
|
|
1548
1541
|
);
|
|
1549
1542
|
}
|
|
1550
1543
|
|
|
@@ -1634,7 +1627,7 @@ function base64ToArrayBuffer(base64) {
|
|
|
1634
1627
|
"api_path" : "INLINE_WASM",
|
|
1635
1628
|
"installation_description" : (typeof window !== 'undefined' ? window?.navigator?.userAgent : ''),
|
|
1636
1629
|
"log_level" : 'Debug',
|
|
1637
|
-
"request_timeout_ms" :
|
|
1630
|
+
"request_timeout_ms" : 30000,
|
|
1638
1631
|
"retry_count" : 0,
|
|
1639
1632
|
"consumer_id" : "",
|
|
1640
1633
|
};
|
|
@@ -1693,21 +1686,22 @@ function base64ToArrayBuffer(base64) {
|
|
|
1693
1686
|
* @param {string} username - The username.
|
|
1694
1687
|
* @returns {Promise<string>} Resolves with the identity_id if it exists.
|
|
1695
1688
|
*/
|
|
1696
|
-
webauthnRetrieve =
|
|
1689
|
+
webauthnRetrieve = (userIdentifier, silent=false) => {
|
|
1697
1690
|
this.credentialID = null;
|
|
1698
1691
|
if(!silent) this.status='CREDENTIAL_RETRIEVING';
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1692
|
+
return this.initializeZsm(userIdentifier)
|
|
1693
|
+
.then(() => this.#zsmApi.webauthn_retrieve(userIdentifier))
|
|
1694
|
+
.then(response => {
|
|
1695
|
+
if(response.error) return false;
|
|
1696
|
+
let rawId = response.result?.get("rawId") || undefined;
|
|
1697
|
+
this.credentialID = rawId;
|
|
1698
|
+
if(!silent) this.status='CREDENTIAL_RETRIEVED';
|
|
1699
|
+
return rawId;
|
|
1700
|
+
})
|
|
1701
|
+
.catch(error => {
|
|
1702
|
+
this.status='CREDENTIAL_RETRIEVAL_FAILED';
|
|
1703
|
+
return Promise.reject(error);
|
|
1704
|
+
});
|
|
1711
1705
|
}
|
|
1712
1706
|
|
|
1713
1707
|
/**
|
|
@@ -1716,19 +1710,17 @@ function base64ToArrayBuffer(base64) {
|
|
|
1716
1710
|
* @param {boolean} createNewIdentity Create a new identity if one does not already exist
|
|
1717
1711
|
* @returns {Promise<Object>} Resolves with the retrieved identity if it exists.
|
|
1718
1712
|
*/
|
|
1719
|
-
checkIdentity =
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
if(!identityID) throw new Error('Unable to acquire identity_id!');
|
|
1727
|
-
return identityID;
|
|
1728
|
-
} catch(err) {
|
|
1713
|
+
checkIdentity = (userIdentifier, createNewIdentity=false) => {
|
|
1714
|
+
this.status='CHECKING_IDENTITY_STARTING';
|
|
1715
|
+
|
|
1716
|
+
return this.initializeZsm(userIdentifier)
|
|
1717
|
+
.then(() => this.#relyingParty.checkServerSideIdentity(createNewIdentity))
|
|
1718
|
+
.then(result => (result.identity_id) )
|
|
1719
|
+
.catch(error => {
|
|
1729
1720
|
this.status='CHECKING_IDENTITY_FAILED';
|
|
1730
|
-
|
|
1731
|
-
|
|
1721
|
+
this.#relyingParty.clearLoginCredentials();
|
|
1722
|
+
return Promise.reject(error);
|
|
1723
|
+
})
|
|
1732
1724
|
}
|
|
1733
1725
|
|
|
1734
1726
|
/**
|
|
@@ -1736,28 +1728,24 @@ function base64ToArrayBuffer(base64) {
|
|
|
1736
1728
|
* @param {string} userIdentifier - The userIdentifier.
|
|
1737
1729
|
* @returns {Promise<Object>} Resolves with the created credential.
|
|
1738
1730
|
*/
|
|
1739
|
-
webauthnCreate =
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
this.status='ENROLLMENT_FAILED';
|
|
1758
|
-
this.#relyingParty.clearEnrollmentCredentials();
|
|
1759
|
-
return Promise.reject(err);
|
|
1760
|
-
}
|
|
1731
|
+
webauthnCreate = userIdentifier => {
|
|
1732
|
+
this.status='ENROLLMENT_STARTING';
|
|
1733
|
+
return this.initializeZsm(userIdentifier)
|
|
1734
|
+
.then(() => this.#relyingParty.registrationStart())
|
|
1735
|
+
.then(publicKey => this.#zsmApi.webauthn_create(publicKey))
|
|
1736
|
+
.then(response => {
|
|
1737
|
+
let result = response.result;
|
|
1738
|
+
const credential = Object.fromEntries(
|
|
1739
|
+
[...result.entries()].map(([k, v]) => [k, k === 'response' ? Object.fromEntries(v.entries()) : v])
|
|
1740
|
+
);
|
|
1741
|
+
this.status='ENROLLMENT_FINISHED'
|
|
1742
|
+
return this.#relyingParty.registrationFinish(credential);
|
|
1743
|
+
})
|
|
1744
|
+
.catch(error => {
|
|
1745
|
+
this.status='ENROLLMENT_FAILED';
|
|
1746
|
+
this.#relyingParty.clearLoginCredentials();
|
|
1747
|
+
return Promise.reject(error);
|
|
1748
|
+
});
|
|
1761
1749
|
}
|
|
1762
1750
|
|
|
1763
1751
|
/**
|
|
@@ -1765,40 +1753,32 @@ function base64ToArrayBuffer(base64) {
|
|
|
1765
1753
|
* @param {string} userIdentifier - The userIdentifier.
|
|
1766
1754
|
* @returns {Promise<Object>} Resolves with the signed challenge and authentication details.
|
|
1767
1755
|
*/
|
|
1768
|
-
webauthnGet =
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
signature : credential.response.signature,
|
|
1791
|
-
signedChallenge : credential.response.clientDataJSON,
|
|
1792
|
-
user_id : authObject.user_id,
|
|
1793
|
-
token : authObject.token,
|
|
1794
|
-
challenge,
|
|
1795
|
-
credential
|
|
1796
|
-
}
|
|
1797
|
-
return authOutput;
|
|
1798
|
-
} catch(err) {
|
|
1756
|
+
webauthnGet = userIdentifier => {
|
|
1757
|
+
this.status='AUTHENTICATION_STARTING';
|
|
1758
|
+
return this.initializeZsm(userIdentifier)
|
|
1759
|
+
.then(() => this.isEnrolled
|
|
1760
|
+
? this.#relyingParty.authenticationStart(this.credentialID)
|
|
1761
|
+
: Promise.reject(new Error(`Credential is missing for ${userIdentifier}`))
|
|
1762
|
+
)
|
|
1763
|
+
.then(data => this.#zsmApi.webauthn_get(data.rcr.publicKey)
|
|
1764
|
+
.then(response => ({ response, challenge: data.rcr.publicKey.challenge }))
|
|
1765
|
+
)
|
|
1766
|
+
.then(({ response, challenge }) => {
|
|
1767
|
+
const credential = Object.fromEntries([...response.result.entries()].map(([k, v]) => [k, k === 'response' ? Object.fromEntries(v.entries()) : v]));
|
|
1768
|
+
return this.#relyingParty.authenticationFinish(credential)
|
|
1769
|
+
.then((output) => ({
|
|
1770
|
+
signature : credential.response.signature,
|
|
1771
|
+
signedChallenge : credential.response.clientDataJSON,
|
|
1772
|
+
user_id : output.user_id,
|
|
1773
|
+
token : output.token,
|
|
1774
|
+
challenge,
|
|
1775
|
+
credential
|
|
1776
|
+
}))
|
|
1777
|
+
}).catch(error => {
|
|
1799
1778
|
this.status='AUTHENTICATION_FAILED';
|
|
1800
|
-
|
|
1801
|
-
|
|
1779
|
+
this.#relyingParty.clearLoginCredentials();
|
|
1780
|
+
return Promise.reject(error);
|
|
1781
|
+
})
|
|
1802
1782
|
}
|
|
1803
1783
|
|
|
1804
1784
|
/**
|
|
@@ -1858,16 +1838,16 @@ function base64ToArrayBuffer(base64) {
|
|
|
1858
1838
|
}
|
|
1859
1839
|
|
|
1860
1840
|
authenticate = async (userIdentifier=this.userIdentifier) => {
|
|
1861
|
-
|
|
1841
|
+
try {
|
|
1862
1842
|
let userIsEnrolled = await this.checkEnrollment(userIdentifier);
|
|
1863
1843
|
if(userIsEnrolled === false) throw(`${userIdentifier} is not enrolled.`);
|
|
1864
1844
|
let authCredentalIdentity = await this.#zsmAPI.webauthnGet(userIdentifier);
|
|
1865
1845
|
return authCredentalIdentity;
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1846
|
+
} catch(e) {
|
|
1847
|
+
e = e.message || e;
|
|
1848
|
+
e = 'Unable to authenticate user:' + e;
|
|
1849
|
+
return new Error(e);
|
|
1850
|
+
}
|
|
1871
1851
|
}
|
|
1872
1852
|
|
|
1873
1853
|
resetDevice = async () => { this.#zsmAPI.webauthnReset(); }
|