@cubist-labs/cubesigner-sdk 0.3.1 → 0.3.8

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 (54) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/api.d.ts +27 -9
  3. package/dist/cjs/src/api.js +58 -22
  4. package/dist/cjs/src/client.d.ts +68 -1
  5. package/dist/cjs/src/client.js +79 -2
  6. package/dist/cjs/src/error.d.ts +3 -0
  7. package/dist/cjs/src/error.js +2 -1
  8. package/dist/cjs/src/key.d.ts +19 -2
  9. package/dist/cjs/src/key.js +22 -2
  10. package/dist/cjs/src/mfa.d.ts +6 -3
  11. package/dist/cjs/src/mfa.js +8 -5
  12. package/dist/cjs/src/response.d.ts +14 -1
  13. package/dist/cjs/src/response.js +65 -26
  14. package/dist/cjs/src/role.d.ts +6 -0
  15. package/dist/cjs/src/role.js +9 -1
  16. package/dist/cjs/src/schema.d.ts +238 -43
  17. package/dist/cjs/src/schema.js +1 -1
  18. package/dist/cjs/src/schema_types.d.ts +3 -0
  19. package/dist/cjs/src/schema_types.js +1 -1
  20. package/dist/cjs/src/session/signer_session_manager.js +3 -3
  21. package/dist/cjs/src/util.js +3 -2
  22. package/dist/esm/package.json +1 -1
  23. package/dist/esm/src/api.d.ts +27 -9
  24. package/dist/esm/src/api.js +56 -20
  25. package/dist/esm/src/client.d.ts +68 -1
  26. package/dist/esm/src/client.js +79 -2
  27. package/dist/esm/src/error.d.ts +3 -0
  28. package/dist/esm/src/error.js +2 -1
  29. package/dist/esm/src/key.d.ts +19 -2
  30. package/dist/esm/src/key.js +22 -2
  31. package/dist/esm/src/mfa.d.ts +6 -3
  32. package/dist/esm/src/mfa.js +8 -5
  33. package/dist/esm/src/response.d.ts +14 -1
  34. package/dist/esm/src/response.js +65 -26
  35. package/dist/esm/src/role.d.ts +6 -0
  36. package/dist/esm/src/role.js +9 -1
  37. package/dist/esm/src/schema.d.ts +238 -43
  38. package/dist/esm/src/schema.js +1 -1
  39. package/dist/esm/src/schema_types.d.ts +3 -0
  40. package/dist/esm/src/schema_types.js +1 -1
  41. package/dist/esm/src/session/signer_session_manager.js +3 -3
  42. package/dist/esm/src/util.js +3 -2
  43. package/package.json +1 -1
  44. package/src/api.ts +66 -19
  45. package/src/client.ts +94 -2
  46. package/src/error.ts +4 -0
  47. package/src/key.ts +31 -2
  48. package/src/mfa.ts +8 -4
  49. package/src/response.ts +50 -4
  50. package/src/role.ts +9 -0
  51. package/src/schema.ts +496 -43
  52. package/src/schema_types.ts +3 -0
  53. package/src/session/signer_session_manager.ts +2 -2
  54. package/src/util.ts +2 -3
package/src/mfa.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  ApiAddFidoChallenge,
5
5
  ApiMfaFidoChallenge,
6
6
  MfaRequestInfo,
7
+ MfaVote,
7
8
  PublicKeyCredential,
8
9
  TotpInfo,
9
10
  } from "./schema_types";
