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