@cubist-labs/cubesigner-sdk 0.4.241 → 0.4.246
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/dist/package.json +1 -1
- package/dist/spec/env/gamma.json +5 -0
- package/dist/src/audit_log.d.ts +5 -5
- package/dist/src/audit_log.js +1 -1
- package/dist/src/client/api_client.d.ts +22 -7
- package/dist/src/client/api_client.d.ts.map +1 -1
- package/dist/src/client/api_client.js +43 -13
- package/dist/src/client/base_client.d.ts +5 -1
- package/dist/src/client/base_client.d.ts.map +1 -1
- package/dist/src/client/base_client.js +16 -10
- package/dist/src/client/session.d.ts +3 -1
- package/dist/src/client/session.d.ts.map +1 -1
- package/dist/src/client/session.js +7 -3
- package/dist/src/client.d.ts +12 -5
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +15 -4
- package/dist/src/diffie_hellman.js +2 -2
- package/dist/src/env.d.ts +7 -0
- package/dist/src/env.d.ts.map +1 -1
- package/dist/src/env.js +14 -1
- package/dist/src/fetch.d.ts.map +1 -1
- package/dist/src/fetch.js +2 -3
- package/dist/src/key.d.ts +17 -1
- package/dist/src/key.d.ts.map +1 -1
- package/dist/src/key.js +19 -3
- package/dist/src/policy.d.ts +24 -7
- package/dist/src/policy.d.ts.map +1 -1
- package/dist/src/policy.js +34 -16
- package/dist/src/response.d.ts +29 -5
- package/dist/src/response.d.ts.map +1 -1
- package/dist/src/response.js +62 -24
- package/dist/src/schema.d.ts +975 -84
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +1 -1
- package/dist/src/schema_types.d.ts +10 -1
- package/dist/src/schema_types.d.ts.map +1 -1
- package/dist/src/schema_types.js +2 -1
- package/dist/src/scopes.d.ts.map +1 -1
- package/dist/src/scopes.js +23 -3
- package/dist/src/user_export.d.ts +1 -1
- package/dist/src/user_export.js +3 -3
- package/dist/src/util.d.ts +7 -0
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +30 -7
- package/package.json +1 -1
- package/src/audit_log.ts +3 -5
- package/src/client/api_client.ts +54 -14
- package/src/client/base_client.ts +13 -3
- package/src/client/session.ts +10 -3
- package/src/client.ts +17 -4
- package/src/diffie_hellman.ts +1 -1
- package/src/env.ts +17 -0
- package/src/fetch.ts +1 -2
- package/src/key.ts +26 -2
- package/src/policy.ts +34 -16
- package/src/response.ts +72 -25
- package/src/schema.ts +1034 -92
- package/src/schema_types.ts +12 -1
- package/src/scopes.ts +22 -2
- package/src/user_export.ts +2 -2
- package/src/util.ts +34 -8
package/src/policy.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
PolicyInfo,
|
|
22
22
|
} from ".";
|
|
23
23
|
|
|
24
|
-
import { loadSubtleCrypto } from ".";
|
|
24
|
+
import { loadSubtleCrypto, encodeToHex, decodeFromHex } from ".";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Named policy rule type.
|
|
@@ -104,7 +104,7 @@ export async function uploadWasmFunction(
|
|
|
104
104
|
// get the SHA-256 hash of the function to get the upload url.
|
|
105
105
|
const subtle = await loadSubtleCrypto();
|
|
106
106
|
const hashBytes = await subtle.digest("SHA-256", policy);
|
|
107
|
-
const hash =
|
|
107
|
+
const hash = encodeToHex(new Uint8Array(hashBytes));
|
|
108
108
|
|
|
109
109
|
// get the upload URL
|
|
110
110
|
const { signed_url } = await apiClient.wasmPolicyUpload({ hash });
|
|
@@ -619,28 +619,46 @@ export class C2FInvocation {
|
|
|
619
619
|
return this.#data.response;
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
-
/**
|
|
623
|
-
|
|
624
|
-
|
|
622
|
+
/**
|
|
623
|
+
* The standard output stream as raw bytes. Usually a UTF-8 encoded string,
|
|
624
|
+
* use {@link TextDecoder} to decode.
|
|
625
|
+
*
|
|
626
|
+
* @returns The standard output stream.
|
|
627
|
+
*/
|
|
628
|
+
get stdoutBytes(): Uint8Array {
|
|
629
|
+
return decodeFromHex(this.#data.stdout);
|
|
625
630
|
}
|
|
626
631
|
|
|
627
|
-
/**
|
|
628
|
-
|
|
629
|
-
|
|
632
|
+
/**
|
|
633
|
+
* The standard error stream as raw bytes. Usually a UTF-8 encoded string, use
|
|
634
|
+
* {@link TextDecoder} to decode.
|
|
635
|
+
*
|
|
636
|
+
* @returns The standard error stream.
|
|
637
|
+
*/
|
|
638
|
+
get stderrBytes(): Uint8Array {
|
|
639
|
+
return decodeFromHex(this.#data.stderr);
|
|
630
640
|
}
|
|
631
641
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
642
|
+
/**
|
|
643
|
+
* The standard output stream as a Buffer. Usually a UTF-8 encoded string.
|
|
644
|
+
*
|
|
645
|
+
* @returns The standard output stream.
|
|
646
|
+
* @deprecated Use {@link stdoutBytes} instead for browser compatibility.
|
|
647
|
+
*/
|
|
648
|
+
get stdout(): Buffer {
|
|
649
|
+
// eslint-disable-next-line no-restricted-globals -- Buffer return type preserved for backwards compatibility
|
|
650
|
+
return Buffer.from(this.stdoutBytes);
|
|
651
|
+
}
|
|
635
652
|
|
|
636
653
|
/**
|
|
637
|
-
*
|
|
654
|
+
* The standard error stream as a Buffer. Usually a UTF-8 encoded string.
|
|
638
655
|
*
|
|
639
|
-
* @
|
|
640
|
-
* @
|
|
656
|
+
* @returns The standard error stream.
|
|
657
|
+
* @deprecated Use {@link stderrBytes} instead for browser compatibility.
|
|
641
658
|
*/
|
|
642
|
-
|
|
643
|
-
|
|
659
|
+
get stderr(): Buffer {
|
|
660
|
+
// eslint-disable-next-line no-restricted-globals -- Buffer return type preserved for backwards compatibility
|
|
661
|
+
return Buffer.from(this.stderrBytes);
|
|
644
662
|
}
|
|
645
663
|
|
|
646
664
|
/**
|
package/src/response.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MfaVote, EnvInterface, MfaReceipts, MfaRequired } from ".";
|
|
2
|
-
import { CubeSignerClient, isManyMfaReceipts } from ".";
|
|
2
|
+
import { CubeSignerClient, MultiRegionEnv, isManyMfaReceipts } from ".";
|
|
3
3
|
import { encodeToBase64Url } from "./util";
|
|
4
|
-
import type { AcceptedResponse } from "./schema_types";
|
|
4
|
+
import type { AcceptedResponse, AcceptedValue, BinanceDryRun, SignDryRun } from "./schema_types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Response type, which can be either a value of type {@link U}
|
|
@@ -29,54 +29,100 @@ export type MapFn<U, V> = (u: U) => V;
|
|
|
29
29
|
* @returns Response whose value for status code 200 is mapped from U to V
|
|
30
30
|
*/
|
|
31
31
|
export function mapResponse<U, V>(resp: Response<U>, mapFn: MapFn<U, V>): Response<V> {
|
|
32
|
-
if ((resp
|
|
32
|
+
if (asAccepted(resp) !== undefined) {
|
|
33
33
|
return resp as AcceptedResponse;
|
|
34
34
|
} else {
|
|
35
35
|
return mapFn(resp as U);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param resp The response to check
|
|
41
|
+
* @returns The {@link AcceptedValue} if the response status code is 202.
|
|
42
|
+
*/
|
|
43
|
+
function asAccepted<U>(resp: Response<U>): AcceptedValue | undefined {
|
|
44
|
+
const acceptedResp = resp as AcceptedResponse;
|
|
45
|
+
return acceptedResp.error_code === "SignDryRun" || acceptedResp.error_code === "MfaRequired"
|
|
46
|
+
? (acceptedResp.accepted ?? undefined)
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
/**
|
|
40
51
|
* A response of a CubeSigner request.
|
|
41
52
|
*/
|
|
42
53
|
export class CubeSignerResponse<U> {
|
|
43
|
-
readonly #env:
|
|
54
|
+
readonly #env: MultiRegionEnv;
|
|
44
55
|
readonly #requestFn: RequestFn<U>;
|
|
45
|
-
readonly #resp: U
|
|
56
|
+
readonly #resp: Response<U>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @returns The {@link AcceptedValue} if the response status code is 202.
|
|
60
|
+
*/
|
|
61
|
+
asAccepted(): AcceptedValue | undefined {
|
|
62
|
+
return asAccepted(this.#resp);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @returns The associated {@link MfaRequired} value, if the response status code is 202 and the response indicates that MFA is required.
|
|
67
|
+
*/
|
|
68
|
+
asMfaRequired(): MfaRequired | undefined {
|
|
69
|
+
return this.asAccepted()?.MfaRequired ?? undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
46
72
|
/**
|
|
47
|
-
*
|
|
73
|
+
* @returns The associated {@link SignDryRun} value, if the response status code is 202 and the response is a dry run of a sign operation.
|
|
48
74
|
*/
|
|
49
|
-
|
|
75
|
+
asSignDryRun(): SignDryRun | undefined {
|
|
76
|
+
return this.asAccepted()?.SignDryRun ?? undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @returns The associated {@link BinanceDryRun} value, if the response status code is 202 and the response is a dry run of a sign operation.
|
|
81
|
+
*/
|
|
82
|
+
asBinanceDryRun(): BinanceDryRun | undefined {
|
|
83
|
+
return this.asAccepted()?.BinanceDryRun ?? undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @returns Whether this response is a "200 Success" (in which case it is safe to call {@link data})
|
|
88
|
+
*/
|
|
89
|
+
isSuccess(): boolean {
|
|
90
|
+
return this.asAccepted() === undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @returns The underlying {@link MfaRequired} response (if any).
|
|
95
|
+
*/
|
|
96
|
+
private get mfaRequired() {
|
|
97
|
+
return this.asAccepted()?.MfaRequired;
|
|
98
|
+
}
|
|
50
99
|
|
|
51
100
|
/** @returns The first MFA id associated with this request (if any) */
|
|
52
101
|
mfaId(): string | undefined {
|
|
53
|
-
return this
|
|
102
|
+
return this.mfaRequired?.id;
|
|
54
103
|
}
|
|
55
104
|
|
|
56
105
|
/** @returns The MFA ids associated with this request (if any) */
|
|
57
106
|
mfaIds(): string[] {
|
|
58
|
-
return this
|
|
107
|
+
return this.mfaRequired?.ids ?? [];
|
|
59
108
|
}
|
|
60
109
|
|
|
61
110
|
/** @returns True if this request requires an MFA approval */
|
|
62
111
|
requiresMfa(): boolean {
|
|
63
|
-
return this
|
|
112
|
+
return this.mfaRequired !== undefined;
|
|
64
113
|
}
|
|
65
114
|
|
|
66
115
|
/**
|
|
67
116
|
* @returns Session information to use for any MFA approval requests (if any was included in the response).
|
|
68
117
|
*/
|
|
69
118
|
async mfaClient(): Promise<CubeSignerClient | undefined> {
|
|
70
|
-
if (this
|
|
71
|
-
const session = (
|
|
119
|
+
if (this.mfaRequired === undefined) return;
|
|
120
|
+
const session = this.asMfaRequired()?.session ?? undefined;
|
|
72
121
|
if (session === undefined) return;
|
|
73
122
|
|
|
74
|
-
const env = this.#env;
|
|
75
123
|
return await CubeSignerClient.create({
|
|
76
|
-
env:
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
org_id: this.#mfaRequired.org_id,
|
|
124
|
+
env: this.#env.spec,
|
|
125
|
+
org_id: this.mfaRequired.org_id,
|
|
80
126
|
session_exp: session.expiration,
|
|
81
127
|
session_info: session.session_info,
|
|
82
128
|
token: session.token,
|
|
@@ -86,8 +132,10 @@ export class CubeSignerResponse<U> {
|
|
|
86
132
|
|
|
87
133
|
/** @returns The response data, if no MFA is required */
|
|
88
134
|
data(): U {
|
|
89
|
-
if (this.
|
|
90
|
-
throw new Error(
|
|
135
|
+
if (!this.isSuccess()) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
"Cannot call `data()` on a 202 Accepted response; use `asMfaRequired()` or `asSignDryRun()`",
|
|
138
|
+
);
|
|
91
139
|
}
|
|
92
140
|
return this.#resp as U;
|
|
93
141
|
}
|
|
@@ -131,7 +179,7 @@ export class CubeSignerResponse<U> {
|
|
|
131
179
|
return this;
|
|
132
180
|
}
|
|
133
181
|
|
|
134
|
-
const mfaOrgId = this
|
|
182
|
+
const mfaOrgId = this.mfaRequired!.org_id;
|
|
135
183
|
const mfaApproval = await client.apiClient.mfaVoteTotp(mfaId, code, vote);
|
|
136
184
|
const mfaConf = mfaApproval.receipt?.confirmation;
|
|
137
185
|
|
|
@@ -174,7 +222,7 @@ export class CubeSignerResponse<U> {
|
|
|
174
222
|
return this;
|
|
175
223
|
}
|
|
176
224
|
|
|
177
|
-
const mfaOrgId = this
|
|
225
|
+
const mfaOrgId = this.mfaRequired!.org_id;
|
|
178
226
|
|
|
179
227
|
const mfaApproval = await client.apiClient.mfaVoteCs(mfaId, mfaVote);
|
|
180
228
|
const mfaConf = mfaApproval.receipt?.confirmation;
|
|
@@ -211,11 +259,10 @@ export class CubeSignerResponse<U> {
|
|
|
211
259
|
* @param resp The response as returned by the OpenAPI client.
|
|
212
260
|
* @internal
|
|
213
261
|
*/
|
|
214
|
-
protected constructor(env:
|
|
262
|
+
protected constructor(env: MultiRegionEnv, requestFn: RequestFn<U>, resp: Response<U>) {
|
|
215
263
|
this.#env = env;
|
|
216
264
|
this.#requestFn = requestFn;
|
|
217
265
|
this.#resp = resp;
|
|
218
|
-
this.#mfaRequired = (this.#resp as AcceptedResponse).accepted?.MfaRequired;
|
|
219
266
|
}
|
|
220
267
|
|
|
221
268
|
/**
|
|
@@ -230,12 +277,12 @@ export class CubeSignerResponse<U> {
|
|
|
230
277
|
* @internal
|
|
231
278
|
*/
|
|
232
279
|
static async create<U>(
|
|
233
|
-
env: EnvInterface,
|
|
280
|
+
env: EnvInterface | MultiRegionEnv,
|
|
234
281
|
requestFn: RequestFn<U>,
|
|
235
282
|
mfaReceipt?: MfaReceipts,
|
|
236
283
|
): Promise<CubeSignerResponse<U>> {
|
|
237
284
|
const seed = await requestFn(this.getMfaHeaders(mfaReceipt));
|
|
238
|
-
return new CubeSignerResponse(env, requestFn, seed);
|
|
285
|
+
return new CubeSignerResponse(MultiRegionEnv.create(env), requestFn, seed);
|
|
239
286
|
}
|
|
240
287
|
|
|
241
288
|
/**
|