@ledgerhq/hw-app-canton 0.6.0 → 0.7.0-nightly.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ledgerhq/hw-app-canton
2
2
 
3
+ ## 0.7.0-nightly.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#12173](https://github.com/LedgerHQ/ledger-live/pull/12173) [`f4965d6`](https://github.com/LedgerHQ/ledger-live/commit/f4965d6dfc64949b0afa765cc9e4b24324b5df1d) Thanks [@ishaba](https://github.com/ishaba)! - add canton full transaction signing support
8
+
3
9
  ## 0.6.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -55,12 +55,13 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
55
55
 
56
56
  #### signTransaction
57
57
 
58
- Sign a Canton transaction.
58
+ Sign a Canton transaction
59
+ using the appropriate signing method based on transaction type.
59
60
 
60
61
  ##### Parameters
61
62
 
62
63
  * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP-32 format
63
- * `txHash` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the transaction hash to sign
64
+ * `data` **(CantonPreparedTransaction | CantonUntypedVersionedMessage | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** either prepared transaction components, untyped versioned message, or txHash string (backwards compatibility)
64
65
 
65
66
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<CantonSignature>** the signature
66
67
 
package/lib/Canton.d.ts CHANGED
@@ -8,6 +8,15 @@ export type CantonAddress = {
8
8
  path: string;
9
9
  };
10
10
  export type CantonSignature = string;
11
+ export type CantonPreparedTransaction = {
12
+ damlTransaction: Uint8Array;
13
+ nodes: Uint8Array[];
14
+ metadata: Uint8Array;
15
+ inputContracts: Uint8Array[];
16
+ };
17
+ export type CantonUntypedVersionedMessage = {
18
+ transactions: string[];
19
+ };
11
20
  /**
12
21
  * Canton BOLOS API
13
22
  */
@@ -23,18 +32,49 @@ export default class Canton {
23
32
  */
24
33
  getAddress(path: string, display?: boolean): Promise<CantonAddress>;
25
34
  /**
26
- * Sign a Canton transaction.
35
+ * Sign a Canton transaction
36
+ * using the appropriate signing method based on transaction type.
27
37
  *
28
38
  * @param path a path in BIP-32 format
29
- * @param txHash the transaction hash to sign
39
+ * @param data either prepared transaction components, untyped versioned message, or txHash string (backwards compatibility)
30
40
  * @return the signature
31
41
  */
32
- signTransaction(path: string, txHash: string): Promise<CantonSignature>;
42
+ signTransaction(path: string, data: CantonPreparedTransaction | CantonUntypedVersionedMessage | string): Promise<CantonSignature>;
43
+ /**
44
+ * Sign a transaction hash (backwards compatibility)
45
+ * @private
46
+ */
47
+ private signTxHash;
48
+ /**
49
+ * Sign a prepared Canton transaction
50
+ * @private
51
+ */
52
+ private signPreparedTransaction;
53
+ /**
54
+ * Sign topology transactions for Canton onboarding
55
+ * @private
56
+ */
57
+ private signUntypedVersionedMessage;
33
58
  /**
34
59
  * Get the app configuration.
35
60
  * @return the app configuration including version
36
61
  */
37
62
  getAppConfiguration(): Promise<AppConfig>;
63
+ /**
64
+ * Validate Uint8Array with descriptive error message
65
+ * @private
66
+ */
67
+ private validateUint8Array;
68
+ /**
69
+ * Unified chunking strategy for sending data to device
70
+ * @private
71
+ */
72
+ private sendChunkedData;
73
+ /**
74
+ * Create optimized chunks from payload
75
+ * @private
76
+ */
77
+ private createChunks;
38
78
  /**
39
79
  * Converts 65-byte Canton format to 64-byte Ed25519:
40
80
  * [40][64_bytes_signature][00] (132 hex chars)
@@ -42,10 +82,16 @@ export default class Canton {
42
82
  */
43
83
  private cleanSignatureFormat;
44
84
  /**
45
- * Helper method to handle transport response and check for errors
85
+ * Check transport response for errors and throw appropriate exceptions
86
+ * @private
87
+ */
88
+ private checkTransportResponse;
89
+ /**
90
+ * Extract response data from transport response
91
+ * APDU responses have format: [data][status_code(2_bytes)]
46
92
  * @private
47
93
  */
48
- private handleTransportResponse;
94
+ private extractResponseData;
49
95
  /**
50
96
  * Serialize a BIP path to a data buffer for Canton BOLOS
51
97
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAiCpD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAU7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA8B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IAwBpC;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB"}
1
+ {"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/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CAAC,oBAAoB;IAe5B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAQ9B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IAwBpC;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB"}
package/lib/Canton.js CHANGED
@@ -8,13 +8,11 @@ const bip32_path_1 = __importDefault(require("bip32-path"));
8
8
  const CLA = 0xe0;
9
9
  const P1_NON_CONFIRM = 0x00;
10
10
  const P1_CONFIRM = 0x01;
11
- // P2 indicating no information.
11
+ const P1_SIGN_UNTYPED_VERSIONED_MESSAGE = 0x01;
12
+ const P1_SIGN_PREPARED_TRANSACTION = 0x02;
12
13
  const P2_NONE = 0x00;
13
- // P2 indicating first APDU in a large request.
14
14
  const P2_FIRST = 0x01;
15
- // P2 indicating that this is not the last APDU in a large request.
16
15
  const P2_MORE = 0x02;
17
- // P2 indicating that this is the last APDU of a message in a multi message request.
18
16
  const P2_MSG_END = 0x04;
19
17
  const INS = {
20
18
  GET_VERSION: 0x03,
@@ -28,6 +26,7 @@ const STATUS = {
28
26
  };
29
27
  const ED25519_SIGNATURE_HEX_LENGTH = 128; // hex characters (64 bytes)
30
28
  const CANTON_SIGNATURE_HEX_LENGTH = 132; // hex characters (66 bytes with framing)
29
+ const MAX_APDU_DATA_LENGTH = 255;
31
30
  /**
32
31
  * Canton BOLOS API
33
32
  */
@@ -49,7 +48,8 @@ class Canton {
49
48
  const serializedPath = this.serializePath(bipPath);
50
49
  const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
51
50
  const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
52
- const responseData = this.handleTransportResponse(response, "address");
51
+ this.checkTransportResponse(response);
52
+ const responseData = this.extractResponseData(response);
53
53
  const { publicKey } = this.extractPublicKeyAndChainCode(responseData);
54
54
  const address = "canton_" + this.publicKeyToAddress(publicKey);
55
55
  return {
@@ -59,23 +59,148 @@ class Canton {
59
59
  };
60
60
  }
61
61
  /**
62
- * Sign a Canton transaction.
62
+ * Sign a Canton transaction
63
+ * using the appropriate signing method based on transaction type.
63
64
  *
64
65
  * @param path a path in BIP-32 format
65
- * @param txHash the transaction hash to sign
66
+ * @param data either prepared transaction components, untyped versioned message, or txHash string (backwards compatibility)
66
67
  * @return the signature
67
68
  */
68
- async signTransaction(path, txHash) {
69
+ async signTransaction(path, data) {
70
+ // Backwards compatibility: handle txHash string format
71
+ if (typeof data === "string") {
72
+ return this.signTxHash(path, data);
73
+ }
74
+ if ("damlTransaction" in data) {
75
+ return this.signPreparedTransaction(path, data);
76
+ }
77
+ else {
78
+ return this.signUntypedVersionedMessage(path, data);
79
+ }
80
+ }
81
+ /**
82
+ * Sign a transaction hash (backwards compatibility)
83
+ * @private
84
+ */
85
+ async signTxHash(path, txHash) {
69
86
  // 1. Send the derivation path
70
87
  const bipPath = bip32_path_1.default.fromString(path).toPathArray();
71
88
  const serializedPath = this.serializePath(bipPath);
72
- const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_FIRST | P2_MORE, serializedPath);
73
- this.handleTransportResponse(pathResponse, "transaction");
74
- // 2. Send the transaction hash
75
- const response = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_MSG_END, Buffer.from(txHash, "hex"));
76
- const responseData = this.handleTransportResponse(response, "transaction");
77
- const rawSignature = responseData.toString("hex");
78
- return this.cleanSignatureFormat(rawSignature);
89
+ const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_SIGN_UNTYPED_VERSIONED_MESSAGE, P2_FIRST | P2_MORE, serializedPath);
90
+ this.checkTransportResponse(pathResponse);
91
+ // 2. Send the transaction hash as a single transaction
92
+ const transactionBuffer = Buffer.from(txHash, "hex");
93
+ const response = await this.transport.send(CLA, INS.SIGN, P1_SIGN_UNTYPED_VERSIONED_MESSAGE, P2_MSG_END, transactionBuffer);
94
+ this.checkTransportResponse(response);
95
+ const responseData = this.extractResponseData(response);
96
+ return this.cleanSignatureFormat(responseData);
97
+ }
98
+ /**
99
+ * Sign a prepared Canton transaction
100
+ * @private
101
+ */
102
+ async signPreparedTransaction(path, components) {
103
+ let responseData = null;
104
+ // 1. Send the derivation path
105
+ const bipPath = bip32_path_1.default.fromString(path).toPathArray();
106
+ const serializedPath = this.serializePath(bipPath);
107
+ const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_SIGN_PREPARED_TRANSACTION, P2_FIRST | P2_MORE, serializedPath);
108
+ this.checkTransportResponse(pathResponse);
109
+ // 2. Send the DAML transaction
110
+ await this.sendChunkedData({
111
+ ins: INS.SIGN,
112
+ p1: P1_SIGN_PREPARED_TRANSACTION,
113
+ payload: Buffer.from(components.damlTransaction),
114
+ isFinal: false,
115
+ });
116
+ // 3. Send each node
117
+ for (const [i, node] of components.nodes.entries()) {
118
+ this.validateUint8Array(node, `Node at index ${i}`);
119
+ await this.sendChunkedData({
120
+ ins: INS.SIGN,
121
+ p1: P1_SIGN_PREPARED_TRANSACTION,
122
+ payload: Buffer.from(node),
123
+ isFinal: false,
124
+ });
125
+ }
126
+ // 4. Send the metadata
127
+ const isFinal = components.inputContracts.length === 0;
128
+ const result = await this.sendChunkedData({
129
+ ins: INS.SIGN,
130
+ p1: P1_SIGN_PREPARED_TRANSACTION,
131
+ payload: Buffer.from(components.metadata),
132
+ isFinal,
133
+ });
134
+ if (isFinal) {
135
+ responseData = result;
136
+ }
137
+ // 5. Send each input contract - last one should return data
138
+ for (const [i, inputContract] of components.inputContracts.entries()) {
139
+ this.validateUint8Array(inputContract, `Input contract at index ${i}`);
140
+ const isFinal = i === components.inputContracts.length - 1;
141
+ const result = await this.sendChunkedData({
142
+ ins: INS.SIGN,
143
+ p1: P1_SIGN_PREPARED_TRANSACTION,
144
+ payload: Buffer.from(inputContract),
145
+ isFinal,
146
+ });
147
+ if (isFinal) {
148
+ responseData = result;
149
+ }
150
+ }
151
+ if (!responseData) {
152
+ throw new Error("No response data received from device");
153
+ }
154
+ return this.cleanSignatureFormat(responseData);
155
+ }
156
+ /**
157
+ * Sign topology transactions for Canton onboarding
158
+ * @private
159
+ */
160
+ async signUntypedVersionedMessage(path, data) {
161
+ const { transactions } = data;
162
+ if (!transactions || transactions.length === 0) {
163
+ throw new TypeError("At least one transaction is required");
164
+ }
165
+ // 1. Send the derivation path
166
+ const bipPath = bip32_path_1.default.fromString(path).toPathArray();
167
+ const serializedPath = this.serializePath(bipPath);
168
+ const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_SIGN_UNTYPED_VERSIONED_MESSAGE, P2_FIRST | P2_MORE, serializedPath);
169
+ this.checkTransportResponse(pathResponse);
170
+ // 2. Send each transaction using chunking for large data
171
+ for (const [i, transaction] of transactions.entries()) {
172
+ if (!transaction) {
173
+ throw new TypeError(`Transaction at index ${i} is undefined or null`);
174
+ }
175
+ const transactionBuffer = Buffer.from(transaction, "hex");
176
+ const isLastTransaction = i === transactions.length - 1;
177
+ if (transactionBuffer.length <= MAX_APDU_DATA_LENGTH) {
178
+ // Small transaction - send directly
179
+ const p2 = isLastTransaction ? P2_MSG_END : P2_MORE | P2_MSG_END;
180
+ const response = await this.transport.send(CLA, INS.SIGN, P1_SIGN_UNTYPED_VERSIONED_MESSAGE, p2, transactionBuffer);
181
+ if (isLastTransaction) {
182
+ this.checkTransportResponse(response);
183
+ const responseData = this.extractResponseData(response);
184
+ return this.cleanSignatureFormat(responseData);
185
+ }
186
+ else {
187
+ this.checkTransportResponse(response);
188
+ }
189
+ }
190
+ else {
191
+ // Large transaction - use chunking
192
+ const responseData = await this.sendChunkedData({
193
+ ins: INS.SIGN,
194
+ p1: P1_SIGN_UNTYPED_VERSIONED_MESSAGE,
195
+ payload: transactionBuffer,
196
+ isFinal: isLastTransaction,
197
+ });
198
+ if (isLastTransaction && responseData) {
199
+ return this.cleanSignatureFormat(responseData);
200
+ }
201
+ }
202
+ }
203
+ throw new TypeError("No transactions provided");
79
204
  }
