@ckb-ccc/joy-id 1.0.31 → 1.0.33

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,27 @@
1
1
  # @ckb-ccc/joy-id
2
2
 
3
+ ## 1.0.33
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#346](https://github.com/ckb-devrel/ccc/pull/346) [`a803d5f`](https://github.com/ckb-devrel/ccc/commit/a803d5fba8d0e082c6aba14db156856025402e72) Thanks [@fghdotio](https://github.com/fghdotio)! - feat(core): add BTC PSBT signing support
9
+
10
+ - Add `SignerBtc.signPsbt()`, `signAndBroadcastPsbt()`, and `broadcastPsbt()` for signing and broadcasting PSBTs
11
+ - Add `SignPsbtOptions` and `InputToSign` for configuring PSBT signing
12
+
13
+
14
+ - [#379](https://github.com/ckb-devrel/ccc/pull/379) [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump pnpm to v11.8.0
15
+
16
+ - Updated dependencies [[`1148a5c`](https://github.com/ckb-devrel/ccc/commit/1148a5c403cde985fb4ba713ccfa0c163d287174), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`a803d5f`](https://github.com/ckb-devrel/ccc/commit/a803d5fba8d0e082c6aba14db156856025402e72), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`6727ffe`](https://github.com/ckb-devrel/ccc/commit/6727ffe05f60e6bfb2060a565c19acb0fd0f375e), [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346), [`a526890`](https://github.com/ckb-devrel/ccc/commit/a5268909ea9d61c4e2f5187a43e2318327b27cae), [`4bb3d9d`](https://github.com/ckb-devrel/ccc/commit/4bb3d9d2ef36b3ee8820036625abd9befb1980c4), [`9f7ecb6`](https://github.com/ckb-devrel/ccc/commit/9f7ecb6ab8db9c6866dad029f2888e1e5cfcbe7d)]:
17
+ - @ckb-ccc/core@1.13.0
18
+
19
+ ## 1.0.32
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`a96dec6`](https://github.com/ckb-devrel/ccc/commit/a96dec6d0517113391b0edc510f1af821a45d5a8)]:
23
+ - @ckb-ccc/core@1.12.5
24
+
3
25
  ## 1.0.31
4
26
  ### Patch Changes
5
27
 
@@ -61,5 +61,21 @@ export declare class BitcoinSigner extends ccc.SignerBtc {
61
61
  * @returns A promise that resolves to the signed message.
62
62
  */
63
63
  signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
64
+ /**
65
+ * Signs a PSBT using JoyID wallet.
66
+ *
67
+ * @param psbtHex - The hex string of PSBT to sign.
68
+ * @returns A promise that resolves to the signed PSBT as a Hex string.
69
+ */
70
+ signPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
71
+ /**
72
+ * Broadcasts a PSBT to the Bitcoin network.
73
+ *
74
+ * @remarks
75
+ * JoyID does not support broadcasting a signed PSBT directly.
76
+ * It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
77
+ */
78
+ broadcastPsbt(_psbtHex: ccc.HexLike, _options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
79
+ signAndBroadcastPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
64
80
  }
65
81
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,aAAc,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ACG,aAAa,CACjB,QAAQ,EAAE,GAAG,CAAC,OAAO,EACrB,QAAQ,CAAC,EAAE,GAAG,CAAC,mBAAmB,GACjC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAMb,oBAAoB,CACxB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,CAAC,EAAE,GAAG,CAAC,mBAAmB,GAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAwBpB"}
package/dist/btc/index.js CHANGED
@@ -150,4 +150,48 @@ export class BitcoinSigner extends ccc.SignerBtc {
150
150
  }, "popup", "/sign-message"), { ...config, type: DappRequestType.SignMessage });
151
151
  return signature;
152
152
  }
153
+ /**
154
+ * Signs a PSBT using JoyID wallet.
155
+ *
156
+ * @param psbtHex - The hex string of PSBT to sign.
157
+ * @returns A promise that resolves to the signed PSBT as a Hex string.
158
+ */
159
+ async signPsbt(psbtHex, options) {
160
+ const { address } = await this.assertConnection();
161
+ const formattedOptions = ccc.SignPsbtOptions.from(options);
162
+ const config = this.getConfig();
163
+ const { tx: signedPsbtHex } = await createPopup(buildJoyIDURL({
164
+ ...config,
165
+ tx: ccc.hexFrom(psbtHex).slice(2),
166
+ options: formattedOptions,
167
+ signerAddress: address,
168
+ autoFinalized: formattedOptions.autoFinalized,
169
+ }, "popup", "/sign-psbt"), { ...config, type: DappRequestType.SignPsbt });
170
+ return ccc.hexFrom(signedPsbtHex);
171
+ }
172
+ /**
173
+ * Broadcasts a PSBT to the Bitcoin network.
174
+ *
175
+ * @remarks
176
+ * JoyID does not support broadcasting a signed PSBT directly.
177
+ * It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
178
+ */
179
+ async broadcastPsbt(_psbtHex, _options) {
180
+ throw new Error("JoyID does not support broadcasting signed PSBTs directly. Use signAndBroadcastPsbt instead.");
181
+ }
182
+ async signAndBroadcastPsbt(psbtHex, options) {
183
+ const { address } = await this.assertConnection();
184
+ const formattedOptions = ccc.SignPsbtOptions.from(options);
185
+ const config = this.getConfig();
186
+ // ccc.hexFrom adds 0x prefix, but BTC expects non-0x
187
+ const { tx: txid } = await createPopup(buildJoyIDURL({
188
+ ...config,
189
+ tx: ccc.hexFrom(psbtHex).slice(2),
190
+ options: formattedOptions,
191
+ signerAddress: address,
192
+ autoFinalized: true, // sendPsbt always finalizes
193
+ isSend: true,
194
+ }, "popup", "/sign-psbt"), { ...config, type: DappRequestType.SignPsbt });
195
+ return ccc.hexFrom(txid);
196
+ }
153
197
  }
