@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.
Files changed (2) hide show
  1. package/package.json +44 -24
  2. package/zsm-client-sdk.js +79 -99
package/package.json CHANGED
@@ -1,29 +1,49 @@
1
1
  {
2
- "name" : "@ideem/zsm-client-sdk",
3
- "version" : "2.2.4",
4
- "description" : "A monolithic library exporting UMFAClient and FIDO2Client.",
5
- "author" : "@JJ (Jason Jurusz) <jj@useideem.com>/<nerdy.deeds@done.cheap>",
6
- "keywords" : [ "ideem", "zsm", "zsm-client-sdk", "UMFAClient", "FIDO2Client", "library", "UMFA", "FIDO2", "client", "authentication", "javascript", "multi-factor", "webauthn", "authentication", "security" ],
7
- "scripts" : {
8
- "start" : "echo 'This is a library, not an application. No start script defined. To use, import the library.'",
9
- "postpack" : "rm -rf ./*.tgz 2>/dev/null && fn=\"$(ls -1 ../ | grep -e ^ideem-zsm)\" && mv \"../$fn\" \"../$(sed -e \"s/^ideem-//\" <<< \"$fn\")\""
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
- "Joel Teply <joel@useideem.com>",
13
- "Todd Decker <todd@useideem.com>",
14
- "Brian Koziel <brian@useideem.com>",
15
- "@JJ <jj@useideem.com>"
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" : "zsm-client-sdk.js",
18
- "module" : "zsm-client-sdk.js",
19
- "browser" : "zsm-client-sdk.js",
20
- "license" : "SEE LICENSE IN LICENSE",
21
- "repository" : {
22
- "type" : "git",
23
- "url" : "https://github.com/useideem/vHSM.git"
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" : "https://github.com/useideem/vHSM/issues",
26
- "homepage" : "http://useideem.com",
27
- "files" : ["zsm-client-sdk.js"],
28
- "engines" : { "node" : ">=20.0.0"}
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 fetch(url, fetchObj)
1540
- .then(response => console.log('response, response.ok :', response, response.ok) || response)
1541
- .then(response => {
1542
- if(!response.ok) throw new Error(`Request failed: ${response.statusText}`);
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" : 100000,
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 = async (userIdentifier, silent=false) => {
1689
+ webauthnRetrieve = (userIdentifier, silent=false) => {
1697
1690
  this.credentialID = null;
1698
1691
  if(!silent) this.status='CREDENTIAL_RETRIEVING';
1699
- await this.initializeZsm(userIdentifier)
1700
- const retrievedUser = await this.#zsmApi.webauthn_retrieve(userIdentifier);
1701
- if(retrievedUser.error) return false;
1702
-
1703
- const userData = retrievedUser.result;
1704
-
1705
- const userDataRes = (!Object.entries(userData).length) ? Object.fromEntries(userData.entries()) : userData;
1706
- const userRawId = userDataRes.rawId || undefined;
1707
-
1708
- if(!userRawId) return false;
1709
- this.credentialID = userRawId;
1710
- return userRawId;
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 = async (userIdentifier, createNewIdentity=false) => {
1720
- try {
1721
- this.status='CHECKING_IDENTITY_STARTING';
1722
- await this.initializeZsm(userIdentifier);
1723
- const resultOfCheck = await this.#relyingParty.checkServerSideIdentity(createNewIdentity);
1724
- if(!resultOfCheck) throw new Error('Unable to communicate with identity server!');
1725
- const identityID = resultOfCheck.identity_id;
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
- return Promise.reject(err);
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 = async (userIdentifier) => {
1740
- try {
1741
- this.status='ENROLLMENT_STARTING';
1742
- await this.initializeZsm(userIdentifier);
1743
- const publicKey = await this.#relyingParty.registrationStart();
1744
- const webAuthnRes = await this.#zsmApi.webauthn_create(publicKey);
1745
-
1746
- if(!webAuthnRes?.result) throw new Error('[mpc_round] webauthnCreate failed');
1747
-
1748
- const credObjRAW = webAuthnRes.result;
1749
- const credential = (!Object.entries(credObjRAW).length) ? Object.fromEntries(credObjRAW.entries()) : credObjRAW;
1750
-
1751
- if(!credential.response) throw new Error('Unable to acquire attestation object!');
1752
- credential.response = (!Object.entries(credential.response).length) ? Object.fromEntries(credential.response.entries()) : credential.response;
1753
-
1754
- const regObject = await this.#relyingParty.registrationFinish(credential);
1755
- return regObject;
1756
- } catch(err) {
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 = async (userIdentifier) => {
1769
- try {
1770
- this.status='AUTHENTICATION_STARTING';
1771
- await this.initializeZsm(userIdentifier)
1772
- if(!this.isEnrolled) throw new Error(`Credential is missing for ${userIdentifier}`);
1773
-
1774
- const authData = await this.#relyingParty.authenticationStart(this.credentialID);
1775
- if(!authData?.rcr?.publicKey) throw new Error(`Unable to acquire public key!`);
1776
-
1777
- const publicKey = authData.rcr.publicKey;
1778
- const challenge = publicKey.challenge;
1779
-
1780
- const webAuthnRes = await this.#zsmApi.webauthn_get(publicKey);
1781
- const credObjRAW = webAuthnRes.result;
1782
- const credential = (!Object.entries(credObjRAW).length) ? Object.fromEntries(credObjRAW.entries()) : credObjRAW;
1783
- credential.challenge = challenge;
1784
-
1785
- if(!credential.response) throw new Error('Unable to acquire credential challenge response!');
1786
- credential.response = (!Object.entries(credential.response).length) ? Object.fromEntries(credential.response.entries()) : credential.response;
1787
-
1788
- const authObject = await this.#relyingParty.authenticationFinish(credential);
1789
- const authOutput = {
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
- return Promise.reject(err);
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
- // try {
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
- // } catch(e) {
1867
- // e = e.message || e;
1868
- // e = 'Unable to authenticate user:' + e;
1869
- // return new Error(e);
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(); }