80
205
  /**
81
206
  * Get the app configuration.
@@ -83,46 +208,100 @@ class Canton {
83
208
  */
84
209
  async getAppConfiguration() {
85
210
  const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2_NONE, Buffer.alloc(0));
86
- const responseData = this.handleTransportResponse(response, "version");
211
+ this.checkTransportResponse(response);
212
+ const responseData = this.extractResponseData(response);
87
213
  const { major, minor, patch } = this.extractVersion(responseData);
88
214
  return {
89
215
  version: `${major}.${minor}.${patch}`,
90
216
  };
91
217
  }
218
+ /**
219
+ * Validate Uint8Array with descriptive error message
220
+ * @private
221
+ */
222
+ validateUint8Array(value, context) {
223
+ if (!value) {
224
+ throw new TypeError(`${context} is undefined or null`);
225
+ }
226
+ if (!(value instanceof Uint8Array)) {
227
+ throw new TypeError(`${context} is not a Uint8Array: ${typeof value}`);
228
+ }
229
+ }
230
+ /**
231
+ * Unified chunking strategy for sending data to device
232
+ * @private
233
+ */
234
+ async sendChunkedData({ ins, p1, payload, isFinal = false, }) {
235
+ const chunks = this.createChunks(payload);
236
+ let responseData = null;
237
+ for (let i = 0; i < chunks.length; i++) {
238
+ const isLastChunk = i === chunks.length - 1;
239
+ let p2 = P2_MORE;
240
+ if (isLastChunk) {
241
+ p2 = isFinal ? P2_MSG_END : P2_MORE | P2_MSG_END;
242
+ }
243
+ const response = await this.transport.send(CLA, ins, p1, p2, chunks[i]);
244
+ if (isFinal && isLastChunk) {
245
+ this.checkTransportResponse(response);
246
+ responseData = this.extractResponseData(response);
247
+ }
248
+ else {
249
+ this.checkTransportResponse(response);
250
+ }
251
+ }
252
+ return responseData;
253
+ }
254
+ /**
255
+ * Create optimized chunks from payload
256
+ * @private
257
+ */
258
+ createChunks(payload) {
259
+ if (payload.length <= MAX_APDU_DATA_LENGTH) {
260
+ return [payload];
261
+ }
262
+ const totalChunks = Math.ceil(payload.length / MAX_APDU_DATA_LENGTH);
263
+ const chunks = new Array(totalChunks);
264
+ let offset = 0;
265
+ for (let i = 0; i < totalChunks; i++) {
266
+ const chunkSize = Math.min(MAX_APDU_DATA_LENGTH, payload.length - offset);
267
+ chunks[i] = payload.slice(offset, offset + chunkSize);
268
+ offset += chunkSize;
269
+ }
270
+ return chunks;
271
+ }
92
272
  /**
93
273
  * Converts 65-byte Canton format to 64-byte Ed25519:
94
274
  * [40][64_bytes_signature][00] (132 hex chars)
95
275
  * @private
96
276
  */
