@ckb-ccc/core 0.0.4 → 0.0.5-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.
Files changed (99) hide show
  1. package/README.md +6 -0
  2. package/dist/ckb/transaction.d.ts +85 -2
  3. package/dist/ckb/transaction.d.ts.map +1 -1
  4. package/dist/ckb/transaction.js +152 -7
  5. package/dist/client/client.d.ts +11 -3
  6. package/dist/client/client.d.ts.map +1 -1
  7. package/dist/client/client.js +44 -2
  8. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  9. package/dist/client/clientPublicMainnet.advanced.js +4 -0
  10. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  11. package/dist/client/clientPublicTestnet.advanced.js +4 -0
  12. package/dist/client/clientTypes.d.ts +48 -1
  13. package/dist/client/clientTypes.d.ts.map +1 -1
  14. package/dist/client/clientTypes.js +27 -1
  15. package/dist/client/jsonRpc/index.d.ts +19 -1
  16. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  17. package/dist/client/jsonRpc/index.js +25 -1
  18. package/dist/client/jsonRpc/transformers.d.ts +17 -3
  19. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  20. package/dist/client/jsonRpc/transformers.js +37 -3
  21. package/dist/client/jsonRpc/types.d.ts +15 -0
  22. package/dist/client/jsonRpc/types.d.ts.map +1 -1
  23. package/dist/fixedPoint/index.d.ts.map +1 -1
  24. package/dist/fixedPoint/index.js +4 -1
  25. package/dist/fixedPoint/index.test.d.ts +2 -0
  26. package/dist/fixedPoint/index.test.d.ts.map +1 -0
  27. package/dist/fixedPoint/index.test.js +43 -0
  28. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  29. package/dist/signer/btc/signerBtc.js +2 -3
  30. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  31. package/dist/signer/evm/signerEvm.js +2 -3
  32. package/dist/signer/index.d.ts +0 -1
  33. package/dist/signer/index.d.ts.map +1 -1
  34. package/dist/signer/index.js +0 -1
  35. package/dist/signer/signer.d.ts +17 -2
  36. package/dist/signer/signer.d.ts.map +1 -1
  37. package/dist/signer/signer.js +17 -1
  38. package/dist.commonjs/ckb/transaction.d.ts +85 -2
  39. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  40. package/dist.commonjs/ckb/transaction.js +150 -5
  41. package/dist.commonjs/client/client.d.ts +11 -3
  42. package/dist.commonjs/client/client.d.ts.map +1 -1
  43. package/dist.commonjs/client/client.js +43 -1
  44. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  45. package/dist.commonjs/client/clientPublicMainnet.advanced.js +4 -0
  46. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  47. package/dist.commonjs/client/clientPublicTestnet.advanced.js +4 -0
  48. package/dist.commonjs/client/clientTypes.d.ts +48 -1
  49. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  50. package/dist.commonjs/client/clientTypes.js +29 -0
  51. package/dist.commonjs/client/jsonRpc/index.d.ts +19 -1
  52. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  53. package/dist.commonjs/client/jsonRpc/index.js +25 -1
  54. package/dist.commonjs/client/jsonRpc/transformers.d.ts +17 -3
  55. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  56. package/dist.commonjs/client/jsonRpc/transformers.js +35 -1
  57. package/dist.commonjs/client/jsonRpc/types.d.ts +15 -0
  58. package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -1
  59. package/dist.commonjs/fixedPoint/index.d.ts.map +1 -1
  60. package/dist.commonjs/fixedPoint/index.js +4 -1
  61. package/dist.commonjs/fixedPoint/index.test.d.ts +2 -0
  62. package/dist.commonjs/fixedPoint/index.test.d.ts.map +1 -0
  63. package/dist.commonjs/fixedPoint/index.test.js +45 -0
  64. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  65. package/dist.commonjs/signer/btc/signerBtc.js +2 -3
  66. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  67. package/dist.commonjs/signer/evm/signerEvm.js +2 -3
  68. package/dist.commonjs/signer/index.d.ts +0 -1
  69. package/dist.commonjs/signer/index.d.ts.map +1 -1
  70. package/dist.commonjs/signer/index.js +0 -1
  71. package/dist.commonjs/signer/signer.d.ts +17 -2
  72. package/dist.commonjs/signer/signer.d.ts.map +1 -1
  73. package/dist.commonjs/signer/signer.js +17 -1
  74. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -1
  75. package/jest.config.js +5 -0
  76. package/package.json +6 -2
  77. package/src/ckb/transaction.ts +198 -3
  78. package/src/client/client.ts +87 -3
  79. package/src/client/clientPublicMainnet.advanced.ts +5 -0
  80. package/src/client/clientPublicTestnet.advanced.ts +5 -0
  81. package/src/client/clientTypes.ts +70 -1
  82. package/src/client/jsonRpc/index.ts +54 -2
  83. package/src/client/jsonRpc/transformers.ts +73 -4
  84. package/src/client/jsonRpc/types.ts +16 -0
  85. package/src/fixedPoint/index.test.ts +55 -0
  86. package/src/fixedPoint/index.ts +7 -1
  87. package/src/signer/btc/signerBtc.ts +6 -3
  88. package/src/signer/evm/signerEvm.ts +2 -3
  89. package/src/signer/index.ts +0 -1
  90. package/src/signer/signer.ts +21 -0
  91. package/dist/signer/helpers.d.ts +0 -40
  92. package/dist/signer/helpers.d.ts.map +0 -1
  93. package/dist/signer/helpers.js +0 -91
  94. package/dist.commonjs/signer/helpers.d.ts +0 -40
  95. package/dist.commonjs/signer/helpers.d.ts.map +0 -1
  96. package/dist.commonjs/signer/helpers.js +0 -96
  97. package/src/signer/helpers.ts +0 -124
  98. package/tsconfig.base.json +0 -21
  99. package/tsconfig.commonjs.json +0 -8
