@canton-network/core-signing-blockdaemon 1.7.0 → 1.9.0

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/index.js CHANGED
@@ -1,305 +1,281 @@
1
- import { PartyMode, SigningProvider, buildController } from '@canton-network/core-signing-lib';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
-
7
- // src/signing-api-sdk.ts
1
+ import { PartyMode, SigningProvider, buildController } from "@canton-network/core-signing-lib";
2
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
3
+ function _typeof(o) {
4
+ "@babel/helpers - typeof";
5
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
+ return typeof o;
7
+ } : function(o) {
8
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9
+ }, _typeof(o);
10
+ }
11
+ //#endregion
12
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
13
+ function toPrimitive(t, r) {
14
+ if ("object" != _typeof(t) || !t) return t;
15
+ var e = t[Symbol.toPrimitive];
16
+ if (void 0 !== e) {
17
+ var i = e.call(t, r || "default");
18
+ if ("object" != _typeof(i)) return i;
19
+ throw new TypeError("@@toPrimitive must return a primitive value.");
20
+ }
21
+ return ("string" === r ? String : Number)(t);
22
+ }
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
25
+ function toPropertyKey(t) {
26
+ var i = toPrimitive(t, "string");
27
+ return "symbol" == _typeof(i) ? i : i + "";
28
+ }
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
31
+ function _defineProperty(e, r, t) {
32
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
33
+ value: t,
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ writable: !0
37
+ }) : e[r] = t, e;
38
+ }
39
+ //#endregion
40
+ //#region src/signing-api-sdk.ts
41
+ /**
42
+ * A TypeScript SDK client for the Wallet Signing API.
43
+ */
8
44
  var SigningAPIClient = class {
9
- constructor(baseUrl) {
10
- __publicField(this, "baseUrl");
11
- __publicField(this, "apiKey");
12
- __publicField(this, "masterKey");
13
- __publicField(this, "caip2");
14
- this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
15
- this.masterKey = "Default";
16
- this.caip2 = "canton:devnet";
17
- }
18
- async post(endpoint, params) {
19
- const url = `${this.baseUrl}${endpoint}`;
20
- const bodyToSend = {
21
- masterKey: this.masterKey,
22
- caip2: this.caip2,
23
- ...params
24
- };
25
- const headers = {
26
- "Content-Type": "application/json"
27
- };
28
- if (this.apiKey) {
29
- headers["Authorization"] = `Bearer ${this.apiKey}`;
30
- }
31
- const response = await fetch(url, {
32
- method: "POST",
33
- headers,
34
- body: JSON.stringify(bodyToSend)
35
- });
36
- if (!response.ok) {
37
- const errorText = await response.text();
38
- throw new Error(
39
- `API call to ${endpoint} failed (${response.status}): ${errorText || response.statusText}`
40
- );
41
- }
42
- if (response.status === 204 || response.headers.get("content-length") === "0") {
43
- return {};
44
- }
45
- return response.json();
46
- }
47
- /**
48
- * Uses the Wallet Provider to sign a transaction.
49
- * @param params - The transaction signing parameters.
50
- */
51
- async signTransaction(params) {
52
- return this.post(
53
- "/signTransaction",
54
- params
55
- );
56
- }
57
- /**
58
- * Get the status of a single transaction by its ID.
59
- * @param params - The transaction ID parameters.
60
- */
61
- async getTransaction(params) {
62
- return this.post(
63
- "/getTransaction",
64
- params
65
- );
66
- }
67
- /**
68
- * Get the status of multiple transactions.
69
- * @param params - Filters for transactions.
70
- */
71
- async getTransactions(params) {
72
- return this.post(
73
- "/getTransactions",
74
- params
75
- );
76
- }
77
- /**
78
- * Get a list of public keys available for signing.
79
- */
80
- async getKeys() {
81
- return this.post("/getKeys", {});
82
- }
83
- /**
84
- * Create a new key at the Wallet Provider.
85
- * @param params - The key creation parameters.
86
- */
87
- async createKey(params) {
88
- return this.post("/createKey", params);
89
- }
90
- /**
91
- * Get configuration parameters (client-side only).
92
- * Returns the current BaseURL, ApiKey, MasterKey, and CAIP2 settings.
93
- */
94
- getConfiguration() {
95
- return {
96
- BaseURL: this.baseUrl,
97
- ApiKey: this.apiKey,
98
- MasterKey: this.masterKey,
99
- CAIP2: this.caip2
100
- };
101
- }
102
- /**
103
- * Set configuration parameters (client-side only).
104
- * Updates only the provided configuration fields.
105
- *
106
- * @param params - Configuration parameters to set. All fields are optional.
107
- */
108
- setConfiguration(params) {
109
- if (params.BaseURL !== void 0) {
110
- this.baseUrl = params.BaseURL.endsWith("/") ? params.BaseURL.slice(0, -1) : params.BaseURL;
111
- }
112
- if (params.ApiKey !== void 0) {
113
- this.apiKey = params.ApiKey;
114
- }
115
- if (params.MasterKey !== void 0) {
116
- this.masterKey = params.MasterKey;
117
- }
118
- if (params.Caip2 !== void 0) {
119
- this.caip2 = params.Caip2;
120
- }
121
- return this.getConfiguration();
122
- }
45
+ constructor(baseUrl) {
46
+ _defineProperty(this, "baseUrl", void 0);
47
+ _defineProperty(this, "apiKey", void 0);
48
+ _defineProperty(this, "masterKey", void 0);
49
+ _defineProperty(this, "caip2", void 0);
50
+ this.baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
51
+ this.masterKey = "Default";
52
+ this.caip2 = "canton:devnet";
53
+ }
54
+ async post(endpoint, params) {
55
+ const url = `${this.baseUrl}${endpoint}`;
56
+ const bodyToSend = {
57
+ masterKey: this.masterKey,
58
+ caip2: this.caip2,
59
+ ...params
60
+ };
61
+ const headers = { "Content-Type": "application/json" };
62
+ if (this.apiKey) headers["Authorization"] = `Bearer ${this.apiKey}`;
63
+ const response = await fetch(url, {
64
+ method: "POST",
65
+ headers,
66
+ body: JSON.stringify(bodyToSend)
67
+ });
68
+ if (!response.ok) {
69
+ const errorText = await response.text();
70
+ throw new Error(`API call to ${endpoint} failed (${response.status}): ${errorText || response.statusText}`);
71
+ }
72
+ if (response.status === 204 || response.headers.get("content-length") === "0") return {};
73
+ return response.json();
74
+ }
75
+ /**
76
+ * Uses the Wallet Provider to sign a transaction.
77
+ * @param params - The transaction signing parameters.
78
+ */
79
+ async signTransaction(params) {
80
+ return this.post("/signTransaction", params);
81
+ }
82
+ /**
83
+ * Get the status of a single transaction by its ID.
84
+ * @param params - The transaction ID parameters.
85
+ */
86
+ async getTransaction(params) {
87
+ return this.post("/getTransaction", params);
88
+ }
89
+ /**
90
+ * Get the status of multiple transactions.
91
+ * @param params - Filters for transactions.
92
+ */
93
+ async getTransactions(params) {
94
+ return this.post("/getTransactions", params);
95
+ }
96
+ /**
97
+ * Get a list of public keys available for signing.
98
+ */
99
+ async getKeys() {
100
+ return this.post("/getKeys", {});
101
+ }
102
+ /**
103
+ * Create a new key at the Wallet Provider.
104
+ * @param params - The key creation parameters.
105
+ */
106
+ async createKey(params) {
107
+ return this.post("/createKey", params);
108
+ }
109
+ /**
110
+ * Get configuration parameters (client-side only).
111
+ * Returns the current BaseURL, ApiKey, MasterKey, and CAIP2 settings.
112
+ */
113
+ getConfiguration() {
114
+ return {
115
+ BaseURL: this.baseUrl,
116
+ ApiKey: this.apiKey,
117
+ MasterKey: this.masterKey,
118
+ CAIP2: this.caip2
119
+ };
120
+ }
121
+ /**
122
+ * Set configuration parameters (client-side only).
123
+ * Updates only the provided configuration fields.
124
+ *
125
+ * @param params - Configuration parameters to set. All fields are optional.
126
+ */
127
+ setConfiguration(params) {
128
+ if (params.BaseURL !== void 0) this.baseUrl = params.BaseURL.endsWith("/") ? params.BaseURL.slice(0, -1) : params.BaseURL;
129
+ if (params.ApiKey !== void 0) this.apiKey = params.ApiKey;
130
+ if (params.MasterKey !== void 0) this.masterKey = params.MasterKey;
131
+ if (params.Caip2 !== void 0) this.caip2 = params.Caip2;
132
+ return this.getConfiguration();
133
+ }
123
134
  };
