@cubist-labs/cubesigner-sdk 0.2.24 → 0.3.1
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/README.md +30 -28
- package/dist/cjs/package.json +41 -0
- package/dist/cjs/spec/env/beta.json +9 -0
- package/dist/cjs/spec/env/gamma.json +9 -0
- package/dist/cjs/spec/env/prod.json +9 -0
- package/dist/cjs/src/api.d.ts +634 -0
- package/dist/cjs/src/api.js +1309 -0
- package/dist/cjs/src/client.d.ts +575 -0
- package/dist/cjs/src/client.js +378 -0
- package/dist/cjs/src/env.d.ts +15 -0
- package/dist/cjs/src/env.js +35 -0
- package/dist/cjs/src/error.d.ts +29 -0
- package/dist/cjs/src/error.js +36 -0
- package/dist/cjs/src/events.d.ts +84 -0
- package/dist/cjs/src/events.js +195 -0
- package/dist/cjs/src/index.d.ts +203 -0
- package/dist/cjs/src/index.js +298 -0
- package/dist/cjs/src/key.d.ts +152 -0
- package/dist/cjs/src/key.js +242 -0
- package/dist/{src/fido.d.ts → cjs/src/mfa.d.ts} +33 -15
- package/dist/cjs/src/mfa.js +169 -0
- package/dist/cjs/src/org.d.ts +99 -0
- package/dist/cjs/src/org.js +95 -0
- package/dist/cjs/src/paginator.d.ts +76 -0
- package/dist/cjs/src/paginator.js +99 -0
- package/dist/cjs/src/response.d.ts +101 -0
- package/dist/cjs/src/response.js +164 -0
- package/dist/cjs/src/role.d.ts +283 -0
- package/dist/cjs/src/role.js +253 -0
- package/dist/cjs/src/schema.d.ts +6209 -0
- package/dist/cjs/src/schema.js +7 -0
- package/dist/cjs/src/schema_types.d.ts +113 -0
- package/dist/cjs/src/schema_types.js +3 -0
- package/dist/cjs/src/session/session_storage.d.ts +27 -0
- package/dist/cjs/src/session/session_storage.js +47 -0
- package/dist/cjs/src/session/signer_session_manager.d.ts +125 -0
- package/dist/cjs/src/session/signer_session_manager.js +239 -0
- package/dist/cjs/src/signer_session.d.ts +41 -0
- package/dist/cjs/src/signer_session.js +77 -0
- package/dist/cjs/src/user_export.d.ts +52 -0
- package/dist/cjs/src/user_export.js +129 -0
- package/dist/cjs/src/util.d.ts +56 -0
- package/dist/cjs/src/util.js +86 -0
- package/dist/esm/package.json +41 -0
- package/dist/esm/spec/env/beta.json +9 -0
- package/dist/esm/spec/env/gamma.json +9 -0
- package/dist/esm/spec/env/prod.json +9 -0
- package/dist/esm/src/api.d.ts +634 -0
- package/dist/esm/src/api.js +1299 -0
- package/dist/esm/src/client.d.ts +575 -0
- package/dist/esm/src/client.js +374 -0
- package/dist/esm/src/env.d.ts +15 -0
- package/dist/esm/src/env.js +9 -0
- package/dist/esm/src/error.d.ts +29 -0
- package/dist/esm/src/error.js +31 -0
- package/dist/esm/src/events.d.ts +84 -0
- package/dist/esm/src/events.js +189 -0
- package/dist/esm/src/index.d.ts +203 -0
- package/dist/esm/src/index.js +276 -0
- package/dist/esm/src/key.d.ts +152 -0
- package/dist/esm/src/key.js +236 -0
- package/dist/esm/src/mfa.d.ts +94 -0
- package/dist/esm/src/mfa.js +163 -0
- package/dist/esm/src/org.d.ts +99 -0
- package/dist/esm/src/org.js +91 -0
- package/dist/esm/src/paginator.d.ts +76 -0
- package/dist/esm/src/paginator.js +94 -0
- package/dist/esm/src/response.d.ts +101 -0
- package/dist/esm/src/response.js +159 -0
- package/dist/esm/src/role.d.ts +283 -0
- package/dist/esm/src/role.js +248 -0
- package/dist/esm/src/schema.d.ts +6209 -0
- package/dist/esm/src/schema.js +6 -0
- package/dist/esm/src/schema_types.d.ts +113 -0
- package/dist/esm/src/schema_types.js +2 -0
- package/dist/esm/src/session/session_storage.d.ts +27 -0
- package/dist/esm/src/session/session_storage.js +43 -0
- package/dist/esm/src/session/signer_session_manager.d.ts +125 -0
- package/dist/esm/src/session/signer_session_manager.js +235 -0
- package/dist/esm/src/signer_session.d.ts +41 -0
- package/dist/esm/src/signer_session.js +72 -0
- package/dist/esm/src/user_export.d.ts +52 -0
- package/dist/esm/src/user_export.js +99 -0
- package/dist/esm/src/util.d.ts +56 -0
- package/dist/esm/src/util.js +76 -0
- package/dist/package.json +13 -45
- package/dist/src/api.d.ts +29 -18
- package/dist/src/api.js +70 -17
- package/dist/src/client.d.ts +35 -14
- package/dist/src/client.js +12 -8
- package/dist/src/error.d.ts +29 -0
- package/dist/src/error.js +36 -0
- package/dist/src/events.d.ts +1 -1
- package/dist/src/events.js +1 -1
- package/dist/src/index.d.ts +8 -11
- package/dist/src/index.js +11 -25
- package/dist/src/key.d.ts +18 -7
- package/dist/src/key.js +52 -19
- package/dist/src/role.d.ts +46 -3
- package/dist/src/role.js +60 -8
- package/dist/src/schema.d.ts +206 -72
- package/dist/src/schema.js +1 -1
- package/dist/src/schema_types.d.ts +3 -0
- package/dist/src/schema_types.js +1 -1
- package/dist/src/session/signer_session_manager.d.ts +49 -13
- package/dist/src/session/signer_session_manager.js +104 -26
- package/dist/src/util.d.ts +14 -0
- package/dist/src/util.js +24 -27
- package/package.json +19 -46
- package/src/api.ts +81 -23
- package/src/client.ts +12 -8
- package/src/error.ts +42 -0
- package/src/events.ts +3 -1
- package/src/index.ts +12 -24
- package/src/key.ts +36 -18
- package/src/role.ts +78 -7
- package/src/schema.ts +269 -110
- package/src/schema_types.ts +3 -0
- package/src/session/session_storage.ts +0 -32
- package/src/session/signer_session_manager.ts +137 -28
- package/src/util.ts +19 -10
- package/tsconfig.json +1 -21
- package/LICENSE-APACHE +0 -177
- package/LICENSE-MIT +0 -25
- package/NOTICE +0 -13
- package/dist/examples/ethers.d.ts +0 -1
- package/dist/examples/ethers.js +0 -142
- package/dist/src/ethers/index.d.ts +0 -95
- package/dist/src/ethers/index.js +0 -208
- package/dist/src/fido.js +0 -148
- package/dist/src/session/cognito_manager.d.ts +0 -71
- package/dist/src/session/cognito_manager.js +0 -129
- package/dist/src/session/generic.d.ts +0 -47
- package/dist/src/session/generic.js +0 -3
- package/dist/src/session/management_session_manager.d.ts +0 -59
- package/dist/src/session/management_session_manager.js +0 -111
- package/dist/src/session/oidc_session_manager.d.ts +0 -78
- package/dist/src/session/oidc_session_manager.js +0 -142
- package/dist/src/session/session_manager.d.ts +0 -99
- package/dist/src/session/session_manager.js +0 -136
- package/dist/src/sign.d.ts +0 -114
- package/dist/src/sign.js +0 -248
- package/dist/test/sessions.d.ts +0 -35
- package/dist/test/sessions.js +0 -56
- package/src/ethers/index.ts +0 -249
- package/src/session/cognito_manager.ts +0 -161
- package/src/session/session_manager.ts +0 -165
package/src/schema_types.ts
CHANGED
|
@@ -56,6 +56,9 @@ export type RefreshSignerSessionRequest = schemas["AuthData"];
|
|
|
56
56
|
|
|
57
57
|
export type EvmSignRequest = schemas["Eth1SignRequest"];
|
|
58
58
|
export type EvmSignResponse = schemas["Eth1SignResponse"];
|
|
59
|
+
export type Eip191SignRequest = schemas["Eip191SignRequest"];
|
|
60
|
+
export type Eip712SignRequest = schemas["Eip712SignRequest"];
|
|
61
|
+
export type Eip191Or712SignResponse = schemas["Eip191Or712SignResponse"];
|
|
59
62
|
export type Eth2SignRequest = schemas["Eth2SignRequest"];
|
|
60
63
|
export type Eth2SignResponse = schemas["Eth2SignResponse"];
|
|
61
64
|
export type Eth2StakeRequest = schemas["StakeRequest"];
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
|
|
3
1
|
/** Interface for storing sessions. */
|
|
4
2
|
export interface SessionStorage<U> {
|
|
5
3
|
/** Store session information */
|
|
@@ -41,33 +39,3 @@ export class MemorySessionStorage<U> implements SessionStorage<U> {
|
|
|
41
39
|
this.#data = data;
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
/** Stores session information in a JSON file */
|
|
46
|
-
export class JsonFileSessionStorage<U> implements SessionStorage<U> {
|
|
47
|
-
readonly #filePath: string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Store session information.
|
|
51
|
-
* @param {U} data The session information to store
|
|
52
|
-
* @return {Promise<void>}
|
|
53
|
-
*/
|
|
54
|
-
async save(data: U): Promise<void> {
|
|
55
|
-
await fs.writeFile(this.#filePath, JSON.stringify(data), "utf-8");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Retrieve session information.
|
|
60
|
-
* @return {Promise<U>} The session information
|
|
61
|
-
*/
|
|
62
|
-
async retrieve(): Promise<U> {
|
|
63
|
-
return JSON.parse(await fs.readFile(this.#filePath, "utf-8"));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Constructor.
|
|
68
|
-
* @param {string} filePath The file path to use for storage
|
|
69
|
-
*/
|
|
70
|
-
constructor(filePath: string) {
|
|
71
|
-
this.#filePath = filePath;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { Events } from "../events";
|
|
2
|
+
import { EnvInterface } from "../env";
|
|
3
|
+
import { Client, createHttpClient, OpClient } from "../api";
|
|
4
|
+
import { MemorySessionStorage, SessionStorage } from "./session_storage";
|
|
5
|
+
import { delay } from "../util";
|
|
1
6
|
import {
|
|
2
7
|
ClientSessionInfo,
|
|
3
8
|
NewSessionResponse,
|
|
4
9
|
RefreshSignerSessionRequest,
|
|
5
10
|
} from "../schema_types";
|
|
6
|
-
import { Client, OpClient } from "../api";
|
|
7
|
-
import { HasEnv, OrgSessionManager, SessionManager } from "./session_manager";
|
|
8
|
-
import { MemorySessionStorage, SessionStorage } from "./session_storage";
|
|
9
11
|
import { EventEmitter } from "../events";
|
|
10
|
-
import {
|
|
12
|
+
import { SessionExpiredError } from "../error";
|
|
13
|
+
import { operations } from "../schema";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_EXPIRATION_BUFFER_SECS = 30;
|
|
11
16
|
|
|
12
17
|
/** JSON representation of our "signer session" file format */
|
|
13
|
-
export interface
|
|
18
|
+
export interface SignerSessionData {
|
|
14
19
|
/** The organization ID */
|
|
15
20
|
org_id: string;
|
|
16
21
|
/** The role ID */
|
|
@@ -23,6 +28,10 @@ export interface SignerSessionObject {
|
|
|
23
28
|
session_info: ClientSessionInfo;
|
|
24
29
|
/** Session expiration (in seconds since UNIX epoch) beyond which it cannot be refreshed */
|
|
25
30
|
session_exp: number | undefined; // may be missing in legacy session files
|
|
31
|
+
/** The environment */
|
|
32
|
+
env: {
|
|
33
|
+
["Dev-CubeSignerStack"]: EnvInterface;
|
|
34
|
+
};
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
/**
|
|
@@ -34,8 +43,6 @@ function secondsSinceEpochToDate(secs: number): Date {
|
|
|
34
43
|
return new Date(secs * 1000);
|
|
35
44
|
}
|
|
36
45
|
|
|
37
|
-
export interface SignerSessionData extends SignerSessionObject, HasEnv {}
|
|
38
|
-
|
|
39
46
|
/** Type of storage required for signer sessions */
|
|
40
47
|
export type SignerSessionStorage = SessionStorage<SignerSessionData>;
|
|
41
48
|
|
|
@@ -50,9 +57,14 @@ export interface SignerSessionLifetime {
|
|
|
50
57
|
grace?: number;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
/**
|
|
54
|
-
export class SignerSessionManager
|
|
60
|
+
/** Generic session manager interface. */
|
|
61
|
+
export class SignerSessionManager {
|
|
62
|
+
readonly env: EnvInterface;
|
|
63
|
+
readonly orgId: string;
|
|
64
|
+
readonly storage: SignerSessionStorage;
|
|
65
|
+
readonly events = new Events();
|
|
55
66
|
readonly #eventEmitter: EventEmitter;
|
|
67
|
+
#refreshing: boolean = false;
|
|
56
68
|
#client: { client: Client; token_exp: Date; session_exp?: Date };
|
|
57
69
|
|
|
58
70
|
/**
|
|
@@ -68,17 +80,20 @@ export class SignerSessionManager extends OrgSessionManager<SignerSessionData> {
|
|
|
68
80
|
* Refreshes the current session if needed, then returns a client using the current session.
|
|
69
81
|
*
|
|
70
82
|
* May **UPDATE/MUTATE** self.
|
|
83
|
+
*
|
|
84
|
+
* @param {operations} operation The operation that this client will be
|
|
85
|
+
* used for. This parameter is used exclusively for more accurate error
|
|
86
|
+
* reporting and does not affect functionality.
|
|
87
|
+
* @return {Client} The client with the current session
|
|
71
88
|
*/
|
|
72
|
-
async client(): Promise<Client> {
|
|
89
|
+
async client(operation?: keyof operations): Promise<Client> {
|
|
73
90
|
await this.refreshIfNeeded();
|
|
74
91
|
|
|
75
92
|
// trigger "session expired" if the session as a whole has expired
|
|
76
93
|
// or if (for whatever reason) the token is still stale
|
|
77
|
-
if (
|
|
78
|
-
SessionManager.hasExpired(this.#client.token_exp) ||
|
|
79
|
-
(this.#client.session_exp && SessionManager.hasExpired(this.#client.session_exp))
|
|
80
|
-
) {
|
|
94
|
+
if (SignerSessionManager.#hasTimestampExpired(this.#client.token_exp) || this.hasExpired()) {
|
|
81
95
|
await this.#eventEmitter.emitSessionExpired();
|
|
96
|
+
throw new SessionExpiredError(operation);
|
|
82
97
|
}
|
|
83
98
|
|
|
84
99
|
return this.#client.client;
|
|
@@ -92,19 +107,15 @@ export class SignerSessionManager extends OrgSessionManager<SignerSessionData> {
|
|
|
92
107
|
});
|
|
93
108
|
}
|
|
94
109
|
|
|
95
|
-
/**
|
|
96
|
-
* Returns whether it's time to refresh this token.
|
|
97
|
-
* @return {boolean} Whether it's time to refresh this token.
|
|
98
|
-
* @internal
|
|
99
|
-
*/
|
|
100
|
-
async isStale(): Promise<boolean> {
|
|
101
|
-
return SessionManager.isStale(this.#client.token_exp);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
110
|
/**
|
|
105
111
|
* Refreshes the session and **UPDATES/MUTATES** self.
|
|
106
112
|
*/
|
|
107
113
|
async refresh(): Promise<void> {
|
|
114
|
+
if (this.hasExpired()) {
|
|
115
|
+
await this.#eventEmitter.emitSessionExpired();
|
|
116
|
+
throw new SessionExpiredError("signerSessionRefresh");
|
|
117
|
+
}
|
|
118
|
+
|
|
108
119
|
const currSession = await this.storage.retrieve();
|
|
109
120
|
|
|
110
121
|
const client = new OpClient("signerSessionRefresh", this.#client.client, this.#eventEmitter);
|
|
@@ -125,7 +136,7 @@ export class SignerSessionManager extends OrgSessionManager<SignerSessionData> {
|
|
|
125
136
|
|
|
126
137
|
await this.storage.save(newSession);
|
|
127
138
|
this.#client = {
|
|
128
|
-
client: this
|
|
139
|
+
client: this.#createClient(newSession.token),
|
|
129
140
|
token_exp: secondsSinceEpochToDate(newSession.session_info.auth_token_exp),
|
|
130
141
|
session_exp: newSession.session_exp
|
|
131
142
|
? secondsSinceEpochToDate(newSession.session_exp)
|
|
@@ -133,6 +144,77 @@ export class SignerSessionManager extends OrgSessionManager<SignerSessionData> {
|
|
|
133
144
|
};
|
|
134
145
|
}
|
|
135
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Returns whether it's time to refresh this token.
|
|
149
|
+
* @return {boolean} Whether it's time to refresh this token.
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
async isStale(): Promise<boolean> {
|
|
153
|
+
return SignerSessionManager.#hasTimestampExpired(
|
|
154
|
+
this.#client.token_exp,
|
|
155
|
+
DEFAULT_EXPIRATION_BUFFER_SECS,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Return whether this session has expired and cannot be refreshed anymore.
|
|
161
|
+
* @return {boolean} Whether this session has expired.
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
hasExpired(): boolean {
|
|
165
|
+
return (
|
|
166
|
+
(this.#client.session_exp || false) &&
|
|
167
|
+
SignerSessionManager.#hasTimestampExpired(this.#client.session_exp)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Refreshes the session if it is about to expire.
|
|
173
|
+
* @return {boolean} Whether the session token was refreshed.
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
async refreshIfNeeded(): Promise<boolean> {
|
|
177
|
+
if (await this.isStale()) {
|
|
178
|
+
if (this.#refreshing) {
|
|
179
|
+
// wait until done refreshing
|
|
180
|
+
while (this.#refreshing) {
|
|
181
|
+
await delay(100);
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
} else {
|
|
185
|
+
// refresh
|
|
186
|
+
this.#refreshing = true;
|
|
187
|
+
try {
|
|
188
|
+
await this.refresh();
|
|
189
|
+
return true;
|
|
190
|
+
} finally {
|
|
191
|
+
this.#refreshing = false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Automatically refreshes the session in the background (if needed) every
|
|
201
|
+
* minute. This is a simple wrapper around `setInterval`.
|
|
202
|
+
* @return {number} The interval ID of the refresh timer.
|
|
203
|
+
*/
|
|
204
|
+
autoRefresh(): RefreshId {
|
|
205
|
+
return setInterval(async () => {
|
|
206
|
+
await this.refreshIfNeeded();
|
|
207
|
+
}, 60 * 1000);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Clears the auto refresh timer.
|
|
212
|
+
* @param {number} timer The timer ID to clear.
|
|
213
|
+
*/
|
|
214
|
+
clearAutoRefresh(timer: RefreshId): void {
|
|
215
|
+
clearInterval(timer);
|
|
216
|
+
}
|
|
217
|
+
|
|
136
218
|
/**
|
|
137
219
|
* @param {EnvInterface} env The CubeSigner environment
|
|
138
220
|
* @param {string} orgId The organization ID
|
|
@@ -188,19 +270,46 @@ export class SignerSessionManager extends OrgSessionManager<SignerSessionData> {
|
|
|
188
270
|
|
|
189
271
|
/**
|
|
190
272
|
* Constructor.
|
|
191
|
-
*
|
|
192
273
|
* @param {SignerSessionData} sessionData Session data
|
|
193
274
|
* @param {SignerSessionStorage} storage The session storage to use.
|
|
194
275
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
276
|
+
constructor(sessionData: SignerSessionData, storage: SignerSessionStorage) {
|
|
277
|
+
this.env = sessionData.env["Dev-CubeSignerStack"];
|
|
278
|
+
this.orgId = sessionData.org_id;
|
|
279
|
+
this.storage = storage;
|
|
197
280
|
this.#eventEmitter = new EventEmitter([this.events]);
|
|
198
281
|
this.#client = {
|
|
199
|
-
client: this
|
|
282
|
+
client: this.#createClient(sessionData.token),
|
|
200
283
|
token_exp: secondsSinceEpochToDate(sessionData.session_info.auth_token_exp),
|
|
201
284
|
session_exp: sessionData.session_exp
|
|
202
285
|
? secondsSinceEpochToDate(sessionData.session_exp)
|
|
203
286
|
: undefined,
|
|
204
287
|
};
|
|
205
288
|
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Creates a new REST client with a given token
|
|
292
|
+
* @param {string} token The authorization token to use for the client
|
|
293
|
+
* @return {Client} The new REST client
|
|
294
|
+
*/
|
|
295
|
+
#createClient(token: string): Client {
|
|
296
|
+
return createHttpClient(this.env.SignerApiRoot, token);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if a timestamp is within {@link bufferSeconds} seconds from expiration.
|
|
301
|
+
* @param {Date} exp The timestamp to check
|
|
302
|
+
* @param {number} bufferSeconds Time buffer in seconds (defaults to 0s)
|
|
303
|
+
* @return {boolean} True if the timestamp has expired
|
|
304
|
+
*/
|
|
305
|
+
static #hasTimestampExpired(exp: Date, bufferSeconds?: number): boolean {
|
|
306
|
+
bufferSeconds ??= 0;
|
|
307
|
+
const expMsSinceEpoch = exp.getTime();
|
|
308
|
+
const nowMsSinceEpoch = new Date().getTime();
|
|
309
|
+
const bufferMs = bufferSeconds * 1000;
|
|
310
|
+
return expMsSinceEpoch < nowMsSinceEpoch + bufferMs;
|
|
311
|
+
}
|
|
206
312
|
}
|
|
313
|
+
|
|
314
|
+
/** Type of the refresh timer ID. */
|
|
315
|
+
export type RefreshId = ReturnType<typeof setInterval>;
|
package/src/util.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
|
|
3
1
|
/** JSON map type */
|
|
4
2
|
export interface JsonMap {
|
|
5
3
|
[member: string]: string | number | boolean | null | JsonArray | JsonMap;
|
|
@@ -9,15 +7,14 @@ export interface JsonMap {
|
|
|
9
7
|
export type JsonArray = Array<string | number | boolean | null | JsonArray | JsonMap>;
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
10
|
+
* Path join
|
|
11
|
+
* @param {string} dir Parent directory
|
|
12
|
+
* @param {string} file Pathname
|
|
13
|
+
* @return {string} New pathname
|
|
14
14
|
*/
|
|
15
|
-
export function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
? `${process.env.HOME}/Library/Application Support`
|
|
19
|
-
: `${process.env.HOME}/.config`;
|
|
20
|
-
return path.join(configDir, "cubesigner");
|
|
15
|
+
export function pathJoin(dir: string, file: string): string {
|
|
16
|
+
const sep = globalThis?.process?.platform === "win32" ? "\\" : "/";
|
|
17
|
+
return `${dir}${sep}${file}`;
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
/**
|
|
@@ -81,3 +78,15 @@ export function encodeToBase64Url(buffer: Iterable<number>): string {
|
|
|
81
78
|
export function delay(ms: number): Promise<void> {
|
|
82
79
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
83
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Converts a string or a uint8 array into a hex string. Strings are encoded in UTF-8 before
|
|
84
|
+
* being converted to hex.
|
|
85
|
+
* @param {string | Uint8Array} message The input
|
|
86
|
+
* @return {string} Hex string prefixed with "0x"
|
|
87
|
+
*/
|
|
88
|
+
export function encodeToHex(message: string | Uint8Array): string {
|
|
89
|
+
return (
|
|
90
|
+
"0x" + (typeof message === "string" ? Buffer.from(message, "utf8") : message).toString("hex")
|
|
91
|
+
);
|
|
92
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"target": "es2021",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"noImplicitAny": true,
|
|
8
|
-
"noImplicitThis": true,
|
|
9
|
-
"alwaysStrict": true,
|
|
10
|
-
"noUnusedLocals": true,
|
|
11
|
-
"noUnusedParameters": true,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"noFallthroughCasesInSwitch": false,
|
|
14
|
-
"inlineSourceMap": true,
|
|
15
|
-
"inlineSources": true,
|
|
16
|
-
"experimentalDecorators": true,
|
|
17
|
-
"strictPropertyInitialization": true,
|
|
18
|
-
"resolveJsonModule": true,
|
|
19
|
-
"esModuleInterop": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
4
|
"outDir": "./dist"
|
|
22
5
|
},
|
|
23
6
|
"typedocOptions": {
|
|
24
7
|
"out": "./docs",
|
|
25
|
-
"excludeInternal": true,
|
|
26
|
-
"excludePrivate": true,
|
|
27
|
-
"excludeProtected": true,
|
|
28
8
|
"entryPoints": ["src/index.ts", "src/env.ts", "src/schema.ts"]
|
|
29
9
|
},
|
|
30
10
|
"exclude": ["spec", "node_modules", "dist"],
|
package/LICENSE-APACHE
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
package/LICENSE-MIT
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Copyright (C) 2022-2023 Cubist, Inc.
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any
|
|
4
|
-
person obtaining a copy of this software and associated
|
|
5
|
-
documentation files (the "Software"), to deal in the
|
|
6
|
-
Software without restriction, including without
|
|
7
|
-
limitation the rights to use, copy, modify, merge,
|
|
8
|
-
publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software
|
|
10
|
-
is furnished to do so, subject to the following
|
|
11
|
-
conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice
|
|
14
|
-
shall be included in all copies or substantial portions
|
|
15
|
-
of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
18
|
-
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
20
|
-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
21
|
-
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
24
|
-
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
-
DEALINGS IN THE SOFTWARE.
|
package/NOTICE
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Copyright (C) 2023 Cubist, Inc.
|
|
2
|
-
|
|
3
|
-
This software is licensed under either of
|
|
4
|
-
|
|
5
|
-
- Apache License, Version 2.0
|
|
6
|
-
(see https://www.apache.org/licenses/LICENSE-2.0 or LICENSE-APACHE)
|
|
7
|
-
|
|
8
|
-
- MIT license
|
|
9
|
-
(see https://opensource.org/licenses/MIT or LICENSE-MIT)
|
|
10
|
-
|
|
11
|
-
at your option.
|
|
12
|
-
|
|
13
|
-
The SPDX identifier for this project is "MIT OR Apache-2.0".
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|