@@ -61,5 +61,21 @@ export declare class BitcoinSigner extends ccc.SignerBtc {
61
61
  * @returns A promise that resolves to the signed message.
62
62
  */
63
63
  signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
64
+ /**
65
+ * Signs a PSBT using JoyID wallet.
66
+ *
67
+ * @param psbtHex - The hex string of PSBT to sign.
68
+ * @returns A promise that resolves to the signed PSBT as a Hex string.
69
+ */
70
+ signPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
71
+ /**
72
+ * Broadcasts a PSBT to the Bitcoin network.
73
+ *
74
+ * @remarks
75
+ * JoyID does not support broadcasting a signed PSBT directly.
76
+ * It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
77
+ */
78
+ broadcastPsbt(_psbtHex: ccc.HexLike, _options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
79
+ signAndBroadcastPsbt(psbtHex: ccc.HexLike, options?: ccc.SignPsbtOptionsLike): Promise<ccc.Hex>;
64
80
  }
65
81
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,SAAS;aA4B5B,IAA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AC,OAAO,EACrB,QAAQ,CAAC,EAAE,GAAG,CAAC,mBAAmB,GACjC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAMb,oBAAoB,CACxB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,OAAO,CAAC,EAAE,GAAG,CAAC,mBAAmB,GAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAwBpB"}
@@ -153,5 +153,49 @@ class BitcoinSigner extends core_1.ccc.SignerBtc {
153
153
  }, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
154
154
  return signature;
155
155
  }
156
+ /**
157
+ * Signs a PSBT using JoyID wallet.
158
+ *
159
+ * @param psbtHex - The hex string of PSBT to sign.
160
+ * @returns A promise that resolves to the signed PSBT as a Hex string.
161
+ */
162
+ async signPsbt(psbtHex, options) {
163
+ const { address } = await this.assertConnection();
164
+ const formattedOptions = core_1.ccc.SignPsbtOptions.from(options);
165
+ const config = this.getConfig();
166
+ const { tx: signedPsbtHex } = await (0, index_js_1.createPopup)((0, common_1.buildJoyIDURL)({
167
+ ...config,
168
+ tx: core_1.ccc.hexFrom(psbtHex).slice(2),
169
+ options: formattedOptions,
170
+ signerAddress: address,
171
+ autoFinalized: formattedOptions.autoFinalized,
172
+ }, "popup", "/sign-psbt"), { ...config, type: common_1.DappRequestType.SignPsbt });
173
+ return core_1.ccc.hexFrom(signedPsbtHex);
174
+ }
175
+ /**
176
+ * Broadcasts a PSBT to the Bitcoin network.
177
+ *
178
+ * @remarks
179
+ * JoyID does not support broadcasting a signed PSBT directly.
180
+ * It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
181
+ */
182
+ async broadcastPsbt(_psbtHex, _options) {
183
+ throw new Error("JoyID does not support broadcasting signed PSBTs directly. Use signAndBroadcastPsbt instead.");
184
+ }
185
+ async signAndBroadcastPsbt(psbtHex, options) {
186
+ const { address } = await this.assertConnection();
187
+ const formattedOptions = core_1.ccc.SignPsbtOptions.from(options);
188
+ const config = this.getConfig();
189
+ // ccc.hexFrom adds 0x prefix, but BTC expects non-0x
190
+ const { tx: txid } = await (0, index_js_1.createPopup)((0, common_1.buildJoyIDURL)({
191
+ ...config,
192
+ tx: core_1.ccc.hexFrom(psbtHex).slice(2),
193
+ options: formattedOptions,
194
+ signerAddress: address,
195
+ autoFinalized: true, // sendPsbt always finalizes
196
+ isSend: true,
197
+ }, "popup", "/sign-psbt"), { ...config, type: common_1.DappRequestType.SignPsbt });
198
+ return core_1.ccc.hexFrom(txid);
199
+ }
156
200
  }