@@ -159,10 +160,12 @@ export class MfaFidoChallenge {
159
160
  /**
160
161
  * Answers this challenge by using the `CredentialsContainer` API to get a credential
161
162
  * based on the the public key credential request options from this challenge.
163
+ *
164
+ * @param {MfaVote} vote Approve or reject the MFA request. Defaults to "approve".
162
165
  */
163
- async createCredentialAndAnswer(): Promise<MfaRequestInfo> {
166
+ async createCredentialAndAnswer(vote?: MfaVote): Promise<MfaRequestInfo> {
164
167
  const cred = await navigator.credentials.get({ publicKey: this.options });
165
- return await this.answer(cred);
168
+ return await this.answer(cred, vote);
166
169
  }
167
170
 
168
171
  /**
@@ -175,8 +178,9 @@ export class MfaFidoChallenge {
175
178
  *
176
179
  * @param {any} cred Credential created by calling the `CredentialContainer`'s `get` method
177
180
  * based on the public key credential request options from this challenge.
181
+ * @param {MfaVote} vote Approve or reject. Defaults to "approve".
178
182
  */
179
- async answer(cred: any): Promise<MfaRequestInfo> {
183
+ async answer(cred: any, vote: MfaVote = "approve"): Promise<MfaRequestInfo> {
180
184
  const answer = <PublicKeyCredential>{
181
185
  id: cred.id,
182
186
  response: {
@@ -185,6 +189,6 @@ export class MfaFidoChallenge {
185
189
  signature: encodeToBase64Url(cred.response.signature),
186
190
  },
187
191
  };
188
- return await this.#api.mfaApproveFidoComplete(this.mfaId, this.challengeId, answer);
192
+ return await this.#api.mfaVoteFidoComplete(this.mfaId, vote, this.challengeId, answer);
189
193
  }
190
194
  }
package/src/response.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CubeSignerClient, SignerSession } from ".";
1
+ import { CubeSignerClient, MfaVote, SignerSession } from ".";
2
2
  import { MfaReceipt } from "./mfa";
3
3
  import { AcceptedResponse, NewSessionResponse } from "./schema_types";
4
4
 
@@ -90,13 +90,39 @@ export class CubeSignerResponse<U> {
90
90
  * @return {CubeSignerResponse<U>} The result of signing with the approval
91
91
  */
92
92
  async approveTotp(session: SignerSession, code: string): Promise<CubeSignerResponse<U>> {
93
+ return await this.#mfaVoteTotp(session, code, "approve");
94
+ }
95
+
96
+ /**
97
+ * Reject the MFA request using a given session and a TOTP code.
98
+ *
99
+ * @param {SignerSession} session Signer session to use
100
+ * @param {string} code 6-digit TOTP code
101
+ */
102
+ async rejectTotp(session: SignerSession, code: string) {
103
+ await this.#mfaVoteTotp(session, code, "reject");
104
+ }
105
+
106
+ /**
107
+ * Approve or reject an MFA request using a given session and a TOTP code.
108
+ *
109
+ * @param {SignerSession} session Signer session to use
110
+ * @param {string} code 6-digit TOTP code
111
+ * @param {MfaVote} vote Approve or reject
112
+ * @return {CubeSignerResponse<U>} The result of signing with the approval
113
+ */
114
+ async #mfaVoteTotp(
115
+ session: SignerSession,
116
+ code: string,
117
+ vote: MfaVote,
118
+ ): Promise<CubeSignerResponse<U>> {
93
119
  if (!this.requiresMfa()) {
94
120
  return this;
95
121
  }
96
122
 
97
123
  const mfaId = this.mfaId();
98
124
  const mfaOrgId = this.#mfaRequired!.org_id;
99
- const mfaApproval = await session.mfaApproveTotp(mfaId, code);
125
+ const mfaApproval = await session.mfaVoteTotp(mfaId, code, vote);
100
126
  const mfaConf = mfaApproval.receipt?.confirmation;
101
127
 
102
128
  if (!mfaConf) {
@@ -107,12 +133,32 @@ export class CubeSignerResponse<U> {
107
133
  }
108
134
 
109
135
  /**
110
- * Approve the MFA request using a given `CubeSignerClient` instance (i.e., its session).
136
+ * Approve the MFA request using a given {@link CubeSignerClient} instance (i.e., its session).
111
137
  *
112
138
  * @param {CubeSignerClient} cs CubeSigner whose session to use
113
139
  * @return {CubeSignerResponse<U>} The result of signing with the approval
114
140
  */
115
141
  async approve(cs: CubeSignerClient): Promise<CubeSignerResponse<U>> {
142
+ return await this.#mfaVoteCs(cs, "approve");
143
+ }
144
+
145
+ /**
146
+ * Reject the MFA request using a given {@link CubeSignerClient} instance (i.e., its session).
147
+ *
148
+ * @param {CubeSignerClient} cs CubeSigner client whose session to use
149
+ */
150
+ async reject(cs: CubeSignerClient) {
151
+ await this.#mfaVoteCs(cs, "reject");
152
+ }
153
+
154
+ /**
155
+ * Approve or reject an MFA request using a given {@link CubeSignerClient} instance (i.e., its session).
156
+ *
157
+ * @param {CubeSignerClient} cs CubeSigner whose session to use
158
+ * @param {MfaVote} mfaVote Approve or reject
159
+ * @return {CubeSignerResponse<U>} The result of signing with the approval
160
+ */
161
+ async #mfaVoteCs(cs: CubeSignerClient, mfaVote: MfaVote): Promise<CubeSignerResponse<U>> {
116
162
  if (!this.requiresMfa()) {
117
163
  return this;
118
164
  }
@@ -120,7 +166,7 @@ export class CubeSignerResponse<U> {
120
166
  const mfaId = this.#mfaRequired!.id;
121
167
  const mfaOrgId = this.#mfaRequired!.org_id;
122
168
 
123
- const mfaApproval = await cs.mfaApprove(mfaId);
169
+ const mfaApproval = await cs.mfaVoteCs(mfaId, mfaVote);
124
170
  const mfaConf = mfaApproval.receipt?.confirmation;
125
171
 
126
172
  if (!mfaConf) {
package/src/role.ts CHANGED
@@ -278,6 +278,15 @@ export class Role {
278
278
  await this.#csc.roleUserAdd(this.id, userId);
279
279
  }
280
280
 
281
+ /**
282
+ * Remove an existing user from an existing role.
283
+ *
284
+ * @param {string} userId The user-id of the user to remove from the role.
285
+ */
286
+ async removeUser(userId: string) {
287
+ await this.#csc.roleUserRemove(this.id, userId);
288
+ }
289
+
281
290
  /**
282
291
  * The list of keys in the role.
283
292
  * @example [