97
277
  cleanSignatureFormat(signature) {
98
- if (signature.length === ED25519_SIGNATURE_HEX_LENGTH) {
99
- return signature;
278
+ const signatureHex = signature.toString("hex");
279
+ if (signatureHex.length === ED25519_SIGNATURE_HEX_LENGTH) {
280
+ return signatureHex;
100
281
  }
101
- if (signature.length === CANTON_SIGNATURE_HEX_LENGTH) {
102
- const cleanedSignature = signature.slice(2, -2);
282
+ if (signatureHex.length === CANTON_SIGNATURE_HEX_LENGTH) {
283
+ const cleanedSignature = signatureHex.slice(2, -2);
103
284
  return cleanedSignature;
104
285
  }
105
- console.warn(`[Canton]: Unknown signature format (${signature.length} chars)`);
106
- return signature;
286
+ return signatureHex;
107
287
  }
108
288
  /**
109
- * Helper method to handle transport response and check for errors
289
+ * Check transport response for errors and throw appropriate exceptions
110
290
  * @private
111
291
  */
112
- handleTransportResponse(response, errorType) {
292
+ checkTransportResponse(response) {
113
293
  const statusCode = response.readUInt16BE(response.length - 2);
114
- const responseData = response.slice(0, response.length - 2);
115
- if (statusCode === STATUS.USER_CANCEL) {
116
- switch (errorType) {
117
- case "address":
118
- throw new errors_1.UserRefusedAddress();
119
- case "transaction":
120
- throw new errors_1.UserRefusedOnDevice();
121
- default:
122
- throw new Error();
123
- }
294
+ if (statusCode !== STATUS.OK) {
295
+ throw new errors_1.TransportStatusError(statusCode);
124
296
  }
125
- return responseData;
297
+ }
298
+ /**
299
+ * Extract response data from transport response
300
+ * APDU responses have format: [data][status_code(2_bytes)]
301
+ * @private
302
+ */
303
+ extractResponseData(response) {
304
+ return response.slice(0, -2);
126
305
  }
127
306
  /**
128
307
  * Serialize a BIP path to a data buffer for Canton BOLOS
@@ -177,9 +356,9 @@ class Canton {
177
356
  */
178
357
  extractVersion(data) {
179
358
  return {
180
- major: parseInt(data.subarray(0, 1).toString("hex"), 16),
181
- minor: parseInt(data.subarray(1, 2).toString("hex"), 16),
182
- patch: parseInt(data.subarray(2, 3).toString("hex"), 16),
359
+ major: Number.parseInt(data.subarray(0, 1).toString("hex"), 16),
360
+ minor: Number.parseInt(data.subarray(1, 2).toString("hex"), 16),
361
+ patch: Number.parseInt(data.subarray(2, 3).toString("hex"), 16),
183
362
  };
184
363
  }
185
364
  }
package/lib/Canton.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Canton.js","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":";;;;;AACA,6CAA2E;AAC3E,4DAAiC;AAEjC,MAAM,GAAG,GAAG,IAAI,CAAC;AAEjB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,gCAAgC;AAChC,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,+CAA+C;AAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,mEAAmE;AACnE,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,oFAAoF;AACpF,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,EAAE,EAAE,MAAM;IACV,WAAW,EAAE,MAAM;CACpB,CAAC;AAEF,MAAM,4BAA4B,GAAG,GAAG,CAAC,CAAC,4BAA4B;AACtE,MAAM,2BAA2B,GAAG,GAAG,CAAC,CAAC,yCAAyC;AAclF;;GAEG;AACH,MAAqB,MAAM;IACzB,SAAS,CAAY;IAErB,YA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ress = {
8
8
  path: string;
9
9
  };
10
10
  export type CantonSignature = string;
11
+ export type CantonPreparedTransaction = {
12
+ damlTransaction: Uint8Array;
13
+ nodes: Uint8Array[];
14
+ metadata: Uint8Array;
15
+ inputContracts: Uint8Array[];
16
+ };
17
+ export type CantonUntypedVersionedMessage = {
18
+ transactions: string[];
19
+ };
11
20
  /**
12
21
  * Canton BOLOS API
13
22
  */
@@ -23,18 +32,49 @@ export default class Canton {
23
32
  */
24
33
  getAddress(path: string, display?: boolean): Promise<CantonAddress>;
25
34
  /**
26
- * Sign a Canton transaction.
35
+ * Sign a Canton transaction
36
+ * using the appropriate signing method based on transaction type.
27
37
  *
28
38
  * @param path a path in BIP-32 format
29
- * @param txHash the transaction hash to sign
39
+ * @param data either prepared transaction components, untyped versioned message, or txHash string (backwards compatibility)
30
40
  * @return the signature
31
41
  */
32
- signTransaction(path: string, txHash: string): Promise<CantonSignature>;
42
+ signTransaction(path: string, data: CantonPreparedTransaction | CantonUntypedVersionedMessage | string): Promise<CantonSignature>;
43
+ /**
44
+ * Sign a transaction hash (backwards compatibility)
45
+ * @private
46
+ */
47
+ private signTxHash;
48
+ /**
49
+ * Sign a prepared Canton transaction
50
+ * @private
51
+ */
52
+ private signPreparedTransaction;
53
+ /**
54
+ * Sign topology transactions for Canton onboarding
55
+ * @private
56
+ */
57
+ private signUntypedVersionedMessage;
33
58
  /**
34
59
  * Get the app configuration.
35
60
  * @return the app configuration including version
36
61
  */
37
62
  getAppConfiguration(): Promise<AppConfig>;
63
+ /**
64
+ * Validate Uint8Array with descriptive error message
65
+ * @private
66
+ */
67
+ private validateUint8Array;
68
+ /**
69
+ * Unified chunking strategy for sending data to device
70
+ * @private
71
+ */
72
+ private sendChunkedData;
73
+ /**
74
+ * Create optimized chunks from payload
75
+ * @private
76
+ */
77
+ private createChunks;
38
78
  /**
39
79
  * Converts 65-byte Canton format to 64-byte Ed25519:
40
80
  * [40][64_bytes_signature][00] (132 hex chars)
@@ -42,10 +82,16 @@ export default class Canton {
42
82
  */
43
83
  private cleanSignatureFormat;
44
84
  /**
45
- * Helper method to handle transport response and check for errors
85
+ * Check transport response for errors and throw appropriate exceptions
86
+ * @private
87
+ */
88
+ private checkTransportResponse;
89
+ /**
90
+ * Extract response data from transport response
91
+ * APDU responses have format: [data][status_code(2_bytes)]
46
92
  * @private
47
93
  */
48
- private handleTransportResponse;
94
+ private extractResponseData;
49
95
  /**
50
96
  * Serialize a BIP path to a data buffer for Canton BOLOS
51
97
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAiCpD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAU7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA8B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO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