@ckb-ccc/joy-id 0.0.6-alpha.0 → 0.0.7-alpha.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.
@@ -90,9 +90,8 @@ export declare class CkbSigner extends ccc.Signer {
90
90
  /**
91
91
  * Prepares a transaction for a sub key.
92
92
  * @private
93
- * @param {ccc.Transaction} tx - The transaction object.
94
- * @param {ccc.WitnessArgs} witness - The witness arguments.
95
- * @returns {Promise<void>}
93
+ * @param tx - The transaction object.
94
+ * @param witness - The witness arguments.
96
95
  * @throws Will throw an error if no COTA cells are found for the sub key wallet.
97
96
  */
98
97
  private prepareTransactionForSubKey;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IA4CrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IA/ClC;;;OAGG;IACH,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;YACW,gBAAgB;IAQ9B;;;;;;;;OAQG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,oBAAQ,EAChB,cAAc,CAAC,oBAAQ,EACvB,eAA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AE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BtE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
package/dist/ckb/index.js CHANGED
@@ -147,12 +147,13 @@ export class CkbSigner extends ccc.Signer {
147
147
  */
148
148
  async prepareTransaction(txLike) {
149
149
  const tx = ccc.Transaction.from(txLike);
150
+ await tx.addCellDepsOfKnownScripts(this.client, ccc.KnownScript.JoyId);
150
151
  const position = await tx.findInputIndexByLock((await this.getAddressObj()).script, this.client);
151
152
  if (position === undefined) {
152
153
  return tx;
153
154
  }
154
155
  const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});
155
- witness.lock = "0x";
156
+ witness.lock = ccc.hexFrom("00".repeat(1000));
156
157
  await this.prepareTransactionForSubKey(tx, witness);
157
158
  tx.setWitnessArgsAt(position, witness);
158
159
  return tx;
@@ -160,9 +161,8 @@ export class CkbSigner extends ccc.Signer {
160
161
  /**
161
162
  * Prepares a transaction for a sub key.
162
163
  * @private
163
- * @param {ccc.Transaction} tx - The transaction object.
164
- * @param {ccc.WitnessArgs} witness - The witness arguments.
165
- * @returns {Promise<void>}
164
+ * @param tx - The transaction object.
165
+ * @param witness - The witness arguments.
166
166
  * @throws Will throw an error if no COTA cells are found for the sub key wallet.
167
167
  */
168
168
  async prepareTransactionForSubKey(tx, witness) {
@@ -179,10 +179,7 @@ export class CkbSigner extends ccc.Signer {
179
179
  });
180
180
  witness.outputType = ccc.hexFrom(unlockEntry);
181
181
  const cotaDeps = [];
182
- for await (const cell of this.client.findCellsByLockAndType(lock, {
183
- ...(await this.client.getKnownScript(ccc.KnownScript.COTA)),
184
- args: "0x",
185
- })) {
182
+ for await (const cell of this.client.findCellsByLockAndType(lock, await ccc.Script.fromKnownScript(this.client, ccc.KnownScript.COTA, "0x"))) {
186
183
  cotaDeps.push(ccc.CellDep.from({
187
184
  depType: "code",
188
185
  outPoint: cell.outPoint,
@@ -201,13 +198,27 @@ export class CkbSigner extends ccc.Signer {
201
198
  async signOnlyTransaction(txLike) {
202
199
  const tx = ccc.Transaction.from(txLike);
203
200
  const { script } = await this.getAddressObj();
201
+ const witnessIndexes = await ccc.reduceAsync(tx.inputs, async (acc, input, i) => {
202
+ await input.completeExtraInfos(this.client);
203
+ if (!input.cellOutput) {
204
+ throw new Error("Unable to complete input");
205
+ }
206
+ if (input.cellOutput.lock.eq(script)) {
207
+ acc.push(i);
208
+ }
209
+ }, []);
210
+ // Trim unnecessary fields to reduce tx size
211
+ await tx.prepareSighashAllWitness(script, 0, this.client);
212
+ tx.inputs.forEach((i) => {
213
+ i.cellOutput = undefined;
214
+ i.outputData = undefined;
215
+ });
204
216
  const config = this.getConfig();
205
217
  const res = await createPopup(buildJoyIDURL({
206
218
  ...config,
207
219
  tx: JSON.parse(tx.stringify()),
208
220
  signerAddress: (await this.assertConnection()).address,
209
- witnessIndex: await tx.findInputIndexByLock(script, this.client),
210
- witnessLastIndex: await tx.findLastInputIndexByLock(script, this.client),
221
+ witnessIndexes,
211
222
  }, "popup", "/sign-ckb-raw-tx"), {
212
223
  ...config,
213
224
  type: DappRequestType.SignCkbRawTx,
@@ -1,2 +1,2 @@
1
1
  export * as JoyIdA from "./advancedBarrel";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,27 +1,48 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }
31
+ : function (o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.JoyIdA = void 0;
27
48
  exports.JoyIdA = __importStar(require("./advancedBarrel"));
@@ -1,3 +1,3 @@
1
1
  export * from "./common";
2
2
  export * from "./connectionsStorage";
3
- //# sourceMappingURL=advancedBarrel.d.ts.map
3
+ //# sourceMappingURL=advancedBarrel.d.ts.map
@@ -1,18 +1,34 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./common"), exports);
18
34
  __exportStar(require("./connectionsStorage"), exports);
@@ -2,4 +2,4 @@ export * from "./btc";
2
2
  export * from "./ckb";
3
3
  export * from "./evm";
4
4
  export * from "./signerFactory";
5
- //# sourceMappingURL=barrel.d.ts.map
5
+ //# sourceMappingURL=barrel.d.ts.map
@@ -1,18 +1,34 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./btc"), exports);
18
34
  __exportStar(require("./ckb"), exports);
@@ -6,60 +6,67 @@ import { ConnectionsRepo } from "../connectionsStorage";
6
6
  * @extends {ccc.SignerBtc}
7
7
  */
8
8
  export declare class BitcoinSigner extends ccc.SignerBtc {
9
- private readonly name;
10
- private readonly icon;
11
- private readonly addressType;
12
- private readonly appUri;
13
- private readonly connectionsRepo;
14
- private connection?;
15
- /**
16
- * Ensures that the signer is connected and returns the connection.
17
- * @private
18
- * @throws Will throw an error if not connected.
19
- * @returns {Connection} The current connection.
20
- */
21
- private assertConnection;
22
- /**
23
- * Creates an instance of BitcoinSigner.
24
- * @param {ccc.Client} client - The client instance.
25
- * @param {string} name - The name of the signer.
26
- * @param {string} icon - The icon URL of the signer.
27
- * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
28
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
30
- */
31
- constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
32
- /**
33
- * Gets the configuration for JoyID.
34
- * @private
35
- * @returns {object} The configuration object.
36
- */
37
- private getConfig;
38
- /**
39
- * Gets the Bitcoin account address.
40
- * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
41
- */
42
- getBtcAccount(): Promise<string>;
43
- /**
44
- * Gets the Bitcoin public key.
45
- * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
46
- */
47
- getBtcPublicKey(): Promise<ccc.Hex>;
48
- /**
49
- * Connects to the provider by requesting authentication.
50
- * @returns {Promise<void>} A promise that resolves when the connection is established.
51
- */
52
- connect(): Promise<void>;
53
- /**
54
- * Checks if the signer is connected.
55
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
56
- */
57
- isConnected(): Promise<boolean>;
58
- /**
59
- * Signs a raw message with the Bitcoin account.
60
- * @param {string | ccc.BytesLike} message - The message to sign.
61
- * @returns {Promise<string>} A promise that resolves to the signed message.
62
- */
63
- signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
9
+ private readonly name;
10
+ private readonly icon;
11
+ private readonly addressType;
12
+ private readonly appUri;
13
+ private readonly connectionsRepo;
14
+ private connection?;
15
+ /**
16
+ * Ensures that the signer is connected and returns the connection.
17
+ * @private
18
+ * @throws Will throw an error if not connected.
19
+ * @returns {Connection} The current connection.
20
+ */
21
+ private assertConnection;
22
+ /**
23
+ * Creates an instance of BitcoinSigner.
24
+ * @param {ccc.Client} client - The client instance.
25
+ * @param {string} name - The name of the signer.
26
+ * @param {string} icon - The icon URL of the signer.
27
+ * @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
28
+ * @param {string} [appUri="https://app.joy.id"] - The application URI.
29
+ * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
30
+ */
31
+ constructor(
32
+ client: ccc.Client,
33
+ name: string,
34
+ icon: string,
35
+ addressType?: "auto" | "p2wpkh" | "p2tr",
36
+ appUri?: string,
37
+ connectionsRepo?: ConnectionsRepo,
38
+ );
39
+ /**
40
+ * Gets the configuration for JoyID.
41
+ * @private
42
+ * @returns {object} The configuration object.
43
+ */
44
+ private getConfig;
45
+ /**
46
+ * Gets the Bitcoin account address.
47
+ * @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
48
+ */
49
+ getBtcAccount(): Promise<string>;
50
+ /**
51
+ * Gets the Bitcoin public key.
52
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
53
+ */
54
+ getBtcPublicKey(): Promise<ccc.Hex>;
55
+ /**
56
+ * Connects to the provider by requesting authentication.
57
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
58
+ */
59
+ connect(): Promise<void>;
60
+ /**
61
+ * Checks if the signer is connected.
62
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
63
+ */
64
+ isConnected(): Promise<boolean>;
65
+ /**
66
+ * Signs a raw message with the Bitcoin account.
67
+ * @param {string | ccc.BytesLike} message - The message to sign.
68
+ * @returns {Promise<string>} A promise that resolves to the signed message.
69
+ */
70
+ signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
64
71
  }
65
- //# sourceMappingURL=index.d.ts.map
72
+ //# sourceMappingURL=index.d.ts.map