@@ -1,7 +1,8 @@
1
1
  import { TransactionLike } from "../../ckb";
2
2
  import { Hex, HexLike } from "../../hex";
3
+ import { Num, NumLike } from "../../num";
3
4
  import { Client } from "../client";
4
- import { ClientTransactionResponse, OutputsValidator } from "../clientTypes";
5
+ import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "../clientTypes";
5
6
  import { JsonRpcPayload } from "./advanced";
6
7
  /**
7
8
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
@@ -38,6 +39,23 @@ export declare abstract class ClientJsonRpc extends Client {
38
39
  * @returns The transaction with status.
39
40
  */
40
41
  getTransaction: (txHash: HexLike) => Promise<ClientTransactionResponse>;
42
+ /**
43
+ * find cells from node.
44
+ *
45
+ * @param key - The search key of cells.
46
+ * @param order - The order of cells.
47
+ * @param limit - The max return size of cells.
48
+ * @param after - Pagination parameter.
49
+ * @returns The found cells.
50
+ */
51
+ findCellsPaged: (key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: NumLike, after?: string) => Promise<ClientFindCellsResponse>;
52
+ /**
53
+ * get cells capacity from node.
54
+ *
55
+ * @param key - The search key of cells.
56
+ * @returns The sum of cells capacity.
57
+ */
58
+ getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
41
59
  /**
42
60
  * Builds a sender function for a JSON-RPC method.
43
61
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAuB,MAAM,YAAY,CAAC;AA0BjE;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;IAS9C,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAT1B;;;;;OAKG;gBAGgB,GAAG,EAAE,MAAM,EACX,OAAO,SA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X,OAAO,SAAQ;IAKlC;;;;OAIG;IAEH,MAAM;IAIN;;;;;;OAMG;IAEH,eAAe,gBAKA,eAAe,cAChB,gBAAgB,GAAG,SAAS,KACrC,QAAQ,GAAG,CAAC,CAAC;IAElB;;;;;OAKG;IAEH,cAAc,WAIA,OAAO,KAAK,QAAQ,yBAAyB,CAAC,CAAC;IAE7D;;;;;;;;OAQG;IAEH,cAAc,QASP,0BAA0B,UACvB,KAAK,GAAG,MAAM,UACd,OAAO,UACP,MAAM,KACX,QAAQ,uBAAuB,CAAC,CAAC;IAEtC;;;;;OAKG;IAEH,gBAAgB,QAIL,0BAA0B,KAAK,QAAQ,GAAG,CAAC,CAAC;IAEvD;;;;;;;OAOG;IAEH,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EACrD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,YAEd,OAAO,EAAE;IAkBjC;;;;;;;OAOG;IAEG,IAAI,CAAC,OAAO,EAAE,cAAc;IA4BlC;;;;;;OAMG;IAEH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQpE"}
@@ -1,5 +1,6 @@
1
1
  import fetch from "cross-fetch";
2
2
  import { hexFrom } from "../../hex";
3
+ import { numFrom, numToHex } from "../../num";
3
4
  import { Client } from "../client";
4
5
  import { JsonRpcTransformers } from "./advanced";
5
6
  /**
@@ -51,6 +52,27 @@ export class ClientJsonRpc extends Client {
51
52
  * @returns The transaction with status.
52
53
  */