124
-
125
- // src/index.ts
135
+ //#endregion
136
+ //#region src/index.ts
126
137
  var BlockdaemonSigningDriver = class {
127
- constructor(config) {
128
- __publicField(this, "client");
129
- __publicField(this, "partyMode", PartyMode.EXTERNAL);
130
- __publicField(this, "signingProvider", SigningProvider.BLOCKDAEMON);
131
- __publicField(this, "controller", (userId) => buildController({
132
- signTransaction: async (params) => {
133
- try {
134
- if (!params.keyIdentifier.publicKey) {
135
- return {
136
- error: "key_not_found",
137
- error_description: "The provided key identifier must include a publicKey."
138
- };
139
- }
140
- const tx = await this.client.signTransaction({
141
- tx: params.tx,
142
- txHash: params.txHash,
143
- keyIdentifier: params.keyIdentifier,
144
- ...params.internalTxId !== void 0 && {
145
- internalTxId: params.internalTxId
146
- },
147
- userIdentifier: userId
148
- });
149
- return {
150
- txId: tx.txId,
151
- status: tx.status,
152
- ...tx.signature !== void 0 && {
153
- signature: tx.signature
154
- },
155
- ...tx.publicKey !== void 0 && {
156
- publicKey: tx.publicKey
157
- },
158
- ...tx.metadata !== void 0 && {
159
- metadata: tx.metadata
160
- }
161
- };
162
- } catch (error) {
163
- return {
164
- error: "signing_error",
165
- error_description: error.message
166
- };
167
- }
168
- },
169
- // TODO remove comment below and write a test once implemented
170
- // v8 ignore next -- @preserve
171
- signMessage: async () => {
172
- return {
173
- error: "not_allowed",
174
- error_description: "Signing messages is not yet supported with Blockdaemon."
175
- };
176
- },
177
- getTransaction: async (params) => {
178
- try {
179
- const tx = await this.client.getTransaction({
180
- txId: params.txId
181
- });
182
- return {
183
- txId: tx.txId,
184
- status: tx.status,
185
- ...tx.signature !== void 0 && {
186
- signature: tx.signature
187
- },
188
- ...tx.publicKey !== void 0 && {
189
- publicKey: tx.publicKey
190
- },
191
- ...tx.metadata !== void 0 && {
192
- metadata: tx.metadata
193
- }
194
- };
195
- } catch (error) {
196
- return {
197
- error: "transaction_not_found",
198
- error_description: error.message
199
- };
200
- }
201
- },
202
- getTransactions: async (params) => {
203
- if (params.publicKeys || params.txIds) {
204
- try {
205
- const transactions = await this.client.getTransactions({
206
- txIds: params.txIds,
207
- publicKeys: params.publicKeys,
208
- userIdentifier: userId
209
- });
210
- return {
211
- transactions: transactions.map((tx) => ({
212
- txId: tx.txId,
213
- status: tx.status,
214
- ...tx.signature !== void 0 && {
215
- signature: tx.signature
216
- },
217
- ...tx.publicKey !== void 0 && {
218
- publicKey: tx.publicKey
219
- },
220
- ...tx.metadata !== void 0 && {
221
- metadata: tx.metadata
222
- }
223
- }))
224
- };
225
- } catch (error) {
226
- return {
227
- error: "fetch_error",
228
- error_description: error.message
229
- };
230
- }
231
- } else {
232
- return {
233
- error: "bad_arguments",
234
- error_description: "either public key or txIds must be supplied"
235
- };
236
- }
237
- },
238
- getKeys: async () => {
239
- try {
240
- const keys = await this.client.getKeys();
241
- return {
242
- keys: keys.map((k) => ({
243
- id: k.id,
244
- name: k.name,
245
- publicKey: k.publicKey,
246
- userIdentifier: userId
247
- }))
248
- };
249
- } catch (error) {
250
- return {
251
- error: "fetch_error",
252
- error_description: error.message
253
- };
254
- }
255
- },
256
- createKey: async (params) => {
257
- try {
258
- const key = await this.client.createKey({
259
- name: params.name,
260
- userIdentifier: userId
261
- });
262
- return {
263
- id: key.id,
264
- name: key.name,
265
- publicKey: key.publicKey
266
- };
267
- } catch (error) {
268
- return {
269
- error: "create_key_error",
270
- error_description: error.message
271
- };
272
- }
273
- },
274
- getConfiguration: async () => {
275
- const config = this.client.getConfiguration();
276
- return {
277
- ...config,
278
- ApiKey: config.ApiKey ? "***HIDDEN***" : void 0,
279
- MasterKey: config.MasterKey ? "***HIDDEN***" : void 0
280
- };
281
- },
282
- setConfiguration: async (params) => {
283
- this.client.setConfiguration({
284
- BaseURL: params["BaseURL"],
285
- ApiKey: params["ApiKey"],
286
- MasterKey: params["MasterKey"],
287
- Caip2: params["Caip2"]
288
- });
289
- return params;
290
- },
291
- // TODO remove comment below and write a test once / if ever implemented
292
- // v8 ignore next -- @preserve
293
- subscribeTransactions: async (_params) => Promise.resolve({})
294
- }));
295
- this.client = new SigningAPIClient(config.baseUrl);
296
- this.client.setConfiguration({
297
- ApiKey: config.apiKey,
298
- Caip2: config.caip2
299
- });
300
- }
138
+ constructor(config) {
139
+ _defineProperty(this, "client", void 0);
140
+ _defineProperty(this, "partyMode", PartyMode.EXTERNAL);
141
+ _defineProperty(this, "signingProvider", SigningProvider.BLOCKDAEMON);
142
+ _defineProperty(this, "controller", (userId) => buildController({
143
+ signTransaction: async (params) => {
144
+ try {
145
+ if (!params.keyIdentifier.publicKey) return {
146
+ error: "key_not_found",
147
+ error_description: "The provided key identifier must include a publicKey."
148
+ };
149
+ const tx = await this.client.signTransaction({
150
+ tx: params.tx,
151
+ txHash: params.txHash,
152
+ keyIdentifier: params.keyIdentifier,
153
+ ...params.internalTxId !== void 0 && { internalTxId: params.internalTxId },
154
+ userIdentifier: userId
155
+ });
156
+ return {
157
+ txId: tx.txId,
158
+ status: tx.status,
159
+ ...tx.signature !== void 0 && { signature: tx.signature },
160
+ ...tx.publicKey !== void 0 && { publicKey: tx.publicKey },
161
+ ...tx.metadata !== void 0 && { metadata: tx.metadata }
162
+ };
163
+ } catch (error) {
164
+ return {
165
+ error: "signing_error",
166
+ error_description: error.message
167
+ };
168
+ }
169
+ },
170
+ // v8 ignore next -- @preserve
171
+ signMessage: async () => {
172
+ return {
173
+ error: "not_allowed",
174
+ error_description: "Signing messages is not yet supported with Blockdaemon."
175
+ };
176
+ },
177
+ getTransaction: async (params) => {
178
+ try {
179
+ const tx = await this.client.getTransaction({ txId: params.txId });
180
+ return {
181
+ txId: tx.txId,
182
+ status: tx.status,
183
+ ...tx.signature !== void 0 && { signature: tx.signature },
184
+ ...tx.publicKey !== void 0 && { publicKey: tx.publicKey },
185
+ ...tx.metadata !== void 0 && { metadata: tx.metadata }
186
+ };
187
+ } catch (error) {
188
+ return {
189
+ error: "transaction_not_found",
190
+ error_description: error.message
191
+ };
192
+ }
193
+ },
194
+ getTransactions: async (params) => {
195
+ if (params.publicKeys || params.txIds) try {
196
+ return { transactions: (await this.client.getTransactions({
197
+ txIds: params.txIds,
198
+ publicKeys: params.publicKeys,
199
+ userIdentifier: userId
200
+ })).map((tx) => ({
201
+ txId: tx.txId,
202
+ status: tx.status,
203
+ ...tx.signature !== void 0 && { signature: tx.signature },
204
+ ...tx.publicKey !== void 0 && { publicKey: tx.publicKey },
205
+ ...tx.metadata !== void 0 && { metadata: tx.metadata }
206
+ })) };
207
+ } catch (error) {
208
+ return {
209
+ error: "fetch_error",
210
+ error_description: error.message
211
+ };
212
+ }
213
+ else return {
214
+ error: "bad_arguments",
215
+ error_description: "either public key or txIds must be supplied"
216
+ };
217
+ },
218
+ getKeys: async () => {
219
+ try {
220
+ return { keys: (await this.client.getKeys()).map((k) => ({
221
+ id: k.id,
222
+ name: k.name,
223
+ publicKey: k.publicKey,
224
+ userIdentifier: userId
225
+ })) };
226
+ } catch (error) {
227
+ return {
228
+ error: "fetch_error",
229
+ error_description: error.message
230
+ };
231
+ }
232
+ },
233
+ createKey: async (params) => {
234
+ try {
235
+ const key = await this.client.createKey({
236
+ name: params.name,
237
+ userIdentifier: userId
238
+ });
239
+ return {
240
+ id: key.id,
241
+ name: key.name,
242
+ publicKey: key.publicKey
243
+ };
244
+ } catch (error) {
245
+ return {
246
+ error: "create_key_error",
247
+ error_description: error.message
248
+ };
249
+ }
250
+ },
251
+ getConfiguration: async () => {
252
+ const config = this.client.getConfiguration();
253
+ return {
254
+ ...config,
255
+ ApiKey: config.ApiKey ? "***HIDDEN***" : void 0,
256
+ MasterKey: config.MasterKey ? "***HIDDEN***" : void 0
257
+ };
258
+ },
259
+ setConfiguration: async (params) => {
260
+ this.client.setConfiguration({
261
+ BaseURL: params["BaseURL"],
262
+ ApiKey: params["ApiKey"],
263
+ MasterKey: params["MasterKey"],
264
+ Caip2: params["Caip2"]
265
+ });
266
+ return params;
267
+ },
268
+ // v8 ignore next -- @preserve
269
+ subscribeTransactions: async (_params) => Promise.resolve({})
270
+ }));
271
+ this.client = new SigningAPIClient(config.baseUrl);
272
+ this.client.setConfiguration({
273
+ ApiKey: config.apiKey,
274
+ Caip2: config.caip2
275
+ });
276
+ }
301
277
  };
302
-
278
+ //#endregion
303
279
  export { SigningAPIClient, BlockdaemonSigningDriver as default };
304
- //# sourceMappingURL=index.js.map
280
+
305
281
  //# sourceMappingURL=index.js.map