157
201
  exports.BitcoinSigner = BitcoinSigner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/joy-id",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "Connector's support for JoyID",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@joyid/ckb": "^1.1.2",
40
40
  "@joyid/common": "^0.2.1",
41
- "@ckb-ccc/core": "1.12.4"
41
+ "@ckb-ccc/core": "1.13.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
package/src/btc/index.ts CHANGED
@@ -198,4 +198,80 @@ export class BitcoinSigner extends ccc.SignerBtc {
198
198
  );
199
199
  return signature;
200
200
  }
201
+
202
+ /**
203
+ * Signs a PSBT using JoyID wallet.
204
+ *
205
+ * @param psbtHex - The hex string of PSBT to sign.
206
+ * @returns A promise that resolves to the signed PSBT as a Hex string.
207
+ */
208
+ async signPsbt(
209
+ psbtHex: ccc.HexLike,
210
+ options?: ccc.SignPsbtOptionsLike,
211
+ ): Promise<ccc.Hex> {
212
+ const { address } = await this.assertConnection();
213
+ const formattedOptions = ccc.SignPsbtOptions.from(options);
214
+
215
+ const config = this.getConfig();
216
+ const { tx: signedPsbtHex } = await createPopup(
217
+ buildJoyIDURL(
218
+ {
219
+ ...config,
220
+ tx: ccc.hexFrom(psbtHex).slice(2),
221
+ options: formattedOptions,
222
+ signerAddress: address,
223
+ autoFinalized: formattedOptions.autoFinalized,
224
+ },
225
+ "popup",
226
+ "/sign-psbt",
227
+ ),
228
+ { ...config, type: DappRequestType.SignPsbt },
229
+ );
230
+
231
+ return ccc.hexFrom(signedPsbtHex);
232
+ }
233
+
234
+ /**
235
+ * Broadcasts a PSBT to the Bitcoin network.
236
+ *
237
+ * @remarks
238
+ * JoyID does not support broadcasting a signed PSBT directly.
239
+ * It only supports "Sign and Broadcast" as a single atomic operation via `signAndBroadcastPsbt`.
240
+ */
241
+ async broadcastPsbt(
242
+ _psbtHex: ccc.HexLike,
243
+ _options?: ccc.SignPsbtOptionsLike,
244
+ ): Promise<ccc.Hex> {
245
+ throw new Error(
246
+ "JoyID does not support broadcasting signed PSBTs directly. Use signAndBroadcastPsbt instead.",
247
+ );
248
+ }
249
+
250
+ async signAndBroadcastPsbt(
251
+ psbtHex: ccc.HexLike,
252
+ options?: ccc.SignPsbtOptionsLike,
253
+ ): Promise<ccc.Hex> {
254
+ const { address } = await this.assertConnection();
255
+ const formattedOptions = ccc.SignPsbtOptions.from(options);
256
+
257
+ const config = this.getConfig();
258
+ // ccc.hexFrom adds 0x prefix, but BTC expects non-0x
259
+ const { tx: txid } = await createPopup(
260
+ buildJoyIDURL(
261
+ {
262
+ ...config,
263
+ tx: ccc.hexFrom(psbtHex).slice(2),
264
+ options: formattedOptions,
265
+ signerAddress: address,
266
+ autoFinalized: true, // sendPsbt always finalizes
267
+ isSend: true,
268
+ },
269
+ "popup",
270
+ "/sign-psbt",
271
+ ),
272
+ { ...config, type: DappRequestType.SignPsbt }, // Use SignPsbt type for both operations
273
+ );
274
+
275
+ return ccc.hexFrom(txid);
276
+ }
201
277
  }