53
54
  this.getTransaction = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.transactionResponseTo);
55
+ /**
56
+ * find cells from node.
57
+ *
58
+ * @param key - The search key of cells.
59
+ * @param order - The order of cells.
60
+ * @param limit - The max return size of cells.
61
+ * @param after - Pagination parameter.
62
+ * @returns The found cells.
63
+ */
64
+ this.findCellsPaged = this.buildSender("get_cells", [
65
+ JsonRpcTransformers.indexerSearchKeyFrom,
66
+ (order) => order ?? "asc",
67
+ (limit) => numToHex(limit ?? 10),
68
+ ], JsonRpcTransformers.findCellsResponseTo);
69
+ /**
70
+ * get cells capacity from node.
71
+ *
72
+ * @param key - The search key of cells.
73
+ * @returns The sum of cells capacity.
74
+ */
75
+ this.getCellsCapacity = this.buildSender("get_cells_capacity", [JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => numFrom(capacity));
54
76
  }
55
77
  /**
56
78
  * Returns the URL of the JSON-RPC server.
@@ -70,7 +92,9 @@ export class ClientJsonRpc extends Client {
70
92
  */
71
93
  buildSender(rpcMethod, inTransformers, outTransformer) {
72
94
  return async (...req) => {
73
- const payload = ClientJsonRpc.buildPayload(rpcMethod, await Promise.all(req.map((v, i) => transform(v, inTransformers[i]))));
95
+ const payload = ClientJsonRpc.buildPayload(rpcMethod, await Promise.all(req
96
+ .concat(Array.from(new Array(Math.max(inTransformers.length - req.length, 0))))
97
+ .map((v, i) => transform(v, inTransformers[i]))));
74
98
  return transform(await this.send(payload), outTransformer);
75
99
  };
76
100
  }
@@ -1,6 +1,8 @@
1
1
  import { CellDep, CellDepLike, CellInput, CellInputLike, CellOutput, CellOutputLike, DepType, DepTypeLike, HashType, HashTypeLike, OutPoint, OutPointLike, Script, ScriptLike, Transaction, TransactionLike } from "../../ckb";
2
- import { ClientTransactionResponse, TransactionStatus } from "../clientTypes";
3
- import { JsonRpcCellDep, JsonRpcCellInput, JsonRpcCellOutput, JsonRpcDepType, JsonRpcHashType, JsonRpcOutPoint, JsonRpcScript, JsonRpcTransaction } from "./types";
2
+ import { Hex } from "../../hex";
3
+ import { NumLike } from "../../num";
4
+ import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, TransactionStatus } from "../clientTypes";
5
+ import { JsonRpcCellDep, JsonRpcCellInput, JsonRpcCellOutput, JsonRpcDepType, JsonRpcHashType, JsonRpcIndexerSearchKey, JsonRpcOutPoint, JsonRpcScript, JsonRpcTransaction } from "./types";
4
6
  export declare class JsonRpcTransformers {
5
7
  static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType;
6
8
  static hashTypeTo(hashType: JsonRpcHashType): HashType;
@@ -18,11 +20,23 @@ export declare class JsonRpcTransformers {
18
20
  static cellDepTo(cellDep: JsonRpcCellDep): CellDep;
19
21
  static transactionFrom(txLike: TransactionLike): JsonRpcTransaction;
20
22
  static transactionTo(tx: JsonRpcTransaction): Transaction;
21
- static transactionResponseTo({ tx_status: { status }, transaction, }: {
23
+ static transactionResponseTo({ tx_status: { status, block_number }, transaction, }: {
22
24
  tx_status: {
23
25
  status: TransactionStatus;
26
+ block_number: Hex;
24
27
  };
25
28
  transaction: JsonRpcTransaction;
26
29
  }): ClientTransactionResponse;
30
+ static rangeFrom([a, b]: [NumLike, NumLike]): [Hex, Hex];
31
+ static indexerSearchKeyFrom(keyLike: ClientIndexerSearchKeyLike): JsonRpcIndexerSearchKey;
32
+ static findCellsResponseTo({ last_cursor, objects, }: {
33
+ last_cursor: string;
34
+ objects: {
35
+ block_number: Hex;
36
+ out_point: JsonRpcOutPoint;
37
+ output: JsonRpcCellOutput;
38
+ output_data: Hex;
39
+ }[];
40
+ }): ClientFindCellsResponse;
27
41
  }
28
42
  //# sourceMappingURL=transformers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EAGhB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAA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AC;YAC3B,MAAM,EAAE,iBAAiB,CAAC;YAC1B,WAAW,EAAE,GAAG,CAAC;SAClB,EAAE,CAAC;KACL,GAAG,uBAAuB;CAa5B"}
@@ -1,6 +1,7 @@
1
- import { CellDep, CellInput, CellOutput, OutPoint, Script, Transaction, depTypeFrom, hashTypeFrom, } from "../../ckb";
2
- import { numToHex } from "../../num";
1
+ import { Cell, CellDep, CellInput, CellOutput, OutPoint, Script, Transaction, depTypeFrom, hashTypeFrom, } from "../../ckb";
2
+ import { numFrom, numToHex } from "../../num";
3
3
  import { apply } from "../../utils";
4
+ import { ClientIndexerSearchKey, } from "../clientTypes";
4
5
  export class JsonRpcTransformers {
5
6
  static hashTypeFrom(hashType) {
6
7
  return hashTypeFrom(hashType);
@@ -113,10 +114,43 @@ export class JsonRpcTransformers {
113
114
  witnesses: tx.witnesses,
114
115
  });
115
116
  }
116
- static transactionResponseTo({ tx_status: { status }, transaction, }) {
117
+ static transactionResponseTo({ tx_status: { status, block_number }, transaction, }) {
117
118
  return {
118
119
  transaction: JsonRpcTransformers.transactionTo(transaction),
119
120
  status,
121
+ blockNumber: numFrom(block_number),
122
+ };
123
+ }
124
+ static rangeFrom([a, b]) {
125
+ return [numToHex(a), numToHex(b)];
126
+ }
127
+ static indexerSearchKeyFrom(keyLike) {
128
+ const key = ClientIndexerSearchKey.from(keyLike);
129
+ return {
130
+ script: JsonRpcTransformers.scriptFrom(key.script),
131
+ script_type: key.scriptType,
132
+ script_search_mode: key.scriptSearchMode,
133
+ filter: apply((filter) => ({
134
+ script: apply(JsonRpcTransformers.scriptFrom, filter.script),
135
+ script_len_range: apply(JsonRpcTransformers.rangeFrom, filter.scriptLenRange),
136
+ output_data: filter.outputData,
137
+ output_data_filter_mode: filter.outputDataSearchMode,
138
+ output_data_len_range: apply(JsonRpcTransformers.rangeFrom, filter.outputDataLenRange),
139
+ output_capacity_range: apply(JsonRpcTransformers.rangeFrom, filter.outputCapacityRange),
140
+ block_range: apply(JsonRpcTransformers.rangeFrom, filter.blockRange),
141
+ }), key.filter),
142
+ with_data: key.withData,
143
+ };
144
+ }
145
+ static findCellsResponseTo({ last_cursor, objects, }) {
146
+ return {
147
+ lastCursor: last_cursor,
148
+ cells: objects.map((cell) => Cell.from({
149
+ blockNumber: cell.block_number,
150
+ outPoint: JsonRpcTransformers.outPointTo(cell.out_point),
151
+ cellOutput: JsonRpcTransformers.cellOutputTo(cell.output),
152
+ outputData: cell.output_data,
153
+ })),
120
154
  };
121
155
  }
122
156
  }
@@ -38,4 +38,19 @@ export type JsonRpcTransaction = {
38
38
  outputs_data: Hex[];
39
39
  witnesses: Hex[];
40
40
  };
41
+ export type JsonRpcIndexerSearchKey = {
42
+ script: JsonRpcScript;
43
+ script_type: "lock" | "type";
44
+ script_search_mode?: "prefix" | "exact" | "partial";
45
+ filter?: {
46
+ script?: JsonRpcScript;
47
+ script_len_range?: [Hex, Hex];
48
+ output_data?: Hex;
49
+ output_data_filter_mode?: "prefix" | "exact" | "partial";
50
+ output_data_len_range?: [Hex, Hex];
51
+ output_capacity_range?: [Hex, Hex];
52
+ block_range?: [Hex, Hex];
53
+ };
54
+ with_data?: boolean;
55
+ };
41
56
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,MAAM,CA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AE,aAAa,CAAC;QACvB,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9B,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,uBAAuB,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;QACzD,qBAAqB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnC,qBAAqB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KAC1B,CAAC;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,MAAM,CAS5E;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,UAAU,CAY5E;AAED;;GAEG;AAEH,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB;;;GAGG;AAEH,eAAO,MAAM,GAAG,QAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,MAAM,CAa5E;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,UAAU,CAc5E;AAED;;GAEG;AAEH,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB;;;GAGG;AAEH,eAAO,MAAM,GAAG,QAAsB,CAAC"}
@@ -17,6 +17,9 @@
17
17
  */
18
18
  export function fixedPointToString(val, decimals = 8) {
19
19
  const str = fixedPointFrom(val).toString();
20
+ if (decimals === 0) {
21
+ return str;
22
+ }
20
23
  const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
21
24
  const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
22
25
  if (r === "") {
@@ -42,7 +45,7 @@ export function fixedPointFrom(val, decimals = 8) {
42
45
  if (typeof val === "bigint") {
43
46
  return val;
44
47
  }
45
- const [l, r] = val.toString().split(".");
48
+ const [l, r] = (typeof val === "number" ? val.toFixed(decimals) : val.toString()).split(".");
46
49
  const lVal = BigInt(l.padEnd(l.length + decimals, "0"));
47
50
  if (r === undefined) {
48
51
  return lVal;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import { fixedPointFrom, fixedPointToString } from ".";
2
+ describe("fixedPointToString", () => {
3
+ const cases = [
4
+ [0n, "0"],
5
+ [1n, "0.00000001"],
6
+ [100000000n, "1"],
7
+ [1000000000n, "10"],
8
+ [1010100000n, "10.101"],
9
+ [11n, "1.1", 1],
10
+ [0n, "0", 1],
11
+ [1n, "1", 0],
12
+ [0n, "0", 0],
13
+ ];
14
+ cases.forEach(([i, o, decimals]) => test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
15
+ expect(fixedPointToString(i, decimals)).toBe(o);
16
+ }));
17
+ });
18
+ describe("fixedPointFrom string", () => {
19
+ const cases = [
20
+ ["0", 0n],
21
+ ["0.00000001", 1n],
22
+ ["1", 100000000n],
23
+ ["10", 1000000000n],
24
+ ["10.101", 1010100000n],
25
+ ["1.1", 11n, 1],
26
+ ["0", 0n, 1],
27
+ ["1", 1n, 0],
28
+ ["0", 0n, 0],
29
+ ];
30
+ cases.forEach(([i, o, decimals]) => test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
31
+ expect(fixedPointFrom(i, decimals)).toBe(o);
32
+ }));
33
+ });
34
+ describe("fixedPointFrom number", () => {
35
+ const cases = [
36
+ [0.00000001, 1n],
37
+ [10.101, 1010100000n],
38
+ [1.1, 11n, 1],
39
+ ];
40
+ cases.forEach(([i, o, decimals]) => test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
41
+ expect(fixedPointFrom(i, decimals)).toBe(o);
42
+ }));
43
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
1
+ {"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IASvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
@@ -6,7 +6,6 @@ import { Transaction, WitnessArgs } from "../../ckb";
6
6
  import { KnownScript } from "../../client";
7
7
  import { hexFrom } from "../../hex";
8
8
  import { numToBytes } from "../../num";
9
- import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
10
9
  import { Signer } from "../signer";
11
10
  /**
12
11
  * An abstract class extending the Signer class for Bitcoin-like signing operations.
@@ -42,7 +41,7 @@ export class SignerBtc extends Signer {
42
41
  */
43
42
  async prepareTransaction(txLike) {
44
43
  const { script } = await this.getRecommendedAddressObj();
45
- return prepareSighashAllWitness(txLike, script, 85, this.client);
44
+ return Transaction.from(txLike).prepareSighashAllWitness(script, 85, this.client);
46
45
  }
47
46
  /**
48
47
  * Signs a transaction without modifying it.
@@ -53,7 +52,7 @@ export class SignerBtc extends Signer {
53
52
  async signOnlyTransaction(txLike) {
54
53
  const tx = Transaction.from(txLike);
55
54
  const { script } = await this.getRecommendedAddressObj();
56
- const info = await getSignHashInfo(tx, script, this.client);
55
+ const info = await tx.getSignHashInfo(script, this.client);
57
56
  if (!info) {
58
57
  return tx;
59
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAK9E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAQpC,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5D,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrE;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAYvE;;;;;OAKG;IAC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C;CA6BxB"}
@@ -4,7 +4,6 @@ import { Transaction, WitnessArgs } from "../../ckb";
4
4
  import { KnownScript } from "../../client";
5
5
  import { hexFrom } from "../../hex";
6
6
  import { numToBytes } from "../../num";
7
- import { getSignHashInfo, prepareSighashAllWitness } from "../helpers";
8
7
  import { Signer } from "../signer";
9
8
  /**
10
9
  * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
@@ -45,7 +44,7 @@ export class SignerEvm extends Signer {
45
44
  */
46
45
  async prepareTransaction(txLike) {
47
46
  const addresses = await this.getAddressObjs();
48
- return addresses.reduce((txPromise, { script }) => txPromise.then((tx) => prepareSighashAllWitness(tx, script, 85, this.client)), Promise.resolve(Transaction.from(txLike)));
47
+ return addresses.reduce((txPromise, { script }) => txPromise.then((tx) => tx.prepareSighashAllWitness(script, 85, this.client)), Promise.resolve(Transaction.from(txLike)));
49
48
  }
50
49
  /**
51
50
  * Signs a transaction without modifying it.
@@ -63,7 +62,7 @@ export class SignerEvm extends Signer {
63
62
  return tx;
64
63
  }
65
64
  async _signOmniLockScriptForTransaction(tx, script, messageTransformer) {
66
- const info = await getSignHashInfo(tx, script, this.client);
65
+ const info = await tx.getSignHashInfo(script, this.client);
67
66
  if (!info) {
68
67
  return tx;
69
68
  }
@@ -1,6 +1,5 @@
1
1
  export * from "./btc";
2
2
  export * from "./ckb";
3
3
  export * from "./evm";
4
- export * from "./helpers";
5
4
  export * from "./signer";
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signer/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC"}
@@ -1,5 +1,4 @@
1
1
  export * from "./btc";
2
2
  export * from "./ckb";
3
3
  export * from "./evm";
4
- export * from "./helpers";
5
4
  export * from "./signer";
@@ -3,6 +3,7 @@ import { BytesLike } from "../bytes";
3
3
  import { Transaction, TransactionLike } from "../ckb";
4
4
  import { Client } from "../client";
5
5
  import { Hex } from "../hex";
6
+ import { Num } from "../num";
6
7
  /**
7
8
  * An abstract class representing a generic signer.
8
9
  * This class provides methods to connect, get addresses, and sign transactions.
@@ -23,6 +24,12 @@ export declare abstract class Signer {
23
24
  * @returns A promise that resolves when the connection is complete.
24
25
  */
25
26
  abstract connect(): Promise<void>;
27
+ /**
28
+ * Disconnects to the signer.
29
+ *
30
+ * @returns A promise that resolves when disconnected.
31
+ */
32
+ disconnect(): Promise<void>;
26
33
  /**
27
34
  * Check if the signer is connected.
28
35
  *
@@ -61,6 +68,12 @@ export declare abstract class Signer {
61
68
  * @returns A promise that resolves to an array of addresses as strings.
62
69
  */
63
70
  getAddresses(): Promise<string[]>;
71
+ /**
72
+ * Gets balance of all addresses
73
+ *
74
+ * @returns A promise that resolves to the balance
75
+ */
76
+ getBalance(): Promise<Num>;
64
77
  /**
65
78
  * Signs a message. This method is not implemented and should be overridden by subclasses.
66
79
  *
@@ -105,15 +118,17 @@ export declare abstract class Signer {
105
118
  */
106
119
  export declare enum SignerType {
107
120
  EVM = "EVM",
108
- BTC = "BTC"
121
+ BTC = "BTC",
122
+ CKB = "CKB"
109
123
  }
110
124
  /**
111
125
  * A class representing information about a signer, including its type and the signer instance.
112
126
  */
113
127
  export declare class SignerInfo {
128
+ name: string;
114
129
  type: SignerType;
115
130
  signer: Signer;
116
- constructor(type: SignerType, signer: Signer);
131
+ constructor(name: string, type: SignerType, signer: Signer);
117
132
  }
118
133
  /**
119
134
  * Represents a wallet with a name, icon, and an array of signer information.
@@ -1 +1 @@
1
- {"version":3,"file":"signer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AAU;IAChB,MAAM,EAAE,MAAM;gBAFd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -9,6 +9,12 @@ export class Signer {
9
9
  get client() {
10
10
  return this.client_;
11
11
  }
12
+ /**
13
+ * Disconnects to the signer.
14
+ *
15
+ * @returns A promise that resolves when disconnected.
16
+ */
17
+ async disconnect() { }
12
18
  /**
13
19
  * Gets the recommended Address object for the signer.
14
20
  *
@@ -35,6 +41,14 @@ export class Signer {
35
41
  async getAddresses() {
36
42
  return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
37
43
  }
44
+ /**
45
+ * Gets balance of all addresses
46
+ *
47
+ * @returns A promise that resolves to the balance
48
+ */
49
+ async getBalance() {
50
+ return this.client.getBalance((await this.getAddressObjs()).map(({ script }) => script));
51
+ }
38
52
  /**
39
53
  * Signs a message. This method is not implemented and should be overridden by subclasses.
40
54
  *
@@ -92,12 +106,14 @@ export var SignerType;
92
106
  (function (SignerType) {
93
107
  SignerType["EVM"] = "EVM";
94
108
  SignerType["BTC"] = "BTC";
109
+ SignerType["CKB"] = "CKB";
95
110
  })(SignerType || (SignerType = {}));
96
111
  /**
97
112
  * A class representing information about a signer, including its type and the signer instance.
98
113
  */
99
114
  export class SignerInfo {
100
- constructor(type, signer) {
115
+ constructor(name, type, signer) {
116
+ this.name = name;
101
117
  this.type = type;
102
118
  this.signer = signer;
103
119
  }
@@ -184,19 +184,25 @@ export declare class CellOutput {
184
184
  static fromBytes(bytes: BytesLike | mol.CellOutput): CellOutput;
185
185
  }
186
186
  export type CellLike = {
187
+ outPoint: OutPointLike;
187
188
  cellOutput: CellOutputLike;
188
189
  outputData: HexLike;
190
+ blockNumber: NumLike;
189
191
  };
190
192
  export declare class Cell {
193
+ outPoint: OutPoint;
191
194
  cellOutput: CellOutput;
192
195
  outputData: Hex;
196
+ blockNumber: Num;
193
197
  /**
194
198
  * Creates an instance of Cell.
195
199
  *
200
+ * @param outPoint - The output point of the cell.
196
201
  * @param cellOutput - The cell output of the cell.
197
202
  * @param outputData - The output data of the cell.
203
+ * @param blockNumber - The block number of the cell.
198
204
  */
199
- constructor(cellOutput: CellOutput, outputData: Hex);
205
+ constructor(outPoint: OutPoint, cellOutput: CellOutput, outputData: Hex, blockNumber: Num);
200
206
  /**
201
207
  * Creates a Cell instance from a CellLike object.
202
208
  *
@@ -210,12 +216,14 @@ export type CellInputLike = {
210
216
  since: NumLike;
211
217
  cellOutput?: CellOutputLike;
212
218
  outputData?: HexLike;
219
+ blockNumber?: NumLike;
213
220
  };
214
221
  export declare class CellInput {
215
222
  previousOutput: OutPoint;
216
223
  since: Num;
217
224
  cellOutput?: CellOutput | undefined;
218
225
  outputData?: `0x${string}` | undefined;
226
+ blockNumber?: bigint | undefined;
219
227
  /**
220
228
  * Creates an instance of CellInput.
221
229
  *
@@ -223,8 +231,9 @@ export declare class CellInput {
223
231
  * @param since - The since value of the cell input.
224
232
  * @param cellOutput - The optional cell output associated with the cell input.
225
233
  * @param outputData - The optional output data associated with the cell input.
234
+ * @param blockNumber - The optional block number associated with the cell input.
226
235
  */
227
- constructor(previousOutput: OutPoint, since: Num, cellOutput?: CellOutput | undefined, outputData?: `0x${string}` | undefined);
236
+ constructor(previousOutput: OutPoint, since: Num, cellOutput?: CellOutput | undefined, outputData?: `0x${string}` | undefined, blockNumber?: bigint | undefined);
228
237
  /**
229
238
  * Creates a CellInput instance from a CellInputLike object.
230
239
  *
@@ -495,6 +504,7 @@ export declare class Transaction {
495
504
  * ```
496
505
  */
497
506
  static fromLumosSkeleton(skeleton: TransactionSkeletonType): Transaction;
507
+ stringify(): string;
498
508
  /**
499
509
  * Converts the raw transaction data to bytes.
500
510
  *
@@ -529,5 +539,78 @@ export declare class Transaction {
529
539
  * ```
530
540
  */
531
541
  static hashWitnessToHasher(witness: HexLike, hasher: Hasher): void;
542
+ /**
543
+ * Computes the signing hash information for a given script.
544
+ *
545
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
546
+ * @param client - The client for complete extra infos in the transaction.
547
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
548
+ * or undefined if no matching input is found.
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
553
+ * if (signHashInfo) {
554
+ * console.log(signHashInfo.message); // Outputs the signing message
555
+ * console.log(signHashInfo.position); // Outputs the witness position
556
+ * }
557
+ * ```
558
+ */
559
+ getSignHashInfo(scriptLike: ScriptLike, client: Client): Promise<{
560
+ message: Hex;
561
+ position: number;
562
+ } | undefined>;
563
+ /**
564
+ * Find the first occurrence of a input with the specified lock
565
+ *
566
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
567
+ * @param client - The client for complete extra infos in the transaction.
568
+ * @returns A promise that resolves to the prepared transaction
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * const index = await tx.findInputIndexByLock(scriptLike, client);
573
+ * ```
574
+ */
575
+ findInputIndexByLock(scriptLike: ScriptLike, client: Client): Promise<number | undefined>;
576
+ /**
577
+ * Get witness at index as WitnessArgs
578
+ *
579
+ * @param index - The index of the witness.
580
+ * @returns The witness parsed as WitnessArgs.
581
+ *
582
+ * @example
583
+ * ```typescript
584
+ * const witnessArgs = await tx.getWitnessArgsAt(0);
585
+ * ```
586
+ */
587
+ getWitnessArgsAt(index: number): WitnessArgs | undefined;
588
+ /**
589
+ * Set witness at index by WitnessArgs
590
+ *
591
+ * @param index - The index of the witness.
592
+ * @param witness - The WitnessArgs to set.
593
+ * @returns The transaction itself.
594
+ *
595
+ * @example
596
+ * ```typescript
597
+ * await tx.setWitnessArgsAt(0, witnessArgs);
598
+ * ```
599
+ */
600
+ setWitnessArgsAt(index: number, witness: WitnessArgs): Transaction;
601
+ /**
602
+ * Prepare dummy witness for sighash all method
603
+ *
604
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
605
+ * @param lockLen - The length of dummy lock bytes.
606
+ * @param client - The client for complete extra infos in the transaction.
607
+ * @returns A promise that resolves to the prepared transaction
608
+ *
609
+ * @example
610
+ * ```typescript
611
+ * await tx.prepareSighashAllWitness(scriptLike, 85, client);
612
+ * ```
613
+ */
614
+ prepareSighashAllWitness(scriptLike: ScriptLike, lockLen: number, client: Client): Promise<Transaction>;
532
615
  }
533
616
  //# sourceMappingURL=transaction.d.ts.map